]> andersk Git - splint.git/blobdiff - src/cgrammar.y
EXtensive code clean up. Almost passes LCLint.
[splint.git] / src / cgrammar.y
index 206a761123c284e39977da215408b4fc25686494..0857a900f84158bbc459d555f53446dc803dcbc5 100644 (file)
@@ -69,7 +69,7 @@ void yyerror (char *s);
 # undef realloc
 # endif
 
-void checkandsetBufState(idDecl id, exprNode is);
+
 %}
 
 %union
@@ -94,6 +94,13 @@ void checkandsetBufState(idDecl id, exprNode is);
  /*@only@*/ exprNodeList alist;
  /*@only@*/ sRefSet srset; 
  /*@only@*/ cstringList cstringlist;
+  /*drl
+    added 1/19/2001
+  */
+  constraint con;
+  constraintList conL;
+  constraintExpr conE;
+  /* drl */
 }
 
 /* standard C tokens */
@@ -161,13 +168,18 @@ void checkandsetBufState(idDecl id, exprNode is);
 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID 
 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
-%token <tok> QNULLTERMINATED
 
+%token <tok> QNULLTERMINATED
 %token <tok> QSETBUFFERSIZE
+%token <tok> QBUFFERCONSTRAINT
+%token <tok> QENSURESCONSTRAINT
 %token <tok> QSETSTRINGLENGTH
-
+%token <tok> QMAXSET
+%token <tok> QMAXREAD
 %token <tok> QTESTINRANGE
 
+
+
 /* identifiers, literals */
 %token <entry> IDENTIFIER
 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID 
@@ -202,6 +214,22 @@ void checkandsetBufState(idDecl id, exprNode is);
 %type <flist> structDeclList structDecl
 %type <srset> locModifies locPlainModifies modList specClauseList
 %type <sr>    mExpr modListExpr specClauseListExpr
+
+/*drl*/
+%type <con>    BufConstraint
+%type <tok> relationalOp
+%type <tok> BufBinaryOp
+%type <tok> bufferModifier
+
+%type <conE> BufConstraintExpr
+
+%type <conE> BufConstraintTerm
+%type <sr> BufConstraintSrefExpr
+
+%type <conL>    BufConstraintList
+
+%type <tok>  BufUnaryOp
+
 %type <enumnamelist> enumeratorList 
 %type <cstringlist> fieldDesignator
 
@@ -231,7 +259,7 @@ void checkandsetBufState(idDecl id, exprNode is);
 %type <tquallist> optGlobQuals
 %type <qtyp> completeType completeTypeSpecifier optCompleteType
 %type <qtyp> completeTypeSpecifierAux altType typeExpression 
-%type <expr> lclintassertion
+/*%type <expr> lclintassertion*/
 
 %start file
 
@@ -293,7 +321,7 @@ namedDeclBase
  | namedDeclBase PushType TLPAREN TRPAREN 
    { setCurrentParams (uentryList_missingParams); 
         }
-   optGlobMods 
+ optGlobMods  optGlobBufConstraints
    { /* need to support globals and modifies here! */
      ctype ct = ctype_makeFunction (idDecl_getCtype ($1), 
                                    uentryList_makeMissingParams ());
@@ -302,12 +330,16 @@ namedDeclBase
      context_popLoc (); 
    }
  | namedDeclBase PushType TLPAREN genericParamList TRPAREN 
-   { setCurrentParams ($4); 
+   { setCurrentParams ($4);
+    
         } 
-   optGlobMods
-   { clearCurrentParams ();
+ optGlobMods  optGlobBufConstraints
+   { setImplictfcnConstraints ();
+     clearCurrentParams ();
      $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
-     context_popLoc (); 
+     context_popLoc ();
+
+     //     printf("Done nameDeclBase\n");
    }
 
 plainNamedDeclBase
@@ -371,6 +403,135 @@ optGlobMods
  : { setProcessingGlobMods (); } optGlobModsRest
    { clearProcessingGlobMods (); }
 
+
+/*drl*/
+
+optGlobBufConstraints
+ : { setProcessingGlobMods (); } optGlobBufConstraintsRest
+   { clearProcessingGlobMods (); }
+
+
+optGlobBufConstraintsRest
+ : optGlobBufConstraintsAux optGlobEnsuresConstraintsAux
+
+
+optGlobEnsuresConstraintsAux
+: {
+  DPRINTF ( ("doing optGlobEnsuresConstraintsAux\n") );
+context_setProtectVars (); enterParamsTemp (); 
+     sRef_setGlobalScopeSafe (); 
+
+}  QENSURESCONSTRAINT BufConstraintList  QENDMACRO
+{
+  setEnsuresConstraints ($3);
+  exitParamsTemp ();
+     sRef_clearGlobalScopeSafe (); 
+     context_releaseVars ();
+  DPRINTF (("done optGlobBufConstraintsAux\n"));}
+ | /*empty*/
+
+
+optGlobBufConstraintsAux
+: {
+  DPRINTF ( ("doing optGlobBufConstraintsAux\n") );
+context_setProtectVars (); enterParamsTemp (); 
+     sRef_setGlobalScopeSafe (); 
+
+}  QBUFFERCONSTRAINT BufConstraintList  QENDMACRO
+{
+  setFunctionConstraints ($3);
+  exitParamsTemp ();
+     sRef_clearGlobalScopeSafe (); 
+     context_releaseVars ();
+  DPRINTF (("done optGlobBufConstraintsAux\n"));}
+ | /*empty*/
+
+BufConstraintList
+: BufConstraint BufConstraintList{ $$ = constraintList_add ($2, $1); }
+| BufConstraint {constraintList c; c = constraintList_makeNew(); c = constraintList_add (c, $1); $$ = c}
+
+BufConstraint
+:  BufConstraintExpr relationalOp BufConstraintExpr TSEMI  {
+ $$ = makeConstraintParse3 ($1, $2, $3);
+ DPRINTF(("Done BufConstraint1\n")); }
+
+bufferModifier
+ : QMAXSET
+ |QMAXREAD
+
+relationalOp
+ : GE_OP
+ | LE_OP
+ | EQ_OP
+
+BufConstraintExpr
+ : BufConstraintTerm 
+ | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3);  DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
+ | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
+   DPRINTF( ("Got BufConstraintExpr BINary Op ") );
+   $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
+
+BufConstraintTerm
+: BufConstraintSrefExpr { $$ =  constraintExpr_makeTermsRef($1);} 
+ | CCONSTANT {  char *t; int c;
+  t =  cstring_toCharsSafe (exprNode_unparse($1));
+  c = atoi( t );
+  $$ = constraintExpr_makeIntLiteral (c);
+}
+
+
+BufConstraintSrefExpr
+: id                              {
+   $$ =
+     checkbufferConstraintClausesId ($1);}
+ | NEW_IDENTIFIER                  { $$ = fixSpecClausesId ($1); }
+
+ | BufConstraintSrefExpr TLSQBR TRSQBR       { $$ = sRef_makeAnyArrayFetch ($1); }
+ |  BufConstraintSrefExpr  TLSQBR CCONSTANT TRSQBR {
+     char *t; int c;
+  t =  cstring_toCharsSafe (exprNode_unparse($3));
+  c = atoi( t );
+   $$ = sRef_makeArrayFetchKnown($1, c); }
+ | TMULT  BufConstraintSrefExpr               { $$ = sRef_constructPointer ($2); }
+ | TLPAREN BufConstraintSrefExpr TRPAREN     { $$ = $2; }  
+ |  BufConstraintSrefExpr TDOT newId          { cstring_markOwned ($3);
+                                           $$ = sRef_buildField ($1, $3); }
+ |  BufConstraintSrefExpr ARROW_OP newId      { cstring_markOwned ($3);
+                                            $$ = sRef_makeArrow ($1, $3); }
+
+/*
+| BufConstraintTerm TLSQBR TRSQBR       { $$ = sRef_makeAnyArrayFetch ($1); }
+ | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
+ | TLPAREN specClauseListExpr TRPAREN     { $$ = $2; }  
+ | specClauseListExpr TDOT newId          { cstring_markOwned ($3);
+                                           $$ = sRef_buildField ($1, $3); }
+*/
+
+/*BufConstraintExpr
+: BufConstraintTerm 
+*/
+
+BufUnaryOp
+: bufferModifier 
+;
+
+BufBinaryOp
+ : TPLUS
+| TMINUS
+;
+
+
+koptPlainGlobMods
+ : { setProcessingGlobMods (); } optPlainGlobModsRest
+   { clearProcessingGlobMods (); }
+
+
+/*: id  {  $$ = unentry_getSref($1);  checkModifiesId ($1); }
+| NEW_INDENTIFIER { $$ = fixModifiesId ($1)} */
+
+/*end*/
+
+
 optPlainGlobMods
  : { setProcessingGlobMods (); } optPlainGlobModsRest
    { clearProcessingGlobMods (); }
@@ -552,7 +713,9 @@ fcnDef
  : fcnDefHdr fcnBody 
    { 
      context_setFunctionDefined (exprNode_loc ($2)); 
-     exprNode_checkFunction (context_getHeader (), $2); 
+     /* exprNode_checkFunction (context_getHeader (), $2); */
+     /* DRL 8 8 2000 */
+     
      context_exitFunction ();
    }
 
@@ -1161,10 +1324,9 @@ stmt
  | iterationStmt 
  | iterStmt
  | jumpStmt 
-/*  | tst1 */
- | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }
-
+/* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
 
+/*
 lclintassertion
  : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n");  uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
   }
@@ -1346,11 +1508,11 @@ stmtList
  
 expressionStmt 
  : TSEMI { $$ = exprNode_createTok ($1); }
- | expr TSEMI { $$ = exprNode_statement ($1); }
+ | expr TSEMI { $$ = exprNode_statement ($1, $2); }
 
 expressionStmtErr
  : TSEMI { $$ = exprNode_createTok ($1); }
- | expr TSEMI { $$ = exprNode_statement ($1); }
+ | expr TSEMI { $$ = exprNode_statement ($1, $2); }
  | expr { $$ = exprNode_checkExpr ($1); } 
 
 ifPred
@@ -1530,14 +1692,14 @@ iterationStmt
  : whilePred stmt 
    { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
  | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI 
-   { $$ = exprNode_statement (exprNode_doWhile ($2, $5)); }
+   { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
  | forPred stmt 
    { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
 
 iterationStmtErr 
  : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
  | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
-   { $$ = exprNode_statement (exprNode_doWhile ($2, $5)); }
+   { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
  | doHeader stmtErr WHILE TLPAREN expr TRPAREN 
    { $$ = exprNode_doWhile ($2, $5); }
  | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
This page took 0.037094 seconds and 4 git commands to generate.