Project

General

Profile

root / trunk / compiler / ooasCompiler / src / org / momut / ooas / codegen / ast / IAstDuplicator.java @ 7

1
/**
2
  *
3
  *                      OOAS Compiler
4
  *
5
  *       Copyright 2015, AIT Austrian Institute of Technology.
6
  * This code is based on the C# Version of the OOAS Compiler, which is
7
  * copyright 2015 by the Institute of Software Technology, Graz University
8
  * of Technology with portions copyright by the AIT Austrian Institute of
9
  * Technology. All rights reserved.
10
  *
11
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
12
  *
13
  * If you modify the file please update the list of contributors below to in-
14
  * clude your name. Please also stick to the coding convention of using TABs
15
  * to do the basic (block-level) indentation and spaces for anything after
16
  * that. (Enable the display of special chars and it should be pretty obvious
17
  * what this means.) Also, remove all trailing whitespace.
18
  *
19
  * Contributors:
20
  *               Willibald Krenn (AIT)
21
  *               Stephan Zimmerer (AIT)
22
  *               Markus Demetz (AIT)
23
  *               Christoph Czurda (AIT)
24
  *
25
  */
26

    
27

    
28
package org.momut.ooas.codegen.ast;
29

    
30
import org.momut.ooas.ast.expressions.ExpressionKind;
31
import org.momut.ooas.ast.identifiers.IdentifierKind;
32
import org.momut.ooas.ast.identifiers.MainModule;
33
import org.momut.ooas.ast.statements.StatementKind;
34
import org.momut.ooas.ast.types.TypeKind;
35

    
36
/**
37
 * Defines a low-level interface that can be used to copy
38
 * the OOAS AST. Initially defined for the C++ backend.
39
 *
40
 * @author willibald
41
 */
42

    
43
public interface IAstDuplicator<T> {
44

    
45
        /** Allocate an identifier */
46
        T createIdentifier(IdentifierKind kind, int subOrd);
47
        /** Allocate a type */
48
        T createType(TypeKind kind);
49
        /** Allocate an expression */
50
        T createExpression(ExpressionKind kind, int subOrd);
51
        /** Allocate a statement */
52
        T createStatement(StatementKind kind);
53
        /** Allocate a new action system instance object */
54
        T createActionSystemInstance();
55
        /** Allocate a new symbol table */
56
        T createSymbolTable();
57
        /** Allocate a new list for method/function parameters */
58
        T createParameterList();
59
        /** Allocate a new list for types */
60
        T createTypeList();
61
        /** Allocate a new list for action system instances */
62
        T createActionSystemInstanceList();
63
        /** Allocate a new statement list */
64
        T createStatementList();
65
        /** Allocate a new expression list */
66
        T createExpressionList();
67
        /** Allocate a new list of identifiers */
68
        T createIdentifierList();
69

    
70
        /** Cast an AstElement object to IScope */
71
        T castToIScope(T input);
72

    
73
        /** Adds an identifier to a symbol table */
74
        boolean addIdentifierToSymbolTable(T symbolTable, T identifier);
75
        /** Adds a parameter identifier to a parameter list */
76
        boolean addParameterIdentifierToList(T parameterList, T param);
77
        /** Adds a type to a type-list */
78
        boolean addTypeToList(T typeList, T type);
79
        /** Adds an instance (ref) to a instance list */
80
        boolean addActionSystemInstanceToList(T objectsList, T instanceRef);
81
        /** Adds an identifier to an identifier block */
82
        boolean addIdentifierToBlock(T idBlock, T idRef);
83
        /** Adds a statement to a statement list */
84
        boolean addStatementToList(T stmtList, T stmntRef);
85
        /** Adds an expression to an expression list */
86
        boolean addExpressionToList(T exprList, T exprRef);
87
        /** Adds an identifier to an identifier list */
88
        boolean addIdentifierToList(T idList, T idRef);
89

    
90
        /** Initialize an EnumIdentifier */
91
        boolean initEnumIdentifier(
92
                        T enumId,
93
                        int line,
94
                        int col,
95
                        String text,
96
                        T scopeRef,
97
                        T typeRef,
98
                        boolean haveValue,
99
                        int value);
100

    
101
        /** Initialize an ConstantIdentifier*/
102
        boolean initConstantIdentifier(
103
                        T constId,
104
                        int line,
105
                        int col,
106
                        String text,
107
                        T scopeRef,
108
                        T typeRef,
109
                        T valueRef);
110

    
111
        /** Initialize an AttributeIdentifier */
112
        boolean initAttributeIdentifier(
113
                        T attrId,
114
                        int line,
115
                        int col,
116
                        String text,
117
                        T scopeRef,
118
                        T typeRef,
119
                        T initRef,
120
                        boolean isStatic,
121
                        boolean isControllable,
122
                        boolean isObservable);
123

    
124
        /** Initialize an ExpressionVarIdentifier */
125
        boolean initExprVarIdentifier(
126
                        T exprVarId,
127
                        int line,
128
                        int col,
129
                        String text,
130
                        T scopeRef,
131
                        T typeRef,
132
                        boolean initialized);
133

    
134
        /** Initialize a ParamIdentifier */
135
        boolean initParamIdentifier(
136
                        T paramId,
137
                        int line,
138
                        int column,
139
                        String text,
140
                        T scopeRef,
141
                        T typeRef);
142

    
143
        /** Initialize a LocalVarIdentifier */
144
        boolean initLocalVarIdentifier(
145
                        T locVarId,
146
                        int line,
147
                        int column,
148
                        String text,
149
                        T scopeRef,
150
                        T typeRef);
151

    
152
        /** Initialize a TypeIdentifier */
153
        boolean initTypeIdentifier(
154
                        T typeId,
155
                        int line,
156
                        int column,
157
                        String text,
158
                        T scopeRef,
159
                        T typeRef,
160
                        String prefix);
161

    
162
        /** Special version of the TypeIdentifier: */
163
        boolean initSelfIdentifier(
164
                        T typeId,
165
                        int line,
166
                        int column,
167
                        String text,
168
                        T scopeRef,
169
                        T typeRef,
170
                        String prefix);
171

    
172
        /** Initialize a MethodIdentifier */
173
        boolean initMethodIdentifier(
174
                        T methodId,
175
                        int line,
176
                        int column,
177
                        String text,
178
                        T scopeRef,
179
                        T typeRef,
180
                        String prefix,
181
                        T parameterListRef,
182
                        T symbolTableRef,
183
                        T bodyRef);
184

    
185
        /** Initialize a Module */
186
        boolean initModule(
187
                        T moduleId,
188
                        int line,
189
                        int column,
190
                        String text,
191
                        T scopeRef,
192
                        T typeRef,
193
                        String prefix,
194
                        T symTabRef);
195

    
196
        /** Initialize the Main Module */
197
        boolean initMainModule(
198
                        T moduleId,
199
                        int line,
200
                        int column,
201
                        String text,
202
                        T scopeRef,
203
                        T typeRef,
204
                        String prefix,
205
                        T symTabRef,
206
                        T identifierListRef);
207

    
208
        /** Initialize an integer type */
209
        boolean initIntType(
210
                        T typeId,
211
                        T identifierRef,
212
                        boolean anonymousType,
213
                        int low,
214
                        int high);
215

    
216
        /** Initialize a bool type */
217
        boolean initBoolType(
218
                        T typeId,
219
                        T identifierRef,
220
                        boolean anonymousType);
221

    
222
        /** Initialize a valued enum type */
223
        boolean initValuedEnumType(
224
                        T typeId,
225
                        T identifierRef,
226
                        boolean anonymousType,
227
                        T symTabRef,
228
                        T intTypeRef);
229

    
230
        /** Initialize a normal enum type */
231
        boolean initEnumType(
232
                        T typeId,
233
                        T identifierRef,
234
                        boolean anonymousType,
235
                        T symTabRef);
236

    
237
        /** Initialize a list type */
238
        boolean initListType(
239
                        T typeId,
240
                        T identifierRef,
241
                        boolean anonymousType,
242
                        T innerTypeRef,
243
                        int maxNumberOfElements);
244

    
245
        /** Initialize a tuple type */
246
        boolean initTupleType(
247
                        T typeId,
248
                        T identifierRef,
249
                        boolean anonymousType,
250
                        T typeListRef);
251

    
252
        /** Initialize a function type */
253
        boolean initFunctionType(
254
                        T typeId,
255
                        T identifierRef,
256
                        boolean anonymousType,
257
                        T paramTypeListRef,
258
                        T returnTypeRef,
259
                        int functionKind,
260
                        boolean isPure);
261

    
262
        /** Initialize an action system instance */
263
        boolean initActionSystemInstance(
264
                        T instance,
265
                        T typeRef,
266
                        String name,
267
                        int numOfCreatedObjs,
268
                        T parentInstanceRef);
269

    
270
        /** Initialize an action system type */
271
        boolean initActionSystemType(
272
                        T typeId,
273
                        T identifierRef,
274
                        boolean anonymousType,
275
                        T baseTypeRef,
276
                        T parentScopeRef,
277
                        T doOdBlockRef,
278
                        T symTab,
279
                        T objectsListRef,
280
                        T derivedObjectsListRef,
281
                        boolean autoConstruction,
282
                        boolean isInSystemDescription);
283

    
284
        /** Initialize a null-type */
285
        boolean initNullType(
286
                        T typeId,
287
                        T identifierRef,
288
                        boolean anonymousType);
289

    
290
        /** Initialize a skip statement */
291
        boolean initSkipStatement(
292
                        T stmnt,
293
                        int line,
294
                        int col);
295

    
296
        /** Initialize a break statement */
297
        boolean initBreakStatement(
298
                        T stmnt,
299
                        int line,
300
                        int col);
301

    
302
        /** Initialize an abort statement */
303
        boolean initAbortStatement(
304
                        T stmnt,
305
                        int line,
306
                        int col);
307

    
308
        /** Initialize a nondet block */
309
        boolean initNondetBlock(
310
                        T block,
311
                        int line,
312
                        int col,
313
                        T symTabRef,
314
                        T stmtListRef,
315
                        T scopeRef);
316

    
317
        /** Initialize a nondet block */
318
        boolean initSeqBlock(
319
                        T block,
320
                        int line,
321
                        int col,
322
                        T symTabRef,
323
                        T stmtListRef,
324
                        T scopeRef,
325
                        T filterExprRef);
326

    
327
        /** Initialize a nondet block */
328
        boolean initPrioBlock(
329
                        T block,
330
                        int line,
331
                        int col,
332
                        T symTabRef,
333
                        T stmtListRef,
334
                        T scopeRef);
335

    
336
        /** Initialize a guarded command */
337
        boolean initGuardedCommand(
338
                        T stmt,
339
                        int line,
340
                        int pos,
341
                        T scopeRef,
342
                        T guardExprRef,
343
                        T bodyRef);
344

    
345
        /** Initialize an assignment statement */
346
        boolean initAssignment(
347
                        T stmt,
348
                        int line,
349
                        int pos,
350
                        T scopeRef,
351
                        T nonDetExprRef,
352
                        T placeExprListRef,
353
                        T valueExprListRef,
354
                        T symTabRef);
355

    
356
        /** Initialize a call expression */
357
        boolean initCall(
358
                        T stmt,
359
                        int line,
360
                        int pos,
361
                        T callExprRef);
362

    
363
        /** Initialize a type expression */
364
        boolean initTypeExpression(
365
                        T expr,
366
                        int line,
367
                        int pos,
368
                        T typeRef,
369
                        T callTargetsIdentifierListRef,
370
                        T symbTabRef);
371

    
372
        /** Initialize an identifier expression */
373
        boolean initIdentifierExpression(
374
                        T expr,
375
                        int line,
376
                        int pos,
377
                        T typeRef,
378
                        T callTargetsIdentifierListRef,
379
                        T symbTabRef,
380
                        T identifierRef,
381
                        boolean isSelf);
382

    
383
        /** Initialize a unary operator */
384
        boolean initUnaryExpression(
385
                        T expr,
386
                        int line,
387
                        int pos,
388
                        T typeRef,
389
                        T callTargetsIdentifierListRef,
390
                        T symbTabRef,
391
                        T child);
392

    
393
        /** Initialize a binary expression */
394
        boolean initBinaryExpression(
395
                        T expr,
396
                        int line,
397
                        int pos,
398
                        T typeRef,
399
                        T callTargetsIdentifierListRef,
400
                        T symbTabRef,
401
                        T left,
402
                        T right);
403

    
404
        /** Initialize a ternary expression */
405
        boolean initTernaryExpression(
406
                        T expr,
407
                        int line,
408
                        int pos,
409
                        T typeRef,
410
                        T callTargetsIdentifierListRef,
411
                        T symbTabRef,
412
                        T left,
413
                        T mid,
414
                        T right,
415
                        T defScopeRef);
416

    
417
        /** Initialize an IntValue expression */
418
        boolean initIntValueExpression(
419
                        T expr,
420
                        int line,
421
                        int pos,
422
                        T typeRef,
423
                        T callTargetsIdentifierListRef,
424
                        T symbTabRef,
425
                        int value);
426

    
427
        /** Initialize a BoolValue expression */
428
        boolean initBoolValueExpression(
429
                        T expr,
430
                        int line,
431
                        int pos,
432
                        T typeRef,
433
                        T callTargetsIdentifierListRef,
434
                        T symbTabRef,
435
                        boolean value);
436

    
437
        /** Initialize a RefValue expression */
438
        boolean initNullValueExpression(
439
                        T expr,
440
                        int line,
441
                        int pos,
442
                        T typeRef,
443
                        T callTargetsIdentifierListRef,
444
                        T symbTabRef);
445

    
446
        /** Initialize a ListConstructor expression */
447
        boolean initListConstructor(
448
                        T expr,
449
                        int line,
450
                        int pos,
451
                        T typeRef,
452
                        T callTargetsIdentifierListRef,
453
                        T symbTabRef,
454
                        T exprList,
455
                        T symTab,
456
                        T parentScope,
457
                        T comprehension,
458
                        boolean hasComprehension);
459

    
460
        /** Initialize a SetConstructor expression */
461
        boolean initSetConstructor(
462
                        T expr,
463
                        int line,
464
                        int pos,
465
                        T typeRef,
466
                        T callTargetsIdentifierListRef,
467
                        T symbTabRef,
468
                        T exprList,
469
                        T symTab,
470
                        T parentScope,
471
                        T comprehension,
472
                        boolean hasComprehension);
473

    
474
        /** Initialize a TupleConstructor expression */
475
        boolean initTupleConstructor(
476
                        T expr,
477
                        int line,
478
                        int pos,
479
                        T typeRef,
480
                        T callTargetsIdentifierListRef,
481
                        T symbTabRef,
482
                        T exprList,
483
                        T tupleTypeId,
484
                        boolean isMatcher);
485

    
486
        /** Initialize an access expression */
487
        boolean initAccessExpression(
488
                        T expr,
489
                        int line,
490
                        int pos,
491
                        T typeRef,
492
                        T callTargetsIdentifierListRef,
493
                        T symbTabRef,
494
                        T left,
495
                        T right);
496

    
497
        /** Initialize a tuple/map access expression */
498
        boolean initTupleMapAccessExpression(
499
                        T expr,
500
                        int line,
501
                        int pos,
502
                        T typeRef,
503
                        T callTargetsIdentifierListRef,
504
                        T symbTabRef,
505
                        T child,
506
                        T argument);
507

    
508
        /** Initialize a tuple/map access expression */
509
        boolean initCallExpression(
510
                        T expr,
511
                        int line,
512
                        int pos,
513
                        T typeRef,
514
                        T callTargetsIdentifierListRef,
515
                        T symbTabRef,
516
                        T child,
517
                        T argumentList,
518
                        T scopeRef);
519

    
520
        /** Initialize a quantifier expression */
521
        boolean initQuantifierExpression(
522
                        T expr,
523
                        int line,
524
                        int pos,
525
                        T typeRef,
526
                        T callTargetsIdentifierListRef,
527
                        T symbTabRef,
528
                        T child,
529
                        T symTabRef,
530
                        T scopeRef);
531

    
532
        /** Initialize an object constructor expression */
533
        boolean initObjectConstructor(
534
                        T expr,
535
                        int line,
536
                        int pos,
537
                        T typeRef,
538
                        T callTargetsIdentifierListRef,
539
                        T symbTabRef,
540
                        T instanceList,
541
                        int currentInstance,
542
                        String name);
543

    
544

    
545
        /** Sets the top level structure of the AST - the main module. */
546
        void setMainModule(MainModule mainModule, T id);
547
}