]>
Commit | Line | Data |
---|---|---|
28bf4b0b | 1 | /* |
2 | ** LCLint - annotation-assisted static program checker | |
3 | ** Copyright (C) 1994-2001 University of Virginia, | |
4 | ** Massachusetts Institute of Technology | |
5 | ** | |
6 | ** This program is free software; you can redistribute it and/or modify it | |
7 | ** under the terms of the GNU General Public License as published by the | |
8 | ** Free Software Foundation; either version 2 of the License, or (at your | |
9 | ** option) any later version. | |
10 | ** | |
11 | ** This program is distributed in the hope that it will be useful, but | |
12 | ** WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | ** General Public License for more details. | |
15 | ** | |
16 | ** The GNU General Public License is available from http://www.gnu.org/ or | |
17 | ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
18 | ** MA 02111-1307, USA. | |
19 | ** | |
20 | ** For information on lclint: lclint-request@cs.virginia.edu | |
21 | ** To report a bug: lclint-bug@cs.virginia.edu | |
22 | ** For more information: http://lclint.cs.virginia.edu | |
23 | */ | |
24 | /* | |
25 | ** mtDeclarationPieces.c | |
26 | */ | |
27 | ||
28 | # include "lclintMacros.nf" | |
29 | # include "basic.h" | |
30 | # include "mtgrammar.h" | |
31 | ||
32 | extern mtDeclarationPieces mtDeclarationPieces_create (void) /*@*/ | |
33 | { | |
34 | return mtDeclarationPieces_undefined; | |
35 | } | |
36 | ||
37 | extern mtDeclarationPieces mtDeclarationPieces_append (mtDeclarationPieces node, | |
38 | /*@only@*/ mtDeclarationPiece piece) | |
39 | /*@modifies node*/ | |
40 | { | |
41 | mtDeclarationPieces tnode = node; | |
42 | mtDeclarationPieces res = (mtDeclarationPieces) dmalloc (sizeof (*node)); | |
43 | ||
44 | res->thisPiece = piece; | |
45 | res->rest = mtDeclarationPieces_undefined; | |
46 | ||
47 | if (mtDeclarationPieces_isUndefined (node)) { | |
48 | return res; | |
49 | } | |
50 | ||
51 | while (mtDeclarationPieces_isDefined (tnode->rest)) | |
52 | { | |
53 | tnode = tnode->rest; | |
54 | } | |
55 | ||
56 | tnode->rest = res; | |
57 | return node; | |
58 | } | |
59 | ||
60 | extern cstring mtDeclarationPieces_unparse (mtDeclarationPieces node) /*@*/ | |
61 | { | |
62 | cstring res = cstring_newEmpty (); | |
63 | ||
64 | while (mtDeclarationPieces_isDefined (node)) | |
65 | { | |
66 | res = message ("%q%q; ", res, mtDeclarationPiece_unparse (node->thisPiece)); | |
67 | node = node->rest; | |
68 | } | |
69 | ||
70 | return res; | |
71 | } | |
72 | ||
73 | mtDeclarationPiece | |
74 | mtDeclarationPieces_findPiece (mtDeclarationPieces pieces, mtPieceKind kind) | |
75 | { | |
76 | bool foundone = FALSE; | |
77 | mtDeclarationPiece res = mtDeclarationPiece_undefined; | |
78 | ||
79 | while (mtDeclarationPieces_isDefined (pieces)) | |
80 | { | |
81 | if (mtDeclarationPiece_matchKind (pieces->thisPiece, kind)) | |
82 | { | |
83 | if (foundone) | |
84 | { | |
85 | llassert (mtDeclarationPiece_isDefined (res)); | |
86 | voptgenerror | |
87 | (FLG_SYNTAX, | |
88 | message ("Metastate declaration has duplicate pieces: %q / %q", | |
89 | mtDeclarationPiece_unparse (res), | |
90 | mtDeclarationPiece_unparse (pieces->thisPiece)), | |
91 | g_currentloc); /*@i43 pieces's should have locs! */ | |
92 | } | |
93 | else | |
94 | { | |
95 | foundone = TRUE; | |
96 | llassert (mtDeclarationPiece_isUndefined (res)); | |
97 | res = pieces->thisPiece; | |
98 | } | |
99 | } | |
100 | ||
101 | pieces = pieces->rest; | |
102 | } | |
103 | ||
104 | return res; | |
105 | } | |
106 | ||
107 | extern void mtDeclarationPieces_free (/*@only@*/ mtDeclarationPieces node) | |
108 | { | |
109 | if (mtDeclarationPieces_isDefined (node)) | |
110 | { | |
111 | mtDeclarationPiece_free (node->thisPiece); | |
112 | mtDeclarationPieces_free (node->rest); | |
113 | } | |
114 | ||
115 | sfree (node); | |
116 | } |