// Licensed under the terms of the GNU GPL
//
// (C) 2001 Ximian, Inc (http://www.ximian.com)
+// (C) 2004 Novell, Inc
//
// TODO:
// (1) Figure out why error productions dont work. `type-declaration' is a
public class CSharpParser {
NamespaceEntry current_namespace;
TypeContainer current_container;
+ TypeContainer current_class;
IIteratorContainer iterator_container;
- // <summary>
- // Current block is used to add statements as we find
- // them.
- // </summary>
+ /// <summary>
+ /// Current block is used to add statements as we find
+ /// them.
+ /// </summary>
+ Block current_block, top_current_block;
- Block current_block;
+ Delegate current_delegate;
- // <summary>
- // Current interface is used by the various declaration
- // productions in the interface declaration to "add"
- // the interfaces as we find them.
- // </summary>
- Interface current_interface;
-
- // <summary>
- // This is used by the unary_expression code to resolve
- // a name against a parameter.
- // </summary>
+ /// <summary>
+ /// This is used by the unary_expression code to resolve
+ /// a name against a parameter.
+ /// </summary>
Parameters current_local_parameters;
- // <summary>
- // Using during property parsing to describe the implicit
- // value parameter that is passed to the "set" and "get"accesor
- // methods (properties and indexers).
- // </summary>
+ /// <summary>
+ /// Using during property parsing to describe the implicit
+ /// value parameter that is passed to the "set" and "get"accesor
+ /// methods (properties and indexers).
+ /// </summary>
Expression implicit_value_parameter_type;
Parameters indexer_parameters;
- // <summary>
- // Used to determine if we are parsing the get/set pair
- // of an indexer or a property
- // </summmary>
+ /// <summary>
+ /// Used to determine if we are parsing the get/set pair
+ /// of an indexer or a property
+ /// </summmary>
bool parsing_indexer;
- //
- // An out-of-band stack.
- //
+ ///
+ /// An out-of-band stack.
+ ///
Stack oob_stack;
- //
- // Switch stack.
- //
+ ///
+ /// Switch stack.
+ ///
Stack switch_stack;
- public bool yacc_verbose_flag;
+ static public int yacc_verbose_flag;
// Name of the file we are parsing
public string name;
- //
- // The current file.
- //
+ ///
+ /// The current file.
+ ///
SourceFile file;
+
+ ///
+ /// Temporary Xml documentation cache.
+ /// For enum types, we need one more temporary store.
+ ///
+ string tmpComment;
+ string enumTypeComment;
+
+
+
+ /// 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
-
-/* v2 tokens */
-%token YIELD
+%token ARGLIST
+%token PARTIAL
/* 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
+%token GENERIC_DIMENSION
/* 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 */
;
opt_EOF
: /* empty */
+ {
+ Lexer.check_incorrect_doc_comment ();
+ }
| EOF
+ {
+ Lexer.check_incorrect_doc_comment ();
+ }
;
outer_declarations
using_directive
: using_alias_directive
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
| using_namespace_directive
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
;
using_alias_directive
: 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 qualified_identifier
+ : opt_attributes NAMESPACE namespace_or_type_name
{
- Attributes attrs = (Attributes) $1;
-
- if (attrs != null) {
- foreach (AttributeSection asec in attrs.AttributeSections)
- if (asec.Target == "assembly")
- RootContext.AddGlobalAttributeSection (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, (string) $3, lexer.Location);
- }
+ MemberName name = (MemberName) $3;
+
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "namespace name expected");
+ else if ((current_namespace.Parent != null) && (name.Left != null)) {
+ Report.Error (134, lexer.Location,
+ "Cannot use qualified namespace names in nested " +
+ "namespace declarations");
+ }
+
+ current_namespace = new NamespaceEntry (
+ current_namespace, file, name.GetName (), lexer.Location);
+ }
namespace_body opt_semicolon
{
current_namespace = current_namespace.Parent;
| COMMA
;
-qualified_identifier
- : IDENTIFIER
- | qualified_identifier DOT IDENTIFIER {
- $$ = (($1).ToString ()) + "." + ($3.ToString ()); }
- ;
+namespace_name
+ : namespace_or_type_name {
+ MemberName name = (MemberName) $1;
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "namespace name expected");
-namespace_name
- : qualified_identifier
+ $$ = name.GetName ();
+ }
;
namespace_body
: OPEN_BRACE
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
opt_using_directives
opt_namespace_member_declarations
CLOSE_BRACE
| namespace_declaration {
current_namespace.DeclarationFound = true;
}
+
+ | field_declaration {
+ Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
+ }
+ | method_declaration {
+ Report.Error (116, lexer.Location, "A namespace can only contain types and namespace declarations");
+ }
;
type_declaration
// Attributes 17.2
//
+global_attributes
+ : attribute_sections
+{
+ if ($1 != null)
+ CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
+
+ $$ = $1;
+}
+
opt_attributes
- : /* empty */
- | attribute_sections { $$ = $1; }
- ;
+ : /* empty */
+ {
+ global_attrs_enabled = false;
+ $$ = null;
+ }
+ | attribute_sections
+ {
+ global_attrs_enabled = false;
+ $$ = $1;
+ }
+ ;
+
attribute_sections
: attribute_section
{
- AttributeSection sect = (AttributeSection) $1;
-
- if (sect.Target == "assembly")
- RootContext.AddGlobalAttributeSection (current_container, sect);
-
-
- $$ = new Attributes ((AttributeSection) $1);
- }
+ ArrayList sect = (ArrayList) $1;
+
+ 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 {
+ $$ = new Attributes (sect);
+ }
+ if ($$ == null) {
+ if (RootContext.Documentation != null) {
+ Lexer.check_incorrect_doc_comment ();
+ Lexer.doc_state =
+ XmlCommentState.Allowed;
+ }
+ }
+ } else {
+ $$ = new Attributes (sect);
+ }
+ current_attr_target = null;
+ }
| attribute_sections attribute_section
{
- Attributes attrs = null;
- AttributeSection sect = (AttributeSection) $2;
+ Attributes attrs = $1 as Attributes;
+ ArrayList sect = (ArrayList) $2;
- if (sect.Target == "assembly")
- RootContext.AddGlobalAttributeSection (current_container, sect);
-
- if ($1 != null) {
- attrs = (Attributes) $1;
- attrs.AddAttributeSection (sect);
- }
-
+ 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 {
+ if (attrs == null)
+ attrs = new Attributes (sect);
+ else
+ 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
$$ = args;
}
+ | named_argument_list COMMA expression
+ {
+ Report.Error (1016, lexer.Location, "Named attribute argument expected");
+ $$ = null;
+ }
;
named_argument
struct_declaration
: opt_attributes
opt_modifiers
- STRUCT IDENTIFIER
+ opt_partial
+ STRUCT member_name
{
- Struct new_struct;
- string full_struct_name = MakeName ((string) $4);
+ MemberName name = MakeName ((MemberName) $5);
+ bool partial = (bool) $3;
+
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, Kind.Struct, lexer.Location);
+
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ current_class = new Struct (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, lexer.Location);
+
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
- 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);
+ lexer.ConstraintsParsing = true;
}
opt_class_base
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
+
+ if ($7 != null)
+ current_class.Bases = (ArrayList) $7;
+
+ current_class.SetParameterInfo ((ArrayList) $8);
+
+ if (RootContext.Documentation != null)
+ current_class.DocComment = Lexer.consume_doc_comment ();
+
+ current_class.Register ();
+ }
struct_body
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
opt_semicolon
{
- Struct new_struct = (Struct) current_container;
-
- if ($6 != null)
- new_struct.Bases = (ArrayList) $6;
+ $$ = current_class;
current_container = current_container.Parent;
- CheckDef (current_container.AddStruct (new_struct), new_struct.Name, new_struct.Location);
- $$ = new_struct;
+ current_class = current_container;
}
- | opt_attributes opt_modifiers STRUCT error {
+ | opt_attributes opt_modifiers opt_partial STRUCT error {
CheckIdentifierToken (yyToken);
}
;
struct_body
- : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
+ : OPEN_BRACE
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ opt_struct_member_declarations CLOSE_BRACE
;
opt_struct_member_declarations
constant_declarators
SEMICOLON
{
+ int modflags = (int) $2;
foreach (VariableDeclaration constant in (ArrayList) $5){
Location l = constant.Location;
+ if ((modflags & Modifiers.STATIC) != 0) {
+ Report.Error (504, l, "The constant '{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
+ continue;
+ }
Const c = new Const (
- (Expression) $4, (string) constant.identifier,
- (Expression) constant.expression_or_array_initializer, (int) $2,
+ current_class, (Expression) $4, (string) constant.identifier,
+ (Expression) constant.expression_or_array_initializer, modflags,
(Attributes) $1, l);
- CheckDef (current_container.AddConstant (c), c.Name, l);
+ if (RootContext.Documentation != null) {
+ c.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ current_container.AddConstant (c);
}
}
;
: constant_declarator
{
ArrayList constants = new ArrayList (4);
- constants.Add ($1);
+ if ($1 != null)
+ constants.Add ($1);
$$ = constants;
}
| constant_declarators COMMA constant_declarator
{
- ArrayList constants = (ArrayList) $1;
-
- constants.Add ($3);
+ if ($3 != null) {
+ ArrayList constants = (ArrayList) $1;
+ constants.Add ($3);
+ }
}
;
{
$$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
}
+ | IDENTIFIER
+ {
+ // A const field requires a value to be provided
+ Report.Error (145, lexer.Location, "A const field requires a value to be provided");
+ $$ = null;
+ }
;
field_declaration
foreach (VariableDeclaration var in (ArrayList) $4){
Location l = var.Location;
- Field field = new Field (type, mod, var.identifier,
+ Field field = new Field (current_class, type, mod, var.identifier,
var.expression_or_array_initializer,
(Attributes) $1, l);
- CheckDef (current_container.AddField (field), field.Name, l);
+ if (RootContext.Documentation != null) {
+ field.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ current_container.AddField (field);
}
}
| opt_attributes
{
$$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
}
+ | STACKALLOC type
+ {
+ Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
+ $$ = null;
+ }
;
method_declaration
: method_header {
iterator_container = (IIteratorContainer) $1;
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.NotAllowed;
}
method_body
{
}
}
- method.Block = (Block) $3;
- CheckDef (current_container.AddMethod (method), method.Name, method.Location);
+ method.Block = (ToplevelBlock) $3;
+ current_container.AddMethod (method);
current_local_parameters = null;
iterator_container = null;
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
;
method_header
: opt_attributes
opt_modifiers
- type
- member_name
+ type namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
- Method method = new Method ((Expression) $3, (int) $2, (string) $4,
- (Parameters) $6, (Attributes) $1, lexer.Location);
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ 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");
+
+ Method method;
+
+ GenericMethod generic = null;
+ if (name.TypeArguments != null) {
+ generic = new GenericMethod (current_namespace, current_class,
+ name, lexer.Location);
+
+ generic.SetParameterInfo ((ArrayList) $9);
+ }
+
+ method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
+ name, (Parameters) $6, (Attributes) $1, lexer.Location);
current_local_parameters = (Parameters) $6;
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
$$ = method;
}
| opt_attributes
opt_modifiers
- VOID
- member_name
+ VOID namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
- Method method = new Method (TypeManager.system_void_expr, (int) $2, (string) $4,
- (Parameters) $6, (Attributes) $1, lexer.Location);
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ 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");
+
+ Method method;
+ GenericMethod generic = null;
+ if (name.TypeArguments != null) {
+ generic = new GenericMethod (current_namespace, current_class,
+ name, lexer.Location);
+
+ generic.SetParameterInfo ((ArrayList) $9);
+ }
+
+ method = new Method (current_class, generic, TypeManager.system_void_expr,
+ (int) $2, false, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
current_local_parameters = (Parameters) $6;
+
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
+ $$ = method;
+ }
+ | opt_attributes
+ opt_modifiers
+ type
+ 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)));
+ MemberName name = (MemberName) $4;
+
+ Method method = new Method (current_class, null, TypeManager.system_void_expr,
+ 0, false, name, (Parameters) $6, (Attributes) $1,
+ lexer.Location);
+
+ current_local_parameters = (Parameters) $6;
+
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
$$ = 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
{
$$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
}
+ | opt_attributes
+ opt_parameter_modifier
+ type
+ {
+ Report.Error (1001, lexer.Location, "Identifier expected");
+ $$ = null;
+ }
| opt_attributes
opt_parameter_modifier
type
CheckIdentifierToken (yyToken);
$$ = null;
}
+ | opt_attributes
+ opt_parameter_modifier
+ type
+ IDENTIFIER
+ ASSIGN
+ constant_expression
+ {
+ Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
+ $$ = null;
+ }
;
opt_parameter_modifier
$$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
note ("type must be a single-dimension array type");
}
+ | opt_attributes PARAMS parameter_modifier type IDENTIFIER
+ {
+ Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
+ $$ = null;
+ }
| opt_attributes PARAMS type error {
CheckIdentifierToken (yyToken);
$$ = null;
}
;
-member_name
- : qualified_identifier
- ;
-
property_declaration
: opt_attributes
opt_modifiers
- type member_name
+ type
+ namespace_or_type_name
+ {
+ if (RootContext.Documentation != null)
+ tmpComment = Lexer.consume_doc_comment ();
+ }
OPEN_BRACE
{
implicit_value_parameter_type = (Expression) $3;
lexer.PropertyParsing = true;
$$ = lexer.Location;
+
+ iterator_container = SimpleIteratorContainer.GetSimple ();
}
accessor_declarations
{
CLOSE_BRACE
{
Property prop;
- Pair pair = (Pair) $7;
+ Pair pair = (Pair) $8;
Accessor get_block = (Accessor) pair.First;
Accessor set_block = (Accessor) pair.Second;
- Location loc = (Location) $6;
- prop = new Property ((Expression) $3, (string) $4, (int) $2, get_block, set_block,
- (Attributes) $1, loc);
+ Location loc = (Location) $7;
+ MemberName name = (MemberName) $4;
+
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "a property can't have type arguments");
+
+ prop = new Property (current_container, (Expression) $3, (int) $2, false,
+ name, (Attributes) $1, get_block, set_block, loc);
+ if (SimpleIteratorContainer.Simple.Yields)
+ prop.SetYields ();
- CheckDef (current_container.AddProperty (prop), prop.Name, loc);
+ current_container.AddProperty (prop);
implicit_value_parameter_type = null;
+ iterator_container = null;
+
+ if (RootContext.Documentation != null)
+ prop.DocComment = ConsumeStoredComment ();
+
}
;
;
get_accessor_declaration
- : opt_attributes GET
+ : opt_attributes opt_modifiers GET
{
// If this is not the case, then current_local_parameters has already
// been set in indexer_declaration
}
accessor_body
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
current_local_parameters = null;
lexer.PropertyParsing = true;
+
+ if (RootContext.Documentation != null)
+ if (Lexer.doc_state == XmlCommentState.Error)
+ Lexer.doc_state = XmlCommentState.NotAllowed;
}
;
set_accessor_declaration
- : opt_attributes SET
+ : opt_attributes opt_modifiers SET
{
Parameter [] args;
Parameter implicit_value_parameter = new Parameter (
}
accessor_body
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
current_local_parameters = null;
lexer.PropertyParsing = true;
+
+ if (RootContext.Documentation != null
+ && Lexer.doc_state == XmlCommentState.Error)
+ Lexer.doc_state = XmlCommentState.NotAllowed;
}
;
interface_declaration
: opt_attributes
opt_modifiers
- INTERFACE IDENTIFIER
+ opt_partial
+ INTERFACE member_name
{
- Interface new_interface;
- string full_interface_name = MakeName ((string) $4);
+ MemberName name = MakeName ((MemberName) $5);
+ bool partial = (bool) $3;
- new_interface = new Interface (current_namespace, current_container, full_interface_name,
- (int) $2, (Attributes) $1, lexer.Location);
- if (current_interface != null) {
- Location l = lexer.Location;
- Report.Error (-2, l, "Internal compiler error: interface inside interface");
- }
- current_interface = new_interface;
- RootContext.Tree.RecordDecl (full_interface_name, new_interface);
- }
- opt_interface_base
- interface_body opt_semicolon
- {
- Interface new_interface = (Interface) current_interface;
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, Kind.Interface, lexer.Location);
- if ($6 != null)
- new_interface.Bases = (ArrayList) $6;
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ current_class = new Interface (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, lexer.Location);
- current_interface = null;
- CheckDef (current_container.AddInterface (new_interface),
- new_interface.Name, new_interface.Location);
- }
- | opt_attributes opt_modifiers INTERFACE error {
- CheckIdentifierToken (yyToken);
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
+
+ lexer.ConstraintsParsing = true;
}
- ;
+ opt_class_base
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
-opt_interface_base
- : /* empty */ { $$ = null; }
- | interface_base
- ;
+ if ($7 != null)
+ current_class.Bases = (ArrayList) $7;
-interface_base
- : COLON interface_type_list { $$ = $2; }
- ;
+ current_class.SetParameterInfo ((ArrayList) $8);
-interface_type_list
- : interface_type
- {
- ArrayList interfaces = new ArrayList (4);
+ if (RootContext.Documentation != null) {
+ current_class.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
- interfaces.Add ($1);
- $$ = interfaces;
+ current_class.Register ();
+ }
+ interface_body
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
- | interface_type_list COMMA interface_type
+ opt_semicolon
{
- ArrayList interfaces = (ArrayList) $1;
- interfaces.Add ($3);
- $$ = interfaces;
+ $$ = current_class;
+
+ current_container = current_container.Parent;
+ current_class = current_container;
+ }
+ | opt_attributes opt_modifiers opt_partial INTERFACE error {
+ CheckIdentifierToken (yyToken);
}
;
interface_member_declaration
: interface_method_declaration
{
- InterfaceMethod m = (InterfaceMethod) $1;
+ Method m = (Method) $1;
+
+ current_container.AddMethod (m);
- CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
| interface_property_declaration
{
- InterfaceProperty p = (InterfaceProperty) $1;
+ Property p = (Property) $1;
- CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
- }
+ current_container.AddProperty (p);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
| interface_event_declaration
{
- InterfaceEvent e = (InterfaceEvent) $1;
+ if ($1 != null){
+ Event e = (Event) $1;
+ current_container.AddEvent (e);
+ }
- CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
| interface_indexer_declaration
{
- InterfaceIndexer i = (InterfaceIndexer) $1;
+ Indexer i = (Indexer) $1;
- CheckDef (current_interface.AddIndexer (i), "indexer", i.Location);
+ current_container.AddIndexer (i);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
;
opt_new
- : /* empty */ { $$ = false; }
- | NEW { $$ = true; }
+ : opt_modifiers
+ {
+ int val = (int) $1;
+ val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, lexer.Location);
+ $$ = val;
+ }
;
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, (bool) $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_class,
+ name, lexer.Location);
+
+ generic.SetParameterInfo ((ArrayList) $9);
+ }
+
+ $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
+ (Parameters) $6, (Attributes) $1, lexer.Location);
+ if (RootContext.Documentation != null)
+ ((Method) $$).DocComment = Lexer.consume_doc_comment ();
}
- | 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, (bool) $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_class,
+ name, lexer.Location);
+
+ generic.SetParameterInfo ((ArrayList) $9);
+ }
+
+ $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
+ true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
+ if (RootContext.Documentation != null)
+ ((Method) $$).DocComment = Lexer.consume_doc_comment ();
}
;
type IDENTIFIER
OPEN_BRACE
{ lexer.PropertyParsing = true; }
- interface_accesors
+ interface_accessors
{ lexer.PropertyParsing = false; }
CLOSE_BRACE
{
- int gs = (int) $7;
+ InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
- $$ = new InterfaceProperty ((Expression) $3, (string) $4, (bool) $2,
- (gs & 1) == 1, (gs & 2) == 2, (Attributes) $1,
- lexer.Location);
+ $$ = new Property (current_class, (Expression) $3, (int) $2, true,
+ new MemberName ((string) $4), (Attributes) $1,
+ pinfo.Get, pinfo.Set, lexer.Location);
+ if (RootContext.Documentation != null)
+ ((Property) $$).DocComment = Lexer.consume_doc_comment ();
}
| opt_attributes
opt_new
}
;
-interface_accesors
- : opt_attributes GET SEMICOLON { $$ = 1; }
- | opt_attributes SET SEMICOLON { $$ = 2; }
- | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
- { $$ = 3; }
- | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
- { $$ = 3; }
+interface_accessors
+ : opt_attributes opt_modifiers GET SEMICOLON
+ { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
+ | opt_attributes opt_modifiers SET SEMICOLON
+ { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
+ | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON
+ { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
+ | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
+ { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
;
interface_event_declaration
: opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
{
- $$ = new InterfaceEvent ((Expression) $4, (string) $5, (bool) $2, (Attributes) $1,
- lexer.Location);
+ $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
+ new MemberName ((string) $5), null,
+ (Attributes) $1, lexer.Location);
+ if (RootContext.Documentation != null)
+ ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
}
| opt_attributes opt_new EVENT type error {
CheckIdentifierToken (yyToken);
$$ = null;
}
+ | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
+ Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
+ $$ = null;
+ }
+ | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
+ Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
+ $$ = null;
+ }
;
interface_indexer_declaration
OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
OPEN_BRACE
{ lexer.PropertyParsing = true; }
- interface_accesors
+ interface_accessors
{ lexer.PropertyParsing = false; }
CLOSE_BRACE
{
- int a_flags = (int) $10;
-
- bool do_get = (a_flags & 1) == 1;
- bool do_set = (a_flags & 2) == 2;
+ InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
- $$ = new InterfaceIndexer ((Expression) $3, (Parameters) $6, do_get, do_set,
- (bool) $2, (Attributes) $1, lexer.Location);
+ $$ = new Indexer (current_class, (Expression) $3,
+ new MemberName (TypeContainer.DefaultIndexerName),
+ (int) $2, true, (Parameters) $6, (Attributes) $1,
+ info.Get, info.Set, lexer.Location);
+ if (RootContext.Documentation != null)
+ ((Indexer) $$).DocComment = ConsumeStoredComment ();
}
;
operator_declaration
- : opt_attributes opt_modifiers operator_declarator operator_body
+ : opt_attributes opt_modifiers operator_declarator
+ {
+ iterator_container = SimpleIteratorContainer.GetSimple ();
+ }
+ operator_body
{
OperatorDeclaration decl = (OperatorDeclaration) $3;
- Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
- decl.arg2type, decl.arg2name, (Block) $4, (Attributes) $1, decl.location);
+ Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
+
+ param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
+ if (decl.arg2type != null)
+ param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
+
+ Operator op = new Operator (
+ current_class, decl.optype, decl.ret_type, (int) $2,
+ new Parameters (param_list, null, decl.location),
+ (ToplevelBlock) $5, (Attributes) $1, decl.location);
+
+ if (RootContext.Documentation != null)
+ op.DocComment = ConsumeStoredComment ();
+
+ if (SimpleIteratorContainer.Simple.Yields)
+ op.SetYields ();
// Note again, checking is done in semantic analysis
current_container.AddOperator (op);
current_local_parameters = null;
+ iterator_container = null;
}
;
op = Operator.OpType.UnaryNegation;
Parameter [] pars = new Parameter [1];
+ Expression type = (Expression) $5;
- pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+ pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
current_local_parameters = new Parameters (pars, null, lexer.Location);
- $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
null, null, lexer.Location);
}
| type OPERATOR overloadable_operator
type IDENTIFIER
CLOSE_PARENS
{
- CheckBinaryOperator ((Operator.OpType) $3);
+ CheckBinaryOperator ((Operator.OpType) $3);
+
+ Parameter [] pars = new Parameter [2];
- Parameter [] pars = new Parameter [2];
+ Expression typeL = (Expression) $5;
+ Expression typeR = (Expression) $8;
- pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
- pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
+ pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
+ pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
current_local_parameters = new Parameters (pars, null, lexer.Location);
+
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
$$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
- (Expression) $5, (string) $6,
- (Expression) $8, (string) $9, lexer.Location);
+ typeL, (string) $6,
+ typeR, (string) $9, lexer.Location);
}
| conversion_operator_declarator
;
constructor_body
{
Constructor c = (Constructor) $3;
- c.Block = (Block) $4;
+ c.Block = (ToplevelBlock) $4;
c.OptAttributes = (Attributes) $1;
c.ModFlags = (int) $2;
+ if (RootContext.Documentation != null)
+ c.DocComment = ConsumeStoredComment ();
+
if (c.Name == current_container.Basename){
if ((c.ModFlags & Modifiers.STATIC) != 0){
if ((c.ModFlags & Modifiers.Accessibility) != 0){
}
} else {
// We let another layer check the validity of the constructor.
- Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
+ //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
}
- CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
+ current_container.AddConstructor (c);
current_local_parameters = null;
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
;
constructor_declarator
- : IDENTIFIER
+ : IDENTIFIER
+ {
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ }
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
oob_stack.Push (lexer.Location);
- current_local_parameters = (Parameters) $3;
+ current_local_parameters = (Parameters) $4;
}
opt_constructor_initializer
{
Location l = (Location) oob_stack.Pop ();
- $$ = new Constructor ((string) $1, (Parameters) $3, (ConstructorInitializer) $6, l);
+ $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
+ (ConstructorInitializer) $7, l);
}
;
;
destructor_declaration
- : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+ : opt_attributes opt_finalizer TILDE
+ {
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.NotAllowed;
+ }
+ }
+ IDENTIFIER OPEN_PARENS CLOSE_PARENS block
{
- if ((string) $4 != current_container.Basename){
+ if ((string) $5 != current_container.Basename){
Report.Error (574, lexer.Location, "Name of destructor must match name of class");
- } else if (!(current_container is Class)){
+ } else if (current_container.Kind != Kind.Class){
Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
} else {
Location l = 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");
}
}
- Method d = new Method (
- TypeManager.system_void_expr, m, "Finalize",
+ Method d = new Destructor (
+ current_class, TypeManager.system_void_expr, m, "Finalize",
new Parameters (null, null, l), (Attributes) $1, l);
+ if (RootContext.Documentation != null)
+ d.DocComment = ConsumeStoredComment ();
- d.Block = (Block) $7;
- CheckDef (current_container.AddMethod (d), d.Name, d.Location);
+ d.Block = (ToplevelBlock) $8;
+ current_container.AddMethod (d);
}
}
;
{
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_class, (Expression) $4, (int) $2, false, name,
+ var.expression_or_array_initializer, (Attributes) $1,
+ lexer.Location);
+
+ current_container.AddEvent (e);
- CheckDef (current_container.AddEvent (e), e.Name, e.Location);
-
+ if (RootContext.Documentation != null) {
+ e.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
}
}
| opt_attributes
opt_modifiers
- EVENT type member_name
+ EVENT type namespace_or_type_name
OPEN_BRACE
{
implicit_value_parameter_type = (Expression) $4;
{
Location loc = (Location) oob_stack.Pop ();
- Pair pair = (Pair) $8;
- Accessor add_accessor = null;
- Accessor rem_accessor = null;
+ if ($8 == null){
+ Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
+ $$ = null;
+ } else {
+ Pair pair = (Pair) $8;
+
+ MemberName name = (MemberName) $5;
+
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "an event can't have type arguments");
+
+ Event e = new EventProperty (
+ current_class, (Expression) $4, (int) $2, false, name, null,
+ (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
+ loc);
+ if (RootContext.Documentation != null) {
+ e.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
- 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);
-
- CheckDef (current_container.AddEvent (e), e.Name, loc);
- implicit_value_parameter_type = null;
+ current_container.AddEvent (e);
+ implicit_value_parameter_type = null;
+ }
+ }
+ | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
+ MemberName mn = (MemberName) $5;
+
+ if (mn.Left != null)
+ Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
+ else
+ Report.Error (71, lexer.Location, "Event declaration should use property syntax");
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
;
{
$$ = new Pair ($2, $1);
}
+ | add_accessor_declaration { $$ = null; }
+ | remove_accessor_declaration { $$ = null; }
+ | error
+ {
+ Report.Error (1055, lexer.Location, "An add or remove accessor expected");
+ $$ = null;
+ }
+ | { $$ = null; }
;
add_accessor_declaration
}
block
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
lexer.EventParsing = true;
}
| opt_attributes ADD error {
}
block
{
- $$ = new Accessor ((Block) $4, (Attributes) $1);
+ $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
lexer.EventParsing = true;
}
| opt_attributes REMOVE error {
Accessor get_block = (Accessor) pair.First;
Accessor set_block = (Accessor) pair.Second;
- indexer = new Indexer (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,
+ TypeContainer.DefaultIndexerName, null);
+ else
+ name = new MemberName (TypeContainer.DefaultIndexerName);
+
+ indexer = new Indexer (current_class, decl.type, name,
+ (int) $2, false, decl.param_list, (Attributes) $1,
+ get_block, set_block, loc);
+ if (RootContext.Documentation != null)
+ indexer.DocComment = ConsumeStoredComment ();
- // Note that there is no equivalent of CheckDef for this case
- // We shall handle this in semantic analysis
-
current_container.AddIndexer (indexer);
current_local_parameters = null;
: type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
{
Parameters pars = (Parameters) $4;
-
- if (pars.FixedParameters == null && pars.ArrayParameter == null){
+ if (pars.HasArglist) {
+ // "__arglist is not valid in this context"
+ Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
+ } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
}
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
$$ = new IndexerDeclaration ((Expression) $1, null, pars);
}
- | type qualified_identifier 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){
+ if (pars.HasArglist) {
+ // "__arglist is not valid in this context"
+ Report.Error (1669, lexer.Location, "__arglist is not valid in this context");
+ } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
}
- $$ = new IndexerDeclaration ((Expression) $1, (string) $2, 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);
+
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
}
;
: opt_attributes
opt_modifiers
ENUM IDENTIFIER
- opt_enum_base
+ opt_enum_base {
+ if (RootContext.Documentation != null)
+ enumTypeComment = Lexer.consume_doc_comment ();
+ }
enum_body
opt_semicolon
{
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);
- foreach (VariableDeclaration ev in (ArrayList) $6) {
- Location loc = (Location) ev.Location;
-
- CheckDef (e.AddEnumMember (ev.identifier,
- (Expression) ev.expression_or_array_initializer,
- loc, ev.OptAttributes),
- ev.identifier, loc);
+ if (RootContext.Documentation != null)
+ e.DocComment = enumTypeComment;
+
+ foreach (VariableDeclaration ev in (ArrayList) $7) {
+ e.AddEnumMember (ev.identifier,
+ (Expression) ev.expression_or_array_initializer,
+ ev.Location, ev.OptAttributes,
+ ev.DocComment);
}
- CheckDef (current_container.AddEnum (e), full_name, enum_location);
- RootContext.Tree.RecordDecl (full_name, e);
+ string name = full_name.GetName ();
+ current_container.AddEnum (e);
+ RootContext.Tree.RecordDecl (name, e);
}
;
;
enum_body
- : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
+ : OPEN_BRACE
{
- $$ = $2;
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ opt_enum_member_declarations
+ {
+ // here will be evaluated after CLOSE_BLACE is consumed.
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ CLOSE_BRACE
+ {
+ $$ = $3;
}
;
enum_member_declaration
: opt_attributes IDENTIFIER
{
- $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
+ VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
+
+ if (RootContext.Documentation != null) {
+ vd.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ $$ = vd;
}
| opt_attributes IDENTIFIER
{
- $$ = lexer.Location;
+ $$ = lexer.Location;
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.NotAllowed;
+ }
}
ASSIGN expression
{
- $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
+ VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
+
+ if (RootContext.Documentation != null)
+ vd.DocComment = ConsumeStoredComment ();
+
+ $$ = vd;
}
;
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;
+ MemberName name = MakeName ((MemberName) $5);
Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
- (int) $2, MakeName ((string) $5), (Parameters) $7,
- (Attributes) $1, l);
-
- CheckDef (current_container.AddDelegate (del), del.Name, l);
- }
+ (int) $2, name, (Parameters) $7, (Attributes) $1, l);
+
+ if (RootContext.Documentation != null) {
+ del.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ current_container.AddDelegate (del);
+ RootContext.Tree.RecordDecl (name.GetName (true), del);
+
+ current_delegate = del;
+
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
+ }
+ SEMICOLON
+ {
+ current_delegate.SetParameterInfo ((ArrayList) $9);
+
+ 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;
+ MemberName name = MakeName ((MemberName) $5);
Delegate del = new Delegate (
current_namespace, current_container,
- TypeManager.system_void_expr, (int) $2, MakeName ((string) $5),
+ TypeManager.system_void_expr, (int) $2, name,
(Parameters) $7, (Attributes) $1, l);
- CheckDef (current_container.AddDelegate (del), del.Name, l);
+ if (RootContext.Documentation != null) {
+ del.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ current_container.AddDelegate (del);
+ RootContext.Tree.RecordDecl (name.GetName (true), del);
+
+ current_delegate = del;
+
+ lexer.ConstraintsParsing = true;
}
- ;
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
+ }
+ SEMICOLON
+ {
+ current_delegate.SetParameterInfo ((ArrayList) $9);
-type_name
- : namespace_or_type_name
+ current_delegate = null;
+ }
;
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);
+ : 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 IDENTIFIER opt_type_argument_list
- {
- Expression right;
+ ;
- //
- // Third argument will become an Expression, when we have sorted out
- // the issues with SimpleName first
- //
- $$ = new MemberAccess ((Expression) $1, (string) $3, 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
{
$$ = $2;
}
+ | GENERIC_DIMENSION
+ {
+ $$ = new TypeArguments ((int) $1, lexer.Location);
+ }
;
type_arguments
: type {
- TypeArguments type_args = new TypeArguments ();
+ TypeArguments type_args = new TypeArguments (lexer.Location);
type_args.Add ((Expression) $1);
$$ = type_args;
}
* 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
| invocation_expression
| element_access
;;
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
$$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
}
| BASE error {
- Report.Error (175, "Use of keyword `base' is not valid in this context");
+ Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
$$ = null;
}
;
{
$$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
}
+ | NEW error
+ {
+ Report.Error (1031, lexer.Location, "Type expected");
+ $$ = null;
+ }
| NEW type error
{
Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
}
;
+void_pointer_expression
+ : void_pointer_expression STAR
+ {
+ $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+ }
+ | VOID STAR
+ {
+ $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
+ }
+ ;
+
typeof_expression
: TYPEOF OPEN_PARENS VOID CLOSE_PARENS
{
$$ = new TypeOfVoid (lexer.Location);
}
- | TYPEOF OPEN_PARENS type CLOSE_PARENS
+ | TYPEOF OPEN_PARENS void_pointer_expression CLOSE_PARENS
{
$$ = new TypeOf ((Expression) $3, lexer.Location);
}
+ | TYPEOF OPEN_PARENS
+ {
+ lexer.TypeOfParsing = true;
+ }
+ type CLOSE_PARENS
+ {
+ lexer.TypeOfParsing = false;
+ $$ = new TypeOf ((Expression) $4, lexer.Location);
+ }
;
sizeof_expression
: DELEGATE opt_anonymous_method_signature {
oob_stack.Push (current_local_parameters);
current_local_parameters = (Parameters)$2;
+
+ // Force the next block to be created as a ToplevelBlock
+ oob_stack.Push (current_block);
+ oob_stack.Push (top_current_block);
+ oob_stack.Push (lexer.Location);
+ current_block = null;
} block {
- 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 ();
- }
+ Location loc = (Location) oob_stack.Pop ();
+ top_current_block = (Block) oob_stack.Pop ();
+ current_block = (Block) oob_stack.Pop ();
+ if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
+ $$ = null;
+ } else {
+ ToplevelBlock anon_block = (ToplevelBlock) $4;
+
+ anon_block.Parent = current_block;
+ $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block,
+ anon_block, loc);
+ }
+ current_local_parameters = (Parameters) oob_stack.Pop ();
+ }
;
opt_anonymous_method_signature
- : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
+ : /* empty */ { $$ = null; }
| anonymous_method_signature
;
anonymous_method_parameter
: opt_parameter_modifier type IDENTIFIER {
- $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
+ $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
+ }
+ | PARAMS type IDENTIFIER {
+ Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
+ $$ = null;
+ }
+ ;
+
+default_value_expression
+ : DEFAULT_OPEN_PARENS type CLOSE_PARENS
+ {
+ $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
}
;
class_declaration
: opt_attributes
opt_modifiers
- CLASS IDENTIFIER
+ opt_partial
+ CLASS member_name
{
- Class new_class;
- string name;
+ MemberName name = MakeName ((MemberName) $5);
+ bool partial = (bool) $3;
+ int mod_flags = (int) $2;
+
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, mod_flags,
+ (Attributes) $1, Kind.Class, lexer.Location);
+
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ if ((mod_flags & Modifiers.STATIC) != 0) {
+ current_class = new StaticClass (
+ current_namespace, current_container, name,
+ mod_flags, (Attributes) $1, lexer.Location);
+ } else {
+ current_class = new Class (
+ current_namespace, current_container, name,
+ mod_flags, (Attributes) $1, lexer.Location);
+ }
- name = MakeName ((string) $4);
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
- 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);
+ lexer.ConstraintsParsing = true;
}
- opt_type_parameter_list
opt_class_base
opt_type_parameter_constraints_clauses
- class_body
- opt_semicolon
{
- Class new_class = (Class) current_container;
+ lexer.ConstraintsParsing = false;
+
+ if ($7 != null) {
+ if (current_class.Name == "System.Object") {
+ Report.Error (537, current_class.Location,
+ "The class System.Object cannot have a base " +
+ "class or implement an interface.");
+ }
+ current_class.Bases = (ArrayList) $7;
+ }
- if ($8 != null && $6 == null)
- Report.Error (-200, new_class.Location,
- "Type parameter constraints only valid if there is a type parameter list");
+ current_class.SetParameterInfo ((ArrayList) $8);
- if ($6 != null)
- CheckDef (new_class.SetParameterInfo ((ArrayList) $6, (ArrayList) $8, new_class.Location), new_class.Name, new_class.Location);
- if ($7 != null)
- new_class.Bases = (ArrayList) $7;
- current_container = current_container.Parent;
- CheckDef (current_container.AddClass (new_class), new_class.Name, new_class.Location);
+ if (RootContext.Documentation != null) {
+ current_class.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
- $$ = new_class;
+ current_class.Register ();
}
- | opt_attributes
- opt_modifiers
- CLASS IDENTIFIER
- WHERE {
- Report.Error (-200, lexer.Location,
- "Type parameter constraints only valid if there is a type parameter list");
- yyErrorFlag = 0;
- $$ = null;
+ class_body
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ opt_semicolon
+ {
+ $$ = current_class;
+
+ current_container = current_container.Parent;
+ current_class = current_container;
}
;
+opt_partial
+ : /* empty */
+ { $$ = (bool) false; }
+ | PARTIAL
+ { $$ = (bool) true; }
+ ;
+
opt_modifiers
: /* empty */ { $$ = (int) 0; }
| 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;
}
;
block
: OPEN_BRACE
{
+ if (current_block == null){
+ current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
+ top_current_block = current_block;
+ } else {
current_block = new Block (current_block, current_local_parameters,
lexer.Location, Location.Null);
+ }
}
opt_statement_list CLOSE_BRACE
{
$$ = current_block;
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
+ if (current_block == null)
+ top_current_block = null;
}
;
current_block = (Block) $1;
}
}
- | embedded_statement
+ | valid_declaration_statement
{
- Statement s = (Statement) $1;
-
-
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
{
- $$ = new EmptyStatement ();
+ $$ = EmptyStatement.Value;
}
;
{
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
;
if ($1 != null){
DictionaryEntry de = (DictionaryEntry) $1;
- $$ = declare_local_constant ((Expression) de.Key, (VariableDeclaration) de.Value);
+ $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
}
}
;
// Ok, the above "primary_expression" is there to get rid of
// both reduce/reduce and shift/reduces in the grammar, it should
// really just be "type_name". If you use type_name, a reduce/reduce
- // creeps up. If you use qualified_identifier (which is all we need
+ // creeps up. If you use namespace_or_type_name (which is all we need
// really) two shift/reduces appear.
//
;
local_constant_declaration
- : CONST local_variable_type constant_declarator
+ : CONST local_variable_type constant_declarators
{
if ($2 != null)
$$ = new DictionaryEntry ($2, $3);
$$ = new If ((Expression) $1, (Statement) $3, l);
if (RootContext.WarningLevel >= 3){
- if ($3 is EmptyStatement)
- Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+ if ($3 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
}
}
$$ = new While ((Expression) $4, (Statement) $6, l);
if (RootContext.WarningLevel >= 3){
- if ($6 is EmptyStatement)
- Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+ if ($6 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
}
}
;
For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
if (RootContext.WarningLevel >= 3){
- if ($10 is EmptyStatement)
- Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+ if ($10 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
}
current_block.AddStatement (f);
;
opt_for_initializer
- : /* empty */ { $$ = new EmptyStatement (); }
+ : /* empty */ { $$ = EmptyStatement.Value; }
| for_initializer
;
;
opt_for_iterator
- : /* empty */ { $$ = new EmptyStatement (); }
+ : /* empty */ { $$ = EmptyStatement.Value; }
| for_iterator
;
{
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;
;
yield_statement
- : YIELD expression SEMICOLON
+ : IDENTIFIER RETURN expression SEMICOLON
{
+ string s = (string) $1;
+ if (s != "yield"){
+ Report.Error (1003, lexer.Location, "; expected");
+ $$ = null;
+ }
+ if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
+ $$ = null;
+ }
if (iterator_container == null){
Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
$$ = null;
} else {
iterator_container.SetYields ();
- $$ = new Yield ((Expression) $2, lexer.Location);
+ $$ = new Yield ((Expression) $3, lexer.Location);
}
}
- | YIELD BREAK SEMICOLON
+ | IDENTIFIER BREAK SEMICOLON
{
+ string s = (string) $1;
+ if (s != "yield"){
+ Report.Error (1003, lexer.Location, "; expected");
+ $$ = null;
+ }
+ if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
+ $$ = null;
+ }
if (iterator_container == null){
Report.Error (204, lexer.Location, "yield statement can only be used within a method, operator or property");
$$ = null;
: TRY block catch_clauses
{
Catch g = null;
- ArrayList s = new ArrayList (4);
- foreach (Catch cc in (ArrayList) $3) {
- if (cc.IsGeneral)
+ ArrayList c = (ArrayList)$3;
+ for (int i = 0; i < c.Count; ++i) {
+ Catch cc = (Catch) c [i];
+ if (cc.IsGeneral) {
+ if (i != c.Count - 1)
+ Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
g = cc;
- else
- s.Add (cc);
+ c.RemoveAt (i);
+ i--;
+ }
}
// Now s contains the list of specific catch clauses
// and g contains the general one.
- $$ = new Try ((Block) $2, s, g, null, lexer.Location);
+ $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
}
| TRY block opt_catch_clauses FINALLY block
{
}
}
- $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
+ $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
}
| TRY block error
{
}
- $$ = new Catch (type, id , (Block) $4, lexer.Location);
+ $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
}
;
type fixed_pointer_declarators
CLOSE_PARENS
{
- Block assign_block = new Block (current_block, Block.Flags.Implicit);
ArrayList list = (ArrayList) $4;
Expression type = (Expression) $3;
Location l = lexer.Location;
int top = list.Count;
+ Block assign_block = new Block (current_block);
+ current_block = assign_block;
+
for (int i = 0; i < top; i++){
Pair p = (Pair) list [i];
LocalInfo v;
v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
if (v == null)
continue;
+
v.ReadOnly = true;
+ v.Pinned = true;
p.First = v;
list [i] = p;
}
- current_block.AddStatement (assign_block);
- current_block = assign_block;
- oob_stack.Push (assign_block);
+
oob_stack.Push (l);
}
embedded_statement
{
Location l = (Location) oob_stack.Pop ();
- Block assign_block = (Block) oob_stack.Pop ();
- ArrayList list = (ArrayList) $4;
- int top = list.Count;
+ Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+
+ if (RootContext.WarningLevel >= 3){
+ if ($7 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
+ }
- $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+ current_block.AddStatement (f);
+ while (current_block.Implicit)
+ current_block = current_block.Parent;
+ $$ = current_block;
+ current_block = current_block.Parent;
}
;
fixed_pointer_declarators
: fixed_pointer_declarator {
- ArrayList declarators = new ArrayList (4);
- declarators.Add ($1);
+ ArrayList declarators = new ArrayList (4);
+ if ($1 != null)
+ declarators.Add ($1);
$$ = declarators;
}
| fixed_pointer_declarators COMMA fixed_pointer_declarator
{
ArrayList declarators = (ArrayList) $1;
- declarators.Add ($3);
+ if ($3 != null)
+ declarators.Add ($3);
$$ = declarators;
}
;
{
$$ = new Pair ($1, $3);
}
+ | IDENTIFIER
+ {
+ Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
+ $$ = null;
+ }
;
lock_statement
expr = (Expression) decl.expression_or_array_initializer;
} else {
ArrayList init = (ArrayList) decl.expression_or_array_initializer;
+ if (init == null) {
+ Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
+ }
expr = new ArrayCreation (type, "", init, decl.Location);
}
public object expression_or_array_initializer;
public Location Location;
public Attributes OptAttributes;
+ public string DocComment;
public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
{
}
}
+/// <summary>
+/// Used to pass around interface property information
+/// </summary>
+public class InterfaceAccessorInfo {
+
+ public readonly Accessor Get, Set;
+
+ public InterfaceAccessorInfo (bool has_get, bool has_set,
+ Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
+ {
+ if (get_mod != 0)
+ Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
+ if (set_mod != 0)
+ Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
+
+ if (has_get)
+ Get = new Accessor (null, 0, get_attrs, get_loc);
+ if (has_set)
+ Set = new Accessor (null, 0, set_attrs, set_loc);
+ }
+
+}
+
+
// <summary>
// A class used to hold info about an indexer declarator
// </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;
}
}
+//
+// We use this when we do not have an object in advance that is an IIteratorContainer
+//
+public class SimpleIteratorContainer : IIteratorContainer {
+ public bool Yields;
+
+ public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();
+
+ //
+ // Reset and return
+ //
+ public static SimpleIteratorContainer GetSimple () {
+ Simple.Yields = false;
+ return Simple;
+ }
+
+ public void SetYields () { Yields = true; }
+}
+
// <summary>
// A class used to hold info about an operator declarator
// </summary>
-
public class OperatorDeclaration {
public Operator.OpType optype;
public Expression ret_type, arg1type, arg2type;
// 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;
-}
-
-// <summary>
-// Used to report back to the user the result of a declaration
-// in the current declaration space
-// </summary>
-void
-CheckDef (DeclSpace.AdditionResult result, string name, Location l)
-{
- if (result == DeclSpace.AdditionResult.Success)
- return;
-
- switch (result){
- case DeclSpace.AdditionResult.NameExists:
- Report.Error (102, l, "The container `" + current_container.Name +
- "' already contains a definition for `"+
- name + "'");
- break;
-
-
- //
- // This is handled only for static Constructors, because
- // in reality we handle these by the semantic analysis later
- //
- case DeclSpace.AdditionResult.MethodExists:
- Report.Error (
- 111, l, "Class `"+current_container.Name+
- "' already defines a member called '" +
- name + "' with the same parameter types (more than one default constructor)");
- break;
-
- case DeclSpace.AdditionResult.EnclosingClash:
- Report.Error (542, l, "Member names cannot be the same as their enclosing type");
- break;
-
- case DeclSpace.AdditionResult.NotAConstructor:
- Report.Error (1520, l, "Class, struct, or interface method must have a return type");
- break;
-
- case DeclSpace.AdditionResult.Error:
- // Error has already been reported.
- break;
- }
-}
-
-void
-CheckDef (bool result, string name, Location l)
-{
- if (result)
- return;
- CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
-}
-
-Expression DecomposeQI (string name, Location loc)
-{
- Expression o;
-
- if (name.IndexOf ('.') == -1){
- return new SimpleName (name, loc);
} else {
- int pos = name.LastIndexOf (".");
- string left = name.Substring (0, pos);
- string right = name.Substring (pos + 1);
-
- o = DecomposeQI (left, loc);
-
- return new MemberAccess (o, right, loc);
+ return new MemberName (current_container.MemberName, class_name);
}
}
//
// 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){
return implicit_block;
}
-Block declare_local_constant (Expression type, VariableDeclaration decl)
+Block declare_local_constants (Expression type, ArrayList declarators)
{
Block implicit_block;
else
implicit_block = current_block;
- if (!(implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
- current_local_parameters, decl.Location))){
+ foreach (VariableDeclaration decl in declarators){
+ implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer,
+ current_local_parameters, decl.Location);
}
return implicit_block;
{
switch (a) {
- case "assembly" : case "field" : case "method" : case "param" : case "property" : case "type" :
+ case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
return;
default :
public void parse ()
{
try {
- if (yacc_verbose_flag)
+ if (yacc_verbose_flag > 1)
yyparse (lexer, new yydebug.yyDebugSimple ());
else
yyparse (lexer);
Tokenizer tokenizer = lexer as Tokenizer;
tokenizer.cleanup ();
} catch (Exception e){
- // Please do not remove this, it is used during debugging
- // of the grammar
//
- Console.WriteLine (e);
+ // Removed for production use, use parser verbose to get the output.
+ //
+ // Console.WriteLine (e);
Report.Error (-25, lexer.Location, "Parsing error");
- if (Driver.parser_verbose)
+ if (yacc_verbose_flag > 0)
Console.WriteLine (e);
}
}
void CheckToken (int error, int yyToken, string msg)
{
if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD){
- Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyName [yyToken].ToLower ()));
+ Report.Error (error, lexer.Location, String.Format ("{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ()));
return;
}
Report.Error (error, lexer.Location, msg);
CheckToken (1041, yyToken, "Identifier expected");
}
+string ConsumeStoredComment ()
+{
+ string s = tmpComment;
+ tmpComment = null;
+ Lexer.doc_state = XmlCommentState.Allowed;
+ return s;
+}
+
/* end end end */
}