Skip to content

Commit 523ff1f

Browse files
authored
Updated C code generators
1 parent 36bd52b commit 523ff1f

18 files changed

+1045
-93
lines changed

ASTBasicTerm.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public ASTTerm getTerm(int i)
6060
return null;
6161
}
6262

63+
public Vector getTerms()
64+
{ Vector res = new Vector();
65+
res.add(new ASTSymbolTerm(value));
66+
return res;
67+
}
68+
6369
public void setValue(String v)
6470
{ value = v; }
6571

@@ -97,6 +103,10 @@ public Vector tokenSequence()
97103
return res;
98104
}
99105

106+
public int termSize()
107+
{ return 1; }
108+
109+
100110
public String asTextModel(PrintWriter out)
101111
{ String id = Identifier.nextIdentifier(tag);
102112
out.println(id + " : " + tag);

ASTCompositeTerm.java

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ public Vector tokenSequence()
200200
return res;
201201
}
202202

203+
public int termSize()
204+
{ int res = 0;
205+
for (int i = 0; i < terms.size(); i++)
206+
{ ASTTerm t = (ASTTerm) terms.get(i);
207+
res = res + t.termSize();
208+
}
209+
return res;
210+
}
211+
203212
public String asTextModel(PrintWriter out)
204213
{ String id = Identifier.nextIdentifier(tag);
205214

@@ -231,9 +240,12 @@ public String cgRules(CGSpec cgs, Vector rules)
231240
Vector tokens = r.lhsTokens;
232241
Vector vars = r.getVariables();
233242

243+
java.util.HashMap matches = new java.util.HashMap();
244+
// vars --> terms
245+
234246
if (tokens.size() > terms.size())
235-
{ // System.out.println("> " + tag + " rule " + r + " does not match " + this);
236-
// System.out.println("!! Too many elements on rule LHS (" + tokens.size() + ") to match subterms: (" + terms.size() + ")");
247+
{ System.out.println("> " + tag + " rule " + r + " does not match " + this);
248+
System.out.println("!! Too many elements on rule LHS (" + tokens.size() + ") to match subterms: (" + terms.size() + ")");
237249
continue;
238250
}
239251
else if (vars.contains("_*") && terms.size() >= tokens.size())
@@ -292,14 +304,31 @@ else if (remainingTokens > remainingTerms)
292304
else if (vars.contains(tok))
293305
{ // allocate terms(j) to tok
294306

295-
// System.out.println(">> Matched variable " + tok +
296-
// " and term " + tm);
297-
eargs.add(tm);
298-
k++;
307+
System.out.println(">> Matched variable " + tok +
308+
" and term " + tm);
309+
310+
ASTTerm oldterm = (ASTTerm) matches.get(tok);
311+
if (oldterm == null)
312+
{ matches.put(tok,tm);
313+
314+
eargs.add(tm);
315+
k++;
316+
}
317+
else if (oldterm.equals(tm))
318+
{
319+
eargs.add(tm);
320+
k++;
321+
}
322+
else
323+
{ System.err.println("!! Same variable " + tok +
324+
" assigned different terms: " +
325+
oldterm + " " + tm);
326+
failed = true;
327+
}
299328
}
300329
else if (tok.equals(tm.literalForm()))
301-
{ // System.out.println(">> Matched token " + tok +
302-
// " and term " + tm);
330+
{ System.out.println(">> Matched token " + tok +
331+
" and term " + tm);
303332
k++;
304333
}
305334
else
@@ -18391,7 +18420,18 @@ else if (restype != null)
1839118420
{ ASTTerm mbody = (ASTTerm) terms.get(3);
1839218421

1839318422
if (";".equals(mbody.literalForm()))
18394-
{ return res + ";\n"; }
18423+
{ if (mtype.modelElement != null &&
18424+
mtype.modelElement instanceof Type)
18425+
{ Expression retval =
18426+
((Type) mtype.modelElement).getDefaultValueExpression();
18427+
Statement interfacestat =
18428+
new ReturnStatement(retval);
18429+
bf.setActivity(interfacestat);
18430+
return res + "\n activity: return " + retval + ";\n";
18431+
}
18432+
return res + ";\n";
18433+
}
18434+
1839518435
res = res + "\n activity:\n";
1839618436

1839718437
for (int i = 3; i < terms.size(); i++)

ASTSymbolTerm.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public Vector symbolTerms()
9191
public Vector nonSymbolTerms()
9292
{ return new Vector(); }
9393

94+
public Vector getTerms()
95+
{ return new Vector(); }
96+
9497
public ASTTerm removeOuterTag()
9598
{ return null; }
9699

@@ -103,6 +106,9 @@ public Vector tokenSequence()
103106
return res;
104107
}
105108

109+
public int termSize()
110+
{ return 1; }
111+
106112
public String asTextModel(PrintWriter out)
107113
{ return "\"" + symbol + "\""; }
108114

0 commit comments

Comments
 (0)