From e4f0ff8172dfda7d65679bb8627af7c31e52d6f3 Mon Sep 17 00:00:00 2001
From: Kristof Szabados <Kristof.Szabados@ericsson.com>
Date: Sun, 27 Nov 2016 13:27:34 +0100
Subject: [PATCH] stricter type usage

Signed-off-by: Kristof Szabados <Kristof.Szabados@ericsson.com>
---
 compiler2/Type.cc          |  8 ++++----
 compiler2/subtypestuff.hh  | 12 ++++++------
 compiler2/ttcn3/TextAST.cc | 15 ++++++++-------
 compiler2/ttcn3/TextAST.hh |  4 ++--
 compiler2/ttcn3/rawAST.y   |  4 ++--
 5 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/compiler2/Type.cc b/compiler2/Type.cc
index 6a1abd332..cd3cbfa94 100644
--- a/compiler2/Type.cc
+++ b/compiler2/Type.cc
@@ -2589,10 +2589,10 @@ namespace Common {
         textAST_enum_def **params=(textAST_enum_def**)
                 Malloc(nof_comps*sizeof(textAST_enum_def*));
         memset(params,0,nof_comps*sizeof(textAST_enum_def*));
-        for (int a = 0; a < textattrib->nof_field_params; a++) {
+        for (size_t a = 0; a < textattrib->nof_field_params; a++) {
           const Identifier& id = *textattrib->field_params[a]->name;
           if (t->u.enums.eis->has_ei_withName(id)) {
-            int index = t->get_eis_index_byName(id);
+            size_t index = t->get_eis_index_byName(id);
             if (params[index]) FATAL_ERROR("Type::chk_text(): duplicate " \
               "attribute for enum `%s'", id.get_dispname().c_str());
             params[index] = textattrib->field_params[a];
@@ -6107,9 +6107,9 @@ namespace Common {
     /*
     size_t pos=s.find_if(0, s.size(), isupper);
     if(pos==s.size()) FATAL_ERROR("Type::get_otaltname() (`%s')", s.c_str());
-    s[pos]=tolower(s[pos]);
+    s[pos]=(char)tolower(s[pos]);
     */
-    s[0]=tolower(s[0]);
+    s[0]=(char)tolower(s[0]);
     Identifier tmp_id(Identifier::ID_NAME, s, true);
     /* This is because the origin of the returned ID must be ASN. */
     return Identifier(Identifier::ID_ASN, tmp_id.get_asnname());
diff --git a/compiler2/subtypestuff.hh b/compiler2/subtypestuff.hh
index 2ec183d4c..24422353c 100644
--- a/compiler2/subtypestuff.hh
+++ b/compiler2/subtypestuff.hh
@@ -369,8 +369,8 @@ RangeListConstraint<LIMITTYPE> RangeListConstraint<LIMITTYPE>::operator~() const
       ret_val.intervals.add(false);
     }
   }
-  int last = values.size()-1;
-  for (int i=0; i<last; i++)
+  size_t last = values.size()-1;
+  for (size_t i=0; i<last; i++)
   {
     if (!intervals[i]) {
       if (values[i].next()==values[i+1].previous()) {
@@ -436,7 +436,7 @@ RangeListConstraint<LIMITTYPE> RangeListConstraint<LIMITTYPE>::set_operation(con
   // sweep (iterate) through both vectors
   bool in_a = false; // we are already in an interval of A
   bool in_b = false;
-  for (int i=0; i<(int)sweep_points.size(); i++)
+  for (size_t i=0; i<sweep_points.size(); i++)
   {
     // set bools for A interval
     bool a_interval = in_a;
@@ -475,7 +475,7 @@ RangeListConstraint<LIMITTYPE> RangeListConstraint<LIMITTYPE>::set_operation(con
   // canonicalization of ret_val
   if (is_union) {
     // connect adjacent limit points with interval: [i,i+1] becomes interval
-    for (int i=1; i<(int)sweep_points.size(); i++)
+    for (size_t i=1; i<sweep_points.size(); i++)
     {
       LIMITTYPE first, second;
       if (sweep_points[i-1].a_idx!=-1) {
@@ -498,9 +498,9 @@ RangeListConstraint<LIMITTYPE> RangeListConstraint<LIMITTYPE>::set_operation(con
   }
   // two adjacent intervals shall be united into one
   RangeListConstraint<LIMITTYPE> ret_val;
-  for (int i=0; i<(int)sweep_points.size(); i++)
+  for (size_t i=0; i<sweep_points.size(); i++)
   {
-    if (is_union) {
+    if (is_union) {//FIXME unnecessary to check in every loop
         if ( (i>0) && sweep_points[i-1].union_interval && sweep_points[i].union_interval) {
           // drop this point, it's in a double interval
         } else {
diff --git a/compiler2/ttcn3/TextAST.cc b/compiler2/ttcn3/TextAST.cc
index 529ea4053..786f0eb1d 100644
--- a/compiler2/ttcn3/TextAST.cc
+++ b/compiler2/ttcn3/TextAST.cc
@@ -55,7 +55,7 @@ TextAST::TextAST(const TextAST *other_val)
     nof_field_params=other_val->nof_field_params;
     if(nof_field_params) field_params=
       (textAST_enum_def**)Malloc(nof_field_params*sizeof(textAST_enum_def*));
-    for(int a=0;a<nof_field_params;a++){
+    for(size_t a=0;a<nof_field_params;a++){
       if(other_val->field_params[a]){
         field_params[a]=(textAST_enum_def*)Malloc(sizeof(textAST_enum_def));
         field_params[a]->name=
@@ -106,7 +106,8 @@ TextAST::~TextAST()
     Free(separator_val);
   }
   if(field_params){
-    for(int a=0;a<nof_field_params;a++){
+    for(size_t a=0;a<nof_field_params;a++){
+      //TODO: lets extract field_params[a] for speed
       if(field_params[a]){
         delete field_params[a]->name;
         Free(field_params[a]->value.encode_token);
@@ -195,9 +196,9 @@ void TextAST::print_TextAST() const
     else printf("  case_insensitive\n\r");
   }
   else printf("NULL\n\r");
-  printf("Number of fields:%i\n\r",nof_field_params);
-  for(int a=0;a<nof_field_params;a++){
-    printf("Field %i:\n\r",a);
+  printf("Number of fields:%lu\n\r",nof_field_params);
+  for(size_t a=0;a<nof_field_params;a++){
+    printf("Field %lu:\n\r",a);
     if(field_params[a]){
     printf("  Name: %s\n\r",field_params[a]->name->get_name().c_str());
     printf("  Encode token:");
@@ -223,9 +224,9 @@ void TextAST::print_TextAST() const
     printf("  Convert: %i\n\r  Just:%i\n\r",decoding_params.convert,decoding_params.just);
 }
 
-int TextAST::get_field_param_index(const Common::Identifier *name)
+size_t TextAST::get_field_param_index(const Common::Identifier *name)
 {
-  for(int a=0;a<nof_field_params;a++){
+  for(size_t a=0;a<nof_field_params;a++){
     if(*field_params[a]->name==*name) return a;
   }
   field_params=(textAST_enum_def **)Realloc(field_params,(nof_field_params+1)*sizeof(textAST_enum_def *));
diff --git a/compiler2/ttcn3/TextAST.hh b/compiler2/ttcn3/TextAST.hh
index 442b81fe2..e8afd7626 100644
--- a/compiler2/ttcn3/TextAST.hh
+++ b/compiler2/ttcn3/TextAST.hh
@@ -51,7 +51,7 @@ class TextAST {
     textAST_matching_values *separator_val;
     textAST_param_values coding_params;
     textAST_param_values decoding_params;
-    int nof_field_params;
+    size_t nof_field_params;
     textAST_enum_def **field_params;
     textAST_matching_values *true_params;
     textAST_matching_values *false_params;  
@@ -63,7 +63,7 @@ class TextAST {
     ~TextAST();
     
     void print_TextAST() const;
-    int get_field_param_index(const Common::Identifier *name);
+    size_t get_field_param_index(const Common::Identifier *name);
 };
 
 void copy_textAST_matching_values(textAST_matching_values **to,
diff --git a/compiler2/ttcn3/rawAST.y b/compiler2/ttcn3/rawAST.y
index 210fd9dcd..20e4ea3e2 100644
--- a/compiler2/ttcn3/rawAST.y
+++ b/compiler2/ttcn3/rawAST.y
@@ -1139,7 +1139,7 @@ XtokendefList:
 Xtokendef:
   XIdentifierOrReserved ':' XEncodeToken
   {
-    int idx = textstruct->get_field_param_index($1);
+    size_t idx = textstruct->get_field_param_index($1);
     if (textstruct->field_params[idx]->value.encode_token) {
       Free(textstruct->field_params[idx]->value.encode_token);
       Common::Location loc(infile, @3);
@@ -1216,7 +1216,7 @@ XDecodingtokendefList:
 Xdecodingtokendef:
   XIdentifierOrReserved ':' XDecodeToken
   {
-    int idx = textstruct->get_field_param_index($1);
+    size_t idx = textstruct->get_field_param_index($1);
     if (textstruct->field_params[idx]->value.decode_token) {
       Free(textstruct->field_params[idx]->value.decode_token);
       Common::Location loc(infile, @3);
-- 
GitLab