Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5a07cd60965e7e719967820ef461d8870e57bf61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<?xml version="1.0" encoding="UTF-8"?>
<templates><template id="ASTAbstractRule.cu" name="ASTAbstractRule.cu" description="ASTAbstractRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
/**&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public abstract class ${typeName} ${extends} {&#13;
	/**&#13;
	 * Construct a new ${typeName}.&#13;
	 */&#13;
	public ${typeName}() {&#13;
		super();&#13;
	}&#13;
&#13;
${ASTVisitorClass_acceptImpl}&#13;
&#13;
}</template><template id="ASTBaseClass.cu" name="ASTBaseClass.cu" description="ASTBaseClass CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
import org.eclipse.gymnast.runtime.core.ast.ASTNode;&#13;
import org.eclipse.gymnast.runtime.core.ast.ASTNodeImpl;&#13;
import org.eclipse.gymnast.runtime.core.ast.TokenInfo;&#13;
&#13;
/**&#13;
 * The superclass of all ASTNodes for language ${astName}.&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public abstract class ${astBaseClassName} extends ${astBaseClassBaseName} {&#13;
&#13;
	protected ${astBaseClassName} _parent;&#13;
&#13;
	/**&#13;
	 * @return the parent of this ASTNode or null if this is the root node of a tree&#13;
	 */&#13;
	public ASTNode getParent() {&#13;
		return _parent;&#13;
	}&#13;
&#13;
	/**&#13;
	 * Construct a new ${astBaseClassName}.&#13;
	 */&#13;
	public ${astBaseClassName}() {&#13;
		super();&#13;
	}&#13;
&#13;
	/**&#13;
	 * Construct a new ${astBaseClassName}.&#13;
	 *&#13;
	 * @param token a Token to initialize the offset and text for this node.&#13;
	 */&#13;
	public ${astBaseClassName}(TokenInfo tokenInfo) {&#13;
		super(tokenInfo);&#13;
	}&#13;
&#13;
	/**&#13;
	 * The external entry point used to initiate the visitor on this node.&#13;
	 * &#13;
	 * @param visitor the Visitor to visit this node tree&#13;
	 */&#13;
	public final void accept(${astVisitorClassName} visitor) {&#13;
		visitor.preVisit(this);&#13;
		acceptImpl(visitor);&#13;
		visitor.postVisit(this);&#13;
	}&#13;
&#13;
	/**&#13;
	 * This method can be overridden by subclasses which should provide exactly&#13;
	 * the same implementation.  Here &lt;code&gt;this&lt;/code&gt; refers to the generic node&#13;
	 * class, but in the subclass implementations &lt;code&gt;this&lt;/code&gt; will refer to&#13;
	 * the specific subclass type.  Thus the correct specific &lt;code&gt;beginVisit&lt;/code&gt;&#13;
	 * and &lt;code&gt;endVisit&lt;/code&gt; methods will be invoked for each subclass and the&#13;
	 * generic methods will be invoked for subclasses that don't need specific visitor&#13;
	 * behavior.&#13;
	 */&#13;
	public void acceptImpl(${astVisitorClassName} visitor) {&#13;
		boolean visitChildren = visitor.beginVisit(this);&#13;
		if (visitChildren) visitChildren(visitor);&#13;
		visitor.endVisit(this);&#13;
	}&#13;
&#13;
	/**&#13;
	 * Iterate through the children of this node and accept the visitor on each.&#13;
	 */&#13;
	protected void visitChildren(${astVisitorClassName} visitor) {&#13;
		for (int i = 0; i &lt; getChildCount(); i++) {&#13;
			ASTNode child = getChild(i);&#13;
			if (child instanceof ${astBaseClassName}) {&#13;
				${astBaseClassName} c = (${astBaseClassName})child;&#13;
				c.accept(visitor);&#13;
			}&#13;
		}&#13;
	}&#13;
&#13;
}&#13;
</template><template id="ASTContainerRule.cu" name="ASTContainerRule.cu" description="ASTContainerRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
import org.eclipse.gymnast.runtime.core.ast.ASTNode;&#13;
&#13;
/**&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public ${typeKind} ${typeName} ${extends} ${implements} {&#13;
&#13;
${^foreach_KeywordLiteral}	public static final String KW_${literal_UC} = "${literal}";&#13;
${^END}&#13;
${^foreach_ChildElement}	private ${childType} _${childName};&#13;
${^END}&#13;
${^foreach_ChildElement}	public ${childType} getAs${childName_UC}() {&#13;
		return _${childName};&#13;
	}&#13;
${^END}&#13;
&#13;
${^foreach_ChildElement}	public boolean isChild${childName_UC}() {&#13;
		return _${childName} != null;&#13;
	}&#13;
${^END}&#13;
&#13;
	/**&#13;
	 * @return the number of children of this ASTNode&#13;
	 */&#13;
	public int getChildCount() {&#13;
		int count = 0;&#13;
${^foreach_ChildElement}		if (_${childName} != null) count++;&#13;
${^END}&#13;
		return count;&#13;
	}&#13;
&#13;
	/**&#13;
	 * @param index the index of a child ASTNode to get&#13;
	 * @return the child ASTNode at the given index&#13;
	 * @throws IndexOutOfBoundsException when the index is out of bounds&#13;
	 */&#13;
	public ASTNode getChild(int index) {&#13;
	    if (index != 0) throw new IndexOutOfBoundsException();&#13;
${^foreach_ChildElement}		if (_${childName} != null) return _${childName};&#13;
${^END}&#13;
		throw new IndexOutOfBoundsException();&#13;
	}&#13;
	&#13;
	/**&#13;
	 * Construct a new ${typeName}.&#13;
	 */&#13;
	public ${typeName}() {&#13;
		super();&#13;
	}&#13;
	&#13;
${^foreach_ChildElement}	public void initAs${childName_UC}(${childTypeOrToken} ${childName}) {&#13;
		if (_${childName}._parent != null) throw new RuntimeException();&#13;
		_${childName}._parent = this;&#13;
		_${childName} = ${childName};&#13;
	}&#13;
${^END}&#13;
&#13;
${ASTVisitorClass_acceptImpl}&#13;
&#13;
}&#13;
</template><template id="ASTListRule.cu" name="ASTListRule.cu" description="ASTListRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
import java.util.ArrayList;&#13;
import org.eclipse.gymnast.runtime.core.ast.ASTNode;&#13;
import org.eclipse.gymnast.runtime.core.ast.TokenInfo;&#13;
&#13;
/**&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public ${typeKind} ${typeName} ${extends} {&#13;
&#13;
	private ArrayList _children = new ArrayList();&#13;
	&#13;
	/**&#13;
	 * @return the number of children of this ASTNode&#13;
	 */&#13;
	public int getChildCount() {&#13;
		return _children.size();&#13;
	}&#13;
&#13;
	/**&#13;
	 * @param index the index of a child ASTNode to get&#13;
	 * @return the child ASTNode at the given index&#13;
	 * @throws IndexOutOfBoundsException when the index is out of bounds&#13;
	 */&#13;
	public ASTNode getChild(int index) {&#13;
		return (ASTNode)_children.get(index);&#13;
	}&#13;
&#13;
	/**&#13;
	 * Add a child to this list.&#13;
	 */&#13;
	public void addChild(${astBaseClassName} child) {&#13;
		if (child == null) return;&#13;
		if (child._parent != null) throw new RuntimeException();&#13;
		_children.add(child);&#13;
		child._parent = this;&#13;
	}&#13;
&#13;
	/**&#13;
	 * Wrap the provided Token in a ${astTokenClassName}&#13;
	 * and add it as a child of this node.&#13;
	 * &#13;
	 * @param token the Token to be added as a child of this node&#13;
	 */&#13;
	public void addChild(TokenInfo tokenInfo) {&#13;
		addChild(new ${astTokenClassName}(tokenInfo));&#13;
	}&#13;
&#13;
	/**&#13;
	 * Construct a new ${typeName}.&#13;
	 */&#13;
	public ${typeName}() {&#13;
		super();&#13;
	}&#13;
&#13;
${ASTVisitorClass_acceptImpl}&#13;
&#13;
}&#13;
</template><template id="ASTSequenceRule.cu" name="ASTSequenceRule.cu" description="ASTSequenceRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
import org.eclipse.gymnast.runtime.core.ast.ASTNode;&#13;
import org.eclipse.gymnast.runtime.core.ast.TokenInfo;&#13;
&#13;
/**&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public ${typeKind} ${typeName} ${extends} ${implements} {&#13;
&#13;
${^foreach_KeywordLiteral}	public static final String KW_${literal_UC} = "${literal}";&#13;
${^END}&#13;
${^foreach_ChildElement}	private ${childType} _${childName};&#13;
${^END}&#13;
${^foreach_ChildElement}	public ${childType} get${childName_UC}() {&#13;
		return _${childName};&#13;
	}&#13;
${^END}&#13;
&#13;
	/**&#13;
	 * @return the number of children of this ASTNode&#13;
	 */&#13;
	public int getChildCount() {&#13;
		int count = 0;&#13;
${^foreach_ChildElement}		if (_${childName} != null) count++;&#13;
${^END}&#13;
		return count;&#13;
	}&#13;
&#13;
	/**&#13;
	 * @param index the index of a child ASTNode to get&#13;
	 * @return the child ASTNode at the given index&#13;
	 * @throws IndexOutOfBoundsException when the index is out of bounds&#13;
	 */&#13;
	public ASTNode getChild(int index) {&#13;
		int count = -1;&#13;
${^foreach_ChildElement}		if ((_${childName} != null) &amp;&amp; (++count == index)) return _${childName};&#13;
${^END}&#13;
		throw new IndexOutOfBoundsException();&#13;
	}&#13;
	&#13;
	/**&#13;
	 * Construct a new ${typeName}.&#13;
	 */&#13;
	public ${typeName}(&#13;
${^foreach_ChildElement}		${childTypeOrToken} ${childName}${comma}&#13;
${^END}	) {&#13;
		super();&#13;
&#13;
${^foreach_ChildElement}		if (${childName} != null) {&#13;
			_${childName} = ${initExpr};&#13;
			if (_${childName}._parent != null) throw new RuntimeException();&#13;
			_${childName}._parent = this;&#13;
		}&#13;
${^END}&#13;
	}&#13;
&#13;
${ASTVisitorClass_acceptImpl}&#13;
&#13;
}&#13;
</template><template id="ASTTokenClass.cu" name="ASTTokenClass.cu" description="ASTTokenClass CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
import org.eclipse.gymnast.runtime.core.ast.ASTNode;&#13;
import org.eclipse.gymnast.runtime.core.ast.TokenInfo;&#13;
&#13;
/**&#13;
 * Represents a token in the language grammar.&#13;
 * Can be subclassed to represent specific token subgroups.&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public class ${astTokenClassName} extends ${astBaseClassName} {&#13;
&#13;
	/**&#13;
	 * @return the number of children of this ASTNode&#13;
	 */&#13;
	public final int getChildCount() {&#13;
		// token rules cannot have children!&#13;
		return 0;&#13;
	}&#13;
&#13;
	/**&#13;
	 * @param index the index of a child ASTNode to get&#13;
	 * @return the child ASTNode at the given index&#13;
	 * @throws IndexOutOfBoundsException when the index is out of bounds&#13;
	 */&#13;
	public final ASTNode getChild(int index) {&#13;
		// token rules cannot have children!&#13;
		throw new IndexOutOfBoundsException();&#13;
	}&#13;
&#13;
	/**&#13;
	 * Construct a new ${astTokenClassName}&#13;
	 */&#13;
	public ${astTokenClassName}(TokenInfo tokenInfo) {&#13;
		super(tokenInfo);&#13;
	}&#13;
&#13;
${ASTVisitorClass_acceptImpl}&#13;
&#13;
}&#13;
</template><template id="ASTTokenRule.cu" name="ASTTokenRule.cu" description="ASTTokenRule CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaRuleCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
import org.eclipse.gymnast.runtime.core.ast.TokenInfo;&#13;
&#13;
/**&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public class ${typeName} extends ${astTokenClassName} {&#13;
&#13;
${^foreach_KeywordLiteral}	public static final String KW_${literal_UC} = "${literal}";&#13;
${^END}&#13;
	&#13;
	/**&#13;
	 * Construct a new ${typeName}.&#13;
	 */&#13;
	public ${typeName}(TokenInfo tokenInfo) {&#13;
		super(tokenInfo);&#13;
	}&#13;
&#13;
${ASTVisitorClass_acceptImpl}&#13;
&#13;
}</template><template id="ASTVisitorClass.cu" name="ASTVisitorClass.cu" description="ASTVisitorClass CompilationUnit template" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaCompUnit" enabled="true" deleted="false" autoinsert="true">package ${astPackageName};&#13;
&#13;
/**&#13;
 * A Visitor pattern stub implementation for language ${astName}.&#13;
 *&#13;
 * ${generatedBy}&#13;
 */&#13;
public class ${astVisitorClassName} {&#13;
&#13;
	/**&#13;
	 * The external entry point used to perform a visit beginning at the given node.&#13;
	 * &#13;
	 * @param node the ${astBaseClassName} to visit&#13;
	 */&#13;
	public final void visit(${astBaseClassName} node) {&#13;
		node.accept(this);&#13;
	}&#13;
&#13;
	/**&#13;
	 * Called just before &lt;code&gt;beginVisit&lt;/code&gt; for each node being visited.&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param node the ${astBaseClassName} currently being visited&#13;
	 */&#13;
	public void preVisit(${astBaseClassName} node) {&#13;
	}&#13;
&#13;
	/**&#13;
	 * Called just after &lt;code&gt;endVisit&lt;/code&gt; for each node being visited.&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param node the ${astBaseClassName} currently being visited&#13;
	 */&#13;
	public void postVisit(${astBaseClassName} node) {&#13;
	}&#13;
&#13;
	/**&#13;
	 * This is called, for each node being visited, just after &lt;code&gt;preVisit&lt;/code&gt; and&#13;
	 * before (optionally) visiting the children of the node.&#13;
	 * This &lt;code&gt;beginVisit&lt;/code&gt; method is the generic one called for node types that&#13;
	 * don't provide a specific overloaded form of &lt;code&gt;beginVisit&lt;/code&gt;.&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param node the ${astBaseClassName} currently being visited&#13;
	 * @return true to visit the children of the node, false to prevent visiting the children of the node&#13;
	 */&#13;
	public boolean beginVisit(${astBaseClassName} node) {&#13;
		return true;&#13;
	}&#13;
&#13;
	/**&#13;
	 * This is called, for each node being visited, after &lt;code&gt;beginVisit&lt;/code&gt; and&#13;
	 * (optionally) visiting the children of the node and before &lt;code&gt;postVisit&lt;/code&gt;.&#13;
	 * This &lt;code&gt;endVisit&lt;/code&gt; method is the generic one called for node types that&#13;
	 * don't provide a specific overloaded form of &lt;code&gt;endVisit&lt;/code&gt;.&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param node the ${astBaseClassName} currently being visited&#13;
	 */&#13;
	public void endVisit(${astBaseClassName} node) {&#13;
	}&#13;
&#13;
	/**&#13;
	 * This is called, for each node being visited, just after &lt;code&gt;preVisit&lt;/code&gt; and&#13;
	 * before (optionally) visiting the children of the node.&#13;
	 * This &lt;code&gt;beginVisit&lt;/code&gt; method is the specific one called for nodes&#13;
	 * of type &lt;code&gt;${astTokenClassName}&lt;/code&gt;&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param tokenNode the node currently being visited&#13;
	 * @return true to visit the children of the node, false to prevent visiting the children of the node&#13;
	 */&#13;
	public boolean beginVisit(${astTokenClassName} tokenNode) {&#13;
		return beginVisit((${astBaseClassName})tokenNode);&#13;
	}&#13;
&#13;
	/**&#13;
	 * This is called, for each node being visited, after &lt;code&gt;beginVisit&lt;/code&gt; and&#13;
	 * (optionally) visiting the children of the node and before &lt;code&gt;postVisit&lt;/code&gt;.&#13;
	 * This &lt;code&gt;endVisit&lt;/code&gt; method is the specific one called for nodes&#13;
	 * of type &lt;code&gt;${astTokenClassName}&lt;/code&gt;&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param tokenNode the node currently being visited&#13;
	 */&#13;
	public void endVisit(${astTokenClassName} tokenNode) {&#13;
		endVisit((${astBaseClassName})tokenNode);&#13;
	}&#13;
&#13;
${^foreach_Rule}	/**&#13;
	 * This is called, for each node being visited, just after &lt;code&gt;preVisit&lt;/code&gt; and&#13;
	 * before (optionally) visiting the children of the node.&#13;
	 * This &lt;code&gt;beginVisit&lt;/code&gt; method is the specific one called for nodes&#13;
	 * of type &lt;code&gt;${ruleName_UC}&lt;/code&gt;&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param ${ruleName_LC} the node currently being visited&#13;
	 * @return true to visit the children of the node, false to prevent visiting the children of the node&#13;
	 */&#13;
	public boolean beginVisit(${ruleName_UC} ${ruleName_LC}) {&#13;
		return beginVisit((${ruleBaseClassName})${ruleName_LC});&#13;
	}&#13;
&#13;
	/**&#13;
	 * This is called, for each node being visited, after &lt;code&gt;beginVisit&lt;/code&gt; and&#13;
	 * (optionally) visiting the children of the node and before &lt;code&gt;postVisit&lt;/code&gt;.&#13;
	 * This &lt;code&gt;endVisit&lt;/code&gt; method is the specific one called for nodes&#13;
	 * of type &lt;code&gt;${ruleName_UC}&lt;/code&gt;&#13;
	 * This may be overridden to provide special behavior at that point in processing.&#13;
	 * &#13;
	 * @param ${ruleName_LC} the node currently being visited&#13;
	 */&#13;
	public void endVisit(${ruleName_UC} ${ruleName_LC}) {&#13;
		endVisit((${ruleBaseClassName})${ruleName_LC});&#13;
	}&#13;
${^END}&#13;
&#13;
}</template><template id="ASTVisitorClass_acceptImpl" name="ASTVisitorClass_acceptImpl" description="acceptImpl method for the visitor framework" context="org.eclipse.gymnast.generators.ast.primordial.templates.JavaMethod" enabled="true" deleted="false" autoinsert="true">	/**&#13;
	 * This method overrides the superclass &lt;code&gt;acceptImpl&lt;/code&gt; providing&#13;
	 * the same implementation.  Here &lt;code&gt;this&lt;/code&gt; refers to this specific node&#13;
	 * class, so the &lt;code&gt;beginVisit&lt;/code&gt; and &lt;code&gt;endVisit&lt;/code&gt; methods&#13;
	 * specific to this type in the visitor will be invoked.&#13;
	 */&#13;
	public void acceptImpl(${astVisitorClassName} visitor) {&#13;
		boolean visitChildren = visitor.beginVisit(this);&#13;
		if (visitChildren) visitChildren(visitor);&#13;
		visitor.endVisit(this);&#13;
	}</template></templates>

Back to the top