/// </summary>
Interface current_interface;
+ Delegate current_delegate;
+
/// <summary>
/// This is used by the unary_expression code to resolve
/// a name against a parameter.
/// The current file.
///
SourceFile file;
+
+
+ /// Current attribute target
+ string current_attr_target;
+
+ /// assembly and module attribute definition is enabled
+ bool global_attrs_enabled = true;
%}
%token EOF
%token VOLATILE
%token WHERE
%token WHILE
+%token ARGLIST
/* C# keywords which are not really keywords */
%token GET "get"
%token CLOSE_PARENS_NO_CAST
%token CLOSE_PARENS_OPEN_PARENS
%token CLOSE_PARENS_MINUS
+%token DEFAULT_OPEN_PARENS
/* Add precedence rules to solve dangling else s/r conflict */
%nonassoc LOWPREC
compilation_unit
: outer_declarations opt_EOF
- | outer_declarations attribute_sections opt_EOF
- | attribute_sections opt_EOF
+ | outer_declarations global_attributes opt_EOF
+ | global_attributes opt_EOF
| opt_EOF /* allow empty files */
;
: USING IDENTIFIER ASSIGN
namespace_or_type_name SEMICOLON
{
- current_namespace.UsingAlias ((string) $2, (Expression) $4, lexer.Location);
+ current_namespace.UsingAlias ((string) $2, (MemberName) $4, lexer.Location);
}
| USING error {
CheckIdentifierToken (yyToken);
// detach them
//
namespace_declaration
- : opt_attributes NAMESPACE namespace_or_type_name
+ : opt_attributes NAMESPACE namespace_name
{
- Attributes attrs = (Attributes) $1;
-
- if (attrs != null) {
- foreach (AttributeSection asec in attrs.AttributeSections)
- if (asec.Target == "assembly")
- CodeGen.Assembly.AddAttribute (current_container, asec);
- else
- Report.Error(1518, Lexer.Location,
- "Attributes cannot be applied to namespaces."
+ if ($1 != null) {
+ Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
+ " Expected class, delegate, enum, interface, or struct");
}
- current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, $3.ToString (), lexer.Location);
+ current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3, lexer.Location);
}
namespace_body opt_semicolon
{
;
namespace_name
- : namespace_or_type_name { $$ = ($1).ToString (); }
+ : namespace_or_type_name {
+ MemberName name = (MemberName) $1;
+
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "namespace name expected");
+
+ $$ = name.GetName ();
+ }
;
namespace_body
// Attributes 17.2
//
+global_attributes
+ : attribute_sections
+{
+ if ($1 != null)
+ CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
+
+ $$ = $1;
+}
+
opt_attributes
: /* empty */
- | attribute_sections { $$ = $1; }
+ {
+ global_attrs_enabled = false;
+ $$ = null;
+ }
+ | attribute_sections
+ {
+ global_attrs_enabled = false;
+ $$ = $1;
+ }
;
+
attribute_sections
: attribute_section
{
- AttributeSection sect = (AttributeSection) $1;
+ ArrayList sect = (ArrayList) $1;
- if (sect.Target == "assembly") {
- CodeGen.Assembly.AddAttribute (current_container, sect);
+ if (global_attrs_enabled) {
+ if (current_attr_target == "module") {
+ CodeGen.Module.AddAttributes (sect);
$$ = null;
- }
- else if (sect.Target == "module") {
- CodeGen.Module.AddAttribute (current_container, sect);
+ } else if (current_attr_target == "assembly") {
+ CodeGen.Assembly.AddAttributes (sect);
$$ = null;
+ } else {
+ $$ = new Attributes (sect);
}
- else
+ } else {
$$ = new Attributes (sect);
}
+ current_attr_target = null;
+ }
| attribute_sections attribute_section
{
Attributes attrs = $1 as Attributes;
- AttributeSection sect = (AttributeSection) $2;
-
- if (sect.Target == "assembly") {
- CodeGen.Assembly.AddAttribute (current_container, sect);
- }
- else if (sect.Target == "module") {
- CodeGen.Module.AddAttribute (current_container, sect);
+ ArrayList sect = (ArrayList) $2;
+
+ if (global_attrs_enabled) {
+ if (current_attr_target == "module") {
+ CodeGen.Module.AddAttributes (sect);
+ $$ = null;
+ } else if (current_attr_target == "assembly") {
+ CodeGen.Assembly.AddAttributes (sect);
+ $$ = null;
+ } else {
+ if (attrs == null)
+ attrs = new Attributes (sect);
+ else
+ attrs.AddAttributes (sect);
}
- else {
+ } else {
if (attrs == null)
attrs = new Attributes (sect);
else
- attrs.AddAttributeSection (sect);
+ attrs.AddAttributes (sect);
}
-
$$ = attrs;
+ current_attr_target = null;
}
;
attribute_section
: OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
{
- string target = null;
-
- if ($2 != null)
- target = (string) $2;
-
- $$ = new AttributeSection (target, (ArrayList) $3);
+ $$ = $3;
}
| OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
{
- $$ = new AttributeSection (null, (ArrayList) $2);
+ $$ = $2;
}
;
attribute_target_specifier
: attribute_target COLON
{
+ current_attr_target = (string)$1;
$$ = $1;
}
;
}
opt_attribute_arguments
{
- //
- // Attributes need a string, not an expression: generic types will fail here.
- //
- $$ = new Attribute (((Expression) $1).ToString (), (ArrayList) $3, (Location) $2);
+ MemberName mname = (MemberName) $1;
+ if (mname.IsGeneric) {
+ Report.Error (404, lexer.Location,
+ "'<' unexpected: attributes cannot be generic");
+ }
+
+ string name = mname.GetName ();
+ if (current_attr_target == "assembly" || current_attr_target == "module")
+ $$ = new GlobalAttribute (current_container, current_attr_target,
+ name, (ArrayList) $3, (Location) $2);
+ else
+ $$ = new Attribute (current_attr_target, name, (ArrayList) $3,
+ (Location) $2);
}
;
attribute_name
- : type_name { /* reserved attribute name or identifier: 17.4 */ }
+ : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
;
opt_attribute_arguments
struct_declaration
: opt_attributes
opt_modifiers
- STRUCT IDENTIFIER
+ STRUCT member_name
{
Struct new_struct;
- string full_struct_name = MakeName ((string) $4);
+ MemberName full_struct_name = MakeName ((MemberName) $4);
new_struct = new Struct (current_namespace, current_container, full_struct_name,
(int) $2, (Attributes) $1, lexer.Location);
current_container = new_struct;
- RootContext.Tree.RecordDecl (full_struct_name, new_struct);
+ RootContext.Tree.RecordDecl (full_struct_name.GetName (true), new_struct);
lexer.ConstraintsParsing = true;
}
- opt_type_parameter_list
opt_class_base
opt_type_parameter_constraints_clauses
{
{
Struct new_struct = (Struct) current_container;
- if ($8 != null && $6 == null)
- Report.Error (-200, new_struct.Location,
- "Type parameter constraints only valid if there is a type parameter list");
- if ($6 != null)
- CheckDef (new_struct.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_struct.Name, new_struct.Location);
+ CheckDef (new_struct.SetParameterInfo ((ArrayList) $7), new_struct.Name, new_struct.Location);
- if ($7 != null)
- new_struct.Bases = (ArrayList) $7;
+ if ($6 != null)
+ new_struct.Bases = (ArrayList) $6;
current_container = current_container.Parent;
CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
method_header
: opt_attributes
opt_modifiers
- type
- member_name
- opt_type_parameter_list
+ type namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
lexer.ConstraintsParsing = true;
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- if ($10 != null && $5 == null)
- Report.Error (-200, lexer.Location,
- "Type parameter constraints only valid if there is a type parameter list");
+
+ MemberName name = (MemberName) $4;
+
+ if ($9 != null && name.TypeArguments == null)
+ Report.Error (80, lexer.Location,
+ "Contraints are not allowed on non-generic declarations");
Method method;
GenericMethod generic = null;
- if ($5 != null) {
+ if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_container,
- (string) $4, (Attributes) $1,
- lexer.Location);
+ name, lexer.Location);
+
+ CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $5, (ArrayList) $10), generic.Name, generic.Location);
- method = new Method (generic, (Expression) $3, (int) $2, (string) $4,
- (Parameters) $7, (Attributes) $1, lexer.Location);
+ method = new Method (generic, (Expression) $3, (int) $2, false, name,
+ (Parameters) $6, (Attributes) $1, lexer.Location);
} else
- method = new Method (current_container, (Expression) $3, (int) $2, (string) $4,
- (Parameters) $7, (Attributes) $1, lexer.Location);
+ method = new Method (current_container, (Expression) $3, (int) $2,
+ false, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
- current_local_parameters = (Parameters) $7;
+ current_local_parameters = (Parameters) $6;
$$ = method;
}
| opt_attributes
opt_modifiers
- VOID
- member_name
- opt_type_parameter_list
+ VOID namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
lexer.ConstraintsParsing = true;
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- if ($10 != null && $5 == null)
- Report.Error (-200, lexer.Location,
- "Type parameter constraints only valid if there is a type parameter list");
+
+ MemberName name = (MemberName) $4;
+
+ if ($9 != null && name.TypeArguments == null)
+ Report.Error (80, lexer.Location,
+ "Contraints are not allowed on non-generic declarations");
Method method;
GenericMethod generic = null;
- if ($5 != null) {
+ if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_container,
- (string) $4, (Attributes) $1,
- lexer.Location);
+ name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $5, (ArrayList) $10), generic.Name, generic.Location);
+
+ CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
method = new Method (generic, TypeManager.system_void_expr, (int) $2,
- (string) $4, (Parameters) $7, (Attributes) $1,
- lexer.Location);
+ false, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
} else
- method = new Method (current_container, TypeManager.system_void_expr, (int) $2,
- (string) $4, (Parameters) $7, (Attributes) $1,
- lexer.Location);
+ method = new Method (current_container, TypeManager.system_void_expr,
+ (int) $2, false, name, (Parameters) $6,
+ (Attributes) $1, lexer.Location);
- current_local_parameters = (Parameters) $7;
+ current_local_parameters = (Parameters) $6;
$$ = method;
}
| opt_attributes
opt_modifiers
type
- modifiers member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
Report.Error (1585, lexer.Location,
String.Format ("Modifier {0} should appear before type",
Modifiers.Name ((int) $4)));
- Method method = new Method (current_container, TypeManager.system_void_expr, 0,
- (string) $5, (Parameters) $7, (Attributes) $1,
+ MemberName name = (MemberName) $4;
+
+ Method method = new Method (current_container, TypeManager.system_void_expr,
+ 0, false, name, (Parameters) $6, (Attributes) $1,
lexer.Location);
- current_local_parameters = (Parameters) $7;
+ current_local_parameters = (Parameters) $6;
$$ = method;
}
;
$$ = new Parameters (pars, (Parameter) $3, lexer.Location);
}
+ | fixed_parameters COMMA ARGLIST
+ {
+ ArrayList pars_list = (ArrayList) $1;
+
+ Parameter [] pars = new Parameter [pars_list.Count];
+ pars_list.CopyTo (pars);
+
+ $$ = new Parameters (pars, true, lexer.Location);
+ }
| parameter_array
{
$$ = new Parameters (null, (Parameter) $1, lexer.Location);
}
+ | ARGLIST
+ {
+ $$ = new Parameters (null, true, lexer.Location);
+ }
;
fixed_parameters
}
;
-member_name
- : IDENTIFIER
- | member_name DOT IDENTIFIER {
- $$ = String.Concat ((string) $1, ".", $3);
- }
- ;
-
property_declaration
: opt_attributes
opt_modifiers
- type member_name
+ type namespace_or_type_name
OPEN_BRACE
{
implicit_value_parameter_type = (Expression) $3;
Accessor get_block = (Accessor) pair.First;
Accessor set_block = (Accessor) pair.Second;
+ MemberName name = (MemberName) $4;
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "a property can't have type arguments");
+
Location loc = (Location) $6;
- prop = new Property (current_container, (Expression) $3, (string) $4, (int) $2,
- get_block, set_block, (Attributes) $1, loc);
+ prop = new Property (current_container, (Expression) $3, (int) $2, false,
+ name, (Attributes) $1, get_block, set_block, loc);
if (SimpleIteratorContainer.Simple.Yields)
prop.SetYields ();
interface_declaration
: opt_attributes
opt_modifiers
- INTERFACE IDENTIFIER
+ INTERFACE member_name
{
Interface new_interface;
- string full_interface_name = MakeName ((string) $4);
+ MemberName full_interface_name = MakeName ((MemberName) $4);
new_interface = new Interface (current_namespace, current_container, full_interface_name,
(int) $2, (Attributes) $1, lexer.Location);
Report.Error (-2, l, "Internal compiler error: interface inside interface");
}
current_interface = new_interface;
- RootContext.Tree.RecordDecl (full_interface_name, new_interface);
+ current_container = new_interface;
+ RootContext.Tree.RecordDecl (
+ full_interface_name.GetName (true), new_interface);
lexer.ConstraintsParsing = true;
}
- opt_type_parameter_list
- opt_interface_base
+ opt_class_base
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
{
Interface new_interface = (Interface) current_interface;
- if ($8 != null && $6 == null)
- Report.Error (-200, new_interface.Location,
- "Type parameter constraints only valid if there is a type parameter list");
-
+ CheckDef (new_interface.SetParameterInfo ((ArrayList) $7), new_interface.Name, new_interface.Location);
if ($6 != null)
- CheckDef (new_interface.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_interface.Name, new_interface.Location);
- if ($7 != null)
- new_interface.Bases = (ArrayList) $7;
+ new_interface.Bases = (ArrayList) $6;
current_interface = null;
+ current_container = current_container.Parent;
CheckDef (current_container.AddInterface (new_interface),
new_interface.Name, new_interface.Location);
}
}
;
-opt_interface_base
- : /* empty */ { $$ = null; }
- | interface_base
- ;
-
-interface_base
- : COLON interface_type_list { $$ = $2; }
- ;
-
-interface_type_list
- : interface_type
- {
- ArrayList interfaces = new ArrayList (4);
-
- interfaces.Add ($1);
- $$ = interfaces;
- }
- | interface_type_list COMMA interface_type
- {
- ArrayList interfaces = (ArrayList) $1;
- interfaces.Add ($3);
- $$ = interfaces;
- }
- ;
-
interface_body
: OPEN_BRACE
opt_interface_member_declarations
interface_member_declaration
: interface_method_declaration
{
- InterfaceMethod m = (InterfaceMethod) $1;
+ Method m = (Method) $1;
CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
}
| interface_property_declaration
{
- InterfaceProperty p = (InterfaceProperty) $1;
+ Property p = (Property) $1;
CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
}
| interface_event_declaration
{
if ($1 != null){
- InterfaceEvent e = (InterfaceEvent) $1;
- CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
- }
+ Event e = (Event) $1;
+ CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
+ }
}
| interface_indexer_declaration
{
- InterfaceIndexer i = (InterfaceIndexer) $1;
+ Indexer i = (Indexer) $1;
- CheckDef (current_interface.AddIndexer (i), "indexer", i.Location);
+ current_interface.AddIndexer (i);
}
;
;
interface_method_declaration
- : opt_attributes opt_new type IDENTIFIER
+ : opt_attributes opt_new type namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
SEMICOLON
{
- $$ = new InterfaceMethod ((Expression) $3, (string) $4, (int) $2,
- (Parameters) $6, (Attributes) $1, lexer.Location);
+ lexer.ConstraintsParsing = false;
+
+ MemberName name = (MemberName) $4;
+
+ if ($9 != null && name.TypeArguments == null)
+ Report.Error (80, lexer.Location,
+ "Contraints are not allowed on non-generic declarations");
+
+ GenericMethod generic = null;
+ if (name.TypeArguments != null) {
+ generic = new GenericMethod (current_namespace, current_container,
+ name, lexer.Location);
+
+ CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+
+ $$ = new Method (generic, (Expression) $3, (int) $2, true, name,
+ (Parameters) $6, (Attributes) $1, lexer.Location);
+ } else
+ $$ = new Method (current_container, (Expression) $3, (int) $2, true,
+ name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
}
- | opt_attributes opt_new VOID IDENTIFIER
+ | opt_attributes opt_new VOID namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
SEMICOLON
{
- $$ = new InterfaceMethod (
- TypeManager.system_void_expr, (string) $4, (int) $2, (Parameters) $6,
- (Attributes) $1, lexer.Location);
+ lexer.ConstraintsParsing = false;
+
+ MemberName name = (MemberName) $4;
+
+ if ($9 != null && name.TypeArguments == null)
+ Report.Error (80, lexer.Location,
+ "Contraints are not allowed on non-generic declarations");
+
+ GenericMethod generic = null;
+ if (name.TypeArguments != null) {
+ generic = new GenericMethod (current_namespace, current_container,
+ name, lexer.Location);
+
+ CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+
+ $$ = new Method (generic, TypeManager.system_void_expr, (int) $2,
+ true, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
+ } else
+ $$ = new Method (current_container, TypeManager.system_void_expr,
+ (int) $2, true, name, (Parameters) $6,
+ (Attributes) $1, lexer.Location);
}
;
{
InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
- $$ = new InterfaceProperty ((Expression) $3, (string) $4, (int) $2,
- pinfo.has_get, pinfo.has_set, (Attributes) $1,
- pinfo.get_attrs, pinfo.set_attrs,
- lexer.Location);
+ $$ = new Property (current_container, (Expression) $3, (int) $2, true,
+ new MemberName ((string) $4), (Attributes) $1,
+ pinfo.Get, pinfo.Set, lexer.Location);
}
| opt_attributes
opt_new
interface_event_declaration
: opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
{
- $$ = new InterfaceEvent ((Expression) $4, (string) $5, (int) $2, (Attributes) $1,
- lexer.Location);
+ $$ = new EventField (current_container, (Expression) $4, (int) $2, true,
+ new MemberName ((string) $5), null,
+ (Attributes) $1, lexer.Location);
}
| opt_attributes opt_new EVENT type error {
CheckIdentifierToken (yyToken);
{
InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
- bool do_get = info.has_get;
- bool do_set = info.has_set;
-
- $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
- (int) $2, (Attributes) $1, (Attributes) info.get_attrs,
- (Attributes) info.set_attrs, lexer.Location);
+ $$ = new Indexer (current_container, (Expression) $3, (int) $2, true,
+ MemberName.Null, (Parameters) $6, (Attributes) $1,
+ info.Get, info.Set, lexer.Location);
}
;
if ((m & Modifiers.UNSAFE) != 0){
if (!RootContext.Unsafe){
Report.Error (227, l,
- "Unsafe code requires the --unsafe command " +
+ "Unsafe code requires the -unsafe command " +
"line option to be specified");
}
}
CheckDef (current_container.AddMethod (d), d.Name, d.Location);
}
}
+ | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
+ string mn = (string) $5;
+
+ if (mn.IndexOf ('.') != -1)
+ Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
+ else
+ Report.Error (71, lexer.Location, "Event declaration should use property syntax");
+ }
;
event_declaration
{
foreach (VariableDeclaration var in (ArrayList) $5) {
- Event e = new Event ((Expression) $4, var.identifier,
- var.expression_or_array_initializer,
- (int) $2, null, null, (Attributes) $1, lexer.Location);
+ MemberName name = new MemberName (var.identifier);
+
+ Event e = new EventField (current_container, (Expression) $4, (int) $2,
+ false, name,
+ var.expression_or_array_initializer,
+ (Attributes) $1, lexer.Location);
CheckDef (current_container.AddEvent (e), e.Name, e.Location);
}
| opt_attributes
opt_modifiers
- EVENT type member_name
+ EVENT type namespace_or_type_name
OPEN_BRACE
{
implicit_value_parameter_type = (Expression) $4;
$$ = null;
} else {
Pair pair = (Pair) $8;
- Accessor add_accessor = null;
- Accessor rem_accessor = null;
- if (pair.First != null)
- add_accessor = (Accessor) pair.First;
- if (pair.Second != null)
- rem_accessor = (Accessor) pair.Second;
-
- Event e = new Event ((Expression) $4, (string) $5, null, (int) $2, add_accessor, rem_accessor,
- (Attributes) $1, loc);
+ MemberName name = (MemberName) $5;
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "an event can't have type arguments");
+
+ Event e = new EventProperty (current_container, (Expression) $4, (int) $2,
+ false, name, null, (Attributes) $1,
+ (Accessor) pair.First, (Accessor) pair.Second,
+ loc);
CheckDef (current_container.AddEvent (e), e.Name, loc);
implicit_value_parameter_type = null;
Accessor get_block = (Accessor) pair.First;
Accessor set_block = (Accessor) pair.Second;
- indexer = new Indexer (current_container, decl.type, decl.interface_type, (int) $2,
- decl.param_list, get_block, set_block, (Attributes) $1, loc);
+ MemberName name;
+ if (decl.interface_type != null)
+ name = new MemberName (decl.interface_type, "", null);
+ else
+ name = MemberName.Null;
+
+ indexer = new Indexer (current_container, decl.type, (int) $2, false,
+ name, decl.param_list, (Attributes) $1,
+ get_block, set_block, loc);
// Note that there is no equivalent of CheckDef for this case
// We shall handle this in semantic analysis
$$ = new IndexerDeclaration ((Expression) $1, null, pars);
}
- | type member_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
+ | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
{
Parameters pars = (Parameters) $6;
if (pars.FixedParameters == null && pars.ArrayParameter == null){
Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
}
- $$ = new IndexerDeclaration ((Expression) $1, $2.ToString (), pars);
+ MemberName name = (MemberName) $2;
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "an indexer can't have type arguments");
+
+ $$ = new IndexerDeclaration ((Expression) $1, name, pars);
}
;
{
Location enum_location = lexer.Location;
- string full_name = MakeName ((string) $4);
+ MemberName full_name = MakeName (new MemberName ((string) $4));
Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
full_name, (Attributes) $1, enum_location);
ev.identifier, loc);
}
- CheckDef (current_container.AddEnum (e), full_name, enum_location);
- RootContext.Tree.RecordDecl (full_name, e);
+ string name = full_name.GetName (false);
+ CheckDef (current_container.AddEnum (e), name, enum_location);
+ RootContext.Tree.RecordDecl (name, e);
}
;
delegate_declaration
: opt_attributes
opt_modifiers
- DELEGATE type
- IDENTIFIER OPEN_PARENS
- opt_formal_parameter_list
- CLOSE_PARENS
- SEMICOLON
+ DELEGATE type member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
Location l = lexer.Location;
- Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
- (int) $2, MakeName ((string) $5), (Parameters) $7,
- (Attributes) $1, l);
+ Delegate del = new Delegate (
+ current_namespace, current_container, (Expression) $4, (int) $2,
+ MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
CheckDef (current_container.AddDelegate (del), del.Name, l);
- }
+
+ current_delegate = del;
+
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
+ }
+ SEMICOLON
+ {
+ CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+
+ current_delegate = null;
+ }
| opt_attributes
opt_modifiers
- DELEGATE VOID
- IDENTIFIER OPEN_PARENS
- opt_formal_parameter_list
- CLOSE_PARENS
- SEMICOLON
+ DELEGATE VOID member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
Location l = lexer.Location;
Delegate del = new Delegate (
current_namespace, current_container,
- TypeManager.system_void_expr, (int) $2, MakeName ((string) $5),
+ TypeManager.system_void_expr, (int) $2, MakeName ((MemberName) $5),
(Parameters) $7, (Attributes) $1, l);
CheckDef (current_container.AddDelegate (del), del.Name, l);
- }
- ;
-type_name
- : namespace_or_type_name
- ;
+ current_delegate = del;
-namespace_or_type_name
- : IDENTIFIER opt_type_argument_list {
- if ($2 == null)
- $$ = new SimpleName ((string) $1, lexer.Location);
- else
- $$ = new ConstructedType ((string) $1, (TypeArguments) $2, lexer.Location);
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
}
- | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
+ SEMICOLON
{
- Expression right;
+ CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
- //
- // Third argument will become an Expression, when we have sorted out
- // the issues with SimpleName first
- //
+ current_delegate = null;
+ }
+ ;
- if ($4 == null)
- $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
- else
- $$ = new GenericMemberAccess ((Expression) $1, (string) $3,
- (TypeArguments) $4, lexer.Location);
+namespace_or_type_name
+ : member_name
+ | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
+ $$ = new MemberName ((MemberName) $1, (string) $3, (TypeArguments) $4);
}
- | namespace_or_type_name DOT DEFAULT
- {
- $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
+ ;
+
+member_name
+ : IDENTIFIER opt_type_argument_list {
+ $$ = new MemberName ((string) $1, (TypeArguments) $2);
}
;
-//
-// TODO:
-// Figure out what to do with the list
-//
opt_type_argument_list
: /* empty */ { $$ = null; }
| OP_GENERICS_LT type_arguments OP_GENERICS_GT
* gets rid of a shift/reduce couple
*/
type
- : type_name { /* class_type */
+ : namespace_or_type_name
+ {
+ $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
}
| builtin_types
| array_type
| VOID { $$ = TypeManager.system_void_expr; }
;
-interface_type
- : type_name
- ;
-
array_type
: type rank_specifiers
{
// 7.5.1: Literals
}
- | type_name
+ | member_name
{
- $$ = $1;
+ $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
}
| parenthesized_expression
| default_value_expression
;;
member_access
- : primary_expression DOT IDENTIFIER
+ : primary_expression DOT IDENTIFIER opt_type_argument_list
{
- $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+ $$ = new MemberAccess ((Expression) $1, (string) $3,
+ (TypeArguments) $4, lexer.Location);
}
- | predefined_type DOT IDENTIFIER
+ | predefined_type DOT IDENTIFIER opt_type_argument_list
{
- $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+ $$ = new MemberAccess ((Expression) $1, (string) $3,
+ (TypeArguments) $4, lexer.Location);
}
;
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
}
+ | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
+ {
+ ArrayList list = (ArrayList) $3;
+ Argument[] args = new Argument [list.Count];
+ list.CopyTo (args, 0);
+
+ Expression expr = new Arglist (args, lexer.Location);
+ $$ = new Argument (expr, Argument.AType.Expression);
+ }
+ | ARGLIST
+ {
+ $$ = new Argument (new ArglistAccess (lexer.Location), Argument.AType.ArgList);
+ }
;
variable_reference
// Foo.Bar.Blah i;
// SimpleName is when you have
// Blah i;
-
+
Expression expr = (Expression) $1;
if (expr is ComposedCast){
$$ = new ComposedCast (expr, (string) $2, lexer.Location);
current_local_parameters = (Parameters)$2;
create_toplevel_block = true;
} block {
- create_toplevel_block = false;
- if (!RootContext.V2){
- Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
+ if (true){
+ Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
$$ = null;
- } else
- $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
- current_local_parameters = (Parameters) oob_stack.Pop ();
+ } else {
+ create_toplevel_block = false;
+ Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
+ if (!RootContext.V2){
+ Report.Error (-213, lexer.Location, "Anonymous methods are only supported in V2");
+ $$ = null;
+ } else
+ $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
+ current_local_parameters = (Parameters) oob_stack.Pop ();
+ }
}
;
;
default_value_expression
- : primary_expression DOT DEFAULT
- {
- $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
- }
- | predefined_type DOT DEFAULT
+ : DEFAULT_OPEN_PARENS type CLOSE_PARENS
{
- $$ = new DefaultValueExpression ((Expression) $1, lexer.Location);
+ $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
}
;
class_declaration
: opt_attributes
opt_modifiers
- CLASS IDENTIFIER
+ CLASS member_name
{
Class new_class;
- string name;
- name = MakeName ((string) $4);
+ MemberName name = MakeName ((MemberName) $4);
new_class = new Class (current_namespace, current_container, name, (int) $2,
(Attributes) $1, lexer.Location);
current_container = new_class;
- RootContext.Tree.RecordDecl (name, new_class);
+ RootContext.Tree.RecordDecl (name.GetName (true), new_class);
lexer.ConstraintsParsing = true;
}
- opt_type_parameter_list
opt_class_base
opt_type_parameter_constraints_clauses
{
{
Class new_class = (Class) current_container;
- if ($8 != null && $6 == null)
- Report.Error (-200, new_class.Location,
- "Type parameter constraints only valid if there is a type parameter list");
-
- if ($6 != null)
- CheckDef (new_class.SetParameterInfo ((ArrayList) $6, (ArrayList) $8), new_class.Name, new_class.Location);
- if ($7 != null) {
+ CheckDef (new_class.SetParameterInfo ((ArrayList) $7), new_class.Name, new_class.Location);
+ if ($6 != null) {
if (new_class.Name == "System.Object") {
Report.Error (537, new_class.Location, "The class System.Object cannot have a base class or implement an interface.");
}
- new_class.Bases = (ArrayList) $7;
+ new_class.Bases = (ArrayList) $6;
}
current_container = current_container.Parent;
CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
$$ = new_class;
}
- | opt_attributes
- opt_modifiers
- CLASS IDENTIFIER
- {
- lexer.ConstraintsParsing = true;
- }
- WHERE {
- Report.Error (-200, lexer.Location,
- "Type parameter constraints only valid if there is a type parameter list");
- yyErrorFlag = 0;
- $$ = null;
- }
;
opt_modifiers
: COLON type_list { $$ = $2; }
;
-opt_type_parameter_list
- : /* empty */ { $$ = null; }
- | type_parameter_list { $$ = $1; }
- ;
-
-type_parameter_list
- : OP_GENERICS_LT type_parameters OP_GENERICS_GT { $$ = $2; }
- ;
-
-type_parameters
- : type_parameter {
- //
- // Do some profiling to find the optimal size, for now we
- // assume most people will be generic on one type (saves space
- //
- ArrayList type_parameters = new ArrayList (1);
- type_parameters.Add ($1);
- $$ = type_parameters;
- }
- | type_parameters COMMA type_parameter {
- ArrayList type_parameters = (ArrayList) $1;
-
- type_parameters.Add ($3);
- $$ = type_parameters;
- }
- ;
-
-type_parameter
- : IDENTIFIER
- ;
-
opt_type_parameter_constraints_clauses
: /* empty */ { $$ = null; }
| type_parameter_constraints_clauses
;
type_parameter_constraints_clauses
- : type_parameter_constraints_clause
+ : type_parameter_constraints_clause {
+ ArrayList constraints = new ArrayList (1);
+ constraints.Add ($1);
+ $$ = constraints;
+ }
| type_parameter_constraints_clauses type_parameter_constraints_clause {
ArrayList constraints = (ArrayList) $1;
;
type_parameter_constraints_clause
- : WHERE type_parameter COLON type_parameter_constraints {
- ArrayList constraints = new ArrayList (1);
- constraints.Add (new Constraints ((string) $2, (ArrayList) $4, lexer.Location));
- $$ = constraints;
+ : WHERE IDENTIFIER COLON type_parameter_constraints {
+ $$ = new Constraints ((string) $2, (ArrayList) $4, lexer.Location);
}
;
type_parameter_constraint
: type
| NEW OPEN_PARENS CLOSE_PARENS {
- $$ = true;
+ $$ = SpecialConstraint.Constructor;
+ }
+ | CLASS {
+ $$ = SpecialConstraint.ReferenceType;
+ }
+ | STRUCT {
+ $$ = SpecialConstraint.ValueType;
}
;
current_block = (Block) $1;
}
}
- | embedded_statement
+ | valid_declaration_statement
{
current_block.AddStatement ((Statement) $1);
}
| labeled_statement
;
-embedded_statement
+valid_declaration_statement
: block
| empty_statement
| expression_statement
| fixed_statement
;
+embedded_statement
+ : valid_declaration_statement
+ | declaration_statement
+ {
+ Report.Error (1023, lexer.Location, "An embedded statement may not be a declaration.");
+ $$ = null;
+ }
+ | labeled_statement
+ {
+ Report.Error (1023, lexer.Location, "An embedded statement may not be a labeled statement.");
+ $$ = null;
+ }
+ ;
+
empty_statement
: SEMICOLON
{
{
LabeledStatement labeled = new LabeledStatement ((string) $1, lexer.Location);
- if (!current_block.AddLabel ((string) $1, labeled)){
- Location l = lexer.Location;
- Report.Error (140, l, "The label '" + ((string) $1) + "' is a duplicate");
- }
- current_block.AddStatement (labeled);
+ if (current_block.AddLabel ((string) $1, labeled, lexer.Location))
+ current_block.AddStatement (labeled);
}
statement
;
{
oob_stack.Push (current_block);
- Block foreach_block = new Block (current_block, Block.Flags.Implicit);
+ Block foreach_block = new Block (current_block);
LocalVariableReference v = null;
Location l = lexer.Location;
LocalInfo vi;
/// </summary>
public class InterfaceAccessorInfo {
- public bool has_get;
- public bool has_set;
- public Attributes get_attrs;
- public Attributes set_attrs;
+ public readonly Accessor Get, Set;
public InterfaceAccessorInfo (bool has_get, bool has_set,
Attributes get_attrs, Attributes set_attrs)
{
- this.has_get = has_get;
- this.has_set = has_set;
- this.get_attrs = get_attrs;
- this.set_attrs = set_attrs;
+ if (has_get)
+ Get = new Accessor (null, get_attrs);
+ if (has_set)
+ Set = new Accessor (null, set_attrs);
}
}
// </summary>
public class IndexerDeclaration {
public Expression type;
- public string interface_type;
+ public MemberName interface_type;
public Parameters param_list;
- public IndexerDeclaration (Expression type, string interface_type, Parameters param_list)
+ public IndexerDeclaration (Expression type, MemberName interface_type,
+ Parameters param_list)
{
this.type = type;
this.interface_type = interface_type;
// Given the @class_name name, it creates a fully qualified name
// based on the containing declaration space
// </summary>
-string
-MakeName (string class_name)
+MemberName
+MakeName (MemberName class_name)
{
string ns = current_namespace.FullName;
- string container_name = current_container.Name;
- if (container_name == ""){
+ if (current_container.Name == ""){
if (ns != "")
- return ns + "." + class_name;
+ return new MemberName (new MemberName (ns), class_name);
else
return class_name;
- } else
- return container_name + "." + class_name;
+ } else {
+ return new MemberName (current_container.MemberName, class_name);
+ }
}
// <summary>
//
// int j = 1; int k = j + 1;
//
- if (current_block.Used) {
+ if (current_block.Used)
implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
- implicit_block.AddChildVariableNames (current_block);
- } else
+ else
implicit_block = current_block;
foreach (VariableDeclaration decl in variable_declarators){