1 | /* |
---|
2 | Copyright (C) 2009 Modelon AB |
---|
3 | |
---|
4 | This program is free software: you can redistribute it and/or modify |
---|
5 | it under the terms of the GNU General Public License as published by |
---|
6 | the Free Software Foundation, version 3 of the License. |
---|
7 | |
---|
8 | This program is distributed in the hope that it will be useful, |
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | GNU General Public License for more details. |
---|
12 | |
---|
13 | You should have received a copy of the GNU General Public License |
---|
14 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | */ |
---|
16 | |
---|
17 | import java.io.ByteArrayOutputStream; |
---|
18 | import java.util.Collection; |
---|
19 | |
---|
20 | import org.jmodelica.util.streams.CodeStream; |
---|
21 | import org.jmodelica.util.streams.NotNullCodeStream; |
---|
22 | |
---|
23 | aspect BasePrinter { |
---|
24 | |
---|
25 | /** |
---|
26 | * Superclass to all classes that perform the dispatch. |
---|
27 | */ |
---|
28 | public class Printer { |
---|
29 | |
---|
30 | private static final Map<String, Map<String, String>> INDENT_MAPS = new HashMap<String, Map<String, String>>(); |
---|
31 | private final Map<String, String> INDENTS; |
---|
32 | |
---|
33 | protected String step; |
---|
34 | |
---|
35 | public Printer(String step) { |
---|
36 | this.step = step; |
---|
37 | Map<String,String> indents = INDENT_MAPS.get(step); |
---|
38 | if (indents == null) { |
---|
39 | indents = new HashMap<String,String>(); |
---|
40 | INDENT_MAPS.put(step, indents); |
---|
41 | } |
---|
42 | INDENTS = indents; |
---|
43 | } |
---|
44 | |
---|
45 | public String indent(String old) { |
---|
46 | String res = INDENTS.get(old); |
---|
47 | if (res == null) { |
---|
48 | res = old + step; |
---|
49 | INDENTS.put(old, res); |
---|
50 | } |
---|
51 | return res; |
---|
52 | } |
---|
53 | |
---|
54 | public void print(ASTNode node, CodeStream str, String indent) { |
---|
55 | } |
---|
56 | |
---|
57 | public void print(Collection<? extends ASTNode> nodes, CodeStream str, String indent) { |
---|
58 | for (ASTNode node : nodes) |
---|
59 | print(node, str, indent); |
---|
60 | } |
---|
61 | |
---|
62 | public void print(String s, CodeStream str) { |
---|
63 | str.print(s); |
---|
64 | } |
---|
65 | |
---|
66 | public String op(FBinExp e) { return e.op(); } |
---|
67 | |
---|
68 | /** |
---|
69 | * Method that returns the printer that should be used when |
---|
70 | * annotations are PrettyPrinted in the flat tree. |
---|
71 | */ |
---|
72 | public PrettyPrinter annotationPrinter() { |
---|
73 | return ASTNode.AnnotationPrettyPrinter; |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | * Method returns true if the supplied attribute should be printed. |
---|
78 | * Checked by PrettyPrinting of FAttributes |
---|
79 | */ |
---|
80 | public boolean inAnnotation() { |
---|
81 | return false; |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | aspect PrettyPrint { |
---|
87 | |
---|
88 | /** |
---|
89 | * Static printer instance. |
---|
90 | */ |
---|
91 | static PrettyPrinter ASTNode.prettyPrinter = new PrettyPrinter(); |
---|
92 | |
---|
93 | /** |
---|
94 | * Select first variant. |
---|
95 | */ |
---|
96 | public class PrettyPrinter extends Printer { |
---|
97 | public PrettyPrinter() { |
---|
98 | super(" "); |
---|
99 | } |
---|
100 | |
---|
101 | public void print(ASTNode node, CodeStream str, String indent) { |
---|
102 | node.prettyPrint(this, str, indent); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * Wraps a prettyPrint() call to be deferred until the sting is needed. |
---|
108 | */ |
---|
109 | public class PrettyPrintDelegate { |
---|
110 | private ASTNode n; |
---|
111 | private String i; |
---|
112 | |
---|
113 | public PrettyPrintDelegate(ASTNode node) { |
---|
114 | this(node, ""); |
---|
115 | } |
---|
116 | |
---|
117 | public PrettyPrintDelegate(ASTNode node, String indent) { |
---|
118 | n = node; |
---|
119 | i = indent; |
---|
120 | } |
---|
121 | |
---|
122 | public String toString() { |
---|
123 | return n.prettyPrint(i); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | public String ASTNode.prettyPrint(String indent) { |
---|
128 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
---|
129 | CodeStream str = new NotNullCodeStream(os); |
---|
130 | prettyPrint(str, indent); |
---|
131 | return os.toString(); |
---|
132 | } |
---|
133 | |
---|
134 | public String ASTNode.prettyPrint(Printer printer) { |
---|
135 | return prettyPrint(printer, ""); |
---|
136 | } |
---|
137 | |
---|
138 | public String ASTNode.prettyPrint(Printer printer, String indent) { |
---|
139 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
140 | CodeStream str = new NotNullCodeStream(baos); |
---|
141 | printer.print(this, str, indent); |
---|
142 | return baos.toString(); |
---|
143 | } |
---|
144 | |
---|
145 | // Override ASTNode.prettyPrint to get method on Python side (jpype bug) |
---|
146 | public String BaseNode.prettyPrint(String indent) { |
---|
147 | return super.prettyPrint(indent); |
---|
148 | } |
---|
149 | |
---|
150 | public void ASTNode.prettyPrint(CodeStream str, String indent) { |
---|
151 | prettyPrint(prettyPrinter, str, indent); |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * Overrides default behaviour since we should use AnnotationPrettyPrinter |
---|
156 | * when printing annotation nodes. |
---|
157 | */ |
---|
158 | @Override |
---|
159 | public void FAnnotationAttribute.prettyPrint(CodeStream str, String indent) { |
---|
160 | prettyPrint(AnnotationPrettyPrinter, str, indent); |
---|
161 | } |
---|
162 | |
---|
163 | public void ASTNode.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
164 | for (ASTNode n : this) |
---|
165 | p.print(n, str, indent); |
---|
166 | } |
---|
167 | |
---|
168 | /** |
---|
169 | * Prints a list of any type of ASTNode, adding <code>sep</code> between nodes. |
---|
170 | * |
---|
171 | * Typical use: <code>list.prettyPrintWithSep(p, str, indent, ", ");</code> |
---|
172 | * (Prints comma-separated list.) |
---|
173 | */ |
---|
174 | public void List.prettyPrintWithSep(Printer p, CodeStream str, String indent, String sep) { |
---|
175 | String prefix = ""; |
---|
176 | for (ASTNode n : this) { |
---|
177 | str.print(prefix); |
---|
178 | p.print(n, str, indent); |
---|
179 | prefix = sep; |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | public String List.toString() { |
---|
184 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
---|
185 | CodeStream str = new CodeStream(os); |
---|
186 | prettyPrintWithSep(prettyPrinter, str, "", ", "); |
---|
187 | return os.toString(); |
---|
188 | } |
---|
189 | |
---|
190 | public static String ASTNode.prettyPrintWithSep(java.util.List<? extends ASTNode> l, String sep) { |
---|
191 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
---|
192 | CodeStream str = new NotNullCodeStream(os); |
---|
193 | prettyPrintWithSep(l, prettyPrinter, str, "", sep); |
---|
194 | return os.toString(); |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | * Prints an ArrayList of any type of ASTNode, adding <code>sep</code> between nodes. |
---|
199 | * |
---|
200 | * Typical use: <code>prettyPrintWithSep(list, p, str, indent, ", ");</code> |
---|
201 | * (Prints comma-separated list.) |
---|
202 | */ |
---|
203 | public static void ASTNode.prettyPrintWithSep(java.util.List<? extends ASTNode> l, Printer p, CodeStream str, String indent, String sep) { |
---|
204 | String prefix = ""; |
---|
205 | for (ASTNode n : l) { |
---|
206 | str.print(prefix); |
---|
207 | p.print(n, str, indent); |
---|
208 | prefix = sep; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | /** |
---|
213 | * Prints a list of any type of ASTNode, adding <code>prefix</code> before each node and |
---|
214 | * <code>suffix</code> after each node. |
---|
215 | */ |
---|
216 | public void List.prettyPrintWithFix(Printer p, CodeStream str, String indent, String prefix, String suffix) { |
---|
217 | for (ASTNode n : this) { |
---|
218 | str.print(prefix); |
---|
219 | p.print(n, str, indent); |
---|
220 | str.print(suffix); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | /** |
---|
225 | * Prints an ArrayList of any type of ASTNode, adding <code>prefix</code> before each node and |
---|
226 | * <code>suffix</code> after each node. |
---|
227 | */ |
---|
228 | public static void ASTNode.prettyPrintWithFix(java.util.List<? extends ASTNode> l, Printer p, CodeStream str, String indent, String prefix, String suffix) { |
---|
229 | for (ASTNode n : l) { |
---|
230 | str.print(prefix); |
---|
231 | p.print(n, str, indent); |
---|
232 | str.print(suffix); |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * Prints a list of any type of ASTNode, adding <code>indent</code> before each node and |
---|
238 | * <code>suffix</code> plus a line break after after each node. |
---|
239 | */ |
---|
240 | public void List.prettyPrintWithIndent(Printer p, CodeStream str, String indent, String suffix) { |
---|
241 | prettyPrintWithFix(p, str, indent, indent, suffix + str.getLineEnder()); |
---|
242 | } |
---|
243 | |
---|
244 | /** |
---|
245 | * Prints an ArrayList of any type of ASTNode, adding <code>indent</code> before each node and |
---|
246 | * <code>suffix</code> plus a line break after after each node. |
---|
247 | */ |
---|
248 | public static void ASTNode.prettyPrintWithIndent(java.util.List<? extends ASTNode> l, Printer p, CodeStream str, String indent, String suffix) { |
---|
249 | prettyPrintWithFix(l, p, str, indent, indent, suffix + str.getLineEnder()); |
---|
250 | } |
---|
251 | |
---|
252 | /** |
---|
253 | * Prints a list of any type of ASTNode, adding <code>indent</code> before each node and |
---|
254 | * a line break after after each node. |
---|
255 | */ |
---|
256 | public void List.prettyPrintWithIndent(Printer p, CodeStream str, String indent) { |
---|
257 | prettyPrintWithFix(p, str, indent, indent, str.getLineEnder()); |
---|
258 | } |
---|
259 | |
---|
260 | /** |
---|
261 | * Prints an ArrayList of any type of ASTNode, adding <code>indent</code> before each node and |
---|
262 | * a line break after after each node. |
---|
263 | */ |
---|
264 | public static void ASTNode.prettyPrintWithIndent(java.util.List<? extends ASTNode> l, Printer p, CodeStream str, String indent) { |
---|
265 | prettyPrintWithFix(l, p, str, indent, indent, str.getLineEnder()); |
---|
266 | } |
---|
267 | |
---|
268 | public void Program.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
269 | for (SrcStoredDefinition sd : getUnstructuredEntitys()) { |
---|
270 | p.print(sd,str,indent); |
---|
271 | } |
---|
272 | } |
---|
273 | |
---|
274 | public void SrcStoredDefinition.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
275 | if (hasSrcWithin()) { |
---|
276 | str.print(indent, "within"); |
---|
277 | if (getSrcWithin().hasPackageName()) { |
---|
278 | str.print(" "); |
---|
279 | p.print(getSrcWithin().getPackageName(),str,indent); |
---|
280 | } |
---|
281 | str.println(";"); |
---|
282 | } |
---|
283 | for (SrcClassDecl cd : getSrcClassDecls()) { |
---|
284 | p.print(cd, str, indent); |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | public void SrcShortClassDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
290 | str.print(indent); |
---|
291 | indent = p.indent(indent); |
---|
292 | if (getEncapsulated()) { |
---|
293 | str.print("encapsulated "); |
---|
294 | } |
---|
295 | if (getPartial()) { |
---|
296 | str.print("partial "); |
---|
297 | } |
---|
298 | if (getRedeclare()) { |
---|
299 | str.print("redeclare "); |
---|
300 | } |
---|
301 | if (getFinal()) { |
---|
302 | str.print("final "); |
---|
303 | } |
---|
304 | if (getInner()) { |
---|
305 | str.print("inner "); |
---|
306 | } |
---|
307 | if (getOuter()) { |
---|
308 | str.print("outer "); |
---|
309 | } |
---|
310 | if (getReplaceable()) { |
---|
311 | str.print("replaceable "); |
---|
312 | } |
---|
313 | |
---|
314 | str.print(getSrcRestriction(), " "); |
---|
315 | p.print(getName(), str, indent); |
---|
316 | str.print(" = ", getSrcExtendsClauseShortClass().getSuper().name()); |
---|
317 | if (getSrcExtendsClauseShortClass().hasSrcArraySubscripts()) { |
---|
318 | p.print(getSrcExtendsClauseShortClass().getSrcArraySubscripts(), str, indent); |
---|
319 | } |
---|
320 | if (getSrcExtendsClauseShortClass().hasSrcClassModification()) { |
---|
321 | p.print(getSrcExtendsClauseShortClass().getSrcClassModification(), str, indent); |
---|
322 | } |
---|
323 | if (hasSrcConstrainingClause()) { |
---|
324 | p.print(getSrcConstrainingClause(), str, indent); |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | public void SrcFullClassDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
329 | str.print(indent); |
---|
330 | if (getEncapsulated()) { |
---|
331 | str.print("encapsulated "); |
---|
332 | } |
---|
333 | if (getPartial()) { |
---|
334 | str.print("partial "); |
---|
335 | } |
---|
336 | if (getRedeclare()) { |
---|
337 | str.print("redeclare "); |
---|
338 | } |
---|
339 | if (getFinal()) { |
---|
340 | str.print("final "); |
---|
341 | } |
---|
342 | if (getInner()) { |
---|
343 | str.print("inner "); |
---|
344 | } |
---|
345 | if (getOuter()) { |
---|
346 | str.print("outer "); |
---|
347 | } |
---|
348 | if (getReplaceable()) { |
---|
349 | str.print("replaceable "); |
---|
350 | } |
---|
351 | |
---|
352 | str.print(getSrcRestriction(), " "); |
---|
353 | if (isClassExtends()) { |
---|
354 | str.print("extends "); |
---|
355 | } |
---|
356 | prettyPrintClassName(p, str, indent); |
---|
357 | |
---|
358 | if (hasSrcStringComment()) { |
---|
359 | p.print(getSrcStringComment(), str, indent); |
---|
360 | } |
---|
361 | |
---|
362 | if (hasSrcConstrainingClause()) { |
---|
363 | str.print("constrainedby "); |
---|
364 | p.print(getSrcConstrainingClause(), str, indent); |
---|
365 | str.print(" "); |
---|
366 | if (hasConstrainingClauseComment()) { |
---|
367 | p.print(getConstrainingClauseComment(), str, indent); |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | str.println(); |
---|
372 | |
---|
373 | for (SrcClause cl : getSrcClauses()) { |
---|
374 | p.print(cl, str, indent); |
---|
375 | } |
---|
376 | |
---|
377 | if (hasSrcExternalClause()) { |
---|
378 | p.print(getSrcExternalClause(), str, indent); |
---|
379 | } |
---|
380 | |
---|
381 | if (hasSrcAnnotation()) { |
---|
382 | p.print(getSrcAnnotation(), str, indent); |
---|
383 | } |
---|
384 | |
---|
385 | p.print(getSrcEndDecl(), str, indent); |
---|
386 | } |
---|
387 | |
---|
388 | public void SrcFullClassDecl.prettyPrintClassName(Printer p, CodeStream str, String indent) { |
---|
389 | p.print(getName(), str, indent); |
---|
390 | } |
---|
391 | |
---|
392 | public void SrcParseAnnotation.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
393 | str.print(indent, "annotation "); |
---|
394 | p.print(getSrcClassModification(), str, indent); |
---|
395 | str.print(";"); |
---|
396 | str.println(); |
---|
397 | } |
---|
398 | |
---|
399 | public void SrcClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
400 | String header = clauseHeader(); |
---|
401 | if (header != null) { |
---|
402 | str.println(indent, header); |
---|
403 | } |
---|
404 | prettyPrintClauseBody(p, str, p.indent(indent), true); |
---|
405 | } |
---|
406 | |
---|
407 | syn String SrcClause.clauseHeader() = clauseHeader(" "); |
---|
408 | syn String SrcClause.clauseHeader(String separator); |
---|
409 | eq SrcPublicElementList.clauseHeader(String separator) = "public"; |
---|
410 | eq SrcDefaultElementList.clauseHeader(String separator) = null; |
---|
411 | eq SrcProtectedElementList.clauseHeader(String separator) = "protected"; |
---|
412 | eq SrcEquationClause.clauseHeader(String separator) = "equation"; |
---|
413 | eq SrcInitialEquationClause.clauseHeader(String separator) = "initial" + separator + "equation"; |
---|
414 | eq SrcAlgorithm.clauseHeader(String separator) = "algorithm"; |
---|
415 | eq SrcInitialAlgorithm.clauseHeader(String separator) = "initial" + separator + "algorithm"; |
---|
416 | |
---|
417 | public abstract void SrcClause.prettyPrintClauseBody(Printer p, CodeStream str, String indent, boolean doFormating); |
---|
418 | |
---|
419 | public void SrcElementList.prettyPrintClauseBody(Printer p, CodeStream str, String indent, boolean doFormatting) { |
---|
420 | boolean prevWantsBlankLine = false; |
---|
421 | boolean first = true; |
---|
422 | for (SrcElement e : getSrcElements()) { |
---|
423 | boolean wantsBlankLine = e.prettyPrintWantsBlankLine(); |
---|
424 | if (doFormatting && !first && (wantsBlankLine || prevWantsBlankLine)) { |
---|
425 | str.println(); |
---|
426 | } |
---|
427 | if (doFormatting && !e.prettyPrintsAsLine()) { |
---|
428 | str.print(indent); |
---|
429 | p.print(e, str, indent); |
---|
430 | str.println(";"); |
---|
431 | } else { |
---|
432 | p.print(e, str, indent); |
---|
433 | } |
---|
434 | prevWantsBlankLine = wantsBlankLine; |
---|
435 | first = false; |
---|
436 | } |
---|
437 | } |
---|
438 | |
---|
439 | syn boolean SrcElement.prettyPrintsAsLine(); |
---|
440 | eq SrcImportClause.prettyPrintsAsLine() = true; |
---|
441 | eq SrcExtendsClause.prettyPrintsAsLine() = false; |
---|
442 | eq SrcComponentClause.prettyPrintsAsLine() = false; |
---|
443 | eq SrcClassDecl.prettyPrintsAsLine() = true; |
---|
444 | eq SrcBadElement.prettyPrintsAsLine() = true; |
---|
445 | |
---|
446 | syn boolean SrcElement.prettyPrintWantsBlankLine() = false; |
---|
447 | eq SrcClassDecl.prettyPrintWantsBlankLine() = true; |
---|
448 | |
---|
449 | public void SrcEquationClause.prettyPrintClauseBody(Printer p, CodeStream str, String indent, boolean doFormatting) { |
---|
450 | for (SrcAbstractEquation e : getSrcAbstractEquations()) { |
---|
451 | p.print(e, str, indent); |
---|
452 | if (doFormatting) { |
---|
453 | str.println(";"); |
---|
454 | } |
---|
455 | } |
---|
456 | } |
---|
457 | |
---|
458 | public void SrcAlgorithm.prettyPrintClauseBody(Printer p, CodeStream str, String indent, boolean doFormatting) { |
---|
459 | for (SrcStatement s : getSrcStatements()) { |
---|
460 | p.print(s, str, indent); |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | public void SrcAssignStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
465 | str.print(indent); |
---|
466 | p.print(getLeft(), str, indent); |
---|
467 | str.print(":="); |
---|
468 | p.print(getRight(), str, indent); |
---|
469 | str.println(';'); |
---|
470 | } |
---|
471 | |
---|
472 | public void SrcFunctionCallStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
473 | str.print(indent, "("); |
---|
474 | boolean first = true; |
---|
475 | for (SrcFunctionCallLeft fcl : getLefts()) { |
---|
476 | if (!first) { |
---|
477 | str.print(","); |
---|
478 | } |
---|
479 | first = false; |
---|
480 | p.print(fcl, str, indent); |
---|
481 | } |
---|
482 | str.print(") := "); |
---|
483 | p.print(getSrcFunctionCall(), str, indent); |
---|
484 | str.println(";"); |
---|
485 | } |
---|
486 | |
---|
487 | public void SrcBreakStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
488 | str.println(indent, "break;"); |
---|
489 | } |
---|
490 | |
---|
491 | public void SrcReturnStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
492 | str.println(indent, "return;"); |
---|
493 | } |
---|
494 | |
---|
495 | public void SrcIfStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
496 | str.print(indent, "if "); |
---|
497 | boolean first = true; |
---|
498 | for (SrcIfWhenClause iwc : getSrcIfWhenClauses()) { |
---|
499 | if (!first) { |
---|
500 | str.print(indent, "elseif "); |
---|
501 | } |
---|
502 | first = false; |
---|
503 | p.print(iwc, str, indent); |
---|
504 | } |
---|
505 | if (hasSrcElseClause()) |
---|
506 | p.print(getSrcElseClause(), str, indent); |
---|
507 | str.println(indent, "end if;"); |
---|
508 | } |
---|
509 | |
---|
510 | public void SrcElseClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
511 | if (getNumStmt() > 0) { |
---|
512 | str.println(indent, "else"); |
---|
513 | for (SrcStatement stmt : getStmts()) { |
---|
514 | p.print(stmt, str, p.indent(indent)); |
---|
515 | } |
---|
516 | } |
---|
517 | } |
---|
518 | |
---|
519 | |
---|
520 | public void SrcWhenStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
521 | str.print(indent, "when "); |
---|
522 | boolean first = true; |
---|
523 | for (SrcIfWhenClause iwc : getSrcIfWhenClauses()) { |
---|
524 | if (!first) { |
---|
525 | str.print(indent, "elsewhen "); |
---|
526 | } |
---|
527 | first = false; |
---|
528 | p.print(iwc, str, p.indent(indent)); |
---|
529 | } |
---|
530 | str.println(indent, "end when;"); |
---|
531 | } |
---|
532 | |
---|
533 | public void SrcIfWhenClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
534 | p.print(getTest(), str, indent); |
---|
535 | str.println(" then"); |
---|
536 | for (SrcStatement s : getSrcStatements()) { |
---|
537 | p.print(s, str, p.indent(indent)); |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | public void SrcForStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
542 | str.print(indent, "for "); |
---|
543 | boolean first = true; |
---|
544 | for (SrcForIndex fi : getSrcForIndexs()) { |
---|
545 | if (!first) { |
---|
546 | str.print(","); |
---|
547 | } |
---|
548 | first = false; |
---|
549 | p.print(fi, str, indent); |
---|
550 | } |
---|
551 | str.println(" loop"); |
---|
552 | p.print(getSrcStatementList(), str, p.indent(indent)); |
---|
553 | str.println(indent, "end for;"); |
---|
554 | } |
---|
555 | |
---|
556 | public void SrcWhileStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
557 | str.print(indent, "while "); |
---|
558 | p.print(getTest(), str, indent); |
---|
559 | str.println(" loop"); |
---|
560 | for (SrcStatement s : getSrcWhileStmts()) |
---|
561 | p.print(s, str, p.indent(indent)); |
---|
562 | str.println(indent, "end while;"); |
---|
563 | } |
---|
564 | |
---|
565 | public void SrcForIndex.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
566 | str.print(getSrcForIndexDecl().name()); |
---|
567 | if (hasSrcExp()) { |
---|
568 | str.print(" in "); |
---|
569 | p.print(getSrcExp(), str, indent); |
---|
570 | } |
---|
571 | } |
---|
572 | |
---|
573 | // For debugging |
---|
574 | public void SrcLibNode.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
575 | str.formatln("%s%structured library '%s' at '%s'", indent, |
---|
576 | (getStructured() ? "S" : "Uns"), name(), dirName()); |
---|
577 | } |
---|
578 | |
---|
579 | syn boolean SrcComponentClause.isEnumComponentClause() = false; |
---|
580 | eq SrcEnumComponentClause.isEnumComponentClause() = true; |
---|
581 | |
---|
582 | public void SrcComponentClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
583 | if (getRedeclare()) { |
---|
584 | str.print("redeclare "); |
---|
585 | } |
---|
586 | if (getFinal()) { |
---|
587 | str.print("final "); |
---|
588 | } |
---|
589 | if (getInner()) { |
---|
590 | str.print("inner "); |
---|
591 | } |
---|
592 | if (getOuter()) { |
---|
593 | str.print("outer "); |
---|
594 | } |
---|
595 | if (getReplaceable()) { |
---|
596 | str.print("replaceable "); |
---|
597 | } |
---|
598 | if (hasSrcTypePrefixFlow()) { |
---|
599 | str.print(getSrcTypePrefixFlow(), " "); |
---|
600 | } |
---|
601 | if (hasSrcTypePrefixVariability()) { |
---|
602 | str.print(getSrcTypePrefixVariability(), " "); |
---|
603 | } |
---|
604 | if (hasSrcTypePrefixInputOutput()) { |
---|
605 | str.print(getSrcTypePrefixInputOutput(), " "); |
---|
606 | } |
---|
607 | |
---|
608 | p.print(getClassName(), str, indent); |
---|
609 | p.print(getTypeArraySubscriptsOpt(), str, indent); |
---|
610 | |
---|
611 | str.print(" "); |
---|
612 | if (isEnumComponentClause()) { |
---|
613 | str.print("("); |
---|
614 | if (hasSrcComponentDecl()) { |
---|
615 | getSrcComponentDecls().prettyPrintWithSep(p, str, indent, ", "); |
---|
616 | } else { |
---|
617 | str.print(":"); |
---|
618 | } |
---|
619 | str.print(")"); |
---|
620 | } else { |
---|
621 | getSrcComponentDecls().prettyPrintWithSep(p, str, indent, ", "); |
---|
622 | } |
---|
623 | |
---|
624 | p.print(getSrcConstrainingClauseOpt(), str, indent); |
---|
625 | } |
---|
626 | |
---|
627 | public void SrcComponentDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
628 | str.print(getName().getID()); |
---|
629 | p.print(getVarArraySubscriptsOpt(), str, indent); |
---|
630 | p.print(getSrcModificationOpt(), str, indent); |
---|
631 | p.print(getSrcConditionalAttributeOpt(), str, indent); |
---|
632 | } |
---|
633 | |
---|
634 | public void SrcConditionalAttribute.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
635 | str.print(" if "); |
---|
636 | p.print(getSrcExp(), str, indent); |
---|
637 | } |
---|
638 | |
---|
639 | public void SrcConstrainingClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
640 | str.print(" constrainedby ", getSrcAccess().name()); |
---|
641 | if (hasSrcClassModification()) { |
---|
642 | str.print(' '); |
---|
643 | p.print(getSrcClassModification(), str, indent); |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | public void SrcArraySubscripts.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
648 | if (getNumSrcSubscript()>0) { |
---|
649 | str.print("["); |
---|
650 | for (int i=0;i<getNumSrcSubscript();i++) { |
---|
651 | p.print(getSrcSubscript(i),str,indent); |
---|
652 | if (i<getNumSrcSubscript()-1) |
---|
653 | str.print(","); |
---|
654 | } |
---|
655 | str.print("]"); |
---|
656 | } |
---|
657 | } |
---|
658 | |
---|
659 | public void SrcColonSubscript.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
660 | str.print(":"); |
---|
661 | } |
---|
662 | |
---|
663 | public void SrcExpSubscript.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
664 | p.print(getSrcExp(),str,indent); |
---|
665 | } |
---|
666 | |
---|
667 | public void SrcRangeExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
668 | for (int i=0;i<getNumSrcExp();i++) { |
---|
669 | p.print(getSrcExp(i),str,indent); |
---|
670 | if (i<getNumSrcExp()-1) |
---|
671 | str.print(":"); |
---|
672 | } |
---|
673 | } |
---|
674 | |
---|
675 | public void SrcImportClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
676 | str.print(indent, "import "); |
---|
677 | prettyPrintPreName(p, str, indent); |
---|
678 | p.print(getPackageName(), str, indent); |
---|
679 | prettyPrintPostName(p, str, indent); |
---|
680 | p.print(getSrcComment(), str, indent); |
---|
681 | str.println(";"); |
---|
682 | } |
---|
683 | |
---|
684 | public void SrcImportClause.prettyPrintPreName(Printer p, CodeStream str, String indent) {} |
---|
685 | |
---|
686 | public void SrcImportClauseRename.prettyPrintPreName(Printer p, CodeStream str, String indent) { |
---|
687 | p.print(getSrcIdDecl(), str, indent); |
---|
688 | str.print(" = "); |
---|
689 | } |
---|
690 | |
---|
691 | public void SrcImportClause.prettyPrintPostName(Printer p, CodeStream str, String indent) {} |
---|
692 | |
---|
693 | public void SrcImportClauseUnqualified.prettyPrintPostName(Printer p, CodeStream str, String indent) { |
---|
694 | str.print(".*"); |
---|
695 | } |
---|
696 | |
---|
697 | public void SrcExtendsClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
698 | str.print(indent, "extends "); |
---|
699 | p.print(getSuper(), str, indent); |
---|
700 | p.print(getSrcClassModificationOpt(), str, indent); |
---|
701 | } |
---|
702 | |
---|
703 | public void SrcCompleteModification.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
704 | p.print(getSrcClassModification(),str,indent); |
---|
705 | if (hasSrcValueModification()) |
---|
706 | p.print(getSrcValueModification(),str,indent); |
---|
707 | } |
---|
708 | |
---|
709 | public void SrcValueModification.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
710 | str.print(" = "); |
---|
711 | p.print(getSrcExp(),str,indent); |
---|
712 | } |
---|
713 | |
---|
714 | public void SrcDummyModification.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
715 | str.print(" = "); |
---|
716 | p.print(myFExp(),str,indent); |
---|
717 | } |
---|
718 | |
---|
719 | public void SrcClassModification.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
720 | str.print("("); |
---|
721 | for (int i = 0; i < getNumSrcArgument(); i++) { |
---|
722 | p.print(getSrcArgument(i), str, indent); |
---|
723 | if (i < getNumSrcArgument() - 1) |
---|
724 | str.print(", "); |
---|
725 | } |
---|
726 | str.print(")"); |
---|
727 | } |
---|
728 | |
---|
729 | public void SrcElementModification.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
730 | if (getEach()) { |
---|
731 | str.print("each "); |
---|
732 | } |
---|
733 | if (getFinal()) { |
---|
734 | str.print("final "); |
---|
735 | } |
---|
736 | p.print(getName(), str, indent); |
---|
737 | if (hasSrcModification()) { |
---|
738 | p.print(getSrcModification(), str, indent); |
---|
739 | } |
---|
740 | } |
---|
741 | |
---|
742 | public void SrcComponentRedeclare.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
743 | if (getEach()) { |
---|
744 | str.print("each "); |
---|
745 | } |
---|
746 | if (getFinal()) { |
---|
747 | str.print("final "); |
---|
748 | } |
---|
749 | p.print(getSrcComponentClause(), str, indent); |
---|
750 | } |
---|
751 | |
---|
752 | public void SrcClassRedeclare.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
753 | if (getEach()) |
---|
754 | str.print("each "); |
---|
755 | if (getFinal()) |
---|
756 | str.print("final "); |
---|
757 | p.print(getSrcBaseClassDecl(), str, indent); |
---|
758 | } |
---|
759 | |
---|
760 | public void Opt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
761 | if (getNumChild()>0) |
---|
762 | p.print(getChild(0),str,indent); |
---|
763 | } |
---|
764 | |
---|
765 | public void SrcEquation.prettyPrint(Printer p,CodeStream str, String indent) { |
---|
766 | p.print(getLeft(),str,indent); |
---|
767 | str.print(" = "); |
---|
768 | p.print(getRight(),str,indent); |
---|
769 | } |
---|
770 | |
---|
771 | public void SrcConnectClause.prettyPrint(Printer p,CodeStream str, String indent) { |
---|
772 | str.print("connect("); |
---|
773 | p.print(getConnector1(),str,indent); |
---|
774 | str.print(","); |
---|
775 | p.print(getConnector2(),str,indent); |
---|
776 | str.print(")"); |
---|
777 | } |
---|
778 | |
---|
779 | public void SrcDotAddExp.prettyPrint(Printer p,CodeStream str, String indent) { |
---|
780 | p.print(getLeft(),str,indent); |
---|
781 | if(!(getRight() instanceof SrcNegExp)) |
---|
782 | str.print(op()); |
---|
783 | p.print(getRight(),str,indent); |
---|
784 | } |
---|
785 | |
---|
786 | public void SrcDotSubExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
787 | p.print(getLeft(),str,indent); |
---|
788 | str.print(op()); |
---|
789 | if (getRight().isAddOrSub()) { |
---|
790 | str.print("("); |
---|
791 | p.print(getRight(),str,indent); |
---|
792 | str.print(")"); |
---|
793 | } else |
---|
794 | p.print(getRight(),str,indent); |
---|
795 | } |
---|
796 | |
---|
797 | public void SrcDotMulExp.prettyPrint(Printer p,CodeStream str, String indent) { |
---|
798 | if (getLeft().isAddOrSub()) { |
---|
799 | str.print("("); |
---|
800 | p.print(getLeft(),str,indent); |
---|
801 | str.print(")"); |
---|
802 | } else |
---|
803 | p.print(getLeft(),str,indent); |
---|
804 | str.print(op()); |
---|
805 | if (getRight().isAddOrSub()) { |
---|
806 | str.print("("); |
---|
807 | p.print(getRight(),str,indent); |
---|
808 | str.print(")"); |
---|
809 | } else |
---|
810 | p.print(getRight(),str,indent); |
---|
811 | } |
---|
812 | |
---|
813 | public void SrcDotDivExp.prettyPrint(Printer p, CodeStream str, String indent){ |
---|
814 | if (getLeft().isAddOrSub()) { |
---|
815 | str.print("("); |
---|
816 | p.print(getLeft(),str,indent); |
---|
817 | str.print(")"); |
---|
818 | } else |
---|
819 | p.print(getLeft(),str,indent); |
---|
820 | str.print(op()); |
---|
821 | str.print("("); |
---|
822 | p.print(getRight(),str,indent); |
---|
823 | str.print(")"); |
---|
824 | } |
---|
825 | |
---|
826 | public void SrcDotPowExp.prettyPrint(Printer p, CodeStream str, String indent){ |
---|
827 | if (!(getLeft().isPrimary())) { |
---|
828 | str.print("("); |
---|
829 | p.print(getLeft(),str,indent); |
---|
830 | str.print(")"); |
---|
831 | } else |
---|
832 | p.print(getLeft(),str,indent); |
---|
833 | str.print(op()); |
---|
834 | if (!(getRight().isPrimary())) { |
---|
835 | str.print("("); |
---|
836 | p.print(getRight(),str,indent); |
---|
837 | str.print(")"); |
---|
838 | } else |
---|
839 | p.print(getRight(),str,indent); |
---|
840 | } |
---|
841 | |
---|
842 | public void SrcNegExp.prettyPrint(Printer p,CodeStream str, String indent){ |
---|
843 | str.print("-"); |
---|
844 | if (getSrcExp().isAddOrSub()) { |
---|
845 | str.print("("); |
---|
846 | p.print(getSrcExp(),str,indent); |
---|
847 | str.print(")"); |
---|
848 | } else |
---|
849 | p.print(getSrcExp(),str,indent); |
---|
850 | } |
---|
851 | |
---|
852 | public void SrcIfExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
853 | prettyPrintAsElseExp(p, str, indent); |
---|
854 | } |
---|
855 | |
---|
856 | public void SrcExp.prettyPrintAsElseExp(Printer p, CodeStream str, String indent) { |
---|
857 | str.print(' '); |
---|
858 | p.print(this, str, indent); |
---|
859 | } |
---|
860 | |
---|
861 | public void SrcIfExp.prettyPrintAsElseExp(Printer p, CodeStream str, String indent) { |
---|
862 | str.print("if "); |
---|
863 | p.print(getSrcIfExp(), str, indent); |
---|
864 | str.print(" then "); |
---|
865 | p.print(getThenExp(), str, indent); |
---|
866 | str.print(" else"); |
---|
867 | getElseExp().prettyPrintAsElseExp(p, str, indent); |
---|
868 | } |
---|
869 | |
---|
870 | public void SrcRealLitExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
871 | str.print(getUNSIGNED_NUMBER()); |
---|
872 | } |
---|
873 | |
---|
874 | public void SrcIntegerLitExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
875 | str.print(getUNSIGNED_INTEGER()); |
---|
876 | } |
---|
877 | |
---|
878 | public void SrcTimeExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
879 | str.print("time"); |
---|
880 | } |
---|
881 | |
---|
882 | public void SrcEndExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
883 | str.print("end"); |
---|
884 | } |
---|
885 | |
---|
886 | public void SrcFunctionCall.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
887 | p.print(getName(),str,indent); |
---|
888 | str.print("("); |
---|
889 | p.print(getSrcFunctionArgumentsOpt(),str,indent); |
---|
890 | str.print(")"); |
---|
891 | } |
---|
892 | |
---|
893 | public void SrcIterExp.prettyPrint(Printer p, CodeStream str, String ident) { |
---|
894 | getSrcExp().prettyPrint(p,str,ident); |
---|
895 | str.print(" for "); |
---|
896 | for (int i = 1; i < getNumChild(); i++) { |
---|
897 | getChild(i).prettyPrint(p, str, ident); |
---|
898 | } |
---|
899 | } |
---|
900 | |
---|
901 | public void SrcFunctionArguments.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
902 | for (int i = 0; i < getNumSrcExp(); i++) { |
---|
903 | p.print(getSrcExp(i), str, indent); |
---|
904 | if (i < getNumSrcExp() + getNumSrcNamedArgument() - 1) { |
---|
905 | str.print(","); |
---|
906 | } |
---|
907 | } |
---|
908 | for (int i = 0; i < getNumSrcNamedArgument(); i++) { |
---|
909 | p.print(getSrcNamedArgument(i), str, indent); |
---|
910 | if (i < getNumSrcNamedArgument() - 1) { |
---|
911 | str.print(","); |
---|
912 | } |
---|
913 | } |
---|
914 | } |
---|
915 | |
---|
916 | public void SrcNamedArgument.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
917 | p.print(getName(), str, indent); |
---|
918 | str.print("="); |
---|
919 | getSrcExp().prettyPrint(p, str, indent); |
---|
920 | } |
---|
921 | |
---|
922 | public void SrcIdDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
923 | str.print(getID()); |
---|
924 | } |
---|
925 | |
---|
926 | public void SrcEndDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
927 | str.println(indent, "end ", getEndID(), ";"); |
---|
928 | } |
---|
929 | |
---|
930 | public void SrcNamedAccess.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
931 | str.print(getID()); |
---|
932 | } |
---|
933 | |
---|
934 | public void SrcArrayAccess.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
935 | str.print(getID()); |
---|
936 | getSrcArraySubscripts().prettyPrint(p, str, indent); |
---|
937 | } |
---|
938 | |
---|
939 | public void SrcDot.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
940 | getSrcAccesss().prettyPrintWithSep(p, str, indent, "."); |
---|
941 | } |
---|
942 | |
---|
943 | public void SrcGlobalAccess.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
944 | str.print("."); |
---|
945 | p.print(getSrcAccess(),str,indent); |
---|
946 | } |
---|
947 | |
---|
948 | public void SrcStringLitExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
949 | str.print("\"", getSTRING(), "\""); |
---|
950 | } |
---|
951 | |
---|
952 | public void SrcBooleanLitExpTrue.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
953 | str.print("true"); |
---|
954 | } |
---|
955 | |
---|
956 | public void SrcBooleanLitExpFalse.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
957 | str.print("false"); |
---|
958 | } |
---|
959 | |
---|
960 | public void SrcArrayConstructor.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
961 | str.print("{"); |
---|
962 | p.print(getSrcFunctionArguments(),str,indent); |
---|
963 | str.print("}"); |
---|
964 | } |
---|
965 | |
---|
966 | public void SrcMatrix.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
967 | str.print("["); |
---|
968 | getRows().prettyPrintWithSep(p, str, indent, "; "); |
---|
969 | str.print("]"); |
---|
970 | } |
---|
971 | |
---|
972 | public void SrcMatrixRow.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
973 | getSrcExps().prettyPrintWithSep(p, str, indent, ", "); |
---|
974 | } |
---|
975 | |
---|
976 | syn boolean SrcExp.isAddOrSub() = false; |
---|
977 | eq SrcDotAddExp.isAddOrSub() = true; |
---|
978 | eq SrcDotSubExp.isAddOrSub() = true; |
---|
979 | syn boolean SrcExp.isPrimary() = false; |
---|
980 | eq SrcAccessExp.isPrimary() = true; |
---|
981 | eq SrcRealLitExp.isPrimary() = true; |
---|
982 | |
---|
983 | public void SrcLogBinExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
984 | p.print(getLeft(),str,indent); |
---|
985 | str.print(op()); |
---|
986 | p.print(getRight(),str,indent); |
---|
987 | } |
---|
988 | |
---|
989 | syn String SrcBinExp.op(); |
---|
990 | eq SrcLtExp.op() = "<"; |
---|
991 | eq SrcLeqExp.op() = "<="; |
---|
992 | eq SrcGtExp .op() = ">"; |
---|
993 | eq SrcGeqExp.op() = ">="; |
---|
994 | eq SrcEqExp.op() = "=="; |
---|
995 | eq SrcNeqExp.op() = "<>"; |
---|
996 | eq SrcOrExp.op() = " or "; |
---|
997 | eq SrcAndExp.op() = " and "; |
---|
998 | eq SrcAddExp.op() = "+"; |
---|
999 | eq SrcSubExp.op() = "-"; |
---|
1000 | eq SrcMulExp.op() = "*"; |
---|
1001 | eq SrcDivExp.op() = "/"; |
---|
1002 | eq SrcPowExp.op() = "^"; |
---|
1003 | eq SrcDotAddExp.op() = ".+"; |
---|
1004 | eq SrcDotSubExp.op() = ".-"; |
---|
1005 | eq SrcDotMulExp.op() = ".*"; |
---|
1006 | eq SrcDotDivExp.op() = "./"; |
---|
1007 | eq SrcDotPowExp.op() = ".^"; |
---|
1008 | |
---|
1009 | public void SrcNotExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1010 | str.print("not "); |
---|
1011 | p.print(getSrcExp(),str,indent); |
---|
1012 | } |
---|
1013 | |
---|
1014 | |
---|
1015 | syn String SrcTypePrefixFlow.toString(); |
---|
1016 | eq SrcFlow.toString() = "flow"; |
---|
1017 | eq SrcStream.toString() = "stream"; |
---|
1018 | syn String SrcTypePrefixInputOutput.toString(); |
---|
1019 | eq SrcInput.toString() = "input"; |
---|
1020 | eq SrcOutput.toString() = "output"; |
---|
1021 | syn String SrcTypePrefixVariability.toString(); |
---|
1022 | eq SrcParameter.toString() = "parameter"; |
---|
1023 | eq SrcDiscrete.toString() = "discrete"; |
---|
1024 | eq SrcConstant.toString() = "constant"; |
---|
1025 | eq SrcContinuous.toString() = ""; |
---|
1026 | |
---|
1027 | syn String FType.toString() = isArray() ? name() + size() : name(); |
---|
1028 | |
---|
1029 | eq FFunctionType.toString() { |
---|
1030 | StringBuilder sb = new StringBuilder(); |
---|
1031 | sb.append("(("); |
---|
1032 | sb.append(getOutputs().toString()); |
---|
1033 | sb.append(") = "); |
---|
1034 | sb.append(getName()); |
---|
1035 | sb.append("("); |
---|
1036 | sb.append(getInputs().toString()); |
---|
1037 | sb.append("))"); |
---|
1038 | if (ndims() > 0) { |
---|
1039 | sb.append(size()); |
---|
1040 | } |
---|
1041 | return sb.toString(); |
---|
1042 | } |
---|
1043 | |
---|
1044 | syn String FRecordComponentType.toString() = getFType() + " " + getName(); |
---|
1045 | |
---|
1046 | public void FRecordComponentType.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1047 | str.print(getFType(), " ", getName()); |
---|
1048 | } |
---|
1049 | |
---|
1050 | } |
---|
1051 | |
---|
1052 | aspect TypeStructurePrint { |
---|
1053 | |
---|
1054 | /** |
---|
1055 | * Returns what is printed by {@link #printStructure(CodeStream)} as a String. |
---|
1056 | */ |
---|
1057 | public String FType.printStructure() { |
---|
1058 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
---|
1059 | CodeStream str = new NotNullCodeStream(os); |
---|
1060 | printStructure(str); |
---|
1061 | return os.toString(); |
---|
1062 | } |
---|
1063 | |
---|
1064 | /** |
---|
1065 | * Prints a string representation of the structure of this type. The |
---|
1066 | * representation for scalar types is its name. The representation for composite |
---|
1067 | * types its name and size, and the name and size of any components. This can be |
---|
1068 | * used to provide more informative error messages for composite types. |
---|
1069 | * |
---|
1070 | * @param str |
---|
1071 | * the stream that is printed to. |
---|
1072 | */ |
---|
1073 | public void FType.printStructure(CodeStream str) { |
---|
1074 | str.print(toString()); |
---|
1075 | } |
---|
1076 | |
---|
1077 | public void FRecordType.printStructure(CodeStream str) { |
---|
1078 | str.print(name()); |
---|
1079 | if (hasComponent()) { |
---|
1080 | str.print("("); |
---|
1081 | String sep = ""; |
---|
1082 | for (FRecordComponentType frct : getComponents()) { |
---|
1083 | str.print(sep); |
---|
1084 | frct.printStructure(str); |
---|
1085 | sep = ", "; |
---|
1086 | } |
---|
1087 | str.print(")"); |
---|
1088 | } |
---|
1089 | if (ndims() > 0) { |
---|
1090 | str.print(size()); |
---|
1091 | } |
---|
1092 | } |
---|
1093 | |
---|
1094 | public void FRecordComponentType.printStructure(CodeStream str) { |
---|
1095 | str.print(getFType().toString()); |
---|
1096 | } |
---|
1097 | |
---|
1098 | } |
---|
1099 | |
---|
1100 | aspect FlatPrettyPrint { |
---|
1101 | |
---|
1102 | public void FClass.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1103 | String nextInd = p.indent(indent); |
---|
1104 | str.formatln("%sfclass %s", indent, name()); |
---|
1105 | ArrayList<FVariable> protectedVars = new ArrayList<FVariable>(); |
---|
1106 | for (FVariable fv : getFVariables()) { |
---|
1107 | if (!fv.isDerivativeVariable() && !fv.isPreVariable() && |
---|
1108 | !fv.getVisibilityType().isRuntimeOptionVisibility()) { |
---|
1109 | if (fv.isProtected()) { |
---|
1110 | protectedVars.add(fv); |
---|
1111 | } else { |
---|
1112 | p.print(fv, str, nextInd); |
---|
1113 | str.println(";"); |
---|
1114 | } |
---|
1115 | } |
---|
1116 | } |
---|
1117 | if (!protectedVars.isEmpty()) { |
---|
1118 | str.println(indent, "protected"); |
---|
1119 | for (FVariable fv : protectedVars) { |
---|
1120 | p.print(fv, str, nextInd); |
---|
1121 | str.println(";"); |
---|
1122 | } |
---|
1123 | } |
---|
1124 | if (getNumFGlobalVariable() > 0) { |
---|
1125 | str.println(indent, "global variables"); |
---|
1126 | for (FVariable fv : getFGlobalVariables()) { |
---|
1127 | p.print(fv, str, nextInd); |
---|
1128 | str.println(";"); |
---|
1129 | } |
---|
1130 | } |
---|
1131 | if (getNumFInitialEquation() > 0) { |
---|
1132 | str.println(indent, "initial equation"); |
---|
1133 | } |
---|
1134 | getFInitialEquations().prettyPrintWithFix(p, str, nextInd, "", ";" + str.getLineEnder()); |
---|
1135 | |
---|
1136 | if (getNumParameterEquation() > 0) { |
---|
1137 | str.println(indent, "parameter equation"); |
---|
1138 | } |
---|
1139 | getParameterEquations().prettyPrintWithFix(p, str, nextInd, "", ";" + str.getLineEnder()); |
---|
1140 | |
---|
1141 | boolean wroteEquation = false; |
---|
1142 | for (FAbstractEquation e : getFAbstractEquations()) { |
---|
1143 | if (e instanceof FAlgorithm) { |
---|
1144 | p.print(e, str, indent); |
---|
1145 | wroteEquation = false; |
---|
1146 | } else { |
---|
1147 | if (!e.isIgnored()) { |
---|
1148 | if (!wroteEquation) { |
---|
1149 | str.println(indent, "equation"); |
---|
1150 | wroteEquation = true; |
---|
1151 | } |
---|
1152 | p.print(e, str, nextInd); |
---|
1153 | str.println(";"); |
---|
1154 | } |
---|
1155 | } |
---|
1156 | } |
---|
1157 | |
---|
1158 | if (getNumFFunctionDecl() > 0 || getNumFRecordDecl() > 0 || |
---|
1159 | getNumFEnumDecl() > 0 || getNumFDerivedType() > 0) { |
---|
1160 | str.println(); |
---|
1161 | str.formatln("%spublic", indent); |
---|
1162 | p.print(getFFunctionDecls(), str, nextInd); |
---|
1163 | p.print(getFRecordDecls(), str, nextInd); |
---|
1164 | p.print(getFEnumDecls(), str, nextInd); |
---|
1165 | p.print(getFDerivedTypes(), str, nextInd); |
---|
1166 | } |
---|
1167 | |
---|
1168 | getFAttributeList().prettyPrintFAnnotationAttributeList(str, p, indent, ";" + str.getLineEnder()); |
---|
1169 | |
---|
1170 | str.println(indent, "end ", name(), ";"); |
---|
1171 | } |
---|
1172 | |
---|
1173 | syn String FVariable.prettyPrintType() = |
---|
1174 | getDerivedType().isEmpty() ? type().scalarType().toString() : getDerivedType(); |
---|
1175 | syn String FAbstractVariable.displayName() = name(); |
---|
1176 | eq FVariable.displayName() = getFAccess().toString(); |
---|
1177 | eq FDerivativeVariable.displayName() = name(); |
---|
1178 | eq FPreBooleanVariable.displayName() = name(); |
---|
1179 | eq FPreEnumVariable.displayName() = name(); |
---|
1180 | eq FPreIntegerVariable.displayName() = name(); |
---|
1181 | eq FPreRealVariable.displayName() = name(); |
---|
1182 | eq FPreStringVariable.displayName() = name(); |
---|
1183 | eq FDummyDerivativeVariable.displayName() = derPrefixName(); |
---|
1184 | eq FDynamicDerivativeVariable.displayName() = dynDerName(); |
---|
1185 | |
---|
1186 | public void FVariable.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1187 | str.print(indent); |
---|
1188 | |
---|
1189 | str.print(getTypePrefixVariability()); |
---|
1190 | |
---|
1191 | if (!getTypePrefixInputOutput().isNone()) { |
---|
1192 | str.print(getTypePrefixInputOutput(), " "); |
---|
1193 | } |
---|
1194 | |
---|
1195 | str.print(prettyPrintType(), " ", displayName()); |
---|
1196 | |
---|
1197 | getFAttributeList().prettyPrintFAttributeList(str, p); |
---|
1198 | |
---|
1199 | if (hasBindingExp()) { |
---|
1200 | str.print(" = "); |
---|
1201 | FExp bindingExp = getBindingExp(); |
---|
1202 | p.print(bindingExp, str, indent); |
---|
1203 | |
---|
1204 | } |
---|
1205 | |
---|
1206 | p.print(getFStringCommentOpt(), str, indent); |
---|
1207 | |
---|
1208 | getFAttributeList().prettyPrintFAnnotationAttributeList(str, p); |
---|
1209 | |
---|
1210 | if (isIndependentParameter() && hasBindingExp()) { |
---|
1211 | str.print(" /* "); |
---|
1212 | try { |
---|
1213 | str.print(getBindingExp().ceval()); |
---|
1214 | } catch (ConstantEvaluationException e){ |
---|
1215 | str.print("evaluation error"); |
---|
1216 | } |
---|
1217 | str.print(" */"); |
---|
1218 | } |
---|
1219 | } |
---|
1220 | |
---|
1221 | public void FVariable.printFAttributes(CodeStream str, String ... attributes) { |
---|
1222 | boolean first = true; |
---|
1223 | for (String attribute : attributes) { |
---|
1224 | if (attributeSet(attribute)) { |
---|
1225 | if (!first) { |
---|
1226 | str.print(','); |
---|
1227 | } |
---|
1228 | first = false; |
---|
1229 | str.print(attribute, "=", attributeExp(attribute)); |
---|
1230 | } |
---|
1231 | } |
---|
1232 | } |
---|
1233 | |
---|
1234 | public void List.prettyPrintFAttributeList(CodeStream str, Printer p) { |
---|
1235 | prettyPrintFAttributeList(str, p, "", ""); |
---|
1236 | } |
---|
1237 | |
---|
1238 | public void List.prettyPrintFAnnotationAttributeList(CodeStream str, Printer p) { |
---|
1239 | prettyPrintFAnnotationAttributeList(str, p, ""); |
---|
1240 | } |
---|
1241 | |
---|
1242 | public void List.prettyPrintFAnnotationAttributeList(CodeStream str, Printer p, String extraEnd) { |
---|
1243 | prettyPrintFAnnotationAttributeList(str, p, " ", extraEnd); |
---|
1244 | } |
---|
1245 | |
---|
1246 | public void List.prettyPrintFAnnotationAttributeList(CodeStream str, Printer p, String extraStart, String extraEnd) { |
---|
1247 | prettyPrintFAttributeList(str, p.annotationPrinter(), extraStart + "annotation", extraEnd); |
---|
1248 | } |
---|
1249 | |
---|
1250 | public void List.prettyPrintFAttributeList(CodeStream str, Printer p, String extraStart, String extraEnd) { |
---|
1251 | boolean firstAttr = true; |
---|
1252 | for (ASTNode astNode : this) { |
---|
1253 | FAttribute attr = (FAttribute)astNode; |
---|
1254 | if (attr.shouldPrettyPrint(p)) { |
---|
1255 | if (!firstAttr) |
---|
1256 | str.print(","); |
---|
1257 | else |
---|
1258 | str.print(extraStart, "("); |
---|
1259 | firstAttr = false; |
---|
1260 | p.print(attr, str, ""); |
---|
1261 | } |
---|
1262 | } |
---|
1263 | if (!firstAttr) { |
---|
1264 | str.print(")", extraEnd); |
---|
1265 | } |
---|
1266 | } |
---|
1267 | |
---|
1268 | public boolean FAttribute.shouldPrettyPrint(Printer p) { |
---|
1269 | if (p.inAnnotation()) |
---|
1270 | return isAnnotation(); |
---|
1271 | return getAttributeSet() && (isModification() || isInternal()); |
---|
1272 | |
---|
1273 | } |
---|
1274 | |
---|
1275 | public void FAttribute.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1276 | |
---|
1277 | if (hasFEach()) |
---|
1278 | str.print("each "); |
---|
1279 | if (hasFFinal()) |
---|
1280 | str.print("final "); |
---|
1281 | str.print(getName().name()); |
---|
1282 | getFAttributeList().prettyPrintFAttributeList(str, p); |
---|
1283 | if (hasValue()) { |
---|
1284 | str.print(" = "); |
---|
1285 | p.print(getValue(),str,""); |
---|
1286 | } |
---|
1287 | } |
---|
1288 | |
---|
1289 | public void FFunctionDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1290 | str.println(indent, "function ", name()); |
---|
1291 | getFFunctionVariables().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1292 | p.print(getFAlgorithm(), str, indent); |
---|
1293 | getFAttributeList().prettyPrintFAnnotationAttributeList(str, p, indent, ";" + str.getLineEnder()); |
---|
1294 | str.println(indent, "end ", name(), ";"); |
---|
1295 | str.println(); |
---|
1296 | } |
---|
1297 | |
---|
1298 | public void FRecordDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1299 | str.println(indent, "record ", name()); |
---|
1300 | getFVariables().prettyPrintWithFix(p, str, p.indent(indent), "", ";" + str.getLineEnder()); |
---|
1301 | str.println(indent, "end ", name(), ";"); |
---|
1302 | str.println(); |
---|
1303 | } |
---|
1304 | |
---|
1305 | public void FEnumDecl.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1306 | str.print(indent, "type ", getName().name(), " = enumeration("); |
---|
1307 | p.print(getFEnumSpecification(), str, indent); |
---|
1308 | str.print(")"); |
---|
1309 | FDerivedType t = myFDerivedType(); |
---|
1310 | if (t != null && t.getFAttributes().getNumChild() > 0) { |
---|
1311 | str.print("("); |
---|
1312 | t.getFAttributes().prettyPrintWithSep(p, str, indent, ", "); |
---|
1313 | str.print(")"); |
---|
1314 | } |
---|
1315 | str.println(";"); |
---|
1316 | str.println(); |
---|
1317 | } |
---|
1318 | |
---|
1319 | public void FDerivedType.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1320 | if (!getBaseType().isEnum()) { |
---|
1321 | str.print(indent, "type ", getName(), " = ", getBaseType()); |
---|
1322 | getFAttributeList().prettyPrintFAttributeList(str, p); |
---|
1323 | str.println(";"); |
---|
1324 | } |
---|
1325 | } |
---|
1326 | |
---|
1327 | public abstract void FEnumSpecification.prettyPrint(Printer p, CodeStream str, String indent); |
---|
1328 | |
---|
1329 | public void FEnumLiteralList.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1330 | getFEnumLiterals().prettyPrintWithSep(p, str, indent, ", "); |
---|
1331 | } |
---|
1332 | |
---|
1333 | public void FEnumLiteral.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1334 | p.print(getName(), str, indent); |
---|
1335 | p.print(getFStringCommentOpt(), str, indent); |
---|
1336 | } |
---|
1337 | |
---|
1338 | public void InstEnumLiteral.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1339 | str.print(indent, name()); |
---|
1340 | SrcStringComment comment = myStringComment(); |
---|
1341 | if (comment != null) { |
---|
1342 | comment.prettyPrint(p, str, indent); |
---|
1343 | } |
---|
1344 | } |
---|
1345 | |
---|
1346 | public void FStringComment.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1347 | str.print(" \"", getComment(), "\""); |
---|
1348 | } |
---|
1349 | |
---|
1350 | public void FFunctionVariable.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1351 | if (!getTypePrefixInputOutput().isNone()) { |
---|
1352 | str.print(getTypePrefixInputOutput(), " "); |
---|
1353 | } |
---|
1354 | str.print(getType().scalarType()); |
---|
1355 | if (isArray()) { |
---|
1356 | str.print("["); |
---|
1357 | for (int i = 0; i < ndims(); i++) { |
---|
1358 | str.print(":"); |
---|
1359 | if (i < ndims() - 1) { |
---|
1360 | str.print(","); |
---|
1361 | } |
---|
1362 | } |
---|
1363 | str.print("]"); |
---|
1364 | } |
---|
1365 | str.print(" ", name()); |
---|
1366 | getFAttributeList().prettyPrintFAttributeList(str, p); |
---|
1367 | if (hasBindingExp()) { |
---|
1368 | str.print(" := "); |
---|
1369 | p.print(getBindingExp(), str, indent); |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | public void FAccessPart.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1374 | str.print(getName()); |
---|
1375 | if (hasFArraySubscripts()) |
---|
1376 | p.print(getFArraySubscripts(),str,indent); |
---|
1377 | } |
---|
1378 | |
---|
1379 | public void FAccess.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1380 | } |
---|
1381 | |
---|
1382 | public void FAccessString.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1383 | str.print(getName()); |
---|
1384 | } |
---|
1385 | |
---|
1386 | public void FAccessFull.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1387 | for (int i = 0, n = getNumFAccessPart(); i < n; i++) { |
---|
1388 | p.print(getFAccessPart(i), str, indent); |
---|
1389 | if (i < n - 1) |
---|
1390 | str.print("."); |
---|
1391 | } |
---|
1392 | } |
---|
1393 | |
---|
1394 | public void FArraySubscripts.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1395 | if (numSubscript()>0) { |
---|
1396 | str.print("["); |
---|
1397 | for (int i=0;i<numSubscript();i++) { |
---|
1398 | subscript(i).prettyPrint(p, str, indent); |
---|
1399 | if (i<numSubscript()-1) |
---|
1400 | str.print(","); |
---|
1401 | } |
---|
1402 | str.print("]"); |
---|
1403 | } |
---|
1404 | } |
---|
1405 | |
---|
1406 | public void FColonSubscript.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1407 | str.print(":"); |
---|
1408 | } |
---|
1409 | |
---|
1410 | public void FIntegerSubscript.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1411 | str.print(getValue()); |
---|
1412 | } |
---|
1413 | |
---|
1414 | public void FExpSubscript.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1415 | p.print(getFExp(),str,indent); |
---|
1416 | } |
---|
1417 | |
---|
1418 | public void IntegerSubscript.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1419 | str.print(value); |
---|
1420 | } |
---|
1421 | |
---|
1422 | public String IntegerSubscript.prettyPrint(String indent) { |
---|
1423 | return String.valueOf(value); |
---|
1424 | } |
---|
1425 | |
---|
1426 | protected void FRangeExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1427 | for (int i=0;i<getNumFExp();i++) { |
---|
1428 | p.print(getFExp(i),str,indent); |
---|
1429 | if (i<getNumFExp()-1) |
---|
1430 | str.print(":"); |
---|
1431 | } |
---|
1432 | } |
---|
1433 | |
---|
1434 | |
---|
1435 | public void FEquation.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1436 | str.print(indent); |
---|
1437 | p.print(getLeft(),str,indent); |
---|
1438 | str.print(" = "); |
---|
1439 | p.print(getRight(),str,indent); |
---|
1440 | getFAttributeList().prettyPrintFAnnotationAttributeList(str, p); |
---|
1441 | } |
---|
1442 | |
---|
1443 | |
---|
1444 | public void FIfWhenElseEquation.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1445 | str.print(indent); |
---|
1446 | if (isElse()) |
---|
1447 | str.print("else"); |
---|
1448 | prettyPrintHead(p, str, indent); |
---|
1449 | getFAbstractEquations().prettyPrintWithFix(p, str, p.indent(indent), "", ";" + str.getLineEnder()); |
---|
1450 | prettyPrintTail(p, str, indent); |
---|
1451 | } |
---|
1452 | |
---|
1453 | protected void FIfWhenElseEquation.prettyPrintHead(Printer p, CodeStream str, String indent) { |
---|
1454 | str.println(); |
---|
1455 | } |
---|
1456 | |
---|
1457 | protected void FIfWhenElseEquation.prettyPrintTail(Printer p, CodeStream str, String indent) { |
---|
1458 | } |
---|
1459 | |
---|
1460 | protected void FIfWhenEquation.prettyPrintHead(Printer p, CodeStream str, String indent) { |
---|
1461 | str.print(ifWhenType(), " "); |
---|
1462 | p.print(getTest(), str, indent); |
---|
1463 | str.println(" then"); |
---|
1464 | } |
---|
1465 | |
---|
1466 | protected void FIfWhenEquation.prettyPrintTail(Printer p, CodeStream str, String indent) { |
---|
1467 | if (hasElse()) |
---|
1468 | p.print(getElse(), str, indent); |
---|
1469 | if (!isElse()) { |
---|
1470 | str.print(indent, "end ", ifWhenType()); |
---|
1471 | } |
---|
1472 | } |
---|
1473 | |
---|
1474 | syn String FIfWhenEquation.ifWhenType(); |
---|
1475 | eq FIfEquation.ifWhenType() = "if"; |
---|
1476 | eq FWhenEquation.ifWhenType() = "when"; |
---|
1477 | |
---|
1478 | |
---|
1479 | public void FConnectClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1480 | str.print(indent, "connect("); |
---|
1481 | p.print(getConnector1(), str, indent); |
---|
1482 | str.print(", "); |
---|
1483 | p.print(getConnector2(), str, indent); |
---|
1484 | str.print(")"); |
---|
1485 | } |
---|
1486 | |
---|
1487 | public void FFunctionCallEquation.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1488 | str.print(indent); |
---|
1489 | if (getNumLeft() > 0) { |
---|
1490 | str.print("("); |
---|
1491 | getLefts().prettyPrintWithSep(p, str, indent, ", "); |
---|
1492 | str.print(") = "); |
---|
1493 | } |
---|
1494 | p.print(getCall(), str, indent); |
---|
1495 | getFAttributeList().prettyPrintFAnnotationAttributeList(str, p); |
---|
1496 | } |
---|
1497 | |
---|
1498 | public void FAlgorithm.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1499 | str.print(indent); |
---|
1500 | str.println("algorithm"); |
---|
1501 | getFStatements().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1502 | } |
---|
1503 | |
---|
1504 | public void FAssignStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1505 | p.print(getLeft(), str, indent); |
---|
1506 | str.print(" := "); |
---|
1507 | p.print(getRight(), str, indent); |
---|
1508 | } |
---|
1509 | |
---|
1510 | public void FFunctionCallStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1511 | if (getNumLeft() > 0) { |
---|
1512 | str.print("("); |
---|
1513 | getLefts().prettyPrintWithSep(p, str, indent, ", "); |
---|
1514 | str.print(") := "); |
---|
1515 | } |
---|
1516 | p.print(getCall(), str, indent); |
---|
1517 | } |
---|
1518 | |
---|
1519 | public void FBreakStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1520 | str.print("break"); |
---|
1521 | } |
---|
1522 | |
---|
1523 | public void FReturnStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1524 | str.print("return"); |
---|
1525 | } |
---|
1526 | |
---|
1527 | public void FIfWhenStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1528 | getFIfWhenClauses().prettyPrintWithSep(p, str, indent, indent + "else"); |
---|
1529 | prettyPrintElse(p, str, indent); |
---|
1530 | str.print(indent, "end ", getKeyword()); |
---|
1531 | } |
---|
1532 | |
---|
1533 | protected void FIfWhenStmt.prettyPrintElse(Printer p, CodeStream str, String indent) {} |
---|
1534 | |
---|
1535 | protected void FIfStmt.prettyPrintElse(Printer p, CodeStream str, String indent) { |
---|
1536 | if (getNumElseStmt() > 0) { |
---|
1537 | str.println(indent, "else"); |
---|
1538 | getElseStmts().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1539 | } |
---|
1540 | } |
---|
1541 | |
---|
1542 | public void FIfWhenClause.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1543 | str.print(getKeyword(), " "); |
---|
1544 | p.print(getTest(), str, indent); |
---|
1545 | str.println(" then"); |
---|
1546 | getFStatements().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1547 | } |
---|
1548 | |
---|
1549 | syn String FIfWhenStmt.getKeyword() = null; |
---|
1550 | eq FIfStmt.getKeyword() = "if"; |
---|
1551 | eq FWhenStmt.getKeyword() = "when"; |
---|
1552 | inh String FIfWhenClause.getKeyword(); |
---|
1553 | eq FIfWhenStmt.getFIfWhenClause(int i).getKeyword() = getKeyword(); |
---|
1554 | |
---|
1555 | public void FForStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1556 | str.print("for "); |
---|
1557 | p.print(getIndex(), str, indent); |
---|
1558 | str.println(" loop"); |
---|
1559 | getForStmts().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1560 | str.print(indent, "end for"); |
---|
1561 | } |
---|
1562 | |
---|
1563 | public void InstForStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1564 | str.print("for "); |
---|
1565 | getInstForIndexList().prettyPrintWithSep(p, str, indent, ", "); |
---|
1566 | str.println(" loop"); |
---|
1567 | getForStmts().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1568 | str.print(indent, "end for"); |
---|
1569 | } |
---|
1570 | |
---|
1571 | public void FWhileStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1572 | str.print("while "); |
---|
1573 | p.print(getTest(), str, indent); |
---|
1574 | str.println(" loop"); |
---|
1575 | getWhileStmts().prettyPrintWithIndent(p, str, p.indent(indent), ";"); |
---|
1576 | str.print(indent, "end while"); |
---|
1577 | } |
---|
1578 | |
---|
1579 | public void FExternalStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1580 | str.print("external "); |
---|
1581 | p.print(getFExternalLanguage(), str, indent); |
---|
1582 | str.print(" "); |
---|
1583 | if (hasReturnVar()) { |
---|
1584 | p.print(getReturnVar(), str, indent); |
---|
1585 | str.print(" = "); |
---|
1586 | } |
---|
1587 | str.print(getName(), "("); |
---|
1588 | getArgs().prettyPrintWithSep(p, str, indent, ", "); |
---|
1589 | str.print(")"); |
---|
1590 | } |
---|
1591 | |
---|
1592 | public void FInitArrayStmt.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1593 | str.print("init "); |
---|
1594 | p.print(getFAccessExp(), str, indent); |
---|
1595 | str.print(" as "); |
---|
1596 | str.print(type()); |
---|
1597 | } |
---|
1598 | |
---|
1599 | public void FExternalLanguage.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1600 | str.print("\"", getLanguage(), "\""); |
---|
1601 | } |
---|
1602 | |
---|
1603 | public void InstExternal.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1604 | str.print("external "); |
---|
1605 | p.print(getFExternalLanguage(), str, indent); |
---|
1606 | str.print(" "); |
---|
1607 | p.print(getInstExternalCall(), str, indent); |
---|
1608 | } |
---|
1609 | |
---|
1610 | public void InstExternalCall.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1611 | if (hasReturnVar()) { |
---|
1612 | p.print(getReturnVar(), str, indent); |
---|
1613 | str.print(" = "); |
---|
1614 | } |
---|
1615 | str.print(getName(), "("); |
---|
1616 | getArgs().prettyPrintWithSep(p, str, indent, ", "); |
---|
1617 | str.print(")"); |
---|
1618 | } |
---|
1619 | |
---|
1620 | syn String FExternalLanguage.getLanguage() = null; |
---|
1621 | eq FCExternalLanguage.getLanguage() = LANGUAGE_STRING; |
---|
1622 | eq FFortran77ExternalLanguage.getLanguage() = LANGUAGE_STRING; |
---|
1623 | eq FBuiltinExternalLanguage.getLanguage() = LANGUAGE_STRING; |
---|
1624 | |
---|
1625 | |
---|
1626 | public final void FExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1627 | boolean addParenthesis = addParenthesis(parentPrecedence()); |
---|
1628 | if (addParenthesis) |
---|
1629 | str.print('('); |
---|
1630 | prettyPrintExp(p, str, indent); |
---|
1631 | if (addParenthesis) |
---|
1632 | str.print(')'); |
---|
1633 | } |
---|
1634 | |
---|
1635 | protected abstract void FExp.prettyPrintExp(Printer p, CodeStream str, String indent); |
---|
1636 | |
---|
1637 | protected void FColonSizeExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1638 | str.print(":"); |
---|
1639 | } |
---|
1640 | |
---|
1641 | protected void FNegExp.prettyPrintExp(Printer p,CodeStream str, String indent){ |
---|
1642 | str.print("- "); |
---|
1643 | p.print(getFExp(),str,indent); |
---|
1644 | } |
---|
1645 | |
---|
1646 | protected void FMatrix.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1647 | str.print("["); |
---|
1648 | getFExps().prettyPrintWithSep(p, str, indent, "; "); |
---|
1649 | str.print("]"); |
---|
1650 | } |
---|
1651 | |
---|
1652 | protected void FMatrixRow.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1653 | getFExps().prettyPrintWithSep(p, str, indent, ", "); |
---|
1654 | } |
---|
1655 | |
---|
1656 | protected void FBinExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1657 | p.print(getLeft(),str,indent); |
---|
1658 | str.print(p.op(this)); |
---|
1659 | p.print(getRight(),str,indent); |
---|
1660 | } |
---|
1661 | |
---|
1662 | syn String FBinExp.op(); |
---|
1663 | eq FLtExp.op() = " < "; |
---|
1664 | eq FLeqExp.op() = " <= "; |
---|
1665 | eq FGtExp .op() = " > "; |
---|
1666 | eq FGeqExp.op() = " >= "; |
---|
1667 | eq FEqExp.op() = " == "; |
---|
1668 | eq FNeqExp.op() = " <> "; |
---|
1669 | eq FOrExp.op() = " or "; |
---|
1670 | eq FAndExp.op() = " and "; |
---|
1671 | eq FAddExp.op() = " + "; |
---|
1672 | eq FSubExp.op() = " - "; |
---|
1673 | eq FMulExp.op() = " * "; |
---|
1674 | eq FDivExp.op() = " / "; |
---|
1675 | eq FPowExp.op() = " ^ "; |
---|
1676 | eq FDotAddExp.op() = " .+ "; |
---|
1677 | eq FDotSubExp.op() = " .- "; |
---|
1678 | eq FDotMulExp.op() = " .* "; |
---|
1679 | eq FDotDivExp.op() = " ./ "; |
---|
1680 | eq FDotPowExp.op() = " .^ "; |
---|
1681 | eq FStringAddExp.op() = " + "; |
---|
1682 | |
---|
1683 | protected void FNoExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1684 | // Dummy node |
---|
1685 | } |
---|
1686 | |
---|
1687 | protected void FUnsupportedExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1688 | } |
---|
1689 | |
---|
1690 | protected void FNotExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1691 | str.print("not "); |
---|
1692 | p.print(getFExp(),str,indent); |
---|
1693 | } |
---|
1694 | |
---|
1695 | protected void FIfExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1696 | prettyPrintAsElseExp(p, str, indent); |
---|
1697 | } |
---|
1698 | |
---|
1699 | public void FExp.prettyPrintAsElseExp(Printer p, CodeStream str, String indent) { |
---|
1700 | str.print(' '); |
---|
1701 | p.print(this, str, indent); |
---|
1702 | } |
---|
1703 | |
---|
1704 | public void FIfExp.prettyPrintAsElseExp(Printer p, CodeStream str, String indent) { |
---|
1705 | str.print("if "); |
---|
1706 | p.print(getIfExp(), str, indent); |
---|
1707 | str.print(" then "); |
---|
1708 | p.print(getThenExp(), str, indent); |
---|
1709 | str.print(" else"); |
---|
1710 | getElseExp().prettyPrintAsElseExp(p, str, indent); |
---|
1711 | } |
---|
1712 | |
---|
1713 | protected void FLitExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1714 | str.print(toString()); |
---|
1715 | } |
---|
1716 | |
---|
1717 | |
---|
1718 | protected void FTimeExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1719 | str.print("time"); |
---|
1720 | } |
---|
1721 | |
---|
1722 | protected void FEndExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1723 | str.print("end"); |
---|
1724 | } |
---|
1725 | |
---|
1726 | protected void FInStreamEpsExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1727 | str.print("_inStreamEpsilon"); |
---|
1728 | } |
---|
1729 | |
---|
1730 | public abstract void CommonAccess.prettyPrint(Printer p, CodeStream str, String indent); |
---|
1731 | |
---|
1732 | protected void CommonAccessExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1733 | p.print(getAccess(), str, indent); |
---|
1734 | } |
---|
1735 | |
---|
1736 | protected void FGlobalAccessExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1737 | str.print("global("); |
---|
1738 | super.prettyPrintExp(p, str, indent); |
---|
1739 | str.print(")"); |
---|
1740 | } |
---|
1741 | |
---|
1742 | public void InstAccess.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1743 | str.print(name()); |
---|
1744 | if (hasFArraySubscripts()) |
---|
1745 | p.print(getFArraySubscripts(), str, indent); |
---|
1746 | } |
---|
1747 | |
---|
1748 | public void InstDot.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1749 | getInstAccesss().prettyPrintWithSep(p, str, indent, "."); |
---|
1750 | } |
---|
1751 | |
---|
1752 | public void InstGlobalAccess.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1753 | str.print("."); |
---|
1754 | p.print(getInstAccess(), str, indent); |
---|
1755 | } |
---|
1756 | |
---|
1757 | protected void FDerExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1758 | str.print(name()); |
---|
1759 | } |
---|
1760 | |
---|
1761 | protected void FDummyDerExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1762 | str.print(derPrefixName()); |
---|
1763 | } |
---|
1764 | |
---|
1765 | protected void FDynamicDerExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1766 | str.print(dynDerName()); |
---|
1767 | } |
---|
1768 | |
---|
1769 | protected void FPreExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1770 | str.print(name()); |
---|
1771 | } |
---|
1772 | |
---|
1773 | protected void InstDerExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1774 | str.print("der("); |
---|
1775 | p.print(getFExp(),str,indent); |
---|
1776 | str.print(")"); |
---|
1777 | } |
---|
1778 | |
---|
1779 | protected void InstHDerExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1780 | str.print("der("); |
---|
1781 | p.print(getFExp(),str,indent); |
---|
1782 | str.format(",%d)", getOrder()); |
---|
1783 | } |
---|
1784 | |
---|
1785 | protected void InstPreExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1786 | str.print("pre("); |
---|
1787 | p.print(getFExp(),str,indent); |
---|
1788 | str.format(")"); |
---|
1789 | } |
---|
1790 | |
---|
1791 | protected void FDSRefExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1792 | str.format("ds(%d, ", getSetId()); |
---|
1793 | p.print(getOrg(), str, indent); |
---|
1794 | str.print(")"); |
---|
1795 | } |
---|
1796 | |
---|
1797 | protected void FDSDerExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1798 | str.format("dsDer(%d, %d)", getSetId(), getNumber()); |
---|
1799 | } |
---|
1800 | |
---|
1801 | protected void FSumExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1802 | str.print("sum("); |
---|
1803 | p.print(getFExp(), str, indent); |
---|
1804 | str.print(")"); |
---|
1805 | } |
---|
1806 | |
---|
1807 | protected void FProductExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1808 | str.print("product("); |
---|
1809 | p.print(getFExp(), str, indent); |
---|
1810 | str.print(")"); |
---|
1811 | } |
---|
1812 | |
---|
1813 | protected void FFunctionCall.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1814 | str.print(getName().name(), "("); |
---|
1815 | getArgs().prettyPrintWithSep(p, str, "", ", "); |
---|
1816 | str.print(")"); |
---|
1817 | } |
---|
1818 | |
---|
1819 | protected void FPartialFunctionCall.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1820 | str.print("function "); |
---|
1821 | super.prettyPrintExp(p, str, indent); |
---|
1822 | } |
---|
1823 | |
---|
1824 | protected void InstFunctionCall.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1825 | str.print(getName().name(), "("); |
---|
1826 | getArgs().prettyPrintWithSep(p, str, "", ", "); |
---|
1827 | str.print(")"); |
---|
1828 | } |
---|
1829 | |
---|
1830 | protected void InstRecordConstructor.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1831 | str.print(getRecord().name(), "("); |
---|
1832 | getArgs().prettyPrintWithSep(p, str, "", ", "); |
---|
1833 | str.print(")"); |
---|
1834 | } |
---|
1835 | |
---|
1836 | public void InstDefaultArgument.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1837 | p.print(getFExp(), str, indent); |
---|
1838 | } |
---|
1839 | |
---|
1840 | public void InstNamedArgument.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1841 | str.print(getName().name(), "="); |
---|
1842 | p.print(getFExp(), str, indent); |
---|
1843 | } |
---|
1844 | |
---|
1845 | protected void FBuiltInFunctionCall.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
1846 | str.print(builtInName(), "("); |
---|
1847 | prettyPrintArguments(p, str, indent); |
---|
1848 | str.print(")"); |
---|
1849 | } |
---|
1850 | |
---|
1851 | protected static final String FBuiltInFunctionCall.SEP = ", "; |
---|
1852 | |
---|
1853 | /** |
---|
1854 | * Pretty-print all arguments of function. |
---|
1855 | * |
---|
1856 | * Default implementation prints all direct FExp children (including those in Lists and Opts), |
---|
1857 | * separated by {@link #SEP}. |
---|
1858 | */ |
---|
1859 | protected void FBuiltInFunctionCall.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1860 | String pre = ""; |
---|
1861 | for (FExp exp : myArgs()) { |
---|
1862 | str.print(pre); |
---|
1863 | p.print(exp, str, indent); |
---|
1864 | pre = SEP; |
---|
1865 | } |
---|
1866 | } |
---|
1867 | |
---|
1868 | protected void FInfArgsFunctionCall.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1869 | getFExps().prettyPrintWithSep(p, str, indent, SEP); |
---|
1870 | } |
---|
1871 | |
---|
1872 | protected void FFillExp.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1873 | p.print(getFillExp(), str, indent); |
---|
1874 | str.print(SEP); |
---|
1875 | super.prettyPrintArguments(p, str, indent); |
---|
1876 | } |
---|
1877 | |
---|
1878 | protected void FCatExp.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1879 | p.print(getDim(), str, indent); |
---|
1880 | str.print(SEP); |
---|
1881 | super.prettyPrintArguments(p, str, indent); |
---|
1882 | } |
---|
1883 | |
---|
1884 | protected void FConnPotentialRoot.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1885 | super.prettyPrintArguments(p, str, indent); |
---|
1886 | if (hasPriority()) { |
---|
1887 | str.print(SEP, "priority="); |
---|
1888 | p.print(getPriority(), str, indent); |
---|
1889 | } |
---|
1890 | } |
---|
1891 | |
---|
1892 | @Override |
---|
1893 | protected void FDelayIndicator.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1894 | myDelayExp().prettyPrintArguments(p, str, indent); |
---|
1895 | } |
---|
1896 | |
---|
1897 | @Override |
---|
1898 | protected void FSpatialDistIndicator.prettyPrintArguments(Printer p, CodeStream str, String indent) { |
---|
1899 | mySpatialDistExp().prettyPrintArguments(p, str, indent); |
---|
1900 | } |
---|
1901 | |
---|
1902 | syn String FBuiltInFunctionCall.builtInName(); |
---|
1903 | eq FRecordConstructor.builtInName() = getRecord().name(); |
---|
1904 | eq FUnsupportedBuiltIn.builtInName() = getName(); |
---|
1905 | eq FAbsExp.builtInName() = "abs"; |
---|
1906 | eq FSignExp.builtInName() = "sign"; |
---|
1907 | eq FSqrtExp.builtInName() = "sqrt"; |
---|
1908 | eq FEnumIntegerExp.builtInName() = "Integer"; |
---|
1909 | eq FStringExp.builtInName() = "String"; |
---|
1910 | eq FDivFuncExp.builtInName() = "div"; |
---|
1911 | eq FModFuncExp.builtInName() = "mod"; |
---|
1912 | eq FRemFuncExp.builtInName() = "rem"; |
---|
1913 | eq FCeilFuncExp.builtInName() = "ceil"; |
---|
1914 | eq FFloorFuncExp.builtInName() = "floor"; |
---|
1915 | eq FIntegerFuncExp.builtInName() = "integer"; |
---|
1916 | eq FSinExp.builtInName() = "sin"; |
---|
1917 | eq FCosExp.builtInName() = "cos"; |
---|
1918 | eq FTanExp.builtInName() = "tan"; |
---|
1919 | eq FAsinExp.builtInName() = "asin"; |
---|
1920 | eq FAcosExp.builtInName() = "acos"; |
---|
1921 | eq FAtanExp.builtInName() = "atan"; |
---|
1922 | eq FAtan2Exp.builtInName() = "atan2"; |
---|
1923 | eq FSinhExp.builtInName() = "sinh"; |
---|
1924 | eq FCoshExp.builtInName() = "cosh"; |
---|
1925 | eq FTanhExp.builtInName() = "tanh"; |
---|
1926 | eq FExpExp.builtInName() = "exp"; |
---|
1927 | eq FLogExp.builtInName() = "log"; |
---|
1928 | eq FLog10Exp.builtInName() = "log10"; |
---|
1929 | eq FScalarExp.builtInName() = "scalar"; |
---|
1930 | eq FVectorExp.builtInName() = "vector"; |
---|
1931 | eq FMatrixExp.builtInName() = "matrix"; |
---|
1932 | eq FTranspose.builtInName() = "transpose"; |
---|
1933 | eq FSymmetric.builtInName() = "symmetric"; |
---|
1934 | eq FCross.builtInName() = "cross"; |
---|
1935 | eq FSkew.builtInName() = "skew"; |
---|
1936 | eq FOuterProduct.builtInName() = "outerProduct"; |
---|
1937 | eq FNdimsExp.builtInName() = "ndims"; |
---|
1938 | eq FSizeExp.builtInName() = "size"; |
---|
1939 | eq FNoEventExp.builtInName() = "noEvent"; |
---|
1940 | eq FSmoothExp.builtInName() = "smooth"; |
---|
1941 | eq InstPreExp.builtInName() = "pre"; |
---|
1942 | eq FEdgeExp.builtInName() = "edge"; |
---|
1943 | eq FChangeExp.builtInName() = "change"; |
---|
1944 | eq FLoadResource.builtInName() = "loadResource"; |
---|
1945 | eq FSampleExp.builtInName() = "sample"; |
---|
1946 | eq FInitialExp.builtInName() = "initial"; |
---|
1947 | eq FTerminalExp.builtInName() = "terminal"; |
---|
1948 | eq FTerminate.builtInName() = "terminate"; |
---|
1949 | eq FReinit.builtInName() = "reinit"; |
---|
1950 | eq FDelayExp.builtInName() = "delay"; |
---|
1951 | eq FSpatialDistExp.builtInName() = "spatialDistribution"; |
---|
1952 | eq FFirstDelayIndicator.builtInName()= "delayIndicatorFirst"; |
---|
1953 | eq FSecondDelayIndicator.builtInName()= "delayIndicatorSecond"; |
---|
1954 | eq FSpatialDistIndicator.builtInName()= "spatialDistIndicator"; |
---|
1955 | eq FAssert.builtInName() = "assert"; |
---|
1956 | eq FIdentity.builtInName() = "identity"; |
---|
1957 | eq FDiagonal.builtInName() = "diagonal"; |
---|
1958 | eq FOnes.builtInName() = "ones"; |
---|
1959 | eq FZeros.builtInName() = "zeros"; |
---|
1960 | eq FFillExp.builtInName() = "fill"; |
---|
1961 | eq FAbstractCat.builtInName() = "cat"; |
---|
1962 | eq FParseArray.builtInName() = "array"; |
---|
1963 | eq FMinExp.builtInName() = "min"; |
---|
1964 | eq FMaxExp.builtInName() = "max"; |
---|
1965 | eq FSumExp.builtInName() = "sum"; |
---|
1966 | eq FProductExp.builtInName() = "product"; |
---|
1967 | eq FLinspace.builtInName() = "linspace"; |
---|
1968 | eq FHomotopyExp.builtInName() = "homotopy"; |
---|
1969 | eq FCardinality.builtInName() = "cardinality"; |
---|
1970 | eq FDecouple.builtInName() = "Subtask.decouple"; |
---|
1971 | eq FSemiLinearExp.builtInName() = "semiLinear"; |
---|
1972 | eq FInStream.builtInName() = "inStream"; |
---|
1973 | eq FDerStream.builtInName() = "derStream"; |
---|
1974 | eq FExInStream.builtInName() = "inStreamExpansion"; |
---|
1975 | eq FActualStream.builtInName() = "actualStream"; |
---|
1976 | eq FGetInstanceName.builtInName() = "getInstanceName"; |
---|
1977 | eq FConnBranch.builtInName() = "Connections.branch"; |
---|
1978 | eq FConnRoot.builtInName() = "Connections.root"; |
---|
1979 | eq FConnPotentialRoot.builtInName() = "Connections.potentialRoot"; |
---|
1980 | eq FConnIsRoot.builtInName() = "Connections.isRoot"; |
---|
1981 | eq FConnRooted.builtInName() = "Connections.rooted"; |
---|
1982 | eq FConnRootedDep.builtInName() = "rooted"; |
---|
1983 | |
---|
1984 | |
---|
1985 | public void FForClauseE.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1986 | str.print(indent, "for "); |
---|
1987 | getFForIndexList().prettyPrintWithSep(p, str, indent, ", "); |
---|
1988 | str.println(" loop"); |
---|
1989 | getFAbstractEquationList().prettyPrintWithFix(p, str, p.indent(indent), "", ";" + str.getLineEnder()); |
---|
1990 | str.print(indent, "end for"); |
---|
1991 | } |
---|
1992 | |
---|
1993 | public void CommonForIndex.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
1994 | str.print(name(), " in "); |
---|
1995 | p.print(getFExp(), str, indent); |
---|
1996 | } |
---|
1997 | |
---|
1998 | @Override |
---|
1999 | public void InstForIndexNoExp.prettyPrint(Printer p, CodeStream str, String indent) { |
---|
2000 | str.print(getInstPrimitive().name()); |
---|
2001 | } |
---|
2002 | |
---|
2003 | protected void FArray.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
2004 | str.print("{"); |
---|
2005 | getFExps().prettyPrintWithSep(p, str, indent, ", "); |
---|
2006 | str.print("}"); |
---|
2007 | } |
---|
2008 | |
---|
2009 | protected void FLongArray.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
2010 | str.print("array("); |
---|
2011 | getFExps().prettyPrintWithSep(p, str, indent, ", "); |
---|
2012 | str.print(")"); |
---|
2013 | } |
---|
2014 | |
---|
2015 | protected void FIterExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
2016 | p.print(getFExp(), str, indent); |
---|
2017 | str.print(" for "); |
---|
2018 | for (int i = getNumForIndex() - 1; i >= 0; i--) { |
---|
2019 | p.print(getForIndex(i), str, indent); |
---|
2020 | if (i > 0) |
---|
2021 | str.print(", "); |
---|
2022 | } |
---|
2023 | } |
---|
2024 | |
---|
2025 | protected void FSubscriptedExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
2026 | str.print("("); |
---|
2027 | p.print(getFExp(), str, indent); |
---|
2028 | str.print(")"); |
---|
2029 | p.print(getFArraySubscripts(), str, indent); |
---|
2030 | } |
---|
2031 | |
---|
2032 | protected void FComponentExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
2033 | str.print("("); |
---|
2034 | p.print(getFExp(), str, indent); |
---|
2035 | str.print(").", getName()); |
---|
2036 | } |
---|
2037 | |
---|
2038 | protected void FDeferExp.prettyPrintExp(Printer p, CodeStream str, String indent) { |
---|
2039 | p.print(getFExp(), str, indent); |
---|
2040 | } |
---|
2041 | |
---|
2042 | public abstract String TypePrefixVariability.toString(); |
---|
2043 | public String Continuous.toString() { return ""; } |
---|
2044 | public String Discrete.toString() { return "discrete "; } |
---|
2045 | public String InitialParameter.toString() { return "initial parameter "; } |
---|
2046 | public String EvalFalseParameter.toString() { return "parameter "; } |
---|
2047 | public String FixedParameter.toString() { return "parameter "; } |
---|
2048 | public String IndexParameter.toString() { return "index parameter"; } |
---|
2049 | public String EvalTrueParameter.toString() { return "eval parameter "; } |
---|
2050 | public String FinalParameter.toString() { return "final parameter "; } |
---|
2051 | public String StructParameter.toString() { return "structural parameter "; } |
---|
2052 | public String LoadResourceParameter.toString() { return "structural (loadResource) parameter "; } |
---|
2053 | public String Constant.toString() { return "constant "; } |
---|
2054 | public String CompositeVariability.toString() { return combine().toString(); } |
---|
2055 | |
---|
2056 | public abstract String TypePrefixVariability.toStringLiteral(); |
---|
2057 | public String Continuous.toStringLiteral() { return "continuous-time"; } |
---|
2058 | public String Discrete.toStringLiteral() { return "discrete-time"; } |
---|
2059 | public String InitialParameter.toStringLiteral() { return "initial parameter"; } |
---|
2060 | public String Parameter.toStringLiteral() { return "parameter"; } |
---|
2061 | public String EvalTrueParameter.toStringLiteral() { return "eval parameter"; } |
---|
2062 | public String FinalParameter.toStringLiteral() { return "final parameter"; } |
---|
2063 | public String StructParameter.toStringLiteral() { return "structural parameter"; } |
---|
2064 | public String Constant.toStringLiteral() { return "constant"; } |
---|
2065 | public String CompositeVariability.toStringLiteral() { return combine().toStringLiteral(); } |
---|
2066 | |
---|
2067 | syn String SrcRestriction.toString(); |
---|
2068 | eq SrcModel.toString() = "model"; |
---|
2069 | eq SrcBlock.toString() = "block"; |
---|
2070 | eq SrcClass.toString() = "class"; |
---|
2071 | eq SrcConnector.toString() = "connector"; |
---|
2072 | eq SrcExpandableConnector.toString() = "expandable connector"; |
---|
2073 | eq SrcType.toString() = "type"; |
---|
2074 | eq SrcPackage.toString() = "package"; |
---|
2075 | eq SrcFunction.toString() = "function"; |
---|
2076 | eq SrcRecord.toString() = "record"; |
---|
2077 | eq SrcOperator.toString() = "operator"; |
---|
2078 | eq SrcOperatorRecord.toString() = "operator record"; |
---|
2079 | eq SrcOperatorFunction.toString() = "operator function"; |
---|
2080 | |
---|
2081 | syn String InstRestriction.toString(); |
---|
2082 | eq InstModel.toString() = "model"; |
---|
2083 | eq InstBlock.toString() = "block"; |
---|
2084 | eq InstMClass.toString() = "class"; |
---|
2085 | eq InstConnector.toString() = "connector"; |
---|
2086 | eq InstExpandableConnector.toString() = "expandable connector"; |
---|
2087 | eq InstMType.toString() = "type"; |
---|
2088 | eq InstMPackage.toString() = "package"; |
---|
2089 | eq InstFunction.toString() = "function"; |
---|
2090 | eq InstMRecord.toString() = "record"; |
---|
2091 | eq InstOperator.toString() = "operator"; |
---|
2092 | eq InstOperatorRecord.toString() = "operator record"; |
---|
2093 | eq InstOperatorFunction.toString() = "operator function"; |
---|
2094 | |
---|
2095 | syn String SrcComponentDecl.toString() = prettyPrint(""); |
---|
2096 | syn String SrcAccess.toString() = prettyPrint(""); |
---|
2097 | syn String SrcModification.toString() = prettyPrint(""); |
---|
2098 | } |
---|
2099 | |
---|
2100 | aspect PrettyPrint_MC { |
---|
2101 | |
---|
2102 | /** |
---|
2103 | * Static printer instance. |
---|
2104 | */ |
---|
2105 | static MCPrettyPrinter ASTNode.printer_MC = new MCPrettyPrinter(); |
---|
2106 | |
---|
2107 | public class MCPrettyPrinter extends Printer { |
---|
2108 | |
---|
2109 | public MCPrettyPrinter() { |
---|
2110 | super(" "); |
---|
2111 | } |
---|
2112 | |
---|
2113 | public void print(ASTNode node, CodeStream str, String indent) { |
---|
2114 | node.prettyPrint(this, str, indent); |
---|
2115 | } |
---|
2116 | |
---|
2117 | } |
---|
2118 | |
---|
2119 | public String ASTNode.prettyPrint_MC(String indent) { |
---|
2120 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
---|
2121 | CodeStream str = new CodeStream(os); |
---|
2122 | prettyPrint(str,indent); |
---|
2123 | return os.toString(); |
---|
2124 | } |
---|
2125 | |
---|
2126 | public void List.prettyPrintFAttributeList_MC(CodeStream str, Printer p) { |
---|
2127 | |
---|
2128 | boolean attrSet = false; |
---|
2129 | boolean firstAttr = true; |
---|
2130 | |
---|
2131 | for (int i=0;i<getNumChild();i++) { |
---|
2132 | if (((FAttribute)getChild(i)).getAttributeSet() && !((FAttribute)getChild(i)).getName().name().equals("fixed")) { |
---|
2133 | attrSet=true; |
---|
2134 | break; |
---|
2135 | } |
---|
2136 | } |
---|
2137 | |
---|
2138 | if (attrSet){ |
---|
2139 | str.print("("); |
---|
2140 | for (int i=0;i<getNumChild();i++) { |
---|
2141 | |
---|
2142 | if (((FAttribute)getChild(i)).getAttributeSet() && !((FAttribute)getChild(i)).getName().name().equals("fixed")) { |
---|
2143 | |
---|
2144 | if (!firstAttr) |
---|
2145 | str.print(","); |
---|
2146 | p.print(((FAttribute)getChild(i)),str,""); |
---|
2147 | |
---|
2148 | firstAttr = false; |
---|
2149 | } |
---|
2150 | } |
---|
2151 | str.print(")"); |
---|
2152 | } |
---|
2153 | } |
---|
2154 | |
---|
2155 | public void FVariable.prettyPrint_MC(Printer p, CodeStream str, String indent) { |
---|
2156 | str.print(indent, getTypePrefixVariability()); |
---|
2157 | if (!getTypePrefixInputOutput().isNone()) { |
---|
2158 | str.print(getTypePrefixInputOutput(), " "); |
---|
2159 | } |
---|
2160 | |
---|
2161 | str.print(prettyPrintType(), " ", nameUnderscore()); |
---|
2162 | getFAttributeList().prettyPrintFAttributeList_MC(str,p); |
---|
2163 | |
---|
2164 | FExp bindingExp = null; |
---|
2165 | if (hasBindingExp()) { |
---|
2166 | bindingExp = getBindingExp(); |
---|
2167 | } else if (hasParameterEquation()) { |
---|
2168 | bindingExp = ((FEquation) parameterEquation()).getRight(); |
---|
2169 | } |
---|
2170 | if (bindingExp != null) { |
---|
2171 | str.print(" = "); |
---|
2172 | p.print(bindingExp,str,indent); |
---|
2173 | } |
---|
2174 | |
---|
2175 | p.print(getFStringCommentOpt(), str, indent); |
---|
2176 | |
---|
2177 | if (isIndependentParameter() && hasBindingExp()) { |
---|
2178 | str.print(" /* "); |
---|
2179 | try { |
---|
2180 | str.print(getBindingExp().ceval()); |
---|
2181 | } catch (ConstantEvaluationException e){ |
---|
2182 | str.print("evaluation error"); |
---|
2183 | } |
---|
2184 | str.print(" */"); |
---|
2185 | } |
---|
2186 | } |
---|
2187 | |
---|
2188 | |
---|
2189 | public void FClass.prettyPrint_MC(Printer p, CodeStream str, String indent) { |
---|
2190 | String nextInd = p.indent(indent); |
---|
2191 | |
---|
2192 | p.print(getFFunctionDecls(), str, indent); |
---|
2193 | p.print(getFRecordDecls(), str, indent); |
---|
2194 | p.print(getFEnumDecls(), str, indent); |
---|
2195 | p.print(getFDerivedTypes(), str, indent); |
---|
2196 | |
---|
2197 | str.println(indent, "model ", nameUnderscore()); |
---|
2198 | for (FVariable fv : getFVariables()) { |
---|
2199 | if (!fv.isDerivativeVariable() && !fv.isPreVariable()) { |
---|
2200 | p.print(fv, str, nextInd); |
---|
2201 | str.println(";"); |
---|
2202 | } |
---|
2203 | } |
---|
2204 | |
---|
2205 | if (getNumFInitialEquation() > 0) { |
---|
2206 | str.println(indent, "initial equation"); |
---|
2207 | } |
---|
2208 | getFInitialEquations().prettyPrintWithFix(p, str, nextInd, "", ";" + str.getLineEnder()); |
---|
2209 | |
---|
2210 | /* |
---|
2211 | if (getNumParameterEquation() > 0) { |
---|
2212 | str.println(indent, "parameter equation"); |
---|
2213 | } |
---|
2214 | getParameterEquations().prettyPrintWithFix(p, str, nextInd, "", ";" + str.getLineEnder()); |
---|
2215 | */ |
---|
2216 | boolean wroteEquation = false; |
---|
2217 | for (FAbstractEquation e : getFAbstractEquations()) { |
---|
2218 | if (e instanceof FAlgorithm) { |
---|
2219 | p.print(e, str, indent); |
---|
2220 | wroteEquation = false; |
---|
2221 | } else { |
---|
2222 | if (!e.isIgnored()) { |
---|
2223 | if (!wroteEquation) { |
---|
2224 | str.println(indent, "equation"); |
---|
2225 | wroteEquation = true; |
---|
2226 | } |
---|
2227 | p.print(e, str, nextInd); |
---|
2228 | str.println(";"); |
---|
2229 | } |
---|
2230 | } |
---|
2231 | } |
---|
2232 | |
---|
2233 | str.println(indent, "end ", nameUnderscore(), ";"); |
---|
2234 | } |
---|
2235 | |
---|
2236 | |
---|
2237 | public void ASTNode.prettyPrint_MC(CodeStream str, String indent) { |
---|
2238 | prettyPrint_MC(printer_MC, str, indent); |
---|
2239 | } |
---|
2240 | |
---|
2241 | public void ASTNode.prettyPrint_MC(Printer p, CodeStream str, String indent) { |
---|
2242 | prettyPrint(p, str, indent); |
---|
2243 | } |
---|
2244 | |
---|
2245 | public void FAccessExp.prettyPrint_MC(Printer p, CodeStream str, String indent) { |
---|
2246 | str.print(nameUnderscore()); |
---|
2247 | } |
---|
2248 | |
---|
2249 | public void FDerExp.prettyPrint_MC(Printer p, CodeStream str, String indent) { |
---|
2250 | str.print("der(", getFAccess().nameUnderscore(), ")"); |
---|
2251 | } |
---|
2252 | |
---|
2253 | } |
---|
2254 | |
---|
2255 | aspect AnnotationPrettyPrinting { |
---|
2256 | /** |
---|
2257 | * Used when prettyprinting FAttribute annotation nodes |
---|
2258 | */ |
---|
2259 | public class AnnotationPrettyPrinter extends PrettyPrinter { |
---|
2260 | |
---|
2261 | @Override |
---|
2262 | public PrettyPrinter annotationPrinter() { |
---|
2263 | return this; |
---|
2264 | } |
---|
2265 | |
---|
2266 | @Override |
---|
2267 | public boolean inAnnotation() { |
---|
2268 | return true; |
---|
2269 | } |
---|
2270 | } |
---|
2271 | |
---|
2272 | public static PrettyPrinter ASTNode.AnnotationPrettyPrinter = new AnnotationPrettyPrinter(); |
---|
2273 | |
---|
2274 | /** |
---|
2275 | * Returns a string listing the annotations in this class declaration and any child class declarations, recursively. |
---|
2276 | * |
---|
2277 | * @param prefix |
---|
2278 | * The string to prefix the annotation string with. |
---|
2279 | */ |
---|
2280 | syn String InstClassDecl.printClassAnnotations(String prefix) = ""; |
---|
2281 | |
---|
2282 | eq InstFullClassDecl.printClassAnnotations(String prefix) { |
---|
2283 | SrcFullClassDecl myDecl = getSrcFullClassDecl(); |
---|
2284 | Opt<SrcAnnotation> myAnnotation = myDecl.getSrcAnnotationOpt(); |
---|
2285 | String myNode = (myAnnotation.numChildren() > 0 ? prefix + myAnnotation.getChild(0).toString() + "\n" : ""); |
---|
2286 | StringBuilder string = new StringBuilder(myNode.contains("__JModelica") ? "" : myNode); |
---|
2287 | for (InstClassDecl decl : getInstClassDecls()) { |
---|
2288 | string.append(decl.printClassAnnotations(prefix + " ")); |
---|
2289 | } |
---|
2290 | return string.toString(); |
---|
2291 | } |
---|
2292 | eq InstAbstractShortClassDecl.printClassAnnotations(String prefix) = getSrcShortClassDecl().srcAnnotation().toString(); |
---|
2293 | |
---|
2294 | /** |
---|
2295 | * Returns a string listing the annotations for components in this class. |
---|
2296 | * |
---|
2297 | * @param prefix |
---|
2298 | * The string to prefix the annotation string with. |
---|
2299 | */ |
---|
2300 | syn String InstClassDecl.printComponentAnnotations() = ""; |
---|
2301 | |
---|
2302 | eq InstFullClassDecl.printComponentAnnotations() { |
---|
2303 | StringBuilder sb = new StringBuilder(); |
---|
2304 | for (InstComponentDecl decl : getInstComponentDecls()) { |
---|
2305 | if (sb.length() > 0) { |
---|
2306 | sb.append('\n'); |
---|
2307 | } |
---|
2308 | sb.append(decl.srcAnnotation().toString()); |
---|
2309 | } |
---|
2310 | return sb.toString(); |
---|
2311 | } |
---|
2312 | } |
---|