Skip to content

Commit f80a528

Browse files
committed
added namespace global processing when definitions are inherited
1 parent b2cccc4 commit f80a528

File tree

19 files changed

+1337
-10
lines changed

19 files changed

+1337
-10
lines changed

act/act_array.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ class Array {
255255
void moveNS (ActNamespace *orig = NULL,
256256
ActNamespace *newns = NULL); ///< moves to new ns
257257

258-
Array *CloneOne ();///< only return a deep copy of the current dense range
258+
Array *CloneOne ();///< only return a deep copy of the
259+
///current dense range
260+
261+
Array *fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
262+
259263

260264
Array *Reduce();///< return a deep copy, but elide
261265
///dimensions that are derefs
@@ -594,6 +598,9 @@ class AExpr {
594598

595599
AExpr *Clone (ActNamespace *orig = NULL, ActNamespace *newns = NULL); ///< deep copy of array expression
596600

601+
AExpr *fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
602+
603+
597604
/**
598605
* Return an InstType corresponding to this array expression
599606
* @param s is the scope

act/act_id.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ class ActId {
147147
* @return a freshly allocated ActID
148148
*/
149149
ActId *Clone (ActNamespace *orig = NULL, ActNamespace *newns = NULL);
150+
151+
/**
152+
* If the ID can't be found in the current namespace but can be
153+
* found in the original namespace, add the namespace qualifier to the
154+
* ID and return a new one.
155+
* @param cur is the current namespace
156+
* @param orig is the original namespace
157+
* @return the updated ID, or the unmodified pointer
158+
*/
159+
ActId *qualifyGlobals (ActNamespace *cur, ActNamespace *orig);
160+
bool isQualifyGlobals (ActNamespace *cur, ActNamespace *orig);
150161

151162
void moveNS (ActNamespace *orig = NULL, ActNamespace *newns = NULL);
152163

@@ -402,6 +413,12 @@ class ActId {
402413

403414
static struct cHashtable *idH; /**< used to canonicalize ID pointers
404415
post-expansion */
416+
417+
418+
// this is used for the remaining of the type, i.e. the "."
419+
// fields. Here we only check arrays.
420+
ActId *_qualifyGlobals (ActNamespace *cur, ActNamespace *orig);
421+
bool _isQualifyGlobals (ActNamespace *cur, ActNamespace *orig);
405422
};
406423

407424

act/array.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ Array *Array::Clone (ActNamespace *orig, ActNamespace *newns)
214214

215215
/*------------------------------------------------------------------------
216216
*
217-
* Array::Clone --
217+
* Array::moveNS --
218218
*
219-
* Deep copy of array
219+
* Deep copy of array, move it to a new namespace
220220
*
221221
*------------------------------------------------------------------------
222222
*/
@@ -236,6 +236,26 @@ void Array::moveNS (ActNamespace *orig, ActNamespace *newns)
236236
}
237237
}
238238

239+
/*------------------------------------------------------------------------
240+
*
241+
* Array::Clone --
242+
*
243+
* Deep copy of array
244+
*
245+
*------------------------------------------------------------------------
246+
*/
247+
Array *Array::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
248+
{
249+
Array *ret;
250+
251+
if (expanded) {
252+
return this;
253+
}
254+
255+
/* XXXX */
256+
return this;
257+
258+
}
239259

240260
/*------------------------------------------------------------------------
241261
*
@@ -2175,3 +2195,5 @@ unsigned int Array::getHash (unsigned int prev, unsigned long sz)
21752195
}
21762196
return prev;
21772197
}
2198+
2199+

act/body.cc

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,3 +2030,164 @@ ActBody *ActBody::Clone(ActNamespace */*replace*/,
20302030
{
20312031
return NULL;
20322032
}
2033+
2034+
2035+
void ActBody::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2036+
{
2037+
return;
2038+
}
2039+
2040+
2041+
void ActBody_Inst::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2042+
{
2043+
t = t->fixGlobalParams (cur, orig);
2044+
if (Next()) {
2045+
Next()->fixGlobalParams (cur, orig);
2046+
}
2047+
}
2048+
2049+
void ActBody_Attribute::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2050+
{
2051+
Array *narr;
2052+
if (arr) {
2053+
arr = arr->fixGlobalParams (cur, orig);
2054+
}
2055+
act_attr *tmp;
2056+
for (tmp = a; tmp; tmp = tmp->next) {
2057+
tmp->e = expr_globalids (tmp->e, cur, orig);
2058+
}
2059+
if (Next()) {
2060+
Next()->fixGlobalParams (cur, orig);
2061+
}
2062+
}
2063+
2064+
void ActBody_Conn::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2065+
{
2066+
if (type == 0) {
2067+
u.basic.lhs = u.basic.lhs->qualifyGlobals (cur, orig);
2068+
u.basic.rhs = u.basic.rhs->fixGlobalParams (cur, orig);
2069+
}
2070+
else {
2071+
u.general.lhs = u.general.lhs->fixGlobalParams (cur, orig);
2072+
u.general.rhs = u.general.rhs->fixGlobalParams (cur, orig);
2073+
}
2074+
if (Next()) {
2075+
Next()->fixGlobalParams (cur, orig);
2076+
}
2077+
}
2078+
2079+
void ActBody_Loop::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2080+
{
2081+
lo = expr_globalids (lo, cur, orig);
2082+
hi = expr_globalids (hi, cur, orig);
2083+
if (b) {
2084+
b->fixGlobalParams (cur, orig);
2085+
}
2086+
if (Next()) {
2087+
Next()->fixGlobalParams (cur, orig);
2088+
}
2089+
}
2090+
2091+
void ActBody_Select::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2092+
{
2093+
ActBody_Select_gc *tmp;
2094+
for (tmp = gc; tmp; tmp = tmp->next) {
2095+
tmp->lo = expr_globalids (tmp->lo, cur, orig);
2096+
tmp->hi = expr_globalids (tmp->hi, cur, orig);
2097+
tmp->g = expr_globalids (tmp->g, cur, orig);
2098+
if (tmp->s) {
2099+
tmp->s->fixGlobalParams (cur, orig);
2100+
}
2101+
}
2102+
if (Next()) {
2103+
Next()->fixGlobalParams (cur, orig);
2104+
}
2105+
}
2106+
2107+
void ActBody_Genloop::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2108+
{
2109+
ActBody_Select_gc *tmp;
2110+
for (tmp = gc; tmp; tmp = tmp->next) {
2111+
tmp->lo = expr_globalids (tmp->lo, cur, orig);
2112+
tmp->hi = expr_globalids (tmp->hi, cur, orig);
2113+
tmp->g = expr_globalids (tmp->g, cur, orig);
2114+
if (tmp->s) {
2115+
tmp->s->fixGlobalParams (cur, orig);
2116+
}
2117+
}
2118+
if (Next()) {
2119+
Next()->fixGlobalParams (cur, orig);
2120+
}
2121+
}
2122+
2123+
void ActBody_Assertion::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2124+
{
2125+
if (type == 0) {
2126+
u.t0.e = expr_globalids (u.t0.e, cur, orig);
2127+
}
2128+
else {
2129+
Assert (type == 1, "Hmm");
2130+
u.t1.id1 = u.t1.id1->qualifyGlobals (cur, orig);
2131+
u.t1.id2 = u.t1.id2->qualifyGlobals (cur, orig);
2132+
}
2133+
if (Next()) {
2134+
Next()->fixGlobalParams (cur, orig);
2135+
}
2136+
}
2137+
2138+
void ActBody_Print::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2139+
{
2140+
listitem_t *li;
2141+
for (li = list_first (l); li; li = list_next (li)) {
2142+
act_func_arguments_t *f = (act_func_arguments_t *) list_value (li);
2143+
if (f->isstring) {
2144+
// nothing
2145+
}
2146+
else {
2147+
f->u.e = expr_globalids (f->u.e, cur, orig);
2148+
}
2149+
}
2150+
if (Next()) {
2151+
Next()->fixGlobalParams (cur, orig);
2152+
}
2153+
}
2154+
2155+
void ActBody_Lang::fixGlobalParams (ActNamespace *cur, ActNamespace *orig)
2156+
{
2157+
switch (t) {
2158+
case LANG_CHP:
2159+
case LANG_HSE:
2160+
chp_fixglobals ((act_chp *)lang, cur, orig);
2161+
break;
2162+
2163+
case LANG_REFINE:
2164+
refine_fixglobals ((act_refine *)lang, cur, orig);
2165+
break;
2166+
2167+
case LANG_DFLOW:
2168+
dflow_fixglobals ((act_dataflow *)lang, cur, orig);
2169+
break;
2170+
2171+
case LANG_PRS:
2172+
prs_fixglobals ((act_prs *)lang, cur, orig);
2173+
break;
2174+
2175+
case LANG_SPEC:
2176+
spec_fixglobals ((act_spec *)lang, cur, orig);
2177+
break;
2178+
2179+
case LANG_SIZE:
2180+
sizing_fixglobals ((act_sizing *)lang, cur, orig);
2181+
break;
2182+
2183+
case LANG_INIT:
2184+
break;
2185+
2186+
case LANG_EXTERN:
2187+
lang_extern_fixglobals (nm, lang, cur, orig);
2188+
break;
2189+
}
2190+
if (Next()) {
2191+
Next()->fixGlobalParams (cur, orig);
2192+
}
2193+
}

act/body.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ class ActBody {
132132
*/
133133
int getLine () { return _line; }
134134

135+
136+
/**
137+
* If a namespace global parameter is used, add the explicit
138+
* qualifier to the identifier.
139+
* @param cur is the current namespace
140+
* @param orig is the original namespace
141+
*/
142+
virtual void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
143+
135144
protected:
136145
int _line; ///< saved away line number information
137146

@@ -194,6 +203,11 @@ class ActBody_Inst : public ActBody {
194203
*/
195204
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
196205

206+
/**
207+
* Update namespace globals
208+
*/
209+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
210+
197211
private:
198212
InstType *t; ///< the type
199213
const char *id; ///< the name of the identifier to be instantiated
@@ -235,6 +249,11 @@ class ActBody_Attribute : public ActBody {
235249
*/
236250
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
237251

252+
/**
253+
* Update namespace globals
254+
*/
255+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
256+
238257
private:
239258
const char *inst;
240259
act_attr *a;
@@ -279,7 +298,7 @@ class ActBody_Conn : public ActBody {
279298
void Expand (ActNamespace *, Scope *);
280299

281300
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
282-
301+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
283302

284303
private:
285304
union {
@@ -327,6 +346,8 @@ class ActBody_Loop : public ActBody {
327346
void Print (FILE *fp);
328347

329348
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
349+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
350+
330351

331352
/**
332353
* @return the loop body
@@ -450,6 +471,7 @@ class ActBody_Select : public ActBody {
450471
void Expand (ActNamespace *, Scope *);
451472

452473
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
474+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
453475

454476
/**
455477
* @return the list of guarded commands
@@ -477,7 +499,7 @@ class ActBody_Genloop : public ActBody {
477499
}
478500
void Expand (ActNamespace *, Scope *);
479501
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
480-
502+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
481503

482504
ActBody_Select_gc *getGC() { return gc; }
483505

@@ -533,6 +555,7 @@ class ActBody_Assertion : public ActBody {
533555
}
534556
void Expand (ActNamespace *, Scope *);
535557
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
558+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
536559

537560
private:
538561
union {
@@ -607,6 +630,7 @@ class ActBody_Print : public ActBody {
607630
}
608631
void Expand (ActNamespace *, Scope *);
609632
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
633+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
610634

611635
private:
612636
list_t *l;
@@ -734,7 +758,7 @@ class ActBody_Lang : public ActBody {
734758
void Expand (ActNamespace *, Scope *);
735759
void Print (FILE *fp);
736760
ActBody *Clone (ActNamespace *replace = NULL, ActNamespace *newns = NULL);
737-
761+
void fixGlobalParams (ActNamespace *cur, ActNamespace *orig);
738762

739763
void *getlang() { return lang; }
740764
enum langtype gettype() { return t; }

0 commit comments

Comments
 (0)