]>
Commit | Line | Data |
---|---|---|
361091cc | 1 | /* |
92c4a786 | 2 | ** constraintExpr.c |
361091cc | 3 | */ |
4 | ||
5 | # include <ctype.h> /* for isdigit */ | |
6 | # include "lclintMacros.nf" | |
7 | # include "basic.h" | |
8 | # include "cgrammar.h" | |
9 | # include "cgrammar_tokens.h" | |
10 | ||
11 | # include "exprChecks.h" | |
12 | # include "aliasChecks.h" | |
13 | # include "exprNodeSList.h" | |
14 | # include "exprData.i" | |
15 | ||
92c4a786 | 16 | /*@-czechfcns@*/ |
17 | ||
18 | //#include "constraintExpr.h" | |
361091cc | 19 | |
92c4a786 | 20 | bool constraintTerm_isIntLiteral (constraintTerm term) |
361091cc | 21 | { |
92c4a786 | 22 | llassert(term); |
23 | ||
24 | if (term->kind == INTLITERAL) | |
25 | return TRUE; | |
26 | ||
27 | return FALSE; | |
361091cc | 28 | } |
29 | ||
30 | constraintTerm constraintTerm_simplify (constraintTerm term) | |
31 | { | |
92c4a786 | 32 | if (term->kind == EXPRNODE) |
bf92e32c | 33 | { |
92c4a786 | 34 | if ( exprNode_knownIntValue (term->value.expr ) ) |
bf92e32c | 35 | { |
92c4a786 | 36 | int temp; |
37 | temp = exprNode_getLongValue (term->value.expr); | |
38 | term->value.intlit = temp; | |
39 | term->kind = INTLITERAL; | |
bf92e32c | 40 | } |
bf92e32c | 41 | } |
361091cc | 42 | return term; |
43 | } | |
44 | ||
92c4a786 | 45 | fileloc constraintTerm_getFileloc (constraintTerm t) |
361091cc | 46 | { |
92c4a786 | 47 | return (fileloc_copy (t->loc) ); |
361091cc | 48 | } |
49 | ||
92c4a786 | 50 | constraintTerm constraintTerm_makeExprNode (/*@only@*/ exprNode e) |
361091cc | 51 | { |
52 | constraintTerm ret = new_constraintTermExpr(); | |
53 | ret->loc = exprNode_getfileloc(e); | |
54 | ret->value.expr = e; | |
55 | ret->kind = EXPRNODE; | |
92c4a786 | 56 | ret = constraintTerm_simplify(ret); |
361091cc | 57 | return ret; |
58 | } | |
59 | ||
92c4a786 | 60 | constraintTerm constraintTerm_copy (constraintTerm term) |
361091cc | 61 | { |
62 | constraintTerm ret; | |
92c4a786 | 63 | ret = new_constraintTermExpr(); |
64 | ret->loc = fileloc_copy (term->loc); | |
65 | ret->value= term->value; | |
66 | ret->kind = term->kind; | |
361091cc | 67 | return ret; |
68 | } | |
69 | ||
92c4a786 | 70 | constraintTerm constraintTerm_setFileloc (constraintTerm term, fileloc loc) |
361091cc | 71 | { |
92c4a786 | 72 | llassert(term); |
73 | term->loc = fileloc_copy(loc); | |
74 | return term; | |
361091cc | 75 | } |
76 | ||
361091cc | 77 | cstring constraintTerm_print (constraintTerm term) |
78 | { | |
79 | cstring s; | |
80 | s = cstring_undefined; | |
81 | ||
82 | llassert (term != NULL); | |
83 | ||
84 | switch (term->kind) | |
85 | { | |
86 | case EXPRNODE: | |
87 | /*@i334*/ //wtf | |
88 | s = message ("%s @ %s ", exprNode_unparse (term->value.expr), | |
89 | fileloc_unparse (term->loc) ); | |
90 | break; | |
91 | case INTLITERAL: | |
361091cc | 92 | s = message (" %d ", term->value.intlit); |
93 | break; | |
92c4a786 | 94 | |
361091cc | 95 | case SREF: |
96 | s = cstring_makeLiteral("Not Implemented\n"); | |
97 | llassert(FALSE); | |
98 | break; | |
99 | } | |
361091cc | 100 | |
92c4a786 | 101 | return s; |
361091cc | 102 | } |
103 | ||
104 | ||
92c4a786 | 105 | constraintTerm constraintTerm_makeIntLiteral (int i) |
106 | { | |
107 | constraintTerm ret = new_constraintTermExpr(); | |
108 | ret->value.intlit = i; | |
109 | ret->kind = INTLITERAL; | |
110 | ret->loc = fileloc_undefined; | |
111 | return ret; | |
112 | } | |
113 | ||
114 | bool constraintTerm_canGetValue (constraintTerm term) | |
bf92e32c | 115 | { |
92c4a786 | 116 | if (term->kind == INTLITERAL) |
117 | return TRUE; | |
118 | else | |
119 | return FALSE; | |
120 | } | |
bf92e32c | 121 | |
92c4a786 | 122 | int constraintTerm_getValue (constraintTerm term) |
123 | { | |
124 | llassert (term->kind == INTLITERAL); | |
125 | return term->value.intlit; | |
bf92e32c | 126 | } |
127 | ||
92c4a786 | 128 | |
129 | ||
bf92e32c | 130 | /* same and similar are similar but not the same*/ |
361091cc | 131 | |
132 | bool constraintTerm_same (constraintTerm term1, constraintTerm term2) | |
133 | { | |
134 | llassert (term1 !=NULL && term2 !=NULL); | |
135 | ||
361091cc | 136 | if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) ) |
137 | { | |
138 | return FALSE; | |
139 | } | |
140 | ||
141 | DPRINTF ( (message | |
142 | ("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2) | |
143 | ) | |
144 | ) | |
145 | ); | |
146 | ||
147 | if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) ) | |
148 | { | |
bf92e32c | 149 | DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) )); |
150 | return TRUE; | |
151 | } | |
152 | else | |
153 | { | |
154 | DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) )); | |
155 | return FALSE; | |
156 | } | |
157 | ||
158 | } | |
159 | ||
160 | bool constraintTerm_similar (constraintTerm term1, constraintTerm term2) | |
161 | { | |
162 | llassert (term1 !=NULL && term2 !=NULL); | |
163 | ||
bf92e32c | 164 | if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) ) |
165 | { | |
166 | return FALSE; | |
167 | } | |
168 | ||
6364363c | 169 | TPRINTF ( (message |
bf92e32c | 170 | ("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2) |
171 | ) | |
172 | ) | |
173 | ); | |
174 | ||
175 | if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) ) | |
176 | { | |
177 | DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) )); | |
361091cc | 178 | return TRUE; |
179 | } | |
180 | else | |
181 | { | |
6364363c | 182 | TPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) )); |
361091cc | 183 | return FALSE; |
184 | } | |
185 | ||
186 | } | |
187 | ||
92c4a786 | 188 | |
189 |