Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

checking.c File Reference

#include "lclintMacros.nf"
#include "llbasic.h"
#include "llgrammar.h"
#include "checking.h"
#include "lclscan.h"

Go to the source code of this file.

Functions

termNode computePossibleSorts ( termNode t)
termNode checkSort ( termNode t)
void checkLclPredicate (ltoken t, lclPredicateNode n)


Function Documentation

void checkLclPredicate ( ltoken t,
lclPredicateNode n )
 

Definition at line 384 of file checking.c.

00385 {
00386   sort theSort;
00387 
00388   if ((n == NULL) || (n->predicate == NULL))
00389     {
00390       llcontbuglit ("checkLclPredicate expects valid lclPredicate.  "
00391                     "Skipping current check");
00392       return;
00393     }
00394 
00395  /* check only if there are no previous errors */
00396 
00397   if (!n->predicate->error_reported)
00398     {
00399      /* check that the sort of n is boolean */
00400       theSort = n->predicate->sort;
00401       if (!sort_compatible (theSort, sort_capBool))
00402         {
00403           if (sort_isNoSort (theSort))
00404             {
00405              ; /* "Expects a boolean term.  Given term has unknown sort" */
00406             }
00407           else
00408             {
00409               cstring clauset = ltoken_getRawString (t);
00410 
00411               if (cstring_firstChar (clauset) == '(')
00412                 {
00413                   clauset = cstring_makeLiteral ("Equality");
00414                 }
00415               else
00416                 {
00417                   /* uppercase first letter */
00418                   clauset = cstring_copy (clauset);
00419                   cstring_setChar (clauset, 1, 
00420                                    (char) toupper (cstring_firstChar (clauset))); 
00421                 }
00422 
00423               lclerror (t, message ("%q expects a boolean term, given %q.", 
00424                                     clauset, sort_unparse (theSort)));
00425               
00426             }
00427         }
00428     }
00429 }

termNode checkSort ( termNode t )
 

Definition at line 223 of file checking.c.

00224 {
00225   sortSet sorts;
00226   sort theSort;
00227   int size;
00228   ltoken errtok;
00229 
00230   (void) computePossibleSorts (t);
00231   sorts = t->possibleSorts;
00232 
00233   llassert (sortSet_isDefined (sorts));
00234 
00235   size = sortSet_size (sorts);
00236   switch (size)
00237     {
00238     case 0:                     /* complain later */
00239       break;
00240     case 1:                     /* just right */
00241       theSort = sortSet_choose (sorts);
00242       assignSorts (t, theSort);
00243       break;
00244     default:
00245      /* we allow C literals to have multiple sorts */
00246       if (t->kind != TRM_LITERAL)
00247         {
00248           errtok = termNode_errorToken (t);
00249           t->error_reported = TRUE;
00250 
00251           lclerror (errtok, 
00252                     message ("Term %q: can have more than one possible type.  Possible types: %q",
00253                              termNode_unparse (t), sortSet_unparseClean (sorts)));
00254         }
00255     }
00256   return t;
00257 }

termNode computePossibleSorts ( termNode t )
 

Definition at line 49 of file checking.c.

Referenced by checkSort().

00050 {
00051   ltoken errtok;
00052 
00053   if (t != (termNode) 0)
00054     {
00055       switch (t->kind)
00056         {
00057         case TRM_LITERAL:
00058         case TRM_CONST:
00059         case TRM_VAR:
00060         case TRM_ZEROARY:
00061         case TRM_SIZEOF:
00062         case TRM_UNCHANGEDALL:
00063         case TRM_UNCHANGEDOTHERS:
00064         case TRM_QUANTIFIER:
00065           break;
00066         case TRM_APPLICATION:
00067           {
00068             bool fail = FALSE;
00069             sortSetList argSorts = sortSetList_new ();
00070             lslOpSet ops;
00071             sortSet standards;
00072 
00073             if (termNodeList_size (t->args) != 0)
00074               {
00075                 termNodeList_elements (t->args, arg)
00076                 {
00077                   (void) computePossibleSorts (arg);
00078 
00079                   if (sortSet_size (arg->possibleSorts) == 0)
00080                     {
00081                       fail = TRUE;
00082                     }
00083                   else
00084                     {
00085                       sortSetList_addh (argSorts, arg->possibleSorts);
00086                     } 
00087                 } end_termNodeList_elements;
00088 
00089                 if (fail)
00090                   {
00091                     lslOpSet_free (t->possibleOps);
00092                     sortSetList_free (argSorts);
00093                     t->possibleOps = lslOpSet_new ();
00094                     return t;
00095                   }
00096               }
00097             
00098             ops = symtable_opsWithLegalDomain (g_symtab, t->name, argSorts, t->given);
00099             lslOpSet_free (t->possibleOps);
00100             t->possibleOps = ops;
00101 
00102             lslOpSet_elements (t->possibleOps, op)
00103               {
00104                 sort sort;
00105                 sort = sigNode_rangeSort (op->signature);
00106                 (void) sortSet_insert (t->possibleSorts, sort);
00107               } end_lslOpSet_elements;
00108 
00109             standards = standardOperators (t->name, argSorts, t->given);
00110 
00111             sortSet_elements (standards, el)
00112               {
00113                 (void) sortSet_insert (t->possibleSorts, el);
00114               } end_sortSet_elements;
00115 
00116             sortSet_free (standards);
00117 
00118             if (!(t->error_reported) && sortSet_size (t->possibleSorts) == 0)
00119               {
00120                 unsigned int arity = termNodeList_size (t->args);
00121                 errtok = nameNode_errorToken (t->name);
00122                 
00123                 /* errorShowPoint (tsource_thisLine (lclsource), ltoken_getCol (errtok)); */
00124                 
00125                 if (isStandardOperator (t->name))
00126                   {
00127                     lclerror (errtok, 
00128                               message ("Type error: %q not declared for %q",
00129                                       nameNode_unparse (t->name), printBadArgs (argSorts)));
00130                   }
00131                 else if (t->name != NULL 
00132                          && symtable_opExistsWithArity (g_symtab, t->name, arity))
00133                   {
00134                     sigNodeSet possibleOps = symtable_possibleOps (g_symtab, t->name);
00135                     cstring opName = nameNode_unparse (t->name);
00136                     
00137                     /*
00138                     ** all these will be standardOperators soon...
00139                     */
00140 
00141                     if (cstring_equalLit (opName, "__ [__]"))
00142                       {
00143                         lclerror (errtok, 
00144                                   message ("Type error: %q not declared for %q",
00145                                           opName, printBadArgs (argSorts)));
00146                       }
00147                     else
00148                       {
00149                         lclerror (errtok, 
00150                                   message ("Type error: %q declared: %q\ngiven: %q",
00151                                           opName, 
00152                                           sigNodeSet_unparseSomeSigs (possibleOps),
00153                                           printBadArgs (argSorts)));
00154                       }
00155                   }
00156                 else
00157                   {
00158                     sigNodeSet possibleOps;
00159                     int npossibleOps;
00160 
00161                     llassert (t->name != NULL);
00162 
00163                     possibleOps = symtable_possibleOps (g_symtab, t->name);
00164                     npossibleOps = sigNodeSet_size (possibleOps);
00165 
00166                     /*
00167                      ** evs --- check is it is wrong arity...
00168                      */
00169                     
00170                     if (npossibleOps == 0)
00171                       {
00172                         lclerror 
00173                           (errtok, 
00174                            message ("Undeclared operator: %q", nameNode_unparse (t->name)));      
00175                       }
00176                     else
00177                       {
00178                         lclerror
00179                           (errtok, 
00180                            message ("Operator %q declared for %q arguments, given %d",
00181                                    nameNode_unparse (t->name),
00182                                    sigNodeSet_unparsePossibleAritys (possibleOps),
00183                                    arity));
00184                       }
00185                   }
00186                 t->error_reported = TRUE;
00187               }
00188             sortSetList_free (argSorts);
00189             break;
00190           }
00191         }
00192     }
00193       
00194   return t;
00195 }


Generated at Fri Nov 3 18:57:50 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000