mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
extract enums and delegates
This commit is contained in:
parent
51bf268084
commit
c6f4268b0a
@ -1143,6 +1143,9 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
_params = new List<ParamRepTemplate> ();
|
_params = new List<ParamRepTemplate> ();
|
||||||
return _params;
|
return _params;
|
||||||
}
|
}
|
||||||
|
set {
|
||||||
|
_params = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _return;
|
private string _return;
|
||||||
|
@ -790,8 +790,25 @@ remove_accessor_declaration:
|
|||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// enum declaration
|
// enum declaration
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
enum_declaration:
|
enum_declaration
|
||||||
'enum' identifier enum_base? enum_body ';'? ;
|
scope NSContext;
|
||||||
|
@init {
|
||||||
|
$NSContext::nss = new List<UseRepTemplate>();
|
||||||
|
EnumRepTemplate eenum = new EnumRepTemplate();
|
||||||
|
}
|
||||||
|
:
|
||||||
|
'enum' identifier enum_base?
|
||||||
|
{
|
||||||
|
Debug("Processing enum: " + $identifier.text);
|
||||||
|
eenum.Uses = this.NameSpaceContext;
|
||||||
|
eenum.TypeName = this.ParentNameSpace + "." + $identifier.text;
|
||||||
|
// Nested types can see things in this space
|
||||||
|
$NSContext::nss.Add(new UseRepTemplate(eenum.TypeName));
|
||||||
|
$NSContext::currentNS = eenum.TypeName;
|
||||||
|
$NSContext::currentTypeRep = eenum;
|
||||||
|
AppEnv[eenum.TypeName] = eenum;
|
||||||
|
}
|
||||||
|
enum_body ';'? ;
|
||||||
enum_base:
|
enum_base:
|
||||||
':' integral_type ;
|
':' integral_type ;
|
||||||
enum_body:
|
enum_body:
|
||||||
@ -799,7 +816,9 @@ enum_body:
|
|||||||
enum_member_declarations:
|
enum_member_declarations:
|
||||||
enum_member_declaration (',' enum_member_declaration)* ;
|
enum_member_declaration (',' enum_member_declaration)* ;
|
||||||
enum_member_declaration:
|
enum_member_declaration:
|
||||||
attributes? identifier ('=' expression)? ;
|
attributes? identifier ('=' expression)?
|
||||||
|
{ ((EnumRepTemplate)$NSContext::currentTypeRep).Members.Add(new EnumMemberRepTemplate($identifier.text, $expression.text)); } // todo: are arbitrary expressions really allowed
|
||||||
|
;
|
||||||
//enum_modifiers:
|
//enum_modifiers:
|
||||||
// enum_modifier+ ;
|
// enum_modifier+ ;
|
||||||
//enum_modifier:
|
//enum_modifier:
|
||||||
@ -808,9 +827,29 @@ integral_type:
|
|||||||
'sbyte' | 'byte' | 'short' | 'ushort' | 'int' | 'uint' | 'long' | 'ulong' | 'char' ;
|
'sbyte' | 'byte' | 'short' | 'ushort' | 'int' | 'uint' | 'long' | 'ulong' | 'char' ;
|
||||||
|
|
||||||
// B.2.12 Delegates
|
// B.2.12 Delegates
|
||||||
delegate_declaration:
|
delegate_declaration
|
||||||
|
scope NSContext;
|
||||||
|
@init {
|
||||||
|
$NSContext::nss = new List<UseRepTemplate>();
|
||||||
|
DelegateRepTemplate dlegate = new DelegateRepTemplate();
|
||||||
|
}
|
||||||
|
:
|
||||||
'delegate' return_type identifier variant_generic_parameter_list?
|
'delegate' return_type identifier variant_generic_parameter_list?
|
||||||
'(' formal_parameter_list? ')' type_parameter_constraints_clauses? ';' ;
|
'(' formal_parameter_list? ')' type_parameter_constraints_clauses? ';'
|
||||||
|
{
|
||||||
|
Debug("Processing delegate: " + $identifier.text);
|
||||||
|
dlegate.Uses = this.NameSpaceContext;
|
||||||
|
dlegate.TypeName = this.ParentNameSpace + "." + $identifier.text;
|
||||||
|
if ($variant_generic_parameter_list.tyargs != null && $variant_generic_parameter_list.tyargs.Count > 0) {
|
||||||
|
// distinguish classes with same name, but differing numbers of type arguments
|
||||||
|
dlegate.TypeName+= "'" + $variant_generic_parameter_list.tyargs.Count.ToString();
|
||||||
|
dlegate.TypeParams = $variant_generic_parameter_list.tyargs.ToArray();
|
||||||
|
}
|
||||||
|
dlegate.Return=$return_type.thetext;
|
||||||
|
dlegate.Params=$formal_parameter_list.paramlist;
|
||||||
|
AppEnv[dlegate.TypeName] = dlegate;
|
||||||
|
}
|
||||||
|
;
|
||||||
delegate_modifiers:
|
delegate_modifiers:
|
||||||
modifier+ ;
|
modifier+ ;
|
||||||
// 4.0
|
// 4.0
|
||||||
@ -847,9 +886,9 @@ type_variable_name:
|
|||||||
identifier ;
|
identifier ;
|
||||||
constructor_constraint:
|
constructor_constraint:
|
||||||
'new' '(' ')' ;
|
'new' '(' ')' ;
|
||||||
return_type:
|
return_type returns [string thetext]:
|
||||||
type
|
type { $thetext = $type.thetext; }
|
||||||
| 'void';
|
| v='void' { $thetext = $v.text; } ;
|
||||||
formal_parameter_list returns [List<ParamRepTemplate> paramlist]
|
formal_parameter_list returns [List<ParamRepTemplate> paramlist]
|
||||||
@init {
|
@init {
|
||||||
$paramlist = new List<ParamRepTemplate>();
|
$paramlist = new List<ParamRepTemplate>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user