1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

fixes needed to stop seg faults on monodevelop

This commit is contained in:
Kevin Glynn 2011-03-11 11:13:27 +01:00
parent 409084a283
commit 9c6356c773
4 changed files with 146 additions and 82 deletions

View File

@ -135,6 +135,24 @@ scope TypeContext {
return root;
}
// embedded statement is ";", or, "{" ... "}", or a single statement. In the latter case we wrap with braces
protected CommonTree embeddedStatementToBlock(IToken tok, CommonTree embedStat) {
if ((!embedStat.IsNil && adaptor.GetType(embedStat) == SEMI) ||
(embedStat.IsNil && adaptor.GetChildCount(embedStat) >= 1 && adaptor.GetType(embedStat) == SEMI)) {
// Do Nothing, already a block
return embedStat;
}
CommonTree root = (CommonTree)adaptor.Nil;
adaptor.AddChild(root, (CommonTree)adaptor.Create(OPEN_BRACE, tok, "{"));
adaptor.AddChild(root, dupTree(embedStat));
adaptor.AddChild(root, (CommonTree)adaptor.Create(CLOSE_BRACE, tok, "}"));
root = (CommonTree)adaptor.RulePostProcessing(root);
return root;
}
// for ["conn", "conn1", "conn2"] generate:
//
// if (conn != null)
@ -378,8 +396,10 @@ primary_expression:
(oc1=object_creation_expression -> $oc1) (pp4=primary_expression_part[ $primary_expression.tree ] -> $pp4 )+ // new Foo(arg, arg).Member
// try the simple one first, this has no argS and no expressions
// symantically could be object creation
| (delegate_creation_expression) => delegate_creation_expression -> delegate_creation_expression // new FooDelegate (MyFunction)
| oc2=object_creation_expression -> $oc2
// keving: No, try object_creation_expression first, it could be new type ( xx ) {}
// can also match delegate_creation, will have to distinguish in NetMaker.g
| (object_creation_expression) => oc2=object_creation_expression -> $oc2
| delegate_creation_expression -> delegate_creation_expression // new FooDelegate (MyFunction)
| anonymous_object_creation_expression -> anonymous_object_creation_expression) // new {int X, string Y}
| sizeof_expression // sizeof (struct)
| checked_expression // checked (...
@ -557,7 +577,7 @@ element_initializer:
object_initializer:
member_initializer_list? ','? '}' ;
member_initializer_list:
member_initializer (',' member_initializer) ;
member_initializer (',' member_initializer)* ;
member_initializer:
identifier '=' initializer_value ;
initializer_value:
@ -1017,7 +1037,7 @@ accessor_declaration [CommonTree atts, CommonTree mods, CommonTree type, string
| sb=block { propBlock = $sb.tree; } ) setm=magicPropSetter[atts, $la.tree, mods, $lm.tree, type, $s.token, propBlock, propName, mkBody, rawVarName] -> $setm)
;
accessor_modifier:
'public' | 'protected' | 'private' | 'internal' ;
'protected' 'internal'? | 'private' | 'internal' 'protected'?;
///////////////////////////////////////////////////////
event_declaration:
@ -1239,7 +1259,7 @@ struct_body [string structName]:
///////////////////////////////////////////////////////
indexer_declaration [CommonTree atts, CommonTree mods, CommonTree type]:
'this' '[' formal_parameter_list ']' '{' indexer_accessor_declarations[atts, mods, type, $formal_parameter_list.tree] '}' ;
'this' '[' formal_parameter_list ']' '{' indexer_accessor_declarations[atts, mods, type, $formal_parameter_list.tree] '}' -> indexer_accessor_declarations ;
//indexer_declarator:
//(type_name '.')?
// 'this' '[' formal_parameter_list ']' ;
@ -1489,6 +1509,7 @@ unchecked_statement:
'unchecked' block ;
lock_statement:
'lock' '(' expression ')' embedded_statement ;
// TODO: Can we avoid surrounding this with braces if not needed?
using_statement
@init {
CommonTree disposers = null;
@ -1497,7 +1518,7 @@ using_statement
u='using' '(' resource_acquisition c=')' embedded_statement
{ disposers = addDisposeVars($c.token, $resource_acquisition.resourceNames); }
f=magicFinally[$c.token, disposers]
magicTry[$u.token, $embedded_statement.tree, null, $f.tree]
magicTry[$u.token, embeddedStatementToBlock($u.token, $embedded_statement.tree), null, $f.tree]
-> OPEN_BRACE[$u.token, "{"]
resource_acquisition SEMI[$c.token, ";"]
magicTry
@ -1588,7 +1609,7 @@ magicPropGetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTr
CommonTree realBody = body;
CommonTree exceptionList = null;
}:
( { mkBody }? => b=magicGetterBody[getTok,varName] { realBody = $b.tree; } | e=magicThrowsException[true,getTok] { exceptionList = $e.tree; })
b=magicGetterBody[mkBody,getTok,varName] { if (mkBody) realBody = $b.tree; } e=magicThrowsException[!mkBody,getTok] { if (!mkBody) exceptionList = $e.tree; }
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } { dupTree(type)} IDENTIFIER[getTok, "get"+propName] { dupTree(realBody) } { exceptionList })
;
magicPropSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken setTok, CommonTree body, string propName, bool mkBody, string varName]
@ -1596,7 +1617,7 @@ magicPropSetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTr
CommonTree realBody = body;
CommonTree exceptionList = null;
}:
( { mkBody }? => b=magicSetterBody[setTok,varName] { realBody = $b.tree; }| e=magicThrowsException[true,setTok] { exceptionList = $e.tree; } )
b=magicSetterBody[mkBody,setTok,varName] { if (mkBody) realBody = $b.tree; } e=magicThrowsException[!mkBody,setTok] { if (!mkBody) exceptionList = $e.tree; }
-> ^(METHOD[$type.token, "METHOD"] { dupTree(mods) } ^(TYPE[setTok, "TYPE"] IDENTIFIER[setTok, "void"] ) IDENTIFIER[setTok, "set"+propName] ^(PARAMS[setTok, "PARAMS"] { dupTree(type)} IDENTIFIER[setTok, "value"]) { dupTree(realBody) } { exceptionList } )
;
@ -1607,10 +1628,14 @@ magicMkPropertyVar[CommonTree type, string varText] :
-> ^(FIELD[$type.token, "FIELD"] PRIVATE[$type.token, "private"] { dupTree(type) } IDENTIFIER[$type.token, varText])
;
magicGetterBody[IToken getTok, string varName]:
-> OPEN_BRACE[getTok,"{"] ^(RETURN[getTok, "return"] IDENTIFIER[getTok, varName]) CLOSE_BRACE[getTok,"}"];
magicSetterBody[IToken setTok, string varName]:
-> OPEN_BRACE[setTok,"{"] IDENTIFIER[setTok, varName] ASSIGN[setTok,"="] IDENTIFIER[setTok, "value"] SEMI[setTok, ";"] CLOSE_BRACE[setTok,"}"] ;
magicGetterBody[bool isOn, IToken getTok, string varName]:
-> { isOn }? OPEN_BRACE[getTok,"{"] ^(RETURN[getTok, "return"] IDENTIFIER[getTok, varName]) CLOSE_BRACE[getTok,"}"]
->
;
magicSetterBody[bool isOn, IToken setTok, string varName]:
-> { isOn }? OPEN_BRACE[setTok,"{"] IDENTIFIER[setTok, varName] ASSIGN[setTok,"="] IDENTIFIER[setTok, "value"] SEMI[setTok, ";"] CLOSE_BRACE[setTok,"}"]
->
;
magicIdxGetter[CommonTree atts, CommonTree localatts, CommonTree mods, CommonTree localmods, CommonTree type, IToken getTok, CommonTree body, CommonTree idxparams]
:

View File

@ -376,10 +376,9 @@ primary_expression returns [int precedence]
// | primary_expression_start primary_expression_part*
| ^(NEW type argument_list? object_or_collection_initializer?) { $precedence = precedence[NEW]; }-> construct(type = {$type.st}, args = {$argument_list.st}, inits = {$object_or_collection_initializer.st})
| 'new' (
// try the simple one first, this has no argS and no expressions
// symantically could be object creation
(delegate_creation_expression) => delegate_creation_expression// new FooDelegate (MyFunction)
| object_creation_expression
// (try the simple one first, this has no argS and no expressions
// symantically could be object creation)
| (delegate_creation_expression) => delegate_creation_expression // new FooDelegate (MyFunction)
| anonymous_object_creation_expression) // new {int X, string Y}
| sizeof_expression // sizeof (struct)
| checked_expression -> { $checked_expression.st } // checked (...
@ -419,7 +418,7 @@ primary_expression_start:
;
primary_expression_extalias:
i1=identifier '::' i2=identifier -> op(pre={ $i1.st }, op = { "::" }, post={ $i2.st })
^('::' i1=identifier i2=identifier) -> op(pre={ $i1.st }, op = { "::" }, post={ $i2.st })
;
@ -596,7 +595,7 @@ element_initializer:
object_initializer:
member_initializer_list? ','? '}' ;
member_initializer_list:
member_initializer (',' member_initializer) ;
member_initializer (',' member_initializer)* ;
member_initializer:
identifier '=' initializer_value ;
initializer_value:
@ -645,8 +644,8 @@ type_name
namespace_or_type_name:
t1=type_or_generic -> { $t1.st }
// keving: external aliases not supported
| ^('::' n2=namespace_or_type_name t2=type_or_generic) -> { $t2.st }
| ^(op='.' n3=namespace_or_type_name t3=type_or_generic) -> op(pre={ $n3.st }, op = { "." }, post={ $t3.st });
| ^('::' n2=type_name t2=type_or_generic) -> { $t2.st }
| ^(op='.' n3=type_name t3=type_or_generic) -> op(pre={ $n3.st }, op = { "." }, post={ $t3.st });
// t1=type_or_generic ('::' t2=type_or_generic)? ('.' ts+=type_or_generic)* -> namespace_or_type(type1={$t1.st}, type2={$t2.st}, types={$ts});
type_or_generic returns [int precedence]
@ -796,7 +795,7 @@ non_assignment_expression returns [int precedence]
elseparens = { comparePrecedence($cop.token, $ce3.precedence) <= 0 })
| ^('??' non_assignment_expression non_assignment_expression)
// All these operators have left to right associativity
| ^((op='=='|op='!='|op='||'|op='&&'|op='|'|op='^'|op='&'|op='>'|op='<'|op='>='|op='<='|op='<<'|op='>>'|op='+'|op='-'|op='*'|op='/'|op='%')
| ^((op='=='|op='!='|op='||'|op='&&'|op='|'|op='^'|op='&'|op='>'|op='<'|op='>='|op='<='|op='<<'|op=RIGHT_SHIFT|op='+'|op='-'|op='*'|op='/'|op='%')
e1=non_assignment_expression e2=non_assignment_expression) { $precedence = precedence[$op.token.Type]; }
-> op(pre={ $e1.st }, op = { $op.token.Text }, post = { $e2.st }, space = { " " },
preparen={ comparePrecedence($op.token, $e1.precedence) < 0 },
@ -1057,7 +1056,7 @@ integral_type:
// B.2.12 Delegates
delegate_declaration:
^(DELEGATE attributes modifiers return_type identifier type_parameter_constraints_clauses? variant_generic_parameter_list[$type_parameter_constraints_clauses.tpConstraints]?
^(DELEGATE attributes? modifiers? return_type identifier type_parameter_constraints_clauses? variant_generic_parameter_list[$type_parameter_constraints_clauses.tpConstraints]?
'(' formal_parameter_list? ')' );
delegate_modifiers:
modifier+ ;
@ -1180,7 +1179,7 @@ statement:
| statement_plus -> statement(statement = { $statement_plus.st })
;
statement_plus:
(identifier ':') => labeled_statement -> statement(statement = { $labeled_statement.st })
labeled_statement -> statement(statement = { $labeled_statement.st })
| embedded_statement -> statement(statement = { $embedded_statement.st })
;
embedded_statement returns [bool isSemi, bool isIf, bool indent]
@ -1222,7 +1221,7 @@ fixed_pointer_initializer:
//'&' variable_reference // unary_expression covers this
expression;
labeled_statement:
identifier ':' statement ;
^(':' identifier statement) -> op(pre={ $identifier.st }, op= { ":" }, post = { $statement.st});
declaration_statement
@init {
List<string> preComments = null;

View File

@ -585,7 +585,7 @@ scope {
$dotNetType = new UnknownRepTemplate(expType.TypeName+".APPLY");
ResolveResult methodResult = expType.Resolve($i2.thetext, $argument_list.argTypes ?? new List<TypeRepTemplate>(), AppEnv);
if (methodResult != null) {
Debug($i2.tree.Token.Line + ": Found '" + $i2.thetext + "'");
DebugDetail($i2.tree.Token.Line + ": Found '" + $i2.thetext + "'");
MethodRepTemplate methodRep = methodResult.Result as MethodRepTemplate;
Dictionary<string,CommonTree> myMap = new Dictionary<string,CommonTree>();
if (!implicitThis) {
@ -623,13 +623,13 @@ scope {
if (expType != null &&
($primary_expression.Count == 1 || !((primary_expression_scope)($primary_expression.ToArray()[1])).parentIsApply)) {
Debug($d1.token.Line + ": '" + $i1.thetext + "' might be a property");
DebugDetail($d1.token.Line + ": '" + $i1.thetext + "' might be a property");
$dotNetType = new UnknownRepTemplate(expType.TypeName+".DOTACCESS."+ $i1.thetext);
ResolveResult fieldResult = expType.Resolve($i1.thetext, false, AppEnv);
if (fieldResult != null) {
Debug($d1.token.Line + ": Found '" + $i1.thetext + "'");
DebugDetail($d1.token.Line + ": Found '" + $i1.thetext + "'");
Dictionary<string,CommonTree> myMap = new Dictionary<string,CommonTree>();
myMap["this"] = wrapExpression($e1.tree, $i1.tree.Token);
ret = mkJavaWrapper(fieldResult.Result.Java, myMap, $i1.tree.Token);
@ -681,10 +681,10 @@ scope {
if (thisType != null && !thisType.IsUnknownType &&
($primary_expression.Count == 1 || !((primary_expression_scope)($primary_expression.ToArray()[1])).parentIsApply)) {
Debug($identifier.tree.Token.Line + ": '" + $identifier.thetext + "' might be a property");
DebugDetail($identifier.tree.Token.Line + ": '" + $identifier.thetext + "' might be a property");
ResolveResult fieldResult = thisType.Resolve($identifier.thetext, false, AppEnv);
if (fieldResult != null) {
Debug($identifier.tree.Token.Line + ": Found '" + $identifier.thetext + "'");
DebugDetail($identifier.tree.Token.Line + ": Found '" + $identifier.thetext + "'");
ret = mkJavaWrapper(fieldResult.Result.Java, null, $i.tree.Token);
AddToImports(fieldResult.Result.Imports);
$dotNetType = fieldResult.ResultType;
@ -743,10 +743,9 @@ scope {
}
}
| 'new' (
// try the simple one first, this has no argS and no expressions
// symantically could be object creation
(delegate_creation_expression) => delegate_creation_expression// new FooDelegate (MyFunction)
| object_creation_expression
// (try the simple one first, this has no argS and no expressions
// symantically could be object creation)
| (delegate_creation_expression) => delegate_creation_expression // new FooDelegate (MyFunction)
| anonymous_object_creation_expression) // new {int X, string Y}
| sizeof_expression // sizeof (struct)
| checked_expression // checked (...
@ -897,7 +896,7 @@ element_initializer:
object_initializer:
member_initializer_list? ','? '}' ;
member_initializer_list:
member_initializer (',' member_initializer) ;
member_initializer (',' member_initializer)* ;
member_initializer:
identifier '=' initializer_value ;
initializer_value:
@ -1422,7 +1421,7 @@ non_assignment_expression returns [TypeRepTemplate dotNetType, string rmId, Type
->^($le $le1 $le2)
| ^(INSTANCEOF non_assignment_expression non_nullable_type) {$dotNetType = BoolType; }
| ^('<<' n7=non_assignment_expression non_assignment_expression) {$dotNetType = $n7.dotNetType; }
| ^('>>' n8=non_assignment_expression non_assignment_expression) {$dotNetType = $n8.dotNetType; }
| ^(RIGHT_SHIFT n8=non_assignment_expression non_assignment_expression) {$dotNetType = $n8.dotNetType; }
// TODO: need to munge these numeric types
| ^('+' n9=non_assignment_expression non_assignment_expression) {$dotNetType = $n9.dotNetType; }
| ^('-' n10=non_assignment_expression non_assignment_expression) {$dotNetType = $n10.dotNetType; }
@ -1766,15 +1765,38 @@ integral_type:
'sbyte' | 'byte' | 'short' | 'ushort' | 'int' | 'uint' | 'long' | 'ulong' | 'char' ;
// B.2.12 Delegates
delegate_declaration:
^(DELEGATE attributes? modifiers? return_type identifier type_parameter_constraints_clauses? variant_generic_parameter_list? '(' formal_parameter_list? ')' ) ;
delegate_declaration
scope NSContext,SymTab;
@init {
$NSContext::namespaces = new List<string>();
$NSContext::globalNamespaces = new List<string>(((NSContext_scope)$NSContext.ToArray()[1]).globalNamespaces);
$NSContext::typeVariables = new List<string>();
$NSContext::globalTypeVariables = new List<string>(((NSContext_scope)$NSContext.ToArray()[1]).globalTypeVariables);
$SymTab::symtab = new Dictionary<string, TypeRepTemplate>();
}
:
^(DELEGATE attributes? modifiers? return_type identifier type_parameter_constraints_clauses? variant_generic_parameter_list?
{ $NSContext::currentNS = NSPrefix(ParentNameSpace) + mkGenericTypeAlias($identifier.thetext, $variant_generic_parameter_list.tyParams);
if (CompUnitName == null)
CompUnitName = $NSContext::currentNS;
$NSContext::namespaces.Add($NSContext::currentNS);
$NSContext::globalNamespaces.Add($NSContext::currentNS);
if ($variant_generic_parameter_list.tyParams != null) {
$NSContext::typeVariables.AddRange($variant_generic_parameter_list.tyParams);
$NSContext::globalTypeVariables.AddRange($variant_generic_parameter_list.tyParams);
}
}
'(' formal_parameter_list? ')' ) ;
delegate_modifiers:
modifier+ ;
// 4.0
variant_generic_parameter_list:
variant_type_variable_name+ ;
variant_type_variable_name:
attributes? variance_annotation? type_variable_name ;
variant_generic_parameter_list returns [List<string> tyParams]
@init {
$tyParams = new List<string>();
}:
(variant_type_variable_name {$tyParams.Add($variant_type_variable_name.thetext); })+ ;
variant_type_variable_name returns [string thetext]:
attributes? variance_annotation? type_variable_name { $thetext = $type_variable_name.thetext; };
variance_annotation:
IN | OUT ;
@ -1784,8 +1806,8 @@ type_parameter_constraints_clause:
// If there are no type constraints on this variable then drop this constraint
^(TYPE_PARAM_CONSTRAINT type_variable_name) ->
| ^(TYPE_PARAM_CONSTRAINT type_variable_name type_name+) ;
type_variable_name:
identifier ;
type_variable_name returns [string thetext]:
identifier { $thetext = $identifier.thetext; };
constructor_constraint:
'new' '(' ')' ;
return_type:
@ -1826,7 +1848,9 @@ scope SymTab;
@init {
$SymTab::symtab = new Dictionary<string,TypeRepTemplate>();
}:
^(EVENT attributes? modifiers? type identifier)
^(e=EVENT attributes? modifiers? t=type i=identifier magicEventCollectionType[$t.tree.Token, $t.tree] )
{ AddToImports("CS2JNet.JavaSupport.language.IEventCollection"); }
-> ^(METHOD[$e.token, "METHOD"] attributes? modifiers? magicEventCollectionType identifier EXCEPTION[$i.tree.Token, "Exception"])
| ^(METHOD attributes? modifiers? type identifier type_parameter_constraints_clauses? type_parameter_list? formal_parameter_list? exception*)
;
@ -1896,7 +1920,7 @@ statement:
(declaration_statement) => declaration_statement
| statement_plus;
statement_plus:
(identifier ':') => labeled_statement
labeled_statement
| embedded_statement
;
embedded_statement:
@ -1953,16 +1977,19 @@ fixed_pointer_initializer:
//'&' variable_reference // unary_expression covers this
expression;
labeled_statement:
identifier ':' statement ;
^(':' identifier statement) ;
declaration_statement:
(local_variable_declaration
| local_constant_declaration) ';' ;
local_variable_declaration:
local_variable_type local_variable_declarators[$local_variable_type.tree, $local_variable_type.dotNetType] ;
local_variable_type returns [TypeRepTemplate dotNetType]:
local_variable_type returns [bool isTypeNode, TypeRepTemplate dotNetType]
@init {
$isTypeNode = false;
}:
('var') => 'var' { $dotNetType = new UnknownRepTemplate("System.Object"); }
| ('dynamic') => 'dynamic' { $dotNetType = new UnknownRepTemplate("System.Object"); }
| type { $dotNetType = $type.dotNetType; };
| type { $dotNetType = $type.dotNetType; $isTypeNode = true; };
local_variable_declarators[CommonTree tyTree, TypeRepTemplate ty]:
local_variable_declarator[$tyTree, $ty] (',' local_variable_declarator[$tyTree, $ty])* ;
local_variable_declarator[CommonTree tyTree, TypeRepTemplate ty]
@ -2085,11 +2112,18 @@ scope SymTab;
}
}
bool needCast = true;
if (elType != null && $local_variable_type.dotNetType != null) {
if (elType.IsA($local_variable_type.dotNetType, AppEnv)) {
needCast = false;
}
}
if (!$local_variable_type.isTypeNode) {
// If local_type is var or dynamic then just leave it there,
// TODO: var will be replaced by its type
needCast = false;
}
else {
if (elType != null && $local_variable_type.dotNetType != null) {
if (elType.IsA($local_variable_type.dotNetType, AppEnv)) {
needCast = false;
}
}
}
// Construct new foreach using newExpression and needCast
if (needCast) {
newType = $magicObjectType.tree;
@ -2154,7 +2188,7 @@ predefined_type returns [TypeRepTemplate dotNetType]
string ns = "";
}
@after {
$dotNetType = new ClassRepTemplate((ClassRepTemplate)AppEnv.Search(ns));
$dotNetType = new ClassRepTemplate((ClassRepTemplate)AppEnv.Search(ns, new UnknownRepTemplate(ns)));
$dotNetType.IsUnboxedType = true;
// In certain contexts we must translate primitive types into their object based equivalent
@ -2289,3 +2323,7 @@ magicThrowableType[bool isOn, IToken tok]:
-> {isOn}? ^(TYPE[tok, "TYPE"] IDENTIFIER[tok, Cfg.TranslatorExceptionIsThrowable ? "Throwable" : "Exception"])
->
;
magicEventCollectionType[IToken tok, CommonTree type]:
-> ^(TYPE[tok, "TYPE"] IDENTIFIER[tok, "IEventCollection"] LTHAN[tok, "<"] { dupTree(type) } GT[tok, ">"] )
;

View File

@ -103,9 +103,9 @@ scope NSContext;
$NSContext::currentTypeRep = null;
}
:
{ Debug("start template extraction"); }
{ DebugDetail("start template extraction"); }
namespace_body
{ Debug("end template extraction"); }
{ DebugDetail("end template extraction"); }
;
namespace_declaration
@ -117,7 +117,7 @@ scope NSContext;
}
:
'namespace' qi=qualified_identifier
{ Debug("namespace: " + $qi.thetext);
{ DebugDetail("namespace: " + $qi.thetext);
$NSContext::searchpath.Add($qi.thetext);
// extend parent namespace
$NSContext::currentNS = NSPrefix(ParentNameSpace) + $qi.thetext;
@ -207,10 +207,12 @@ primary_expression:
| primary_expression_start primary_expression_part*
| 'new' ( (object_creation_expression ('.'|'->'|'[')) =>
object_creation_expression primary_expression_part+ // new Foo(arg, arg).Member
// try the simple one first, this has no argS and no expressions
// symantically could be object creation
| (delegate_creation_expression) => delegate_creation_expression// new FooDelegate (MyFunction)
| object_creation_expression
// (try the simple one first, this has no argS and no expressions
// symantically could be object creation)
// keving: try object_creation_expression first, it could be new type ( xx ) {}
// can also match delegate_creation, will have to distinguish in NetMaker.g
| (object_creation_expression) => object_creation_expression
| delegate_creation_expression // new FooDelegate (MyFunction)
| anonymous_object_creation_expression) // new {int X, string Y}
| sizeof_expression // sizeof (struct)
| checked_expression // checked (...
@ -366,7 +368,7 @@ element_initializer:
object_initializer:
member_initializer_list? ','? '}' ;
member_initializer_list:
member_initializer (',' member_initializer) ;
member_initializer (',' member_initializer)* ;
member_initializer:
identifier '=' initializer_value ;
initializer_value:
@ -682,7 +684,7 @@ scope NSContext;
:
'class' type_or_generic
{
Debug("Processing class: " + $type_or_generic.type);
DebugDetail("Processing class: " + $type_or_generic.type);
// For class System.Dictionary<K,V>
// The Type Rep has TypeName "System.Dictionary", TypeArgs "K","V" is stored at System/Dictionary'2.xml
// and will be used as [System.]Dictionary[Type1,Type2]
@ -731,7 +733,7 @@ constant_declarators [string type]:
constant_declarator[$type] (',' constant_declarator[$type])* ;
constant_declarator [string type]:
identifier { ((ClassRepTemplate)$NSContext::currentTypeRep).Fields.Add(new FieldRepTemplate($type, $identifier.text)); } ('=' constant_expression)?
{ Debug("Processing constant declaration: " + $identifier.text); }
{ DebugDetail("Processing constant declaration: " + $identifier.text); }
;
constant_expression:
expression;
@ -750,7 +752,7 @@ variable_declarator [string type, bool isEvent]:
else {
((ClassRepTemplate)$NSContext::currentTypeRep).Fields.Add(f);
}; } ('=' variable_initializer)?
{ Debug("Processing " + (isEvent ? "event" : "field") + " declaration: " + $type_name.text); }
{ DebugDetail("Processing " + (isEvent ? "event" : "field") + " declaration: " + $type_name.text); }
; // eg. event EventHandler IInterface.VariableName = Foo;
///////////////////////////////////////////////////////
@ -760,7 +762,7 @@ method_header [string returnType]:
member_name '(' fpl=formal_parameter_list? ')'
{ ((InterfaceRepTemplate)$NSContext::currentTypeRep).Methods.Add(new MethodRepTemplate($returnType, $member_name.name, ($member_name.tyargs == null ? null : $member_name.tyargs.ToArray()), $fpl.paramlist)); }
type_parameter_constraints_clauses?
{ Debug("Processing method declaration: " + $member_name.name); }
{ DebugDetail("Processing method declaration: " + $member_name.name); }
;
method_body:
block ;
@ -774,7 +776,7 @@ property_declaration[string type]:
propRep.CanRead = $accessor_declarations.hasGetter;
propRep.CanWrite = $accessor_declarations.hasSetter;
((InterfaceRepTemplate)$NSContext::currentTypeRep).Properties.Add(propRep); }
{ Debug("Processing property declaration: " + $member_name.name); }
{ DebugDetail("Processing property declaration: " + $member_name.name); }
;
accessor_declarations returns [bool hasGetter, bool hasSetter]
@int {
@ -790,7 +792,7 @@ get_accessor_declaration:
set_accessor_declaration:
accessor_modifier? 'set' accessor_body ;
accessor_modifier:
'public' | 'protected' | 'private' | 'internal' ;
'protected' 'internal'? | 'private' | 'internal' 'protected'? ;
accessor_body:
block ;
@ -799,7 +801,7 @@ event_declaration:
'event' type
((member_name '{') => member_name '{' event_accessor_declarations '}' { ((ClassRepTemplate)$NSContext::currentTypeRep).Events.Add(new FieldRepTemplate($type.thetext, $member_name.name)); }
| variable_declarators[$type.thetext, true] ';') // typename=foo;
{ Debug("Processing event declaration: " + $member_name.name); }
{ DebugDetail("Processing event declaration: " + $member_name.name); }
;
event_modifiers:
modifier+ ;
@ -824,7 +826,7 @@ scope NSContext;
:
'enum' identifier enum_base?
{
Debug("Processing enum: " + $identifier.text);
DebugDetail("Processing enum: " + $identifier.text);
eenum.TypeName = NSPrefix(ParentNameSpace) + $identifier.text;
// Nested types can see things in this space
$NSContext::searchpath.Add(eenum.TypeName);
@ -845,7 +847,7 @@ enum_member_declarations:
enum_member_declaration:
attributes? identifier ('=' expression)?
{ ((EnumRepTemplate)$NSContext::currentTypeRep).Members.Add(new EnumMemberRepTemplate($identifier.text, $expression.text)); } // todo: are arbitrary expressions really allowed
{ Debug("Processing enum member: " + $identifier.text); }
{ DebugDetail("Processing enum member: " + $identifier.text); }
;
//enum_modifiers:
// enum_modifier+ ;
@ -866,7 +868,7 @@ scope NSContext;
'delegate' return_type identifier variant_generic_parameter_list?
'(' formal_parameter_list? ')' type_parameter_constraints_clauses? ';'
{
Debug("Processing delegate: " + $identifier.text);
DebugDetail("Processing delegate: " + $identifier.text);
String genericNameSpace = NSPrefix(ParentNameSpace) + mkGenericTypeAlias($identifier.text, $variant_generic_parameter_list.tyargs);
dlegate.TypeName = NSPrefix(ParentNameSpace) + $identifier.text;
if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) {
@ -958,7 +960,7 @@ scope NSContext;
:
'interface' identifier variant_generic_parameter_list?
{
Debug("Processing interface: " + $identifier.text);
DebugDetail("Processing interface: " + $identifier.text);
String genericNameSpace = NSPrefix(ParentNameSpace) + mkGenericTypeAlias($identifier.text, $variant_generic_parameter_list.tyargs);
iface.TypeName = NSPrefix(ParentNameSpace) + $identifier.text;
if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) {
@ -998,7 +1000,7 @@ interface_property_declaration [string returnType]:
propRep.CanRead = $interface_accessor_declarations.hasGetter;
propRep.CanWrite = $interface_accessor_declarations.hasSetter;
((InterfaceRepTemplate)$NSContext::currentTypeRep).Properties.Add(propRep); }
{ Debug("Processing interface property declaration: " + $identifier.text); }
{ DebugDetail("Processing interface property declaration: " + $identifier.text); }
;
interface_method_declaration [string returnType]:
identifier gal=generic_argument_list?
@ -1006,18 +1008,18 @@ interface_method_declaration [string returnType]:
{ MethodRepTemplate meth = new MethodRepTemplate($returnType, $identifier.text, (gal == null ? null : $gal.tyargs.ToArray()), $fpl.paramlist);
((InterfaceRepTemplate)$NSContext::currentTypeRep).Methods.Add(meth); }
type_parameter_constraints_clauses? ';'
{ Debug("Processing interface method declaration: " + $identifier.text); }
{ DebugDetail("Processing interface method declaration: " + $identifier.text); }
;
interface_event_declaration:
//attributes? 'new'?
'event' type identifier { ((InterfaceRepTemplate)$NSContext::currentTypeRep).Events.Add(new FieldRepTemplate($type.thetext, $identifier.text)); } ';'
{ Debug("Processing interface event declaration: " + $identifier.text); }
{ DebugDetail("Processing interface event declaration: " + $identifier.text); }
;
interface_indexer_declaration [string returnType]:
// attributes? 'new'? type
'this' '[' fpl=formal_parameter_list ']' '{' interface_accessor_declarations '}'
{ ((InterfaceRepTemplate)$NSContext::currentTypeRep).Indexers.Add(new IndexerRepTemplate($returnType, $fpl.paramlist)); }
{ Debug("Processing interface indexer declaration"); }
{ DebugDetail("Processing interface indexer declaration"); }
;
interface_accessor_declarations returns [bool hasGetter, bool hasSetter]
@int {
@ -1046,7 +1048,7 @@ scope NSContext;
:
'struct' type_or_generic
{
Debug("Processing struct: " + $type_or_generic.type);
DebugDetail("Processing struct: " + $type_or_generic.type);
String genericNameSpace = NSPrefix(ParentNameSpace) + mkGenericTypeAlias($type_or_generic.type, $type_or_generic.generic_arguments);
strukt.TypeName = NSPrefix(ParentNameSpace) + $type_or_generic.type;
if ($type_or_generic.generic_arguments.Count > 0) {
@ -1109,7 +1111,7 @@ indexer_declarator [string returnType, string prefix]:
//(type_name '.')?
'this' '[' fpl=formal_parameter_list ']'
{ ((InterfaceRepTemplate)$NSContext::currentTypeRep).Indexers.Add(new IndexerRepTemplate($returnType, $fpl.paramlist)); }
{ Debug("Processing indexer declaration"); }
{ DebugDetail("Processing indexer declaration"); }
;
///////////////////////////////////////////////////////
@ -1129,7 +1131,7 @@ operator_declarator [string returnType]
else {
((ClassRepTemplate)$NSContext::currentTypeRep).BinaryOps.Add(meth);
}
Debug("Processing operator declaration: " + meth.Name);
DebugDetail("Processing operator declaration: " + meth.Name);
}:
'operator'
(('+' { opText = "+"; } | '-' { opText = "-"; }) '(' t0=type i0=identifier { paramList.Add(new ParamRepTemplate($t0.thetext, $i0.text)); } (binary_operator_declarator[paramList] | unary_operator_declarator { unaryOp = true; })
@ -1153,7 +1155,7 @@ conversion_operator_declarator:
CastRepTemplate kast = new CastRepTemplate($tf.thetext, $tt.thetext);
kast.SurroundingType = $NSContext::currentTypeRep;
((ClassRepTemplate)$NSContext::currentTypeRep).Casts.Add(kast);
Debug("Processing conversion declaration");
DebugDetail("Processing conversion declaration");
}
;
operator_body:
@ -1168,7 +1170,7 @@ constructor_declarator:
ConstructorRepTemplate cRep = new ConstructorRepTemplate($fpl.paramlist);
cRep.SurroundingType = $NSContext::currentTypeRep;
((ClassRepTemplate)$NSContext::currentTypeRep).Constructors.Add(cRep);
Debug("Processing constructor declaration");
DebugDetail("Processing constructor declaration");
}
;
constructor_initializer: