File: java.ast

package info (click to toggle)
libxtc-rats-java 1.15.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 18,580 kB
  • sloc: java: 288,962; ansic: 20,406; ml: 14,775; makefile: 1,358; cpp: 621; sh: 352; xml: 259; perl: 123
file content (389 lines) | stat: -rw-r--r-- 6,832 bytes parent folder | download
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
// java.ast            see license.txt for copyright and terms of use
// Java abstract syntax

// The main documentation is in java.ast.html.

// note: wherever ASTList or FakeList is used, its elements are listed
// in the order they appear lexically in the input file, i.e. left to
// right and then top to bottom

// How do I decide between ASTList and FakeList?  Creating ASTLists
// can be done with left recursion, which saves stack space, whereas
// FakeLists require right recursion.  But, ASTLists cannot safely
// be yielded as semantic values if there's any chance they'll be
// yielded more than once.
//
// So, I use FakeList everywhere I can accept the stack growth.  The
// only places I cannot accept this growth are places where it is
// relatively common for the list to have >100 elements.  Those
// places are:
//   - toplevel forms (including namespace members)
//   - statement lists in compound statements
//   - class/struct members
//   - compound initializers
//
// In these places where I use ASTList, I encapsulate it in another
// class if necessary to avoid yielding it as a semantic value.


// emitted verbatim into generated header (java.ast.gen.h)
verbatim {
  #include "java_flags.h"
}

// use a new astgen feature: make a visitor!
// option visitor ASTVisitor;
// option dvisitor DelegatorASTVisitor;
// dsw: these turn on incomplete experimental ast xml serialization
// and de-serialization code
// option xmlVisitor ToXmlASTVisitor;
// option xmlParser astxml;

// emit gdb() methods for debugging
option gdb;

// definitions

// ----- Compilation unit

class CompilationUnit (
  PackageDeclaration package,
  FakeList<ImportDeclaration>* imports,
  FakeList<Declaration>* declarations
);

class PackageDeclaration (
  SourceLoc loc,
  QualifiedIdentifier name
);

class ImportDeclaration (
  SourceLoc loc,
  QualifiedIdentifier name,
  bool isComplete
) {
  public ImportDeclaration* next = NULL;
}

// ----- Declarations

class FormalParameter(
  bool isFinal,
  Type type,
  Identifier id,
  int dimensions
) {
  public FormalParameter* next = NULL;
}

class Declarator(
  Identifier id,
  int dimensions,
  Expression initializer
) {
  public Declarator* next = NULL;
}

class Declaration (
  SourceLoc loc,
  Modifiers modifiers
) {
  public Declaration* next = NULL;

  -> FieldDeclaration (
    Type type,
    FakeList<Declarator>* declarators
  );

  -> MethodDeclaration (
    Type result,
    Identifier id,
    FakeList<FormalParameter>* parameters,
    int dimensions,
    FakeList<Expression>* exceptions,
    Block block = NULL
  );

  -> ConstructorDeclaration (
    Identifier id,
    FakeList<FormalParameter>* parameters,
    FakeList<Expression>* exceptions,
    Block block
  );

  -> ClassDeclaration (
    Identifier id,
    FakeList<Type>* superclass,
    FakeList<Type>* interfaces,
    FakeList<Declaration>* body
  );

  -> InterfaceDeclaration (
    Identifier id,
    FakeList<Type>* interfaces,
    FakeList<Declaration>* body
  );

  -> BlockDeclaration (
    bool isStatic,
    Block block
  );
}

// ----- Statements

class Statement (
  SourceLoc loc
) {
  public Statement* next = NULL;

  -> Block (
    FakeList<Statement>* statements
  );

  -> DeclarationStatement (
    Declaration declaration
  );

  -> IfStatement (
    Expression test,
    Statement consequence,
    Statement alternative = NULL
  );
 
  -> ForStatement (
    ForInit initializer,
    Expression test,
    FakeList<Expression>* updates,
    Statement body
  );

  -> WhileStatement (
    Expression condition,
    Statement body
  );

  -> DoStatement (
    Statement body,
    Expression condition
  );

  -> TryStatement (
    Block body,
    FakeList<CatchClause>* catchClauses,
    Block finallyClase = NULL
  );

  -> SwitchStatement (
    Expression condition,
    FakeList<Statement>* body
  );

  -> SynchronizedStatement (
    Expression expr,
    Block block
  );

  -> ReturnStatement (
    Expression expr
  );

  -> ThrowStatement (
    Expression expr
  );

  -> BreakStatement (
    Identifier id
  );

  -> ContinueStatement (
    Identifier id
  );

  -> LabeledStatement (
    Identifier label,
    Statement statement
  );

  -> CaseClause (
    Expression condition,
    FakeList<Statement>* statements
  );

  -> DefaultClause (
    FakeList<Statement>* statements
  );

  -> ExpressionStatement (
    Expression expr
  );

  -> EmptyStatement (
  );

}

class ForInit {

  -> ForInitDeclarators (
    bool isFinal,
    Type type,
    FakeList<Declarator>* declarators
  );

  -> ForInitExpressions (
    FakeList<Expression>* expressions = NULL
  );

}

class CatchClause (
  FormalParameter param,
  Block block
) {
  public CatchClause* next = NULL;
}

class Expression (
  SourceLoc loc
) {
  public Expression* next = NULL;

  -> AssignmentExpression (
    Expression left,
    BinaryOperator op,
    Expression right
  );

  -> ConditionalExpression (
    Expression test,
    Expression consequent,
    Expression alternative
  );

  -> BinaryOperation (
    Expression first,
    BinaryOperator op,
    Expression second
  );

  -> UnaryOperation (
    UnaryOperator op,
    Expression expr
  );

  -> CastExpression (
    Type type,
    Expression expr
  );

  -> SubscriptExpression (
    Expression base,
    Expression index
  );

  -> InvocationExpression (
    Expression base,
    FakeList<Expression>* arguments
  );

  -> SelectionExpression (
    Expression base,
    Expression selector
  );

  -> ClassSelectionExpression (
    Expression base
  );

  -> DimensionExpression (
    Expression size
  );

  -> ArrayInitializer(
    FakeList<Expression>* entries
  );

  -> ThisExpression (
  );

  -> SuperExpression (
  );

  -> VoidClassExpression (
  );

  -> NewClassExpression (
    QualifiedIdentifier name,
    FakeList<Expression>* arguments,
    FakeList<Declaration>* body
  );

  -> NewArrayExpression (
    TypeName type,
    FakeList<Expression>* dimExpr,
    int dim,
    ArrayInitializer init = NULL
  );

  // rgrimm: To make the compiler happy, the fake list has expressions
  // as its members, though in real life they should be identifiers.
  -> QualifiedIdentifier (
    FakeList<Expression>* identifiers
  );

  -> Identifier (
    StringRef name
  );

  -> IntLiteral (
    StringRef text
  );

  -> FloatLiteral (
    StringRef text
  );

  -> StringLiteral (
    StringRef text
  );

  -> CharLiteral (
    StringRef text
  );

  -> BooleanLiteral (
    bool value
  );

  -> NullLiteral (
  );

}

// ----- Types

class Type (
  TypeName name,
  int dimensions = 0
) {
  public Type* next = NULL;
}

class TypeName {

  -> BasicTypeName (
    BasicType type
  );

  -> ReferenceTypeName (
    QualifiedIdentifier name
  );

}

// ----- Identifiers

// For consistency, identifiers are expressions; see above.

// EOF