]> andersk Git - splint.git/blobdiff - src/cgrammar.y
Merged this branch with the one in the splint.sf.net repository.
[splint.git] / src / cgrammar.y
index 4a08b45a6a67832750e8596b6b4c274248ae08b9..1d2ceba5f390a3a4151cd482d626867e2eea780f 100644 (file)
@@ -94,7 +94,7 @@ extern void yyerror (char *);
   /*@only@*/ modifiesClause modsclause;
   /*@only@*/ warnClause warnclause;
   /*@only@*/ stateClause stateclause;
-  /*@only@*/ pointers pointers;
+
   /*@only@*/ functionConstraint fcnconstraint; 
 
   /*@only@*/ metaStateConstraint msconstraint;
@@ -183,7 +183,7 @@ extern void yyerror (char *);
 %token <tok> QNOTREACHED
 
 /* type qualifiers: */
-%token <tok> QCONST QRESTRICT QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
+%token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
@@ -237,7 +237,7 @@ extern void yyerror (char *);
 %token <msinfo> METASTATE_NAME 
 %type <msinfo> metaStateName
 %type <cname> enumerator newId  /*@-varuse@*/ /* yacc declares yytranslate here */
-%type <pointers> pointers /*@=varuse@*/
+%type <count> pointers /*@=varuse@*/
 
 %type <tok> doHeader stateTag conditionTag startConditionClause
 %type <typequal> exitsQualifier checkQualifier stateQualifier 
@@ -251,7 +251,7 @@ extern void yyerror (char *);
 %type <ntyp> namedDecl namedDeclBase optNamedDecl
 %type <ntyp> plainNamedDecl plainNamedDeclBase
 %type <ntyp> structNamedDecl
-%type <ntyp> fcnDefHdrAux plainFcn
+%type <ntyp> fcnDefHdrAux plainFcn fcnDefHdr
 
 %type <oentry> paramDecl 
 %type <entry> id 
@@ -312,8 +312,8 @@ extern void yyerror (char *);
 
 %type <expr> designator designatorList designation
 
-%type <typequal> storageSpecifier typeQualifier typeModifier globQual innerMods
-%type <tquallist> optGlobQuals innerModsList
+%type <typequal> storageSpecifier typeQualifier typeModifier globQual
+%type <tquallist> optGlobQuals
 %type <qtyp> completeType completeTypeSpecifier optCompleteType
 %type <qtyp> completeTypeSpecifierAux altType typeExpression 
 
@@ -330,12 +330,47 @@ externalDefs
  | externalDefs externalDef { context_checkGlobalScope (); }
 
 externalDef
- : fcnDef optSemi { uentry_clearDecl (); } 
+: fcnDef optSemi  { uentry_clearDecl (); } 
  | constantDecl   { uentry_clearDecl (); } 
  | fcnDecl        { uentry_clearDecl (); }
  | iterDecl       { uentry_clearDecl (); } 
  | macroDef       { uentry_clearDecl (); } 
- | initializer    { uentry_checkDecl (); exprNode_free ($1); }
+ | initializer    {  //drl added 04/02/2002
+     if (willOutputCode  )
+       {
+        exprNode_unparse($1);
+        
+        if (exprNode_isDefined($1) && ( ($1)->kind == XPR_INIT) )
+          {
+            if ( ctype_isFunctionPointer (($1)->edata->init->id->typ->type ) )
+              {
+                outputCode(message("%s;\n", ctype_unparseFunctionPointer (($1)->edata->init->id->typ->type, qualList_unparse(($1)->edata->init->id->typ->quals), cstring_copy( ($1)->edata->init->id->id  ) ))
+                           );
+              }
+            else if ( ctype_isFunction (($1)->edata->init->id->typ->type ) )
+              {
+                outputCode(message("%s;\n", ctype_unparseFunction (($1)->edata->init->id->typ->type, cstring_copy( ($1)->edata->init->id->id  ) ))
+                           );
+              }
+            else
+              {
+                outputCode(message("%s;\n", exprNode_unparse(($1) ) ));
+              }
+          }
+        
+        else if (exprNode_isDefined($1) )
+          {
+            outputCode(message("%s;\n", exprNode_unparse(($1) ) ));
+          }
+        else
+          {
+            /*drl try outputing nothing so that there is not an unnecessary semicolon*/
+            // outputCode(message("%s;\n", exprNode_unparse(($1) ) ));
+          }
+        
+       }
+     
+uentry_checkDecl (); exprNode_free ($1); }
  | TSEMI          { uentry_clearDecl (); /* evans 2002-02-08: okay to have a null statement */ }  
  | error          { uentry_clearDecl (); } 
 
@@ -467,7 +502,9 @@ macroDef
  | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); } 
 
 fcnDefHdr
- : fcnDefHdrAux { clabstract_declareFunction ($1); }
+ : fcnDefHdrAux {  clabstract_declareFunction ($1);
+ DPRINTF (message ("fcnDefHdr is: %s", idDecl_unparseC($1) ) );
+ $$ = $1; }
 
 metaStateConstraint
  : metaStateSpecifier TASSIGN metaStateExpression 
@@ -500,7 +537,7 @@ BufConstraintList
 
 BufConstraint
 :  BufConstraintExpr relationalOp BufConstraintExpr {
- $$ = makeConstraintParse3 ($1, $2, $3);
+ $$ = constraint_makeConstraintLltok ($1, $2, $3);
  DPRINTF(("Done BufConstraint1\n")); }
 
 bufferModifier
@@ -727,7 +764,7 @@ fcnDef
      context_setFunctionDefined (exprNode_loc ($2)); 
      exprNode_checkFunction (context_getHeader (),  $2); 
      /* DRL 8 8 2000 */
-     
+     DPRINTF(message ("Header: %s\n", idDecl_unparseC($1) ) );
      context_exitFunction ();
    }
 
@@ -790,7 +827,7 @@ specClauseList
     }
 
 primaryExpr
- : id { $$ = exprNode_fromIdentifier ($1); }
+ : id { int tmpMark1; $$ = exprNode_fromIdentifier ($1); }
  | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); } 
  | cconstantExpr
  | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
@@ -806,7 +843,7 @@ postfixExpr
  | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
  | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
  | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
- | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
+ | postfixExpr NotType TDOT newId IsType {int tmpMark2;  $$ = exprNode_fieldAccess ($1, $3, $4); }
  | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
  | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
  | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
@@ -831,10 +868,8 @@ unaryExpr
  | offsetofExpr    { $$ = $1; }
 
 fieldDesignator
- : fieldDesignator TDOT newId         { $$ = cstringList_add ($1, $3); }
- | fieldDesignator TLSQBR expr TRSQBR { $$ = $1; }
-   /* evans 2002-07-02: offsetof designators can use array indexes */
- | newId                              { $$ = cstringList_single ($1); }
+ : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
+ | newId                      { $$ = cstringList_single ($1); }
 
 offsetofExpr
  : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
@@ -961,8 +996,12 @@ initializer
 
 instanceDecl
  : completeTypeSpecifier IsType TSEMI 
-   { $$ = exprNode_makeError (); } 
-     /*
+{
+  if (willOutputCode  )
+    outputCode(message( "%s;\n",  qtypetryToPrintStruct($1) ));
+  
+  $$ = exprNode_makeError (); }
+    /*
      ** This causes r/r conflicts with function definitions.
      ** Instead we need to snarf one first. (gack)
      **
@@ -980,15 +1019,29 @@ instanceDecl
      processNamedDecl ($3); 
    }
    IsType optDeclarators TSEMI IsType 
-   { 
-     unsetProcessingVars (); 
-     $$ = exprNode_makeEmptyInitialization ($3); 
+   {
+     ctype ct;
+
+     ct = idDecl_getCtype ($3);
+     idDecl_setTyp ($3, qtype_copy ($1) );
+     idDecl_replaceCtype($3, ct);
+     
+     unsetProcessingVars ();
+     /*drl 04-17-2002 added exprNode_concat */
+     $$ = exprNode_concat ($7, exprNode_makeEmptyInitialization ($3) );
      DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
    }
  | completeTypeSpecifier NotType namedDecl NotType TASSIGN 
    { setProcessingVars ($1); processNamedDecl ($3); }
    IsType init optDeclarators TSEMI IsType 
-   { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8)); 
+   {
+     ctype ct;
+
+     ct = idDecl_getCtype ($3);
+     idDecl_setTyp ($3, qtype_copy ($1) );
+     idDecl_replaceCtype($3, ct);
+
+     $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8)); 
      unsetProcessingVars ();
    }
 
@@ -1004,7 +1057,16 @@ namedInitializer
 typeDecl
  : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); } 
    NotType namedInitializerList IsType optWarnClause TSEMI 
-   { clabstract_declareType ($5, $7); }
+   {
+     if ( willOutputCode  )
+       {
+        outputCode(message( "typedef %s;",
+                            //      qtypetryToPrintStruct($2),
+                            exprNode_unparse(exprNodeList_head ($5) )
+                            ) 
+                   );
+       }
+     clabstract_declareType ($5, $7);   } 
  | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
  | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ } 
 
@@ -1213,7 +1275,6 @@ definedQualifier
 typeQualifier
  : QCONST IsType       { $$ = qual_createConst (); }
  | QVOLATILE IsType    { $$ = qual_createVolatile (); }
- | QRESTRICT IsType    { $$ = qual_createRestrict (); }
  | definedQualifier IsType { $$ = $1; } 
  | stateQualifier IsType { $$ = $1; } 
  | exitsQualifier IsType { $$ = $1; }
@@ -1366,6 +1427,7 @@ optNamedDecl
  | pointers TYPE_NAME    
    { 
      qtype qt = qtype_unknown ();
+
      qtype_adjustPointers ($1, qt);
      $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
    }
@@ -1382,19 +1444,18 @@ genericParamList
  | NotType paramIdList { $$ = handleParamIdList ($2); }  
 
 innerMods
- : QCONST    { $$ = qual_createConst (); }
- | QRESTRICT { $$ = qual_createRestrict (); }
- | QVOLATILE { $$ = qual_createVolatile (); }
+ : QCONST    {setInnerConstQual(); /* ignored for now */; }
+ | QVOLATILE { ; }
 
 innerModsList
- : innerMods { $$ = qualList_single ($1); }
- | innerModsList innerMods { $$ = qualList_add ($1, $2); }
+ : innerMods { ; }
+ | innerModsList innerMods { ; }
 
 pointers
- : TMULT { $$ = pointers_create ($1); }
- | TMULT innerModsList { $$ = pointers_createMods ($1, $2); }
- | TMULT pointers { $$ = pointers_extend (pointers_create ($1), $2); } 
- | TMULT innerModsList pointers { $$ = pointers_extend (pointers_createMods ($1, $2), $3); }
+ : TMULT { $$ = 1; }
+ | TMULT innerModsList { $$ = 1; }
+ | TMULT pointers { $$ = 1 + $2; }
+ | TMULT innerModsList pointers { $$ = 1 + $3; }
 
 paramIdList
  : idList 
@@ -1760,7 +1821,7 @@ postfixIterExpr
  | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
  | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
        { $$ = exprNode_vaArg ($1, $3, $5); }
- | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
+ | postfixExpr NotType TDOT newId IsType {int tmpMark1; $$ = exprNode_fieldAccess ($1, $3, $4); }
  | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
  | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
  | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
@@ -1895,7 +1956,8 @@ optComma
  | TCOMMA { ; } 
 
 id
- : IDENTIFIER 
+: IDENTIFIER {
+  ; } 
 
 newId
  : NEW_IDENTIFIER 
This page took 0.149261 seconds and 4 git commands to generate.