Commit 0ba05d0d authored by Miklos Magyari's avatar Miklos Magyari

OOP: initial lexer/parser support for OOP

Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 928c64d4
......@@ -12,6 +12,7 @@ lexer grammar Ttcn3BaseLexer;
/*
* author Arpad Lovassy
* author Miklos Magyari
*/
@header {
......@@ -152,6 +153,8 @@ import org.eclipse.titan.designer.AST.Location;
boolean contains_match = false;
/** binstr contains whitespace characters */
boolean contains_ws = false;
/** error is reported for invalid characters */
boolean invalid_char_reported = false;
/** token start index */
int startIndex = 0;
......@@ -236,7 +239,8 @@ tokens {
CALL, CASE, CATCH,
CHARKEYWORD, CHARSTRING, CHECK,
CHECKSTATE, CLEAR, COMPLEMENTKEYWORD,
CHECKSTATE, CLASS,
CLEAR, COMPLEMENTKEYWORD,
COMPONENT, CONNECT, CONST,
CONTINUE, CONTROL, CREATE,
......@@ -250,7 +254,8 @@ tokens {
EXCEPT, EXCEPTION, EXECUTE,
EXTENDS, EXTENSION, EXTERNAL,
FAIL, FALSE, FLOAT,
FAIL, FALSE, FINALLY,
FLOAT,
FOR, FRIEND, FROM,
FUNCTION,
......@@ -278,7 +283,8 @@ tokens {
NOWAIT, NOT_A_NUMBER, NULL1,
NULL2,
OBJECTIDENTIFIERKEYWORD, OCTETSTRING, OF,
OBJECTIDENTIFIERKEYWORD, OBJECTKEYWORD, OCTETSTRING,
OF,
OMIT, ON, OPTIONAL,
OR, OR4B, OUT,
OVERRIDEKEYWORD,
......@@ -286,6 +292,7 @@ tokens {
PARAM, PASS, PATTERNKEYWORD,
PERMUTATION, PORT, PUBLIC,
PRESENT, PRIVATE, PROCEDURE,
PROTECTED,
RAISE, READ, REALTIME,
RECEIVE, RECORD, RECURSIVE,
......@@ -296,10 +303,11 @@ tokens {
SELECT, SELF, SEND,
SENDER, SET, SETVERDICT,
SETSTATE, SIGNATURE, START,
STOP, SUBSET, SUPERSET,
SYSTEM,
STOP, SUBSET, SUPER,
SUPERSET, SYSTEM,
TEMPLATE, TESTCASE, TIMEOUT,
TEMPLATE, TESTCASE, THIS,
TIMEOUT,
TIMER, TIMESTAMP, TO,
TRIGGER, TRUE, TYPE,
......@@ -405,6 +413,8 @@ ASSIGNMENTCHAR: ':=';
PORTREDIRECTSYMBOL: '->';
CLASSCASTING: '=>';
CSTRING:
'"'
( '\\' .
......@@ -440,6 +450,7 @@ HSTRING:
half_oct = false;
contains_match = false;
contains_ws = false;
invalid_char_reported = false;
startIndex = getCharIndex();
}
'\''
......@@ -459,6 +470,7 @@ HSTRING:
| ~['0-9A-Fa-f?* \t\r\n\f]
// We make sure, that the options do NOT have any intersection
{ errorChar("Invalid character `" + (char)_input.LA(0) + "' in binary string");
invalid_char_reported = true;
setType( BHOSTRING_WRONG );
}
)*
......@@ -496,7 +508,9 @@ HSTRING:
error("Octetstring match contains half octet(s)");
setType( BHOSTRING_WRONG );
} else {
error("Octetstring value contains odd number of hexadecimal digits");
if (invalid_char_reported == false) {
error("Octetstring value contains odd number of hexadecimal digits");
}
setType( BHOSTRING_WRONG );
}
}
......@@ -527,6 +541,8 @@ TITANSPECIFICCATCH: '@catch';
TITANSPECIFICUPDATEKEYWORD: '@update';
// modifier keywords
ABSTRACTKEYWORD: '@abstract';
FINALKEYWORD: '@final';
NOCASEKEYWORD: '@nocase';
LAZYKEYWORD: '@lazy';
DECODEDKEYWORD: '@decoded';
......
......@@ -13,6 +13,7 @@ import Ttcn3BaseLexer;
/*
* author Arpad Lovassy
* author Miklos Magyari
*/
@header
......@@ -46,7 +47,8 @@ import Ttcn3BaseLexer;
CALL: 'call'; CASE: 'case'; CATCH: 'catch';
CHARKEYWORD: 'char'; CHARSTRING: 'charstring'; CHECK: 'check';
CHECKSTATE: 'checkstate'; CLEAR: 'clear'; COMPLEMENTKEYWORD: 'complement';
CHECKSTATE: 'checkstate'; CLASS: 'class';
CLEAR: 'clear'; COMPLEMENTKEYWORD: 'complement';
COMPONENT: 'component'; CONNECT: 'connect'; CONST: 'const';
CONTINUE: 'continue'; CONTROL: 'control'; CREATE: 'create';
......@@ -60,7 +62,8 @@ import Ttcn3BaseLexer;
EXCEPT: 'except'; EXCEPTION: 'exception'; EXECUTE: 'execute';
EXTENDS: 'extends'; EXTENSION: 'extension'; EXTERNAL: 'external';
FAIL: 'fail'; FALSE: 'false'; FLOAT: 'float';
FAIL: 'fail'; FALSE: 'false'; FINALLY: 'finally';
FLOAT: 'float';
FOR: 'for'; FRIEND: 'friend'; FROM: 'from';
FUNCTION: 'function';
......@@ -84,10 +87,11 @@ import Ttcn3BaseLexer;
MODULE: 'module'; MODULEPAR: 'modulepar'; MTC: 'mtc';
NOBLOCK: 'noblock'; NONE: 'none'; NOT: 'not';
NOT4B: 'not4b'; NOWAIT: 'nowait'; NOT_A_NUMBER: 'not_a_number';
NULL1: 'null'; NULL2: 'NULL';
NOT4B: 'not4b'; NOWAIT: 'nowait';
NOT_A_NUMBER: 'not_a_number'; NULL1: 'null'; NULL2: 'NULL';
OBJECTIDENTIFIERKEYWORD: 'objid'; OCTETSTRING: 'octetstring'; OF: 'of';
OBJECTIDENTIFIERKEYWORD: 'objid'; OBJECTKEYWORD: 'object'; OCTETSTRING: 'octetstring';
OF: 'of';
OMIT: 'omit'; ON: 'on'; OPTIONAL: 'optional';
OR: 'or'; OR4B: 'or4b'; OUT: 'out';
OVERRIDEKEYWORD: 'override';
......@@ -95,6 +99,7 @@ import Ttcn3BaseLexer;
PARAM: 'param'; PASS: 'pass'; PATTERNKEYWORD: 'pattern';
PERMUTATION: 'permutation'; PORT: 'port'; PUBLIC: 'public';
PRESENT: 'present'; PRIVATE: 'private'; PROCEDURE: 'procedure';
PROTECTED: 'protected';
RAISE: 'raise'; READ: 'read'; RECEIVE: 'receive';
RECORD: 'record'; RECURSIVE: 'recursive'; REFERS: 'refers';
......@@ -104,10 +109,11 @@ import Ttcn3BaseLexer;
SELECT: 'select'; SELF: 'self'; SEND: 'send';
SENDER: 'sender'; SET: 'set'; SETVERDICT: 'setverdict';
SETSTATE: 'setstate'; SIGNATURE: 'signature'; START: 'start';
STOP: 'stop'; SUBSET: 'subset'; SUPERSET: 'superset';
SYSTEM: 'system';
STOP: 'stop'; SUBSET: 'subset'; SUPER: 'super';
SUPERSET: 'superset'; SYSTEM: 'system';
TEMPLATE: 'template'; TESTCASE: 'testcase'; TIMEOUT: 'timeout';
TEMPLATE: 'template'; TESTCASE: 'testcase'; THIS: 'this';
TIMEOUT: 'timeout';
TIMER: 'timer'; TO: 'to'; TRIGGER: 'trigger';
TRUE: 'true'; TYPE: 'type';
......
......@@ -391,6 +391,7 @@ public boolean isErrorListEmpty() {
/**
* @author Kristof Szabados
* @author Arpad Lovassy
* @author Miklos Magyari
*/
pr_TTCN3File:
......@@ -714,6 +715,7 @@ pr_StructuredTypeDef returns[Def_Type def_type]
| t9 = pr_FunctionTypeDef { $def_type = $t9.def_type; }
| t10 = pr_AltstepTypeDef { $def_type = $t10.def_type; }
| t11 = pr_TestcaseTypeDef { $def_type = $t11.def_type; }
| t12 = pr_ClassTypeDef { }
);
pr_RecordDef returns[Def_Type def_type]
......@@ -1862,9 +1864,9 @@ pr_PortElement[Reference portTypeReference]
}
};
pr_ConstDef returns[List<Definition> array]:
pr_ConstDef returns[List<Definition> array, Type type]:
( col = pr_ConstKeyword
t = pr_Type
t = pr_Type { $type = $t.type; }
a = pr_ConstList[ $t.type ] { $array = $a.array; }
)
{ for(int i = 0; i < $array.size(); i++) {
......@@ -1885,8 +1887,11 @@ pr_ConstList[Type type] returns[List<Definition> array]
$array = new ArrayList<Definition>();
}:
( a = pr_SingleConstDef[type] { if($a.def_const != null) { $array.add($a.def_const); } }
| b = pr_SingleClassConstDef
( pr_Comma
a = pr_SingleConstDef[type] { if($a.def_const != null) { $array.add($a.def_const); } }
( a = pr_SingleConstDef[type] { if($a.def_const != null) { $array.add($a.def_const); } }
| b = pr_SingleClassConstDef
)
)*
);
......@@ -2009,9 +2014,10 @@ pr_TestcaseTypeDef returns[Def_Type def_type]
}
};
pr_TemplateDef returns[Def_Template def_template]
pr_TemplateDef returns[Def_Template def_template, Type type]
@init {
$def_template = null;
$type = null;
TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
Template_definition_helper helper = new Template_definition_helper();
Reference derivedReference = null;
......@@ -2020,7 +2026,7 @@ pr_TemplateDef returns[Def_Template def_template]
( col = pr_TemplateKeyword
( t = pr_TemplateRestriction { templateRestriction = $t.templateRestriction; } )?
lf = pr_OptLazyOrFuzzyModifier { eval = $lf.eval; }
pr_BaseTemplate[helper]
base = pr_BaseTemplate[helper] { $type = helper.type; }
( d = pr_DerivedDef { derivedReference = $d.reference; } )?
pr_AssignmentChar
b = pr_TemplateBody
......@@ -3049,7 +3055,8 @@ pr_FunctionInstance returns[Reference temporalReference]
$temporalReference = null;
ParsedActualParameters parameters = null;
}:
( t = pr_FunctionRef { $temporalReference = $t.reference; }
( ((pr_Identifier | SUPER) DOT)?
t = pr_FunctionRef { $temporalReference = $t.reference; }
a = pr_LParen
( p = pr_FunctionActualParList { parameters = $p.parsedParameters; } )?
endcol = pr_RParen
......@@ -3852,7 +3859,7 @@ pr_GlobalModuleId returns [Reference reference]
( i = pr_Identifier
( DOT
pr_ObjectIdentifierValue
{ if ($i.identifier != null) { $reference = new Reference($i.identifier); } }
{ if ($i.identifier != null) { $reference = new Reference($i.identifier);} }
| { if($i.identifier != null) {
$reference = new Reference(null);
FieldSubReference subReference = new FieldSubReference($i.identifier);
......@@ -4431,23 +4438,24 @@ pr_ControlStatement returns[Statement statement]
$statement.setLocation(getLocation( $start, getLastVisibleToken())); }
);
pr_VarInstance returns[List<Definition> definitions]
pr_VarInstance returns[List<Definition> definitions, Type type]
@init {
$definitions = new ArrayList<Definition>();
List<Identifier> identifiers = null;
TemplateRestriction.Restriction_type templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
parameterEvaluationType eval = parameterEvaluationType.NORMAL_EVAL;
$type = null;
}:
( col = pr_VarKeyword
( tr = pr_TemplateOptRestricted { templateRestriction = $tr.templateRestriction; }
lf = pr_OptLazyOrFuzzyModifier { eval = $lf.eval; }
t = pr_Type
t = pr_Type { $type = $t.type; }
pr_TempVarList[ $definitions, $t.type, templateRestriction ]
|
lf = pr_OptLazyOrFuzzyModifier { eval = $lf.eval; }
t2 = pr_Type
t2 = pr_Type { $type = $t2.type; }
pr_VarList[ $definitions, $t2.type, eval ]
)
)
)
{
if ( $definitions.size() > 0 ) {
......@@ -4744,11 +4752,21 @@ pr_CreateOpEnd [Reference temporalReference]
b = pr_RParen { endcol = $b.stop; }
)?
( c = ALIVE { endcol = $c; isAlive = true; } )?
|
col2 = pr_Dot
a2 = pr_CreateKeyword { endcol = $a2.stop; }
( pr_LParen
(
pr_FunctionActualParList
)
b2 = pr_RParen { endcol = $b2.stop; }
)?
)
{
$value = new ComponentCreateExpression($temporalReference, name, location, isAlive);
$value.setLocation( getLocation( $temporalReference.getLocation(), endcol ) );
};
}
;
pr_SystemOp returns[SystemComponentExpression value]
@init {
......@@ -6114,6 +6132,7 @@ pr_PredefinedType returns[Type type]
| FLOAT { $type = new Float_Type(); }
| ADDRESS { $type = new Address_Type(); }
| DEFAULT { $type = new Default_Type(); }
| OBJECTKEYWORD { $type = new Anytype_Type(); }
| ANYTYPE
{
Reference reference = new Reference(null);
......@@ -6252,6 +6271,7 @@ pr_PredefinedValue returns [Value value]
$value.setLocation(getLocation( $OMIT)); }
| v7 = pr_ObjectIdentifierValue { $value = $v7.value; }
| v8 = pr_Macro { $value = $v8.value; }
| bho = BHOSTRING_WRONG
);
pr_FloatValue returns[Real_Value value]
......@@ -6376,7 +6396,12 @@ pr_ReferencedValue returns[Value value]
Reference temporalReference = null;
List<ISubReference> subReferences = null;
}:
( t = pr_ValueReference { temporalReference = $t.reference; }
(
( t = pr_ValueReference { temporalReference = $t.reference; }
| pr_Identifier DOT i = pr_PredefOrIdentifier pr_ExtendedFieldReference? { temporalReference = new Reference($i.identifier); }
| pr_Identifier DOT pr_Identifier LPAREN pr_FunctionActualParList? RPAREN pr_ExtendedFieldReference?
| pr_Identifier DOT pr_ObjectIdentifierValue DOT pr_Identifier pr_ExtendedFieldReference?
)
( e = pr_ExtendedFieldReference { subReferences = $e.subReferences; } )?
)
{
......@@ -6401,22 +6426,27 @@ pr_ValueReference returns[Reference reference]
@init {
$reference = null;
}:
( ( r = pr_GlobalModuleId { $reference = $r.reference; }
( ( ( r = pr_GlobalModuleId { $reference = $r.reference; }
| th = pr_ThisKeyword
| SUPER
)
pr_Dot
)?
id = pr_Identifier
)
{
if ( $id.identifier != null ) {
if ( $reference == null ) {
$reference = new Reference(null);
id = pr_Identifier {
if ( $id.identifier != null ) {
if ( $reference == null ) {
$reference = new Reference(null);
}
FieldSubReference subReference = new FieldSubReference($id.identifier);
subReference.setLocation($id.identifier.getLocation());
$reference.addSubReference(subReference);
$reference.setLocation(getLocation( $start, getLastVisibleToken()));//TODO: maybe this can be improved too.
}
FieldSubReference subReference = new FieldSubReference($id.identifier);
subReference.setLocation($id.identifier.getLocation());
$reference.addSubReference(subReference);
$reference.setLocation(getLocation( $start, getLastVisibleToken()));//TODO: maybe this can be improved too.
}
};
| th = pr_ThisKeyword {
}
);
pr_AddressValue returns[Value value]
@init {
......@@ -7269,6 +7299,7 @@ pr_BasicStatements returns[Statement statement]
$statement.setLocation(getLocation( $start, getLastVisibleToken()));
}
}
| pr_SelectClass { $statement = null; }
);
pr_Expression returns[Value value]
......@@ -7601,7 +7632,8 @@ pr_Primary returns[Value value]
Reference index_reference = null;
boolean applyFound = false;
}:
( t = pr_ValueReference { temporalReference = $t.reference; }
(
t = pr_ValueReference { temporalReference = $t.reference; }
( ( a11 = pr_LParen
(p1 = pr_FunctionActualParList { parameters = $p1.parsedParameters; } )?
a12 = pr_RParen
......@@ -7725,7 +7757,7 @@ pr_Primary returns[Value value]
)?
( p2 = pr_ApplyOpEnd
{ $value = new ApplyExpression( $value, $p2.parsedParameters );
$value.setLocation(getLocation( $t.start, $p2.stop));
$value.setLocation(getLocation( $t.start, $p2.stop));
}
)*
( pr_Dot
......@@ -7874,6 +7906,8 @@ pr_OpCall returns[Value value]
| v7 = pr_CheckStateOp { $value = $v7.value; }
| v8 = pr_GetRefOp { $value = $v8.value; }
| v9 = pr_nowOp { $value = $v9.value; }
| v10 = pr_ClassCastingOp { $value = null; }
| v11 = pr_OfClassOp { $value = null; }
);
pr_CheckStateOp returns[Value value]
......@@ -8908,3 +8942,242 @@ pr_KeywordLessGlobalModuleId returns [Reference reference]
{ $reference = new Reference($i.identifier); }
)
);
pr_ClassTypeDef
@init {
Configuration_Helper runsonHelper = new Configuration_Helper();
Configuration_Helper mtcHelper = new Configuration_Helper();
Configuration_Helper systemspecHelper = new Configuration_Helper();
}:
( ( ext = pr_ExtKeyword )?
kw = pr_ClassKeyword
m = pr_Modifier
i = pr_Identifier
ecd = pr_ExtendsClassDef
(pr_RunsOnSpec[runsonHelper])?
(pr_MTCSpec[mtcHelper])?
(pr_SystemSpec[systemspecHelper])?
pr_BeginChar
cml = pr_ClassMemberList
pr_EndChar
fd = pr_FinallyDef
)
;
pr_ClassKeyword:
(
CLASS
);
pr_ThisKeyword:
(
THIS
);
pr_Modifier
:
(f = FINALKEYWORD {
})?
(a = ABSTRACTKEYWORD
{
}
)?
;
pr_ExtendsClassDef:
(
EXTENDS
( t = pr_ReferencedType
{
}
| OBJECTKEYWORD
)
)?;
pr_ClassMemberList
:
(
cm = pr_ClassMember
pr_WithStatement? SEMICOLON?
)*
;
pr_ClassMember
:
(
( vis = pr_OopVisibility
{
}
)?
( var = pr_VarInstance
{
}
| pr_TimerInstance
| con = pr_ConstDef
{
}
| tpl = pr_ClassTemplateDef
{
}
| func = pr_ClassFunctionDef
{
}
| c = pr_ClassConstructorDef
{
}
| pr_TypeDef
)
)
;
pr_OopVisibility
:
( PRIVATE
| PUBLIC
| PROTECTED
)
{
};
pr_FinallyDef
:
(
FINALLY sb=pr_StatementBlock
)?;
pr_ClassFunctionDef
:
(
pr_ExtKeyword?
col = pr_FunctionKeyword
mod = pr_Modifier
pr_DeterministicModifier?
id = pr_Identifier
start1 = pr_LParen
(pl = pr_FunctionFormalParList )?
end = pr_RParen
( rh = pr_ReturnType
{
}
)?
( sb=pr_StatementBlock )?
)
;
pr_ClassConstructorDef
:
( id = pr_CreateKeyword
LPAREN
( pl = pr_FunctionFormalParList )?
RPAREN
(
pr_ExtKeyword LPAREN
pr_FunctionFormalParList
RPAREN
)?
(
COLON
sc = pr_Identifier
LPAREN
sp = pr_FunctionActualParList
endparen = RPAREN
{
}
)?
( sb=pr_StatementBlock )?
)
;
pr_SingleClassConstDef
:
( i = pr_Identifier
( d = pr_ArrayDef
{
}
)?
( a = pr_AssignmentChar
v = pr_Expression )?
)
;
pr_ClassTemplateDef
@init {
Template_definition_helper helper = new Template_definition_helper();
}:
( col = pr_TemplateKeyword
( t = pr_TemplateRestriction )?
lf = pr_OptLazyOrFuzzyModifier
base = pr_BaseTemplate[helper]
( d = pr_DerivedDef )?
( pr_AssignmentChar
b = pr_TemplateBody )?
)
;
pr_ConstructorCall:
(
pr_Dot CREATE
(
LPAREN pr_FunctionActualParList? RPAREN
)?
);
pr_ClassCastingOp:
( pr_VariableRef CLASSCASTING
( pr_ReferencedType
| OBJECTKEYWORD
| LPAREN pr_VariableRef RPAREN
)
);
pr_OfClassOp:
(