]> andersk Git - splint.git/blobdiff - src/mtDeclarationNode.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / mtDeclarationNode.c
index 1f8eb3fb9ef348da2be640182a591a8c292617c9..a90270b53cb0bd3fa361b643a973438d114cfbb7 100644 (file)
@@ -1,6 +1,6 @@
 /*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2001 University of Virginia,
+** Splint - annotation-assisted static program checker
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on lclint: lclint-request@cs.virginia.edu
-** To report a bug: lclint-bug@cs.virginia.edu
-** For more information: http://lclint.cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
+** For more information: http://www.splint.org
 */
 /*
 ** mtDeclarationNode.c
 */
 
-# include "lclintMacros.nf"
+# include "splintMacros.nf"
 # include "basic.h"
-# include "mtgrammar.h"
 
 extern mtDeclarationNode mtDeclarationNode_create (mttok name, mtDeclarationPieces pieces) /*@*/ 
 {
@@ -62,6 +61,9 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
   metaStateInfo msinfo;
   int nvalues;
 
+  cstring defaultMergeMessage = 
+    cstring_makeLiteralTemp ("Incompatible state merge (default behavior)");
+
   pieces = node->pieces;
 
   /*
@@ -84,7 +86,7 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
       mvals = mtValuesNode_getValues (mtv);
     }
 
-  /*@-usedef@*/ /*@i34 lclint should figure this out... */
+  /*@-usedef@*/ /* splint should figure this out... */
   nvalues = cstringList_size (mvals);
   /*@=usedef@*/
 
@@ -376,10 +378,6 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
        } end_mtLoseReferenceList_elements ;
     }
   
-  /*@-usedef@*/
-  DPRINTF (("metastate: %s", metaStateInfo_unparse (msinfo)));
-  /*@=usedef@*/
-
   tmerge = stateCombinationTable_create (nvalues);
 
   /* Default merge is to make all incompatible mergers errors. */
@@ -391,8 +389,7 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
          if (i != j) 
            {
              stateCombinationTable_set 
-               (tmerge, i, j, metaState_error,
-                cstring_makeLiteral ("Incompatible state merge (default behavior)"));
+               (tmerge, i, j, metaState_error, cstring_copy (defaultMergeMessage));
            }
        }
     }
@@ -495,7 +492,7 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
            {
              for (j = low2index; j <= high2index; j++)
                {
-                 /*@i32 check for multiple definitions! */
+                 /* Need to add checks for multiple definitions! */
                  
                  if (mtTransferAction_isError (taction))
                    {
@@ -515,6 +512,42 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
                    }
                }
            }
+
+         /*
+         ** Unless otherwise indicated, merging is symmetric:
+         */
+
+         for (i = low1index; i <= high1index; i++)
+           {
+             for (j = low2index; j <= high2index; j++)
+               {
+                 cstring msg;
+
+                 if (stateCombinationTable_lookup (tmerge, j, i, &msg) == metaState_error)
+                   {
+                     if (cstring_equal (msg, defaultMergeMessage))
+                       {
+                         /* Override the default action */
+                         if (mtTransferAction_isError (taction))
+                           {
+                             stateCombinationTable_update
+                               (tmerge, 
+                                j, i,
+                                vindex,
+                                cstring_copy (mtTransferAction_getMessage (taction)));
+                           }
+                         else
+                           {
+                             stateCombinationTable_update
+                               (tmerge, 
+                                j, i, 
+                                vindex,
+                                cstring_undefined);
+                           }
+                       }
+                   }
+               }
+           }
        } end_mtMergeClauseList_elements ;  
     }
 
@@ -580,59 +613,47 @@ extern void mtDeclarationNode_process (mtDeclarationNode node, bool isglobal)
          if (cstringList_contains (mvals, mvalue)) 
            {
              int vindex = cstringList_getIndex (mvals, mvalue);
+             mtContextKind mkind;
 
              if (mtContextNode_isReference (mcontext))
                {
-                 if (metaStateInfo_getDefaultRefValue (msinfo) != stateValue_error)
-                   {
-                     voptgenerror
-                       (FLG_SYNTAX,
-                        message ("Duplicate defaults declaration for context %q: %q",
-                                 mtContextNode_unparse (mcontext), 
-                                 mtDefaultsDecl_unparse (mdecl)),
-                        mtDefaultsDecl_getLoc (mdecl));
-                   }
-                 else
-                   {
-                     metaStateInfo_setDefaultRefValue (msinfo, vindex);
-                   }
+                 mkind = MTC_REFERENCE;
                }
              else if (mtContextNode_isParameter (mcontext))
                {
-                 if (metaStateInfo_getDefaultParamValue (msinfo) != stateValue_error)
-                   {
-                     voptgenerror
-                       (FLG_SYNTAX,
-                        message ("Duplicate defaults declaration for context %q: %q",
-                                 mtContextNode_unparse (mcontext), 
-                                 mtDefaultsDecl_unparse (mdecl)),
-                        mtDefaultsDecl_getLoc (mdecl));
-                   }
-                 else
-                   {
-                     metaStateInfo_setDefaultParamValue (msinfo, vindex);
-                   }
+                 mkind = MTC_PARAM;
                }
              else if (mtContextNode_isResult (mcontext))
                {
-                 if (metaStateInfo_getDefaultResultValue (msinfo) != stateValue_error)
-                   {
-                     voptgenerror
-                       (FLG_SYNTAX,
-                        message ("Duplicate defaults declaration for context %q: %q",
-                                 mtContextNode_unparse (mcontext), 
-                                 mtDefaultsDecl_unparse (mdecl)),
-                        mtDefaultsDecl_getLoc (mdecl));
-                   }
-                 else
-                   {
-                     metaStateInfo_setDefaultResultValue (msinfo, vindex);
-                   }
+                 mkind = MTC_RESULT;
+               }
+             else if (mtContextNode_isLiteral (mcontext))
+               {
+                 mkind = MTC_LITERAL;
+               }
+             else if (mtContextNode_isNull (mcontext))
+               {
+                 mkind = MTC_NULL;
                }
              else
                {
+                 DPRINTF (("Bad: %s", mtContextNode_unparse (mcontext)));
                  BADBRANCH;
                }
+
+             if (metaStateInfo_getDefaultValueContext (msinfo, mkind) != stateValue_error)
+               {
+                 voptgenerror
+                   (FLG_SYNTAX,
+                    message ("Duplicate defaults declaration for context %q: %q",
+                             mtContextNode_unparse (mcontext), 
+                             mtDefaultsDecl_unparse (mdecl)),
+                    mtDefaultsDecl_getLoc (mdecl));
+               }
+             else
+               {
+                 metaStateInfo_setDefaultValueContext (msinfo, mkind, vindex);
+               }
            }
          else
            {
This page took 0.073051 seconds and 4 git commands to generate.