parser.delphi initial commit.

This commit is contained in:
bitwave 2013-05-25 16:10:03 +02:00
parent 9731dae7f9
commit 1a965a4d2f
176 changed files with 29977 additions and 0 deletions

4
ch.bitwave.parser.delphi/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/target
/.settings
/.classpath
/.project

View File

@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ch.bitwave</groupId>
<artifactId>maven.platform.parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>parser.delphi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>
<dependency>
<groupId>ch.bitwave</groupId>
<artifactId>platform</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.0</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<visitor>true</visitor>
<outputDirectory>src/main/java</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<!-- Parsing a large Delphi unit creates a huge parse tree, so we need
a larger heap. -->
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,554 @@
/*------------------------------------------------------------------
* ANTLR4 Delphi grammar
*
* Based on previous work done by Kathleen Jensen, Niklaus Wirth,
* Hakki Dogusan, Piet Schoutteten, Terence Parr and Marton Papp.
*
* 2013:
* ANTLR4-adaption and Delphi syntax by Florian Winkelman.
*------------------------------------------------------------------*/
grammar Delphi;
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
delphiUnit: UNIT identifier ES interfaceSection implementationSection END? DOT;
interfaceSection: INTERFACE interfaceDeclarationSection*;
interfaceDeclarationSection: usesSection | typeSection | constSection | varSection | labelSection | proceduralDeclaration;
implementationSection: IMPLEMENTATION implementationDeclarationSection* implementationBlocks* compoundStatement?;
implementationDeclarationSection: usesSection | typeSection | constSection | varSection | labelSection;
usesSection: USES identifier (COMMA identifier)* ES;
labelSection: LABEL identifierList ES;
typeSection: TYPE typeDeclarations ES;
typeDeclarations: typeDeclaration (ES typeDeclaration)*;
typeDeclaration: identifier EQ type;
variableDeclarations: variableDeclaration (ES variableDeclarations)* ES?;
ancestorDeclaration: '(' identifierList? ')';
interfaceDeclarationBody: guidSpecifier? interfaceMemberDeclarations? END;
guidSpecifier: '[' (identifier | literalString) ']';
interfaceMemberDeclarations: interfaceMemberDeclaration*;
interfaceMemberDeclaration: (propertyDeclaration | methodDeclaration) ES;
classDeclarationBody: classMemberDeclaration* END;
classMemberDeclaration: PRIVATE | PROTECTED | PUBLIC | PUBLISHED | (fieldDeclaration | propertyDeclaration | methodDeclaration) ES;
fieldDeclaration: variableDeclaration;
variableDeclaration: identifierList typeSpecifier? defaultValue?;
propertyDeclaration: PROPERTY identifier propertyAccessDeclaration? typeSpecifier readAccessorDeclaration? writeAccessorDeclaration? defaultModifier?;
defaultModifier: ES DEFAULT;
readAccessorDeclaration: READ identifier;
writeAccessorDeclaration: WRITE identifier;
propertyAccessDeclaration: '[' parameterList ']';
defaultValue: EQ expression;
typeSpecifier: COLON type;
identifierList: identifier (COMMA identifier)*;
proceduralDeclaration: functionDeclaration | procedureDeclaration;
procedureDeclaration: PROCEDURE identifier parametersDeclaration? functionDirective* ES;
functionDeclaration: FUNCTION identifier parametersDeclaration? typeSpecifier functionDirective* ES;
methodDeclaration: memberConstructorDeclaration | memberDestructorDeclaration
| memberProcedureDeclaration | memberFunctionDeclaration;
functionDirective:
overloadDirective
| inlineDirective
| assemblerDirective
| callConventionDirective
| oldCallConventionDirective
| hintingDirective
| varargsDirective
| externalDirective
| forwardDirective
| UNSAFE;
overloadDirective: ES OVERLOAD;
forwardDirective: ES FORWARD;
inlineDirective: ES INLINE;
assemblerDirective: ES ASSEMBLER;
methodDirective:
reintroduceDirective
| overloadDirective
| bindingDirective
| abstractDirective
| finalDirective
| inlineDirective
| assemblerDirective
| callConventionDirective
| hintingDirective
| dispIDDirective;
reintroduceDirective: ES REINTRODUCE;
dispIDDirective: ES DISPID expression;
bindingDirective:
messageDirective
| staticDirective
| dynamicDirective
| overrideDirective
| virtualDirective;
messageDirective: ES MESSAGE expression;
staticDirective: ES STATIC;
dynamicDirective: ES DYNAMIC;
overrideDirective: ES OVERRIDE;
virtualDirective: ES VIRTUAL;
abstractDirective: ES ABSTRACT;
finalDirective: ES FINAL;
callConventionDirective:
cdeclDirective
| pascalDirective
| registerDirective
| safecallDirective
| stdcallDirective
| exportDirective;
cdeclDirective: ES CDECL;
pascalDirective: ES PASCAL;
registerDirective: ES REGISTER;
safecallDirective: ES SAFECALL;
stdcallDirective: ES STDCALL;
exportDirective: ES EXPORT;
oldCallConventionDirective:
farDirective
| localDirective
| nearDirective;
farDirective: ES FAR;
localDirective: ES LOCAL;
nearDirective: ES NEAR;
hintingDirective:
deprecatedDirective
| experimentalDirective
| platformDirective
| libraryDirective;
deprecatedDirective: ES DEPRECATED literalString?;
experimentalDirective: ES EXPERIMENTAL;
platformDirective: ES PLATFORM;
libraryDirective: ES LIBRARY;
varargsDirective: ES VARARGS;
externalDirective: ES EXTERNAL constant externalSpecifier*;
externalSpecifier: NAME constant | INDEX constant;
memberProcedureDeclaration: PROCEDURE identifier parametersDeclaration? methodDirective*;
memberFunctionDeclaration: FUNCTION identifier parametersDeclaration? typeSpecifier methodDirective*;
memberConstructorDeclaration: CONSTRUCTOR identifier parametersDeclaration? methodDirective*;
memberDestructorDeclaration: DESTRUCTOR identifier methodDirective*;
parametersDeclaration: '(' parameterList? ')';
parameterList: parameterDeclaration (ES parameterDeclaration)*;
parameterDeclaration: paramModifier? identifierList typeSpecifier? defaultValue?;
paramModifier: CONST | VAR | OUT;
constSection: CONST (constDeclaration ES)*;
constDeclaration: identifier typeDefinition? '=' initializer;
initializer: arrayInitializer | recordInitializer | expression;
arrayInitializer: '(' constantList ')';
recordInitializer: '(' recordItemList ')';
typeDefinition: COLON type;
elementList: element ( COMMA element )*;
element: expression ( DOTDOT expression )?;
varSection: VAR (variableDeclaration ES)*;
memberImplementation: memberConstructorImplementation | memberDestructorImplementation
| memberProcedureImplementation | memberFunctionImplementation;
memberConstructorImplementation: CONSTRUCTOR qualifiedIdentifier parametersDeclaration? ES codeBlock;
memberDestructorImplementation: DESTRUCTOR qualifiedIdentifier ES codeBlock;
memberProcedureImplementation: PROCEDURE qualifiedIdentifier parametersDeclaration? ES codeBlock;
memberFunctionImplementation: FUNCTION qualifiedIdentifier parametersDeclaration? typeSpecifier ES codeBlock;
functionImplementation: FUNCTION identifier parametersDeclaration? typeSpecifier ES codeBlock;
procedureImplementation: PROCEDURE identifier parametersDeclaration? ES codeBlock;
implementationBlock: memberImplementation | proceduralImplementation;
proceduralImplementation: procedureImplementation | functionImplementation;
localBlock: (proceduralImplementation | proceduralDeclaration) ES?;
implementationBlocks: implementationBlock (ES implementationBlock)* ES?;
qualifiedIdentifier: identifier DOT identifier;
codeBlock: (localBlock | implementationDeclarationSection)* compoundStatement;
statements: statement (ES statement)*;
statement: labelledStatement | unlabelledStatement;
labelledStatement: label COLON unlabelledStatement;
unlabelledStatement: simpleStatement | structuredStatement;
simpleStatement: assignmentStatement | memberAccessStatement | raiseException | gotoStatement | emptyStatement;
structuredStatement: compoundStatement | conditionalStatement | repetetiveStatement | withStatement;
compoundStatement: BEGIN statements END;
conditionalStatement: ifStatement | caseStatement | tryBlock;
repetetiveStatement: whileStatement | repeatStatement | forStatement;
assignmentStatement: (variable | memberAccess) ASSIGNMENT expression;
memberAccessStatement: memberAccess;
forStatement: FOR identifier ASSIGNMENT expression (TO | DOWNTO) expression DO statement;
whileStatement: WHILE expression DO statement;
repeatStatement: REPEAT statements UNTIL expression;
ifStatement: IF expression THEN statement (ELSE statement)?;
memberAccess: INHERITED | INHERITED? memberInvocation (DOT memberInvocation)*;
memberInvocation: (bracketedExpression | functionCall) dimensionQualifiers? POINTER?;
functionCall: identifier argumentList?;
argumentList: '(' expressionList? ')';
expressionList: expression (COMMA expression)*;
expression: simpleExpression (expressionOperator simpleExpression)?;
expressionOperator: EQ | NEQ | LT | LTE | GTE | GT | IN;
simpleExpression: term (simpleOperator term)*;
simpleOperator: PLUS | MINUS | OR | XOR;
term: signedFactor (termOperator signedFactor)*;
termOperator: STAR | MOD | AND | SLASH | DIV | SLASH | SHL | SHR;
sign: PLUS | MINUS;
signedFactor: sign? factor;
factor: (variable | constant | memberAccess | bracketedExpression
| typeCheck | negation) (AS typeIdentifier)?;
negation: NOT factor;
variable: AT? identifier (dimensionQualifiers | POINTER*)?;
recordItemList: recordItem (COMMA recordItem)*;
recordItem: '(' recordFieldList ')' | recordFieldList;
recordFieldList: recordField (ES recordField)*;
recordField: identifier COLON expression;
typeCheck: memberAccess IS type;
bracketedExpression: '(' expression ')';
raiseException: RAISE expression?;
tryBlock: TRY statements (exceptClause | finallyClause);
exceptClause: EXCEPT (exceptionHandlers ES? | statements) elseCase? END;
exceptionHandlers: exceptionHandler (ES exceptionHandler)*;
exceptionHandler: ON identifier typeSpecifier? DO statement;
finallyClause: FINALLY statements END;
caseStatement: CASE memberAccess OF caseItems elseCase? END;
caseItems: caseItem (ES caseItem)* ES?;
caseItem: constantList COLON statement;
elseCase: ELSE statements ES?;
label: unsignedInteger | identifier;
gotoStatement: GOTO label;
emptyStatement: ;
withStatement: WITH expressionList DO statement;
type: simpleType | structuredType | pointerType | classType | classOfClassType | interfaceType
| procedureType | functionType;
classType: CLASS ancestorDeclaration? classDeclarationBody?;
classOfClassType: CLASS OF typeIdentifier;
interfaceType: INTERFACE (ancestorDeclaration? interfaceDeclarationBody)?;
procedureType: PROCEDURE parametersDeclaration? (OF OBJECT)? functionDirective*;
functionType: FUNCTION parametersDeclaration? typeSpecifier (OF OBJECT)? functionDirective*;
simpleType: scalarType | subrangeType | typeIdentifier | qualifiedTypeIdentifier | staticStringType;
scalarType: '(' scalarDeclarations ')';
scalarDeclarations: scalarDeclaration (COMMA scalarDeclaration)*;
scalarDeclaration: identifier (EQ constant)?;
/* the subrangeType takes const arguments but must support complex const expressions like Low(TFooEnum) */
subrangeType: expression DOTDOT expression;
structuredType: PACKED unpackedStructuredType | unpackedStructuredType;
unpackedStructuredType: arrayType | recordType | setType | fileType;
staticStringType: STRING '(' (identifier | unsignedNumber) ')';
arrayType: ARRAY dimensionQualifiers? OF componentType;
/* adds dimensional qualifiers to an expression, which tell which subordinate element of the object to resolve. */
dimensionQualifiers: '[' dimensionQualifier ( COMMA dimensionQualifier )* ']';
/* The qualifier must support constants (0), ranges (0..1), expressions (intIndex + 3) etc. */
dimensionQualifier: simpleType | expression;
componentType: type;
recordType: RECORD recordFieldDeclaration END;
recordFieldDeclaration: ( fixedPart ( ES variantPart | ES )? | variantPart );
fixedPart: recordSection ( ES recordSection )*;
recordSection: identifierList COLON type;
variantPart: CASE (identifier COLON)? typeIdentifier OF variant ( ES variant | ES )*;
variant: constantList COLON '(' recordFieldDeclaration ')';
setType: SET OF simpleType;
fileType: FILE^ OF! type | FILE;
pointerType: POINTER^ typeIdentifier;
/* The identifier must be considered a constant because it may identify one. */
constant: unsignedNumber | signedNumber | literalString | primitiveFunctionConstant
| charLiteralConstant | setConstant | nil | identifier;
nil: NIL;
constantList: constant ( COMMA constant )*;
setConstant: '[' elementList? ']';
signedNumber: sign unsignedNumber;
unsignedNumber: unsignedInteger | unsignedReal;
unsignedInteger: LITERAL_INTEGER | HEX_LITERAL;
unsignedReal: LITERAL_REAL;
literalString: LITERAL_STRING;
primitiveFunctionConstant: typeIdentifier '(' constant ')';
charLiteralConstant: HASH unsignedInteger;
/* the identifier has to cover every lexer token because otherwise method calls and
indirections will fail if they match such a token. Not the END token though. */
identifier: IDENT | typeIdentifier | NAME | MESSAGE | INDEX | WRITE | READ | OBJECT | SET | PROPERTY | UNIT
| INTERFACE | IMPLEMENTATION | USES | TYPE | CLASS | BEGIN | OUT;
typeIdentifier: IDENT | CHR | CHAR | BOOLEAN | INTEGER | CARDINAL | REAL | DOUBLE | STRING;
qualifiedTypeIdentifier: IDENT DOT IDENT;
/*------------------------------------------------------------------
* LEXER RULES
*------------------------------------------------------------------*/
COMMA: ',';
END: 'end';
LINE_COMMENT: '//' ~[\r\n]* '\r'? '\n' -> channel(HIDDEN);
BLOCK_COMMENT1: '{' .*? '}' -> channel(HIDDEN);
BLOCK_COMMENT2: '(*' .*? '*)' -> channel(HIDDEN);
WS: ( '\t' | ' ' | '\r' | '\n' )+ -> channel(HIDDEN);
ES: ';';
UNIT: 'unit';
INTERFACE: 'interface';
USES: 'uses';
TYPE: 'type';
CLASS: 'class';
PRIVATE: 'private';
PROTECTED: 'protected';
PUBLIC: 'public';
PUBLISHED: 'published';
PROCEDURE: 'procedure';
FUNCTION: 'function';
CONSTRUCTOR: 'constructor';
DESTRUCTOR: 'destructor';
BEGIN: 'begin';
VAR: 'var';
CONST: 'const';
OUT: 'out';
FORWARD: 'forward';
VIRTUAL: 'virtual';
ABSTRACT: 'abstract';
OVERRIDE: 'override';
OVERLOAD: 'overload';
REINTRODUCE: 'reintroduce';
INHERITED: 'inherited';
IMPLEMENTATION: 'implementation';
INTEGER: 'integer';
CARDINAL: 'cardinal';
BOOLEAN: 'boolean';
STRING: 'string';
DOT: '.';
DOTDOT: '..';
CHAR: 'char';
CHR: 'chr';
HASH: '#';
REAL: 'real';
DOUBLE: 'double';
PACKED: 'packed';
RECORD: 'record';
ARRAY: 'array';
COLON: ':';
FILE: 'file';
FOR: 'for';
WHILE: 'while';
REPEAT: 'repeat';
UNTIL: 'until';
IF: 'if';
THEN: 'then';
ELSE: 'else';
CASE: 'case';
OF: 'of';
ON: 'on';
TRY: 'try';
EXCEPT: 'except';
FINALLY: 'finally';
RAISE: 'raise';
POINTER: '^';
ASSIGNMENT: ':=';
TO: 'to';
DOWNTO: 'downto';
DO: 'do';
AS: 'as';
IS: 'is';
MINUS: '-';
PLUS: '+';
SLASH: '/';
STAR: '*';
NEQ: '<>';
EQ: '=';
GT: '>';
LT: '<';
GTE: '>=';
LTE: '<=';
MOD: 'mod';
DIV: 'div';
NOT: 'not';
AND: 'and';
OR: 'or';
XOR: 'xor';
SHL: 'shl';
SHR: 'shr';
OBJECT: 'object';
SET: 'set';
IN: 'in';
NIL: 'nil';
AT: '@';
GOTO: 'goto';
PROPERTY: 'property';
READ: 'read';
WRITE: 'write';
CDECL: 'cdecl';
STDCALL: 'stdcall';
UNSAFE: 'unsafe';
INLINE: 'inline';
ASSEMBLER: 'assembler';
DISPID: 'dispid';
MESSAGE: 'message';
STATIC: 'static';
DYNAMIC: 'dynamic';
FINAL: 'final';
PASCAL: 'pascal';
REGISTER: 'register';
SAFECALL: 'safecall';
EXPORT: 'export';
FAR: 'far';
LOCAL: 'local';
NEAR: 'near';
DEPRECATED: 'deprecated';
EXPERIMENTAL: 'experimental';
PLATFORM: 'platform';
LIBRARY: 'library';
VARARGS: 'varargs';
EXTERNAL: 'external';
NAME: 'name';
INDEX: 'index';
DEFAULT: 'default';
LABEL: 'label';
WITH: 'with';
IDENT: [a-zA-Z_] [a-zA-Z0-9_]*;
LITERAL_INTEGER: [0-9]+;
HEX_LITERAL: '$' [a-fA-F0-9]+;
fragment EXPONENTIAL_NOTATION: [0-9]+ (DOT [0-9]+)? 'e' (MINUS | PLUS)? [0-9]+;
fragment FP_NOTATION: [0-9]+ (DOT [0-9]+);
LITERAL_REAL: EXPONENTIAL_NOTATION | FP_NOTATION;
LITERAL_STRING: '\'' (~ '\'' | '\'\'')* '\'';

View File

@ -0,0 +1,257 @@
ASSEMBLER=105
FUNCTION=22
SHR=91
EXTERNAL=123
LT=81
STAR=77
WHILE=54
MOD=84
SHL=90
CONST=27
POINTER=67
CASE=60
CHAR=43
DO=71
FAR=115
DEPRECATED=118
NOT=86
DISPID=106
EXCEPT=64
TYPE=15
FINAL=110
NAME=124
DOWNTO=70
BEGIN=25
EXPERIMENTAL=119
DOUBLE=47
IMPLEMENTATION=36
VAR=26
EXPORT=114
ES=11
RAISE=66
EQ=79
GOTO=97
UNSAFE=103
REGISTER=112
VIRTUAL=30
ARRAY=50
NEAR=117
RECORD=49
LINE_COMMENT=7
STATIC=108
BLOCK_COMMENT2=9
PRIVATE=17
BLOCK_COMMENT1=8
ELSE=59
ON=62
LOCAL=116
INHERITED=35
FILE=52
OF=61
PASCAL=111
TRY=63
REAL=46
UNIT=12
PACKED=48
WS=10
SAFECALL=113
NIL=95
PROPERTY=98
OUT=28
USES=14
READ=99
UNTIL=56
OR=88
GT=80
REPEAT=55
INLINE=104
CDECL=101
END=6
CONSTRUCTOR=23
DYNAMIC=109
DESTRUCTOR=24
PROTECTED=18
CLASS=16
FORWARD=29
LITERAL_INTEGER=130
VARARGS=122
GTE=82
FOR=53
LIBRARY=121
DOTDOT=42
ABSTRACT=31
AND=87
PUBLISHED=20
LTE=83
IF=57
AT=96
INDEX=125
AS=72
BOOLEAN=39
SLASH=76
THEN=58
IN=94
OBJECT=92
COMMA=5
IS=73
IDENT=129
MESSAGE=107
PLUS=75
HEX_LITERAL=131
PLATFORM=120
DOT=41
WITH=128
INTEGER=37
XOR=89
TO=69
DEFAULT=126
HASH=45
SET=93
MINUS=74
REINTRODUCE=34
WRITE=100
PROCEDURE=21
CHR=44
LITERAL_STRING=133
COLON=51
LITERAL_REAL=132
NEQ=78
FINALLY=65
LABEL=127
OVERRIDE=32
T__1=3
T__0=4
T__3=1
T__2=2
OVERLOAD=33
STDCALL=102
ASSIGNMENT=68
INTERFACE=13
DIV=85
PUBLIC=19
STRING=40
CARDINAL=38
'end'=6
'>='=82
'string'=40
'integer'=37
':='=68
'type'=15
'with'=128
';'=11
'downto'=70
'shr'=91
'<>'=78
'for'=53
'uses'=14
'protected'=18
'^'=67
'is'=73
'deprecated'=118
'static'=108
'dispid'=106
'message'=107
'and'=87
'write'=100
'until'=56
'try'=63
'var'=26
'dynamic'=109
'implementation'=36
':'=51
'('=4
'not'=86
'of'=61
'default'=126
'public'=19
']'=1
'real'=46
'finally'=65
'shl'=90
'platform'=120
'const'=27
'export'=114
'div'=85
'='=79
'object'=92
'unit'=12
'virtual'=30
'xor'=89
'case'=60
'boolean'=39
'override'=32
'label'=127
'<='=83
'external'=123
'chr'=44
'<'=81
'['=3
'or'=88
'name'=124
'read'=99
'#'=45
'out'=28
'/'=76
'reintroduce'=34
'then'=58
'experimental'=119
'varargs'=122
'>'=80
'raise'=66
'file'=52
'+'=75
'procedure'=21
'.'=41
'function'=22
'assembler'=105
'library'=121
'pascal'=111
'property'=98
'else'=59
'final'=110
'near'=117
'cardinal'=38
'as'=72
'set'=93
'unsafe'=103
'array'=50
'private'=17
'if'=57
'while'=54
'-'=74
'published'=20
','=5
'in'=94
'..'=42
'class'=16
'begin'=25
'mod'=84
'overload'=33
'repeat'=55
'goto'=97
'stdcall'=102
'@'=96
'inline'=104
')'=2
'destructor'=24
'on'=62
'do'=71
'char'=43
'index'=125
'inherited'=35
'abstract'=31
'constructor'=23
'far'=115
'double'=47
'to'=69
'nil'=95
'packed'=48
'safecall'=113
'forward'=29
'*'=77
'local'=116
'register'=112
'record'=49
'cdecl'=101
'except'=64
'interface'=13

View File

@ -0,0 +1,257 @@
ASSEMBLER=105
FUNCTION=22
SHR=91
EXTERNAL=123
LT=81
STAR=77
WHILE=54
MOD=84
SHL=90
CONST=27
POINTER=67
CASE=60
CHAR=43
DO=71
FAR=115
DEPRECATED=118
NOT=86
DISPID=106
EXCEPT=64
TYPE=15
FINAL=110
NAME=124
DOWNTO=70
BEGIN=25
EXPERIMENTAL=119
DOUBLE=47
IMPLEMENTATION=36
VAR=26
EXPORT=114
ES=11
RAISE=66
EQ=79
GOTO=97
UNSAFE=103
REGISTER=112
VIRTUAL=30
ARRAY=50
NEAR=117
RECORD=49
LINE_COMMENT=7
STATIC=108
BLOCK_COMMENT2=9
PRIVATE=17
BLOCK_COMMENT1=8
ELSE=59
ON=62
LOCAL=116
INHERITED=35
FILE=52
OF=61
PASCAL=111
TRY=63
REAL=46
UNIT=12
PACKED=48
WS=10
SAFECALL=113
NIL=95
PROPERTY=98
OUT=28
USES=14
READ=99
UNTIL=56
OR=88
GT=80
REPEAT=55
INLINE=104
CDECL=101
END=6
CONSTRUCTOR=23
DYNAMIC=109
DESTRUCTOR=24
PROTECTED=18
CLASS=16
FORWARD=29
LITERAL_INTEGER=130
VARARGS=122
GTE=82
FOR=53
LIBRARY=121
DOTDOT=42
ABSTRACT=31
AND=87
PUBLISHED=20
LTE=83
IF=57
AT=96
INDEX=125
AS=72
BOOLEAN=39
SLASH=76
THEN=58
IN=94
OBJECT=92
COMMA=5
IS=73
IDENT=129
MESSAGE=107
PLUS=75
HEX_LITERAL=131
PLATFORM=120
DOT=41
WITH=128
INTEGER=37
XOR=89
TO=69
DEFAULT=126
HASH=45
SET=93
MINUS=74
REINTRODUCE=34
WRITE=100
PROCEDURE=21
CHR=44
LITERAL_STRING=133
COLON=51
LITERAL_REAL=132
NEQ=78
FINALLY=65
LABEL=127
OVERRIDE=32
T__1=3
T__0=4
T__3=1
T__2=2
OVERLOAD=33
STDCALL=102
ASSIGNMENT=68
INTERFACE=13
DIV=85
PUBLIC=19
STRING=40
CARDINAL=38
'end'=6
'>='=82
'string'=40
'integer'=37
':='=68
'type'=15
'with'=128
';'=11
'downto'=70
'shr'=91
'<>'=78
'for'=53
'uses'=14
'protected'=18
'^'=67
'is'=73
'deprecated'=118
'static'=108
'dispid'=106
'message'=107
'and'=87
'write'=100
'until'=56
'try'=63
'var'=26
'dynamic'=109
'implementation'=36
':'=51
'('=4
'not'=86
'of'=61
'default'=126
'public'=19
']'=1
'real'=46
'finally'=65
'shl'=90
'platform'=120
'const'=27
'export'=114
'div'=85
'='=79
'object'=92
'unit'=12
'virtual'=30
'xor'=89
'case'=60
'boolean'=39
'override'=32
'label'=127
'<='=83
'external'=123
'chr'=44
'<'=81
'['=3
'or'=88
'name'=124
'read'=99
'#'=45
'out'=28
'/'=76
'reintroduce'=34
'then'=58
'experimental'=119
'varargs'=122
'>'=80
'raise'=66
'file'=52
'+'=75
'procedure'=21
'.'=41
'function'=22
'assembler'=105
'library'=121
'pascal'=111
'property'=98
'else'=59
'final'=110
'near'=117
'cardinal'=38
'as'=72
'set'=93
'unsafe'=103
'array'=50
'private'=17
'if'=57
'while'=54
'-'=74
'published'=20
','=5
'in'=94
'..'=42
'class'=16
'begin'=25
'mod'=84
'overload'=33
'repeat'=55
'goto'=97
'stdcall'=102
'@'=96
'inline'=104
')'=2
'destructor'=24
'on'=62
'do'=71
'char'=43
'index'=125
'inherited'=35
'abstract'=31
'constructor'=23
'far'=115
'double'=47
'to'=69
'nil'=95
'packed'=48
'safecall'=113
'forward'=29
'*'=77
'local'=116
'register'=112
'record'=49
'cdecl'=101
'except'=64
'interface'=13

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum AccessKind {
PRIVATE, PROTECTED, PUBLIC;
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum AccessModifierKind {
DEFAULT, PRIVATE, PROTECTED, PUBLIC, PUBLISHED;
}

View File

@ -0,0 +1,52 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class AncestorDeclaration extends Node {
private List<Identifier> ancestors;
public AncestorDeclaration() {
this.ancestors = new ArrayList<Identifier>();
}
@Override
public void remove(final Node node) {
this.ancestors.remove(node);
}
@Override
protected boolean internalAdd(final Node node) {
if (node instanceof Identifier) {
this.ancestors.add((Identifier) node);
return true;
}
return false;
}
public void addImport(final Identifier ref) {
internalAdd(ref);
}
public List<Identifier> getAncestors() {
return Collections.unmodifiableList(this.ancestors);
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.ancestors);
}
@Override
public String toString() {
return "AncestorDeclaration";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitAncestorDeclaration(this);
}
}

View File

@ -0,0 +1,43 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ArrayInitializer extends Node {
private List<Constant> constants;
public ArrayInitializer() {
this.constants = new ArrayList<Constant>();
}
@Override
public void remove(final Node node) {
this.constants.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Constant) {
this.constants.add((Constant) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.constants);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitArrayInitializer(this);
}
@Override
public String toString() {
return "ArrayInitializer";
}
}

View File

@ -0,0 +1,63 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ArrayType extends Type {
private List<DimensionQualifier> qualifiers;
private Type componentType;
public Type getComponentType() {
return this.componentType;
}
public void setComponentType(final Type componentType) {
this.componentType = componentType;
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitArrayType(this);
}
public ArrayType() {
this.qualifiers = new ArrayList<DimensionQualifier>();
}
public List<DimensionQualifier> getQualifiers() {
return this.qualifiers;
}
@Override
public void remove(final Node node) {
if (this.componentType == node) {
this.componentType = null;
} else {
this.qualifiers.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Type) {
this.componentType = (Type) node;
return true;
}
if (node instanceof DimensionQualifier) {
this.qualifiers.add((DimensionQualifier) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.qualifiers);
contribute(details, this.componentType);
}
@Override
public String toString() {
return "ArrayType";
}
}

View File

@ -0,0 +1,68 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class AssignmentStatement extends SimpleStatement {
private Node variable;
private Expression value;
public Node getVariable() {
return this.variable;
}
public void setVariable(final Node variable) {
this.variable = variable;
}
public Expression getValue() {
return this.value;
}
public void setValue(final Expression value) {
this.value = value;
}
@Override
public void remove(final Node node) {
if (this.variable == node) {
this.variable = null;
} else if (this.value == node) {
this.value = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.variable == null) {
assertNodeType(node, Node.class);
this.variable = node;
return true;
}
if (this.value == null) {
assertNodeType(node, Expression.class);
this.value = (Expression) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.variable, this.value);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("AssignmentStatement [variable=").append(this.variable).append(", value=")
.append(this.value).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitAssignmentStatement(this);
}
}

View File

@ -0,0 +1,10 @@
package ch.bitwave.lang.delphi.ast;
public class BlockComment extends Comment {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitBlockComment(this);
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public interface BlockItem {
}

View File

@ -0,0 +1,41 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class BracketedExpression extends Node {
private Expression content;
@Override
public void remove(final Node node) {
if (this.content == node) {
this.content = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.content == null) {
assertNodeType(node, Expression.class);
this.content = (Expression) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.content);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("BracketedExpression ").append(this.content);
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitBracketedExpression(this);
}
}

View File

@ -0,0 +1,67 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class CaseItem extends Node {
// constantList COLON statement;
private List<Constant> constants;
private Statement statement;
public CaseItem() {
this.constants = new ArrayList<Constant>();
}
public Statement getStatement() {
return this.statement;
}
public void setStatement(final Statement statement) {
this.statement = statement;
}
public List<Constant> getConstants() {
return this.constants;
}
@Override
public void remove(final Node node) {
if (node instanceof Statement) {
this.statement = null;
} else {
this.constants.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Statement) {
this.statement = (Statement) node;
return true;
}
if (node instanceof Constant) {
this.constants.add((Constant) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.constants);
contribute(details, this.statement);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitCaseItem(this);
}
@Override
public String toString() {
return "CaseItem";
}
}

View File

@ -0,0 +1,83 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class CaseStatement extends ConditionalStatement {
// CASE memberAccess OF caseItems elseCase? END;
private MemberAccess access;
private List<CaseItem> items;
private ElseCase elseCase;
public CaseStatement() {
this.items = new ArrayList<CaseItem>();
}
public MemberAccess getAccess() {
return this.access;
}
public void setAccess(final MemberAccess access) {
this.access = access;
}
public ElseCase getElseCase() {
return this.elseCase;
}
public void setElseCase(final ElseCase elseCase) {
this.elseCase = elseCase;
}
public List<CaseItem> getItems() {
return this.items;
}
@Override
public void remove(final Node node) {
if (this.access == node) {
this.access = null;
} else if (this.elseCase == node) {
this.elseCase = null;
} else {
this.items.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof MemberAccess) {
this.access = (MemberAccess) node;
return true;
}
if (node instanceof ElseCase) {
this.elseCase = (ElseCase) node;
return true;
}
if (node instanceof CaseItem) {
this.items.add((CaseItem) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.access);
details.addAll(this.items);
contribute(details, this.elseCase);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitCaseStatement(this);
}
@Override
public String toString() {
return "CaseStatement";
}
}

View File

@ -0,0 +1,43 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class ClassOfClassType extends Type {
private TypeIdentifier type;
public TypeIdentifier getType() {
return this.type;
}
public void setType(final TypeIdentifier type) {
this.type = type;
}
@Override
public void remove(final Node node) {
if (this.type == node) {
this.type = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof TypeIdentifier) {
this.type = (TypeIdentifier) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.type);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitClassOfClassType(this);
}
}

View File

@ -0,0 +1,61 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ClassType extends ClassifierDeclaration {
private List<MemberDeclaration> declarations;
public ClassType() {
this.declarations = new ArrayList<MemberDeclaration>();
}
public List<MemberDeclaration> getDeclarations() {
return this.declarations;
}
@Override
public String toString() {
return "ClassType";
}
@Override
public void remove(final Node node) {
super.remove(node);
this.declarations.remove(node);
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
details.addAll(this.declarations);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof MemberDeclaration) {
this.declarations.add((MemberDeclaration) node);
return true;
}
return false;
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitClassType(this);
}
@Override
public boolean isAbstract() {
for (MemberDeclaration declaration : this.declarations) {
if (declaration.isAbstract()) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,40 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public abstract class ClassifierDeclaration extends Type {
private AncestorDeclaration ancestorDeclaration;
public AncestorDeclaration getAncestorDeclaration() {
return this.ancestorDeclaration;
}
public void setAncestorDeclaration(final AncestorDeclaration ancestorDeclaration) {
this.ancestorDeclaration = ancestorDeclaration;
}
@Override
public void remove(final Node node) {
if (this.ancestorDeclaration == node) {
this.ancestorDeclaration = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof AncestorDeclaration) {
this.ancestorDeclaration = (AncestorDeclaration) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.ancestorDeclaration);
}
public abstract boolean isAbstract();
}

View File

@ -0,0 +1,64 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class CodeBlock extends Node {
private List<Node> sections;
private CompoundStatement content;
public CodeBlock() {
this.sections = new ArrayList<Node>();
}
public CompoundStatement getContent() {
return this.content;
}
public void setContent(final CompoundStatement content) {
this.content = content;
}
public List<Node> getSections() {
return this.sections;
}
@Override
public void remove(final Node node) {
if (this.content == node) {
this.content = null;
}
this.sections.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof DeclarationSection || node instanceof ProceduralImplementation
|| node instanceof ProceduralDeclaration) {
this.sections.add(node);
return true;
}
if (node instanceof CompoundStatement) {
this.content = (CompoundStatement) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.sections);
contribute(details, this.content);
}
@Override
public String toString() {
return "CodeBlock";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitCodeBlock(this);
}
}

View File

@ -0,0 +1,14 @@
package ch.bitwave.lang.delphi.ast;
public abstract class Comment extends TerminalNode {
private String body;
public String getBody() {
return this.body;
}
public void setBody(final String body) {
this.body = body;
}
}

View File

@ -0,0 +1,47 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class CompoundStatement extends StructuredStatement {
private List<Statement> statements;
public CompoundStatement() {
this.statements = new ArrayList<Statement>();
}
@Override
public void remove(final Node node) {
this.statements.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Statement) {
this.statements.add((Statement) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.statements);
}
public void addStatement(final Statement stm) {
this.statements.add(stm);
}
@Override
public String toString() {
return "CompoundStatement";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitCompoundStatement(this);
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public abstract class ConditionalStatement extends StructuredStatement {
}

View File

@ -0,0 +1,71 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class ConstDeclaration extends IdentifiedNode {
private Type type;
private Initializer initializer;
public Type getType() {
return this.type;
}
public void setType(final Type type) {
this.type = type;
}
public Initializer getInitializer() {
return this.initializer;
}
public void setInitializer(final Initializer initializer) {
this.initializer = initializer;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.type == node) {
this.type = null;
} else if (this.initializer == node) {
this.initializer = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof Type) {
this.type = (Type) node;
return true;
}
if (node instanceof Initializer) {
this.initializer = (Initializer) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.type, this.initializer);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitConstDeclaration(this);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ConstDeclaration [type=").append(this.type).append(", initializer=")
.append(this.initializer).append(", identifier=").append(getIdentifier())
.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,47 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ConstSection extends DeclarationSection {
private List<ConstDeclaration> constants;
public ConstSection() {
this.constants = new ArrayList<ConstDeclaration>();
}
public List<ConstDeclaration> getConstants() {
return this.constants;
}
@Override
public void remove(final Node node) {
this.constants.remove(node);
}
@Override
protected boolean internalAdd(final Node node) {
if (node instanceof ConstDeclaration) {
this.constants.add((ConstDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.constants);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitConstSection(this);
}
@Override
public String toString() {
return "ConstSection";
}
}

View File

@ -0,0 +1,20 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public abstract class Constant extends Node {
@Override
public void remove(final Node node) {
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum ContextKind {
NONE, ANCESTOR_DECLARATION, METHOD_IMPLEMENTATION
}

View File

@ -0,0 +1,9 @@
package ch.bitwave.lang.delphi.ast;
public abstract class DeclarationSection extends Section {
public boolean isOnUnit() {
return this.getParent() instanceof UnitSection;
}
}

View File

@ -0,0 +1,558 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public abstract class DelphiSyntaxAdapter implements DelphiSyntaxVisitor {
/**
* Visits all details of this node in their natural order.
*
* @param node
*/
protected void descend(final Node node) {
for (Node detail : node.getDetails()) {
detail.accept(this);
}
}
protected void acceptList(final List<? extends Node> list) {
for (Node node : list) {
node.accept(this);
}
}
@Override
public void visitAncestorDeclaration(final AncestorDeclaration node) {
descend(node);
}
@Override
public void visitArrayInitializer(final ArrayInitializer node) {
descend(node);
}
@Override
public void visitArrayType(final ArrayType node) {
descend(node);
}
@Override
public void visitAssignmentStatement(final AssignmentStatement node) {
descend(node);
}
@Override
public void visitBracketedExpression(final BracketedExpression node) {
descend(node);
}
@Override
public void visitCaseItem(final CaseItem node) {
descend(node);
}
@Override
public void visitCaseStatement(final CaseStatement node) {
descend(node);
}
@Override
public void visitClassifierDeclaration(final ClassifierDeclaration node) {
descend(node);
}
@Override
public void visitClassType(final ClassType node) {
descend(node);
}
@Override
public void visitCodeBlock(final CodeBlock node) {
descend(node);
}
@Override
public void visitCompoundStatement(final CompoundStatement node) {
descend(node);
}
@Override
public void visitConstDeclaration(final ConstDeclaration node) {
descend(node);
}
@Override
public void visitConstSection(final ConstSection node) {
descend(node);
}
@Override
public void visitDimensionQualifier(final DimensionQualifier node) {
descend(node);
}
@Override
public void visitElseCase(final ElseCase node) {
descend(node);
}
@Override
public void visitEmptyStatement(final EmptyStatement node) {
descend(node);
}
@Override
public void visitExpression(final Expression node) {
descend(node);
}
@Override
public void visitFactor(final Factor node) {
descend(node);
}
@Override
public void visitFieldDeclaration(final FieldDeclaration node) {
descend(node);
}
@Override
public void visitForStatement(final ForStatement node) {
descend(node);
}
@Override
public void visitFunctionCall(final FunctionCall node) {
descend(node);
}
@Override
public void visitFunctionImplementation(final FunctionImplementation node) {
descend(node);
}
@Override
public void visitGotoStatement(final GotoStatement node) {
descend(node);
}
@Override
public void visitGuidSpecifier(final GuidSpecifier node) {
descend(node);
}
@Override
public void visitIdentifier(final Identifier node) {
descend(node);
}
@Override
public void visitIfStatement(final IfStatement node) {
descend(node);
}
@Override
public void visitImplementationSection(final ImplementationSection node) {
descend(node);
}
@Override
public void visitInterfaceSection(final InterfaceSection node) {
descend(node);
}
@Override
public void visitInterfaceType(final InterfaceType node) {
descend(node);
}
@Override
public void visitLabel(final Label node) {
descend(node);
}
@Override
public void visitLabelledStatement(final LabelledStatement node) {
descend(node);
}
@Override
public void visitLabelSection(final LabelSection node) {
descend(node);
}
@Override
public void visitLiteralString(final LiteralString node) {
descend(node);
}
@Override
public void visitMemberAccess(final MemberAccess node) {
descend(node);
}
@Override
public void visitMemberConstructorDeclaration(final MemberConstructorDeclaration node) {
descend(node);
}
@Override
public void visitMemberConstructorImplementation(final MemberConstructorImplementation node) {
descend(node);
}
@Override
public void visitMemberDestructorDeclaration(final MemberDestructorDeclaration node) {
descend(node);
}
@Override
public void visitMemberDestructorImplementation(final MemberDestructorImplementation node) {
descend(node);
}
@Override
public void visitMemberFunctionDeclaration(final MemberFunctionDeclaration node) {
descend(node);
}
@Override
public void visitMemberFunctionImplementation(final MemberFunctionImplementation node) {
descend(node);
}
@Override
public void visitMemberInvocation(final MemberInvocation node) {
descend(node);
}
@Override
public void visitMemberProcedureDeclaration(final MemberProcedureDeclaration node) {
descend(node);
}
@Override
public void visitMemberProcedureImplementation(final MemberProcedureImplementation node) {
descend(node);
}
@Override
public void visitMethodDirective(final MethodDirective node) {
descend(node);
}
@Override
public void visitNil(final Nil node) {
descend(node);
}
@Override
public void visitParameterDeclaration(final ParameterDeclaration node) {
descend(node);
}
@Override
public void visitPointerType(final PointerType node) {
descend(node);
}
@Override
public void visitProcedureImplementation(final ProcedureImplementation node) {
descend(node);
}
@Override
public void visitProcedureType(final ProcedureType node) {
descend(node);
}
@Override
public void visitPropertyDeclaration(final PropertyDeclaration node) {
descend(node);
}
@Override
public void visitQualifiedIdentifier(final QualifiedIdentifier node) {
descend(node);
}
@Override
public void visitRaiseExceptionStatement(final RaiseExceptionStatement node) {
descend(node);
}
@Override
public void visitRecordInitializer(final RecordInitializer node) {
descend(node);
}
@Override
public void visitRecordType(final RecordType node) {
descend(node);
}
@Override
public void visitRepeatStatement(final RepeatStatement node) {
descend(node);
}
@Override
public void visitScalarDeclaration(final ScalarDeclaration node) {
descend(node);
}
@Override
public void visitSetConstant(final SetConstant node) {
descend(node);
}
@Override
public void visitSetType(final SetType node) {
descend(node);
}
@Override
public void visitSignedFactor(final SignedFactor node) {
descend(node);
}
@Override
public void visitSignedNumber(final SignedNumber node) {
descend(node);
}
@Override
public void visitSimpleExpression(final SimpleExpression node) {
descend(node);
}
@Override
public void visitSimpleExpressionOperator(final SimpleExpressionOperator node) {
descend(node);
}
@Override
public void visitStaticStringType(final StaticStringType node) {
descend(node);
}
@Override
public void visitSubrangeType(final SubrangeType node) {
descend(node);
}
@Override
public void visitTerm(final Term node) {
descend(node);
}
@Override
public void visitTermOperator(final TermOperator node) {
descend(node);
}
@Override
public void visitTryBlock(final TryBlock node) {
descend(node);
}
@Override
public void visitTypeCheck(final TypeCheck node) {
descend(node);
}
@Override
public void visitTypeDeclaration(final TypeDeclaration node) {
descend(node);
}
@Override
public void visitTypeIdentifier(final TypeIdentifier node) {
descend(node);
}
@Override
public void visitTypeSection(final TypeSection node) {
descend(node);
}
@Override
public void visitUnit(final Unit node) {
descend(node);
}
@Override
public void visitUnsignedInteger(final UnsignedInteger node) {
descend(node);
}
@Override
public void visitUnsignedReal(final UnsignedReal node) {
descend(node);
}
@Override
public void visitUsesSection(final UsesSection node) {
descend(node);
}
@Override
public void visitVariable(final Variable node) {
descend(node);
}
@Override
public void visitVariableDeclaration(final VariableDeclaration node) {
descend(node);
}
@Override
public void visitVarSection(final VarSection node) {
descend(node);
}
@Override
public void visitWhileStatement(final WhileStatement node) {
descend(node);
}
@Override
public void visitWithStatement(final WithStatement node) {
descend(node);
}
@Override
public void visitInitializer(final Initializer node) {
descend(node);
}
@Override
public void visitElement(final Element node) {
descend(node);
}
@Override
public void visitFinallyClause(final FinallyClause node) {
descend(node);
}
@Override
public void visitRecordField(final RecordField node) {
descend(node);
}
@Override
public void visitRecordSection(final RecordSection node) {
descend(node);
}
@Override
public void visitScalarType(final ScalarType node) {
descend(node);
}
@Override
public void visitVariantPart(final VariantPart node) {
descend(node);
}
@Override
public void visitPropertyAccessDeclaration(final PropertyAccessDeclaration node) {
descend(node);
}
@Override
public void visitWriteAccessorDeclaration(final WriteAccessorDeclaration node) {
descend(node);
}
@Override
public void visitReadAccessorDeclaration(final ReadAccessorDeclaration node) {
descend(node);
}
@Override
public void visitVariant(final Variant node) {
descend(node);
}
@Override
public void visitFixedPart(final FixedPart node) {
descend(node);
}
@Override
public void visitRecordFieldDeclaration(final RecordFieldDeclaration node) {
descend(node);
}
@Override
public void visitMemberAccessStatement(final MemberAccessStatement node) {
descend(node);
}
@Override
public void visitBlockComment(final BlockComment node) {
descend(node);
}
@Override
public void visitLineComment(final LineComment node) {
descend(node);
}
@Override
public void visitPropertyModifier(final PropertyModifier node) {
descend(node);
}
@Override
public void visitFunctionDirective(final FunctionDirective node) {
descend(node);
}
@Override
public void visitFunctionType(final FunctionType node) {
descend(node);
}
@Override
public void visitExceptClause(final ExceptClause node) {
descend(node);
}
@Override
public void visitExceptionHandler(final ExceptionHandler node) {
descend(node);
}
@Override
public void visitRecordItem(final RecordItem node) {
descend(node);
}
@Override
public void visitFunctionDeclaration(final FunctionDeclaration node) {
descend(node);
}
@Override
public void visitProcedureDeclaration(final ProcedureDeclaration node) {
descend(node);
}
@Override
public void visitClassOfClassType(final ClassOfClassType node) {
descend(node);
}
@Override
public void visitQualifiedTypeIdentifier(final QualifiedTypeIdentifier node) {
descend(node);
}
@Override
public void visitPrimitiveFunctionConstant(final PrimitiveFunctionConstant node) {
descend(node);
}
}

View File

@ -0,0 +1,218 @@
package ch.bitwave.lang.delphi.ast;
public interface DelphiSyntaxVisitor {
void visitAncestorDeclaration(final AncestorDeclaration node);
void visitArrayInitializer(ArrayInitializer node);
void visitArrayType(final ArrayType node);
void visitAssignmentStatement(final AssignmentStatement node);
void visitBracketedExpression(final BracketedExpression node);
void visitCaseItem(CaseItem node);
void visitCaseStatement(final CaseStatement node);
void visitClassifierDeclaration(final ClassifierDeclaration node);
void visitClassType(final ClassType node);
void visitCodeBlock(final CodeBlock node);
void visitCompoundStatement(final CompoundStatement node);
void visitConstDeclaration(final ConstDeclaration node);
void visitConstSection(ConstSection node);
void visitDimensionQualifier(final DimensionQualifier node);
void visitElseCase(ElseCase node);
void visitEmptyStatement(EmptyStatement node);
void visitExpression(final Expression node);
void visitFactor(final Factor node);
void visitFieldDeclaration(final FieldDeclaration node);
void visitForStatement(ForStatement node);
void visitFunctionCall(final FunctionCall node);
void visitFunctionImplementation(FunctionImplementation node);
void visitGotoStatement(GotoStatement node);
void visitGuidSpecifier(GuidSpecifier node);
void visitIdentifier(Identifier node);
void visitIfStatement(IfStatement node);
void visitImplementationSection(final ImplementationSection node);
void visitInterfaceSection(final InterfaceSection node);
void visitInterfaceType(final InterfaceType node);
void visitLabel(Label node);
void visitLabelledStatement(final LabelledStatement node);
void visitLabelSection(LabelSection labelSection);
void visitLiteralString(final LiteralString node);
void visitMemberAccess(MemberAccess node);
void visitMemberConstructorDeclaration(MemberConstructorDeclaration node);
void visitMemberConstructorImplementation(final MemberConstructorImplementation node);
void visitMemberDestructorDeclaration(MemberDestructorDeclaration node);
void visitMemberDestructorImplementation(final MemberDestructorImplementation node);
void visitMemberFunctionDeclaration(MemberFunctionDeclaration node);
void visitMemberFunctionImplementation(final MemberFunctionImplementation node);
void visitMemberInvocation(final MemberInvocation node);
void visitMemberProcedureDeclaration(MemberProcedureDeclaration node);
void visitMemberProcedureImplementation(final MemberProcedureImplementation node);
void visitMethodDirective(MethodDirective node);
void visitNil(Nil node);
void visitParameterDeclaration(final ParameterDeclaration node);
void visitPointerType(PointerType node);
void visitProcedureImplementation(ProcedureImplementation node);
void visitProcedureType(ProcedureType node);
void visitPropertyDeclaration(final PropertyDeclaration node);
void visitQualifiedIdentifier(final QualifiedIdentifier node);
void visitRaiseExceptionStatement(RaiseExceptionStatement node);
void visitRecordInitializer(RecordInitializer node);
void visitRecordType(RecordType node);
void visitRepeatStatement(RepeatStatement node);
void visitScalarDeclaration(ScalarDeclaration node);
void visitSetConstant(SetConstant node);
void visitSetType(SetType node);
void visitSignedFactor(final SignedFactor node);
void visitSignedNumber(final SignedNumber node);
void visitSimpleExpression(final SimpleExpression node);
void visitSimpleExpressionOperator(SimpleExpressionOperator node);
void visitStaticStringType(StaticStringType node);
void visitSubrangeType(SubrangeType node);
void visitTerm(final Term node);
void visitTermOperator(TermOperator node);
void visitTryBlock(TryBlock node);
void visitTypeCheck(TypeCheck node);
void visitTypeDeclaration(final TypeDeclaration node);
void visitTypeIdentifier(TypeIdentifier node);
void visitTypeSection(final TypeSection node);
void visitUnit(final Unit node);
void visitUnsignedInteger(UnsignedInteger node);
void visitUnsignedReal(final UnsignedReal node);
void visitUsesSection(final UsesSection node);
void visitVariable(final Variable node);
void visitVariableDeclaration(VariableDeclaration node);
void visitVarSection(VarSection node);
void visitWhileStatement(WhileStatement node);
void visitWithStatement(WithStatement node);
void visitInitializer(Initializer node);
void visitElement(Element node);
void visitFinallyClause(FinallyClause node);
void visitRecordField(RecordField node);
void visitRecordSection(RecordSection node);
void visitScalarType(ScalarType node);
void visitVariantPart(VariantPart node);
void visitPropertyAccessDeclaration(PropertyAccessDeclaration node);
void visitWriteAccessorDeclaration(WriteAccessorDeclaration node);
void visitReadAccessorDeclaration(ReadAccessorDeclaration node);
void visitVariant(Variant node);
void visitFixedPart(FixedPart node);
void visitRecordFieldDeclaration(RecordFieldDeclaration node);
void visitMemberAccessStatement(MemberAccessStatement node);
void visitBlockComment(BlockComment node);
void visitLineComment(LineComment node);
void visitPropertyModifier(PropertyModifier node);
void visitFunctionDirective(FunctionDirective node);
void visitFunctionType(FunctionType node);
void visitExceptClause(ExceptClause node);
void visitExceptionHandler(ExceptionHandler node);
void visitRecordItem(RecordItem node);
void visitFunctionDeclaration(FunctionDeclaration node);
void visitProcedureDeclaration(ProcedureDeclaration node);
void visitClassOfClassType(ClassOfClassType node);
void visitQualifiedTypeIdentifier(QualifiedTypeIdentifier node);
void visitPrimitiveFunctionConstant(PrimitiveFunctionConstant node);
}

View File

@ -0,0 +1,43 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class DimensionQualifier extends Node {
private Node content;
public Node getContent() {
return this.content;
}
public void setContent(final Node content) {
this.content = content;
}
@Override
public void remove(final Node node) {
if (this.content == node) {
this.content = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.content == null) {
this.content = node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.content);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitDimensionQualifier(this);
}
}

View File

@ -0,0 +1,36 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public abstract class DimensionalNode extends Node {
private List<DimensionQualifier> qualifiers;
public DimensionalNode() {
this.qualifiers = new ArrayList<DimensionQualifier>();
}
public List<DimensionQualifier> getQualifiers() {
return this.qualifiers;
}
@Override
public void remove(final Node node) {
this.qualifiers.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof DimensionQualifier) {
this.qualifiers.add((DimensionQualifier) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.qualifiers);
}
}

View File

@ -0,0 +1,60 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class Element extends Node {
private Expression first;
private Expression second;
public Expression getFirst() {
return this.first;
}
public void setFirst(final Expression first) {
this.first = first;
}
public Expression getSecond() {
return this.second;
}
public void setSecond(final Expression second) {
this.second = second;
}
@Override
public void remove(final Node node) {
if (this.first == node) {
this.first = null;
} else if (this.second == node) {
this.second = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Expression) {
if (this.first == null) {
this.first = (Expression) node;
return true;
}
if (this.second == null) {
this.second = (Expression) node;
return true;
}
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.first, this.second);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitElement(this);
}
}

View File

@ -0,0 +1,51 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ElseCase extends Node {
private List<Statement> statements;
public List<Statement> getStatements() {
return this.statements;
}
public ElseCase() {
this.statements = new ArrayList<Statement>();
}
@Override
public void remove(final Node node) {
this.statements.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Statement) {
this.statements.add((Statement) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.statements);
}
public void addStatement(final Statement stm) {
this.statements.add(stm);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitElseCase(this);
}
@Override
public String toString() {
return "ElseCase";
}
}

View File

@ -0,0 +1,32 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class EmptyStatement extends SimpleStatement {
@Override
public void remove(final Node node) {
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitEmptyStatement(this);
}
@Override
public String toString() {
return "EmptyStatement";
}
}

View File

@ -0,0 +1,72 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ExceptClause extends TryHandler {
// EXCEPT (exceptionHandlers ES? | statements) (ELSE statements)? END;
private List<ExceptionHandler> handlers;
private ElseCase elseCase;
public ExceptClause() {
super();
this.handlers = new ArrayList<ExceptionHandler>();
}
public ElseCase getElseCase() {
return this.elseCase;
}
public void setElseCase(final ElseCase elseCase) {
this.elseCase = elseCase;
}
public List<ExceptionHandler> getHandlers() {
return this.handlers;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (node instanceof ExceptionHandler) {
this.handlers.remove(node);
} else if (node instanceof ElseCase) {
this.elseCase = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof ExceptionHandler) {
this.handlers.add((ExceptionHandler) node);
return true;
}
if (node instanceof ElseCase) {
this.elseCase = (ElseCase) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
details.addAll(this.handlers);
contribute(details, this.elseCase);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitExceptClause(this);
}
@Override
public String toString() {
return "ExceptClause";
}
}

View File

@ -0,0 +1,67 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class ExceptionHandler extends IdentifiedNode {
// ON identifier typeSpecifier? DO statement;
private Type exceptionType;
private Statement statement;
public Type getExceptionType() {
return this.exceptionType;
}
public void setExceptionType(final Type exceptionType) {
this.exceptionType = exceptionType;
}
public Statement getStatement() {
return this.statement;
}
public void setStatement(final Statement statement) {
this.statement = statement;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.exceptionType == node) {
this.exceptionType = null;
} else if (this.statement == node) {
this.statement = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof Type) {
this.exceptionType = (Type) node;
return true;
}
if (node instanceof Statement) {
this.statement = (Statement) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.exceptionType, this.statement);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitExceptionHandler(this);
}
@Override
public String toString() {
return "ExceptionHandler";
}
}

View File

@ -0,0 +1,77 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class Expression extends Node {
private ExpressionOperatorKind operator = ExpressionOperatorKind.NONE;
private SimpleExpression leftOperand;
private SimpleExpression rightOperand;
public ExpressionOperatorKind getOperator() {
return this.operator;
}
public void setOperator(final ExpressionOperatorKind operator) {
this.operator = operator;
}
public SimpleExpression getLeftOperand() {
return this.leftOperand;
}
public void setLeftOperand(final SimpleExpression leftOperand) {
this.leftOperand = leftOperand;
}
public SimpleExpression getRightOperand() {
return this.rightOperand;
}
public void setRightOperand(final SimpleExpression rightOperand) {
this.rightOperand = rightOperand;
}
@Override
public void remove(final Node node) {
if (this.leftOperand == node) {
this.leftOperand = null;
} else if (this.rightOperand == node) {
this.rightOperand = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
assertNodeType(node, SimpleExpression.class);
SimpleExpression expr = (SimpleExpression) node;
if (this.leftOperand == null) {
this.leftOperand = expr;
return true;
}
if (this.rightOperand == null) {
this.rightOperand = expr;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.leftOperand, this.rightOperand);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Expression ").append(this.leftOperand);
if (this.operator != null && !ExpressionOperatorKind.NONE.equals(this.operator)) {
builder.append(" ").append(this.operator).append(" ").append(this.rightOperand);
}
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitExpression(this);
}
}

View File

@ -0,0 +1,16 @@
package ch.bitwave.lang.delphi.ast;
public enum ExpressionOperatorKind {
NONE(""), EQUAL("="), NOT_EQUAL("<>"), LESS_THAN("<"), GREATER_THAN(">"), LESS_EQUAL("<="), GRATER_EQUAL(
">="), IN("in");
private String label;
private ExpressionOperatorKind(final String label) {
this.label = label;
}
public String getLabel() {
return this.label;
}
}

View File

@ -0,0 +1,65 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class Factor extends Node {
private TypeIdentifier castType;
private Node content;
public Node getContent() {
return this.content;
}
public void setContent(final Node content) {
this.content = content;
}
public TypeIdentifier getCastType() {
return this.castType;
}
public void setCastType(final TypeIdentifier castType) {
this.castType = castType;
}
@Override
public void remove(final Node node) {
if (this.content == node) {
this.content = null;
} else if (this.castType == node) {
this.castType = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.content == null) {
this.content = node;
return true;
}
if (node instanceof TypeIdentifier) {
this.castType = (TypeIdentifier) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.content, this.castType);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Factor [castType=").append(this.castType).append(", content=")
.append(this.content).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFactor(this);
}
}

View File

@ -0,0 +1,52 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class FieldDeclaration extends MemberDeclaration {
private VariableDeclaration variable;
public FieldDeclaration(final AccessModifierKind accessKind) {
super(accessKind);
}
public VariableDeclaration getVariable() {
return this.variable;
}
public void setVariable(final VariableDeclaration variable) {
this.variable = variable;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.variable == node) {
this.variable = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (this.variable == null) {
assertNodeType(node, VariableDeclaration.class);
this.variable = (VariableDeclaration) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.variable);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFieldDeclaration(this);
}
}

View File

@ -0,0 +1,11 @@
package ch.bitwave.lang.delphi.ast;
public class FinallyClause extends TryHandler {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFinallyClause(this);
}
}

View File

@ -0,0 +1,47 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class FixedPart extends Node {
private List<RecordSection> sections;
public FixedPart() {
this.sections = new ArrayList<RecordSection>();
}
public List<RecordSection> getSections() {
return this.sections;
}
@Override
public void remove(final Node node) {
this.sections.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof RecordSection) {
this.sections.add((RecordSection) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.sections);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFixedPart(this);
}
@Override
public String toString() {
return "FixedPart";
}
}

View File

@ -0,0 +1,105 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class ForStatement extends RepetitiveStatement {
private Identifier variable;
private Expression startExpression;
private Expression endExpression;
private boolean ascending;
private Statement body;
public void setVariable(final Identifier variable) {
this.variable = variable;
}
public void setStartExpression(final Expression startExpression) {
this.startExpression = startExpression;
}
public void setEndExpression(final Expression endExpression) {
this.endExpression = endExpression;
}
public void setAscending(final boolean ascending) {
this.ascending = ascending;
}
public boolean isAscending() {
return this.ascending;
}
public void setBody(final Statement body) {
this.body = body;
}
public Identifier getVariable() {
return this.variable;
}
public Expression getStartExpression() {
return this.startExpression;
}
public Expression getEndExpression() {
return this.endExpression;
}
public Statement getBody() {
return this.body;
}
@Override
public void remove(final Node node) {
if (this.variable == node) {
this.variable = null;
} else if (this.startExpression == node) {
this.startExpression = null;
} else if (this.endExpression == node) {
this.endExpression = null;
} else if (this.body == node) {
this.body = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Identifier) {
this.variable = (Identifier) node;
return true;
}
if (node instanceof Expression) {
if (this.startExpression == null) {
this.startExpression = (Expression) node;
return true;
}
if (this.endExpression == null) {
this.endExpression = (Expression) node;
return true;
}
return false;
}
if (node instanceof Statement) {
this.body = (Statement) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.variable, this.startExpression, this.endExpression, this.body);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitForStatement(this);
}
@Override
public String toString() {
return "ForStatement";
}
}

View File

@ -0,0 +1,69 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class FunctionCall extends IdentifiedNode {
private List<Expression> arguments;
private TypeIdentifier type;
public FunctionCall() {
this.arguments = new ArrayList<Expression>();
}
public TypeIdentifier getType() {
return this.type;
}
public void setType(final TypeIdentifier type) {
this.type = type;
}
public List<Expression> getArguments() {
return this.arguments;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.type == node) {
this.type = null;
} else {
this.arguments.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof TypeIdentifier) {
this.type = (TypeIdentifier) node;
return true;
}
if (node instanceof Expression) {
this.arguments.add((Expression) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.arguments);
contribute(details, this.type);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FunctionCall [identifier=").append(getIdentifier()).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFunctionCall(this);
}
}

View File

@ -0,0 +1,50 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class FunctionDeclaration extends ProceduralDeclaration {
private Type returnType;
public Type getReturnType() {
return this.returnType;
}
public void setReturnType(final Type returnType) {
this.returnType = returnType;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.returnType == node) {
this.returnType = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
assertNodeType(node, Type.class);
this.returnType = (Type) node;
return true;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.returnType);
}
@Override
public String toString() {
return "FunctionDeclaration";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFunctionDeclaration(this);
}
}

View File

@ -0,0 +1,26 @@
package ch.bitwave.lang.delphi.ast;
public class FunctionDirective extends TerminalNode {
private FunctionDirectiveKind kind;
public FunctionDirectiveKind getKind() {
return this.kind;
}
public void setKind(final FunctionDirectiveKind kind) {
this.kind = kind;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FunctionModifier [kind=").append(this.kind).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFunctionDirective(this);
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum FunctionDirectiveKind {
CDECL, STDCALL, OVERLOAD, FORWARD;
}

View File

@ -0,0 +1,55 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class FunctionImplementation extends ProceduralImplementation {
// FUNCTION qualifiedIdentifier parametersDeclaration? typeSpecifier ES
// codeBlock;
private Type returnType;
public Type getReturnType() {
return this.returnType;
}
public void setReturnType(final Type returnType) {
this.returnType = returnType;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (node instanceof Type) {
this.returnType = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof Type) {
this.returnType = (Type) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.returnType);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFunctionImplementation(this);
}
@Override
public String toString() {
return "FunctionImplementation";
}
}

View File

@ -0,0 +1,49 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class FunctionType extends InvokableType {
private TypeIdentifier returnType;
public TypeIdentifier getReturnType() {
return this.returnType;
}
public void setReturnType(final TypeIdentifier returnType) {
this.returnType = returnType;
}
@Override
public void remove(final Node node) {
super.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof TypeIdentifier) {
this.returnType = (TypeIdentifier) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.returnType);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitFunctionType(this);
}
@Override
public String toString() {
return "FunctionType";
}
}

View File

@ -0,0 +1,35 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class GotoStatement extends SimpleStatement {
private Label label;
@Override
public void remove(final Node node) {
if (this.label == node) {
this.label = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Label) {
this.label = (Label) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.label);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitGotoStatement(this);
}
}

View File

@ -0,0 +1,42 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class GuidSpecifier extends Node {
private Node contents;
@Override
public void remove(final Node node) {
if (this.contents == node) {
this.contents = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.contents == null) {
this.contents = node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.contents);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitGuidSpecifier(this);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GuidSpecifier [contents=").append(this.contents).append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,37 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public abstract class IdentifiedNode extends Node {
private Identifier identifier;
public Identifier getIdentifier() {
return this.identifier;
}
public void setIdentifier(final Identifier identifier) {
this.identifier = identifier;
}
@Override
public void remove(final Node node) {
if (this.identifier == node) {
this.identifier = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Identifier) {
this.identifier = (Identifier) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.identifier);
}
}

View File

@ -0,0 +1,29 @@
package ch.bitwave.lang.delphi.ast;
public class Identifier extends Constant {
private String name;
public Identifier() {
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Identifier [name=").append(this.name).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitIdentifier(this);
}
}

View File

@ -0,0 +1,72 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class IfStatement extends ConditionalStatement {
private Expression condition;
private Statement trueCase;
private Statement falseCase;
public Expression getCondition() {
return this.condition;
}
public Statement getTrueCase() {
return this.trueCase;
}
public Statement getFalseCase() {
return this.falseCase;
}
@Override
public void remove(final Node node) {
if (this.condition == node) {
this.condition = null;
} else if (this.trueCase == node) {
this.trueCase = null;
} else if (this.falseCase == null) {
this.falseCase = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Expression) {
this.condition = (Expression) node;
return true;
}
if (node instanceof Statement) {
if (this.trueCase == null) {
this.trueCase = (Statement) node;
return true;
} else if (this.falseCase == null) {
this.falseCase = (Statement) node;
return true;
}
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.condition, this.trueCase, this.falseCase);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitIfStatement(this);
}
/**
* Tells whether this if statement has a false case statement which is
* executed if the condition is not met.
*
* @return true if the statement has a false case.
*/
public boolean hasFalseCase() {
return this.falseCase != null;
}
}

View File

@ -0,0 +1,52 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ImplementationSection extends UnitSection {
private List<InvokableImplementation> implementations;
public ImplementationSection() {
this.implementations = new ArrayList<InvokableImplementation>();
}
@Override
public String toString() {
return "ImplementationSection";
}
public List<InvokableImplementation> getImplementations() {
return Collections.unmodifiableList(this.implementations);
}
@Override
public void remove(final Node node) {
super.remove(node);
this.implementations.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof InvokableImplementation) {
this.implementations.add((InvokableImplementation) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
details.addAll(this.implementations);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitImplementationSection(this);
}
}

View File

@ -0,0 +1,48 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class Initializer extends Node {
private Node contents;
public Node getContents() {
return this.contents;
}
public void setContents(final Node contents) {
this.contents = contents;
}
@Override
public void remove(final Node node) {
if (this.contents == node) {
this.contents = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.contents == null) {
this.contents = node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.contents);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitInitializer(this);
}
@Override
public String toString() {
return "Initializer";
}
}

View File

@ -0,0 +1,30 @@
package ch.bitwave.lang.delphi.ast;
public class InterfaceSection extends UnitSection {
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof ProceduralDeclaration) {
addProceduralDeclaration((ProceduralDeclaration) node);
return true;
}
return false;
}
public void addProceduralDeclaration(final ProceduralDeclaration node) {
insertNode(node);
}
@Override
public String toString() {
return "InterfaceSection";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitInterfaceSection(this);
}
}

View File

@ -0,0 +1,74 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class InterfaceType extends ClassifierDeclaration {
private GuidSpecifier guid;
private List<MemberDeclaration> members;
public InterfaceType() {
this.members = new ArrayList<MemberDeclaration>();
}
public List<MemberDeclaration> getMembers() {
return this.members;
}
public GuidSpecifier getGuid() {
return this.guid;
}
public void setGuid(final GuidSpecifier guid) {
this.guid = guid;
}
@Override
public String toString() {
return "InterfaceType";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitInterfaceType(this);
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.guid == node) {
this.guid = null;
} else {
this.members.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof GuidSpecifier) {
this.guid = (GuidSpecifier) node;
return true;
}
if (node instanceof MemberDeclaration) {
this.members.add((MemberDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.guid);
details.addAll(this.members);
}
@Override
public boolean isAbstract() {
return true;
}
}

View File

@ -0,0 +1,14 @@
package ch.bitwave.lang.delphi.ast;
/**
* Signals that an attempt was made to add a node of an invalid type.
*/
public class InvalidNodeException extends Exception {
public InvalidNodeException(final String message) {
super(message);
}
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,70 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public abstract class InvokableImplementation extends Node implements Parameterized {
private List<ParameterDeclaration> parameters;
private CodeBlock codeBlock;
public InvokableImplementation() {
this.parameters = new ArrayList<ParameterDeclaration>();
}
public CodeBlock getCodeBlock() {
return this.codeBlock;
}
public void setCodeBlock(final CodeBlock codeBlock) {
this.codeBlock = codeBlock;
}
public void setParameters(final List<ParameterDeclaration> parameters) {
this.parameters = parameters;
}
@Override
public void addParameter(final ParameterDeclaration param) {
this.parameters.add(param);
}
@Override
public List<ParameterDeclaration> getParameters() {
return getDetailsOfType(ParameterDeclaration.class);
}
@Override
public void remove(final Node node) {
if (this.codeBlock == node) {
this.codeBlock = null;
} else {
this.parameters.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof CodeBlock) {
this.codeBlock = (CodeBlock) node;
return true;
}
if (node instanceof ParameterDeclaration) {
this.parameters.add((ParameterDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.parameters);
contribute(details, this.codeBlock);
}
@Override
public boolean hasParameters() {
return !this.parameters.isEmpty();
}
}

View File

@ -0,0 +1,73 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public abstract class InvokableType extends Type implements Parameterized {
private List<ParameterDeclaration> parameters;
private boolean ofObject;
private List<FunctionDirective> modifiers;
public InvokableType() {
this.parameters = new ArrayList<ParameterDeclaration>();
this.modifiers = new ArrayList<FunctionDirective>();
}
public boolean isOfObject() {
return this.ofObject;
}
public void setOfObject(final boolean ofObject) {
this.ofObject = ofObject;
}
@Override
public List<ParameterDeclaration> getParameters() {
return this.parameters;
}
public List<FunctionDirective> getModifiers() {
return this.modifiers;
}
@Override
public void remove(final Node node) {
this.parameters.remove(node);
this.modifiers.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof FunctionDirective) {
this.modifiers.add((FunctionDirective) node);
return true;
}
if (node instanceof ParameterDeclaration) {
this.parameters.add((ParameterDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.parameters);
details.addAll(this.modifiers);
}
@Override
public String toString() {
return "ProcedureType";
}
@Override
public boolean hasParameters() {
return !this.parameters.isEmpty();
}
@Override
public void addParameter(final ParameterDeclaration param) {
this.parameters.add(param);
}
}

View File

@ -0,0 +1,43 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class Label extends Node {
private Node contents;
public Node getContents() {
return this.contents;
}
public void setContents(final Node contents) {
this.contents = contents;
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitLabel(this);
}
@Override
public void remove(final Node node) {
if (this.contents == node) {
this.contents = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.contents == null) {
this.contents = node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.contents);
}
}

View File

@ -0,0 +1,36 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class LabelSection extends DeclarationSection {
private List<Label> labels;
public LabelSection() {
this.labels = new ArrayList<Label>();
}
@Override
public void remove(final Node node) {
this.labels.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
assertNodeType(node, Label.class);
this.labels.add((Label) node);
return true;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.labels);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitLabelSection(this);
}
}

View File

@ -0,0 +1,59 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class LabelledStatement extends Statement {
private Label label;
private UnlabelledStatement statement;
public Label getLabel() {
return this.label;
}
public void setLabel(final Label label) {
this.label = label;
}
public UnlabelledStatement getStatement() {
return this.statement;
}
public void setStatement(final UnlabelledStatement statement) {
this.statement = statement;
}
@Override
public void remove(final Node node) {
if (this.label == node) {
this.label = null;
} else if (this.statement == node) {
this.statement = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (this.label == null) {
assertNodeType(node, Label.class);
this.label = (Label) node;
return true;
}
if (this.statement == null) {
assertNodeType(node, UnlabelledStatement.class);
this.statement = (UnlabelledStatement) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.label, this.statement);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitLabelledStatement(this);
}
}

View File

@ -0,0 +1,10 @@
package ch.bitwave.lang.delphi.ast;
public class LineComment extends Comment {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitLineComment(this);
}
}

View File

@ -0,0 +1,27 @@
package ch.bitwave.lang.delphi.ast;
public class LiteralString extends Constant {
private String value;
public String getValue() {
return this.value;
}
public void setValue(final String value) {
this.value = value;
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitLiteralString(this);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("LiteralString [value=").append(this.value).append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,23 @@
package ch.bitwave.lang.delphi.ast;
public abstract class Member extends Node {
private AccessKind accessModifier;
private String name;
public AccessKind getAccessModifier() {
return this.accessModifier;
}
public void setAccessModifier(final AccessKind accessModifier) {
this.accessModifier = accessModifier;
}
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
}

View File

@ -0,0 +1,58 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class MemberAccess extends Node {
private boolean callInherited;
private List<MemberInvocation> invocations;
public MemberAccess() {
this.invocations = new ArrayList<MemberInvocation>();
}
public boolean isCallInherited() {
return this.callInherited;
}
public void setCallInherited(final boolean callInherited) {
this.callInherited = callInherited;
}
public List<MemberInvocation> getInvocations() {
return this.invocations;
}
@Override
public void remove(final Node node) {
this.invocations.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof MemberInvocation) {
this.invocations.add((MemberInvocation) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.invocations);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MemberAccess [callInherited=").append(this.callInherited).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberAccess(this);
}
}

View File

@ -0,0 +1,47 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class MemberAccessStatement extends SimpleStatement {
private MemberAccess access;
public MemberAccess getAccess() {
return this.access;
}
public void setAccess(final MemberAccess access) {
this.access = access;
}
@Override
public void remove(final Node node) {
if (this.access == node) {
this.access = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof MemberAccess) {
this.access = (MemberAccess) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.access);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberAccessStatement(this);
}
@Override
public String toString() {
return "MemberAccessStatement";
}
}

View File

@ -0,0 +1,20 @@
package ch.bitwave.lang.delphi.ast;
public class MemberConstructorDeclaration extends MethodDeclaration {
public MemberConstructorDeclaration(final AccessModifierKind accessKind) {
super(accessKind);
}
@Override
public String toString() {
return "MemberConstructorDeclaration";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberConstructorDeclaration(this);
}
}

View File

@ -0,0 +1,10 @@
package ch.bitwave.lang.delphi.ast;
public class MemberConstructorImplementation extends MethodImplementation {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberConstructorImplementation(this);
}
}

View File

@ -0,0 +1,27 @@
package ch.bitwave.lang.delphi.ast;
import ch.bitwave.platform.codestyle.DBC;
public abstract class MemberDeclaration extends IdentifiedNode {
private AccessModifierKind accessKind;
public MemberDeclaration(final AccessModifierKind accessKind) {
super();
DBC.PRE.assertNotNull(accessKind, "member access modifier");
this.accessKind = accessKind;
}
public AccessModifierKind getAccessKind() {
return this.accessKind;
}
public void setAccessKind(final AccessModifierKind accessKind) {
this.accessKind = accessKind;
}
public boolean isAbstract() {
return false;
}
}

View File

@ -0,0 +1,19 @@
package ch.bitwave.lang.delphi.ast;
public class MemberDestructorDeclaration extends MethodDeclaration {
public MemberDestructorDeclaration(final AccessModifierKind accessKind) {
super(accessKind);
}
@Override
public String toString() {
return "MemberDestructorDeclaration";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberDestructorDeclaration(this);
}
}

View File

@ -0,0 +1,10 @@
package ch.bitwave.lang.delphi.ast;
public class MemberDestructorImplementation extends MethodImplementation {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberDestructorImplementation(this);
}
}

View File

@ -0,0 +1,54 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class MemberFunctionDeclaration extends MethodDeclaration {
private Type returnType;
public MemberFunctionDeclaration(final AccessModifierKind accessKind) {
super(accessKind);
}
public Type getReturnType() {
return this.returnType;
}
public void setReturnType(final Type returnType) {
this.returnType = returnType;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.returnType == node) {
this.returnType = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
assertNodeType(node, Type.class);
this.returnType = (Type) node;
return true;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.returnType);
}
@Override
public String toString() {
return "MemberFunctionDeclaration";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberFunctionDeclaration(this);
}
}

View File

@ -0,0 +1,52 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class MemberFunctionImplementation extends MethodImplementation {
private Type returnType;
public Type getReturnType() {
return this.returnType;
}
public void setReturnType(final Type returnType) {
this.returnType = returnType;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.returnType == node) {
this.returnType = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof Type) {
this.returnType = (Type) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.returnType);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberFunctionImplementation(this);
}
@Override
public String toString() {
return "MemberFunctionImplementation";
}
}

View File

@ -0,0 +1,64 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class MemberInvocation extends DimensionalNode {
private Node content;
private boolean dereference;
public boolean isDereference() {
return this.dereference;
}
public void setDereference(final boolean dereference) {
this.dereference = dereference;
}
public Node getContent() {
return this.content;
}
public void setContent(final Node content) {
this.content = content;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.content == node) {
this.content = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node)) {
return true;
}
if (this.content == null) {
this.content = node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.content);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MemberInvocation [dereference=").append(this.dereference).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberInvocation(this);
}
}

View File

@ -0,0 +1,19 @@
package ch.bitwave.lang.delphi.ast;
public class MemberProcedureDeclaration extends MethodDeclaration {
public MemberProcedureDeclaration(final AccessModifierKind accessKind) {
super(accessKind);
}
@Override
public String toString() {
return "MemberProcedureDeclaration";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberProcedureDeclaration(this);
}
}

View File

@ -0,0 +1,15 @@
package ch.bitwave.lang.delphi.ast;
public class MemberProcedureImplementation extends MethodImplementation {
@Override
public String toString() {
return "MemberProcedureImplementation";
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMemberProcedureImplementation(this);
}
}

View File

@ -0,0 +1,74 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public abstract class MethodDeclaration extends MemberDeclaration implements Parameterized {
private List<ParameterDeclaration> parameters;
private List<MethodDirective> directives;
public MethodDeclaration(final AccessModifierKind accessKind) {
super(accessKind);
this.directives = new ArrayList<MethodDirective>();
this.parameters = new ArrayList<ParameterDeclaration>();
}
@Override
public List<ParameterDeclaration> getParameters() {
return this.parameters;
}
public List<MethodDirective> getDirectives() {
return this.directives;
}
@Override
public void remove(final Node node) {
super.remove(node);
this.directives.remove(node);
this.parameters.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof MethodDirective) {
this.directives.add((MethodDirective) node);
return true;
}
if (node instanceof ParameterDeclaration) {
this.parameters.add((ParameterDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
details.addAll(this.parameters);
details.addAll(this.directives);
}
@Override
public boolean hasParameters() {
return !this.parameters.isEmpty();
}
@Override
public void addParameter(final ParameterDeclaration decl) {
this.parameters.add(decl);
}
@Override
public boolean isAbstract() {
for (MethodDirective directive : this.directives) {
if (MethodDirectiveKind.ABSTRACT.equals(directive.getKind()))
return true;
}
return false;
}
}

View File

@ -0,0 +1,26 @@
package ch.bitwave.lang.delphi.ast;
public class MethodDirective extends TerminalNode {
MethodDirectiveKind kind;
public MethodDirectiveKind getKind() {
return this.kind;
}
public void setKind(final MethodDirectiveKind kind) {
this.kind = kind;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MethodModifier [kind=").append(this.kind).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitMethodDirective(this);
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum MethodDirectiveKind {
VIRTUAL, OVERRIDE, OVERLOAD, REINTRODUCE, ABSTRACT;
}

View File

@ -0,0 +1,42 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public abstract class MethodImplementation extends InvokableImplementation {
private QualifiedIdentifier identifier;
public QualifiedIdentifier getIdentifier() {
return this.identifier;
}
public void setIdentifier(final QualifiedIdentifier identifier) {
this.identifier = identifier;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.identifier == node) {
this.identifier = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (this.identifier == null) {
assertNodeType(node, QualifiedIdentifier.class);
this.identifier = (QualifiedIdentifier) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.identifier);
super.contributeDetails(details);
}
}

View File

@ -0,0 +1,32 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class Nil extends Constant {
@Override
public void remove(final Node node) {
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitNil(this);
}
@Override
public String toString() {
return "Nil";
}
}

View File

@ -0,0 +1,131 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class Node {
private Node parent;
public Node() {
}
public Node getParent() {
return this.parent;
}
public void setParent(final Node parent) {
this.parent = parent;
}
public abstract void remove(@Nullable final Node node);
public final void add(@Nullable final Node node) throws InvalidNodeException {
if (!internalAdd(node)) {
throw prepareCannotAddException(node);
}
}
protected abstract boolean internalAdd(@Nullable final Node node) throws InvalidNodeException;
public final List<Node> getDetails() {
List<Node> result = new ArrayList<Node>();
contributeDetails(result);
return result;
}
protected abstract void contributeDetails(final List<Node> details);
public final int getDetailCount() {
return getDetails().size();
}
@SuppressWarnings("unchecked")
public final <T> T findDetailOfType(@Nonnull final Class<T> desiredClass) {
for (Node node : getDetails()) {
if (desiredClass.isAssignableFrom(node.getClass())) {
return (T) node;
}
}
return null;
}
@SuppressWarnings("unchecked")
public final <T> List<T> getDetailsOfType(final Class<T> desiredClass) {
List<T> list = new ArrayList<T>();
for (Node node : getDetails()) {
if (desiredClass.isAssignableFrom(node.getClass())) {
list.add((T) node);
}
}
return list;
}
protected final List<Node> createNodeList(final Node... nodes) {
List<Node> result = new ArrayList<Node>();
for (Node node : nodes) {
if (node != null) {
result.add(node);
}
}
return result;
}
protected final void contribute(final List<Node> list, final Node... nodes) {
for (Node node : nodes) {
if (node != null) {
list.add(node);
}
}
}
protected final void assertNodeType(final Node node, final Class<? extends Node> validClass)
throws InvalidNodeException {
Class<? extends Node> nodeClass = node.getClass();
if (!validClass.isAssignableFrom(nodeClass)) {
String message = String.format(
"Node %s cannot be added to node %s (only type %s is valid).", node.toString(),
this.toString(), validClass.getSimpleName());
throw new InvalidNodeException(message);
}
}
protected InvalidNodeException prepareCannotAddException(final Node node) {
return new InvalidNodeException(String.format(
"Cannot add more nodes to %s (given node is %s)", this.toString(), node.toString()));
}
/**
* Accepts this node without recursing into its details.
*
* @param visitor
* the visitor to visit.
*/
public abstract void accept(@Nonnull DelphiSyntaxVisitor visitor);
/**
* Accepts this node and then recurses into its details.
*
* @param visitor
* the visitor to visit.
*/
public void acceptTree(@Nonnull final DelphiSyntaxVisitor visitor) {
accept(visitor);
for (Node detail : getDetails()) {
detail.acceptTree(visitor);
}
}
/**
* Tells whether this is a procedural node, which is a procedure or function
* declaration or implementation.
*
* @return true if this is a procedural node.
*/
public boolean isProcedural() {
return false;
}
}

View File

@ -0,0 +1,110 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class ParameterDeclaration extends Node {
private ParameterModifierKind modifier;
private List<Identifier> identifiers;
private Type type;
private Expression defaultValue;
public ParameterDeclaration() {
super();
this.identifiers = new ArrayList<Identifier>();
}
public Type getType() {
return this.type;
}
public void setType(final Type type) {
this.type = type;
}
public ParameterModifierKind getModifier() {
return this.modifier;
}
public void setModifier(final ParameterModifierKind modifier) {
this.modifier = modifier;
}
public Expression getDefaultValue() {
return this.defaultValue;
}
public void setDefaultValue(final Expression defaultValue) {
this.defaultValue = defaultValue;
}
public List<Identifier> getIdentifiers() {
return getDetailsOfType(Identifier.class);
}
public void addIdentifier(final Identifier ident) {
this.identifiers.add(ident);
}
public String getIdentifierNames() {
List<Identifier> ids = getIdentifiers();
StringBuilder sb = new StringBuilder();
for (Identifier identifier : ids) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(identifier.getName());
}
return sb.toString();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ParameterDeclaration [modifier=").append(this.modifier)
.append(", defaultValue=").append(this.defaultValue).append(", identifiers=")
.append(getIdentifierNames()).append("]");
return builder.toString();
}
@Override
public void remove(final Node node) {
if (this.defaultValue == node) {
this.defaultValue = null;
} else if (this.type == node) {
this.type = null;
} else {
this.identifiers.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Identifier) {
this.identifiers.add((Identifier) node);
return true;
}
if (node instanceof Type) {
this.type = (Type) node;
return true;
}
if (this.defaultValue == null) {
assertNodeType(node, Expression.class);
this.defaultValue = (Expression) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.identifiers);
contribute(details, this.defaultValue);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitParameterDeclaration(this);
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum ParameterModifierKind {
DEFAULT, CONST, VAR, OUT;
}

View File

@ -0,0 +1,13 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public interface Parameterized {
void addParameter(ParameterDeclaration decl);
List<ParameterDeclaration> getParameters();
boolean hasParameters();
}

View File

@ -0,0 +1,48 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class PointerType extends Type {
private Type type;
public Type getType() {
return this.type;
}
public void setType(final Type type) {
this.type = type;
}
@Override
public void remove(final Node node) {
if (this.type == node) {
this.type = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof Type) {
this.type = (Type) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.type);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitPointerType(this);
}
@Override
public String toString() {
return "PointerType";
}
}

View File

@ -0,0 +1,60 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public class PrimitiveFunctionConstant extends Constant {
// typeIdentifier '(' constant ')';
private TypeIdentifier castType;
private Constant argument;
public TypeIdentifier getCastType() {
return this.castType;
}
public void setCastType(final TypeIdentifier castType) {
this.castType = castType;
}
public Constant getArgument() {
return this.argument;
}
public void setArgument(final Constant argument) {
this.argument = argument;
}
@Override
public void remove(final Node node) {
if (this.castType == node) {
this.castType = null;
} else if (this.argument == node) {
this.argument = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof TypeIdentifier) {
this.castType = (TypeIdentifier) node;
return true;
}
if (node instanceof Constant) {
this.argument = (Constant) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.castType, this.argument);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitPrimitiveFunctionConstant(this);
}
}

View File

@ -0,0 +1,69 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public abstract class ProceduralDeclaration extends IdentifiedNode implements Parameterized {
private List<ParameterDeclaration> parameters;
private List<FunctionDirective> modifiers;
public ProceduralDeclaration() {
this.modifiers = new ArrayList<FunctionDirective>();
this.parameters = new ArrayList<ParameterDeclaration>();
}
@Override
public List<ParameterDeclaration> getParameters() {
return this.parameters;
}
public List<FunctionDirective> getModifiers() {
return this.modifiers;
}
@Override
public void remove(final Node node) {
super.remove(node);
this.modifiers.remove(node);
this.parameters.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof FunctionDirective) {
this.modifiers.add((FunctionDirective) node);
return true;
}
if (node instanceof ParameterDeclaration) {
this.parameters.add((ParameterDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
details.addAll(this.parameters);
details.addAll(this.modifiers);
}
@Override
public boolean hasParameters() {
return !this.parameters.isEmpty();
}
@Override
public void addParameter(final ParameterDeclaration decl) {
this.parameters.add(decl);
}
@Override
public boolean isProcedural() {
return true;
}
}

View File

@ -0,0 +1,47 @@
package ch.bitwave.lang.delphi.ast;
import java.util.List;
public abstract class ProceduralImplementation extends InvokableImplementation {
private Identifier identifier;
public Identifier getIdentifier() {
return this.identifier;
}
public void setIdentifier(final Identifier identifier) {
this.identifier = identifier;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.identifier == node) {
this.identifier = null;
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (this.identifier == null) {
assertNodeType(node, Identifier.class);
this.identifier = (Identifier) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
contribute(details, this.identifier);
super.contributeDetails(details);
}
@Override
public boolean isProcedural() {
return true;
}
}

View File

@ -0,0 +1,15 @@
package ch.bitwave.lang.delphi.ast;
public class ProcedureDeclaration extends ProceduralDeclaration {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitProcedureDeclaration(this);
}
@Override
public String toString() {
return "ProcedureDeclaration";
}
}

View File

@ -0,0 +1,10 @@
package ch.bitwave.lang.delphi.ast;
public class ProcedureImplementation extends ProceduralImplementation {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitProcedureImplementation(this);
}
}

View File

@ -0,0 +1,15 @@
package ch.bitwave.lang.delphi.ast;
public class ProcedureType extends InvokableType {
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitProcedureType(this);
}
@Override
public String toString() {
return "FunctionType";
}
}

View File

@ -0,0 +1,43 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class PropertyAccessDeclaration extends Node {
private List<ParameterDeclaration> parameters;
public PropertyAccessDeclaration() {
this.parameters = new ArrayList<ParameterDeclaration>();
}
@Override
public void remove(final Node node) {
this.parameters.remove(node);
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (node instanceof ParameterDeclaration) {
this.parameters.add((ParameterDeclaration) node);
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
details.addAll(this.parameters);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitPropertyAccessDeclaration(this);
}
@Override
public String toString() {
return "PropertyAccessDeclaration";
}
}

View File

@ -0,0 +1,117 @@
package ch.bitwave.lang.delphi.ast;
import java.util.ArrayList;
import java.util.List;
public class PropertyDeclaration extends MemberDeclaration {
private PropertyAccessDeclaration accessDeclaration;
private Type type;
private ReadAccessorDeclaration readAccessor;
private WriteAccessorDeclaration writeAccessor;
private List<PropertyModifier> modifiers;
public PropertyDeclaration(final AccessModifierKind access) {
super(access);
this.modifiers = new ArrayList<PropertyModifier>();
}
public List<PropertyModifier> getModifiers() {
return this.modifiers;
}
public PropertyAccessDeclaration getAccessDeclaration() {
return this.accessDeclaration;
}
public void setAccessDeclaration(final PropertyAccessDeclaration accessDeclaration) {
this.accessDeclaration = accessDeclaration;
}
public Type getType() {
return this.type;
}
public void setType(final Type type) {
this.type = type;
}
public ReadAccessorDeclaration getReadAccessor() {
return this.readAccessor;
}
public void setReadAccessor(final ReadAccessorDeclaration readAccessor) {
this.readAccessor = readAccessor;
}
public WriteAccessorDeclaration getWriteAccessor() {
return this.writeAccessor;
}
public void setWriteAccessor(final WriteAccessorDeclaration writeAccessor) {
this.writeAccessor = writeAccessor;
}
@Override
public void remove(final Node node) {
super.remove(node);
if (this.accessDeclaration == node) {
this.accessDeclaration = null;
} else if (this.type == node) {
this.type = null;
} else if (this.readAccessor == node) {
this.readAccessor = null;
} else if (this.writeAccessor == node) {
this.writeAccessor = null;
} else {
this.modifiers.remove(node);
}
}
@Override
protected boolean internalAdd(final Node node) throws InvalidNodeException {
if (super.internalAdd(node))
return true;
if (node instanceof PropertyModifier) {
this.modifiers.add((PropertyModifier) node);
return true;
}
if (node instanceof PropertyAccessDeclaration) {
this.accessDeclaration = (PropertyAccessDeclaration) node;
return true;
}
if (node instanceof Type) {
this.type = (Type) node;
return true;
}
if (node instanceof ReadAccessorDeclaration) {
this.readAccessor = (ReadAccessorDeclaration) node;
return true;
}
if (node instanceof WriteAccessorDeclaration) {
this.writeAccessor = (WriteAccessorDeclaration) node;
return true;
}
return false;
}
@Override
protected void contributeDetails(final List<Node> details) {
super.contributeDetails(details);
contribute(details, this.accessDeclaration, this.type, this.readAccessor,
this.writeAccessor);
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitPropertyDeclaration(this);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PropertyDeclaration [identifier=").append(this.getIdentifier()).append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,26 @@
package ch.bitwave.lang.delphi.ast;
public class PropertyModifier extends TerminalNode {
PropertyModifierKind kind;
public PropertyModifierKind getKind() {
return this.kind;
}
public void setKind(final PropertyModifierKind kind) {
this.kind = kind;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PropertyModifier [kind=").append(this.kind).append("]");
return builder.toString();
}
@Override
public void accept(final DelphiSyntaxVisitor visitor) {
visitor.visitPropertyModifier(this);
}
}

View File

@ -0,0 +1,5 @@
package ch.bitwave.lang.delphi.ast;
public enum PropertyModifierKind {
DEFAULT;
}

Some files were not shown because too many files have changed in this diff Show More