// 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
namespace Mono.CSharp
{
using System.Collections;
- using Mono.Languages;
/// <summary>
/// The C# Parser
/// </summary>
- public class CSharpParser : GenericParser {
+ public class CSharpParser {
NamespaceEntry current_namespace;
TypeContainer current_container;
+ TypeContainer current_class;
IIteratorContainer iterator_container;
/// Current block is used to add statements as we find
/// them.
/// </summary>
- Block current_block;
-
- /// <summary>
- /// If true, creates a toplevel block in the block production
- /// This is flagged by the delegate creation
- /// </summary>
- bool create_toplevel_block;
-
- /// <summary>
- /// <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;
+ Block current_block, top_current_block;
/// <summary>
/// This is used by the unary_expression code to resolve
///
Stack switch_stack;
+ static public int yacc_verbose_flag;
+
+ // Name of the file we are parsing
+ public string name;
+
///
/// 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 WHILE
%token ARGLIST
+%token PARTIAL
/* C# keywords which are not really keywords */
%token GET "get"
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);
+ MemberName name = (MemberName) $4;
+ current_namespace.UsingAlias ((string) $2, name.GetTypeExpression (lexer.Location), lexer.Location);
}
| USING error {
CheckIdentifierToken (yyToken);
using_namespace_directive
: USING namespace_name SEMICOLON
{
- current_namespace.Using ((string) $2, lexer.Location);
+ MemberName ns_name = (MemberName) $2;
+ current_namespace.Using (ns_name.GetTypeExpression (lexer.Location), lexer.Location);
}
;
+ " Expected class, delegate, enum, interface, or struct");
}
- current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, $3.ToString (), lexer.Location);
- }
+ MemberName name = (MemberName) $3;
+
+ 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;
;
namespace_name
- : namespace_or_type_name { $$ = ($1).ToString (); }
+ : namespace_or_type_name
;
namespace_body
: OPEN_BRACE
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
opt_using_directives
opt_namespace_member_declarations
CLOSE_BRACE
attribute_sections
: attribute_section
- {
+ {
ArrayList sect = (ArrayList) $1;
if (global_attrs_enabled) {
} 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 = $1 as Attributes;
}
opt_attribute_arguments
{
+ Location loc = (Location) $2;
+ MemberName mname = (MemberName) $1;
+ MemberName left = mname.Left;
+ string identifier = mname.Name;
+
+ Expression left_expr = left == null ? null : left.GetTypeExpression (loc);
+
if (current_attr_target == "assembly" || current_attr_target == "module")
- $$ = new GlobalAttribute (current_container, current_attr_target, (string) ($1).ToString (), (ArrayList) $3, (Location) $2);
+ $$ = new GlobalAttribute (current_container, current_attr_target,
+ left_expr, identifier, (ArrayList) $3, loc);
else
- $$ = new Attribute (current_attr_target, (string) ($1).ToString (), (ArrayList) $3, (Location) $2);
+ $$ = new Attribute (current_attr_target, left_expr, identifier, (ArrayList) $3, loc);
}
;
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);
- 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);
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
}
opt_class_base
+ {
+ if ($7 != null)
+ current_class.Bases = (ArrayList) $7;
+
+ 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
int mod = (int) $2;
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);
+ (Attributes) $1, var.Location);
- 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
+ opt_modifiers
+ FIXED
+ type
+ fixed_variable_declarators
+ SEMICOLON
+ {
+ Expression type = (Expression) $4;
+ int mod = (int) $2;
+
+ foreach (VariableDeclaration var in (ArrayList) $5) {
+ FixedField field = new FixedField (current_class, type, mod, var.identifier,
+ (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
+
+ if (RootContext.Documentation != null) {
+ field.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ current_container.AddField (field);
+ }
+ }
| opt_attributes
opt_modifiers
VOID
}
;
+fixed_variable_declarators
+ : fixed_variable_declarator
+ {
+ ArrayList decl = new ArrayList (2);
+ decl.Add ($1);
+ $$ = decl;
+ }
+ | fixed_variable_declarators COMMA fixed_variable_declarator
+ {
+ ArrayList decls = (ArrayList) $1;
+ decls.Add ($3);
+ $$ = $1;
+ }
+ ;
+
+fixed_variable_declarator
+ : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
+ {
+ $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
+ }
+ ;
+
variable_declarators
: variable_declarator
{
{
$$ = 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 (current_container, (Expression) $3, (int) $2,
- false, (string) $4, (Parameters) $6,
- (Attributes) $1, lexer.Location);
+ MemberName name = (MemberName) $4;
+
+ Method method = new Method (current_class, (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 (current_container, TypeManager.system_void_expr,
- (int) $2, false, (string) $4, (Parameters) $6,
+ MemberName name = (MemberName) $4;
+
+ Method method = new Method (current_class, 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 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, false, (string) $5, (Parameters) $7,
- (Attributes) $1, lexer.Location);
+ MemberName name = (MemberName) $4;
+
+ Method method = new Method (current_class, TypeManager.system_void_expr,
+ 0, false, name, (Parameters) $7, (Attributes) $1,
+ lexer.Location);
current_local_parameters = (Parameters) $7;
+
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
$$ = method;
}
;
$$ = new Parameters (pars, true, lexer.Location);
}
+ | parameter_array COMMA fixed_parameters
+ {
+ Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
+ $$ = null;
+ }
+ | ARGLIST COMMA fixed_parameters
+ {
+ Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
+ $$ = null;
+ }
| parameter_array
{
$$ = new Parameters (null, (Parameter) $1, lexer.Location);
{
$$ = 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
- : namespace_or_type_name { $$ = ($1).ToString (); }
- ;
-
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;
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 (current_container, (Expression) $3, (int) $2, false,
- (string) $4, (Attributes) $1, get_block, set_block, loc);
+ Location loc = (Location) $7;
+ MemberName name = (MemberName) $4;
+
+ prop = new Property (current_class, (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");
+ if (partial) {
+ ClassPart part = PartialContainer.CreatePart (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, Kind.Interface, lexer.Location);
+
+ current_container = part.PartialContainer;
+ current_class = part;
+ } else {
+ current_class = new Interface (
+ current_namespace, current_container, name, (int) $2,
+ (Attributes) $1, lexer.Location);
+
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
}
- current_interface = new_interface;
- current_container = new_interface;
- RootContext.Tree.RecordDecl (full_interface_name, new_interface);
}
opt_class_base
- interface_body opt_semicolon
- {
- Interface new_interface = (Interface) current_interface;
+ {
+ current_class.Bases = (ArrayList) $7;
- if ($6 != null)
- new_interface.Bases = (ArrayList) $6;
+ if (RootContext.Documentation != null) {
+ current_class.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
+ current_class.Register ();
+ }
+ interface_body
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ opt_semicolon
+ {
+ $$ = current_class;
- current_interface = null;
current_container = current_container.Parent;
- CheckDef (current_container.AddInterface (new_interface),
- new_interface.Name, new_interface.Location);
+ current_class = current_container;
}
- | opt_attributes opt_modifiers INTERFACE error {
+ | opt_attributes opt_modifiers opt_partial INTERFACE error {
CheckIdentifierToken (yyToken);
}
;
{
Method m = (Method) $1;
- CheckDef (current_interface.AddMethod (m), m.Name, m.Location);
+ if (m.IsExplicitImpl)
+ Report.Error (541, lexer.Location,
+ "Explicit interface declaration can only be declared in a class or struct");
+
+ current_container.AddMethod (m);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
| interface_property_declaration
{
Property p = (Property) $1;
- CheckDef (current_interface.AddProperty (p), p.Name, p.Location);
- }
+ if (p.IsExplicitImpl)
+ Report.Error (541, lexer.Location,
+ "Explicit interface declaration can only be declared in a class or struct");
+
+ current_container.AddProperty (p);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
| interface_event_declaration
{
if ($1 != null){
Event e = (Event) $1;
- CheckDef (current_interface.AddEvent (e), e.Name, lexer.Location);
+
+ if (e.IsExplicitImpl)
+ Report.Error (541, lexer.Location,
+ "Explicit interface declaration can only be declared in a class or struct");
+
+ current_container.AddEvent (e);
}
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
| interface_indexer_declaration
{
Indexer i = (Indexer) $1;
- current_interface.AddIndexer (i);
+ if (i.IsExplicitImpl)
+ Report.Error (541, lexer.Location,
+ "Explicit interface declaration can only be declared in a class or struct");
+
+ current_container.AddIndexer (i);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ | delegate_declaration
+ {
+ Report.Error (524, lexer.Location, "Interfaces can not declare delegates");
}
+ | class_declaration
+ {
+ Report.Error (524, lexer.Location, "Interfaces can not declare classes");
+ }
+ | struct_declaration
+ {
+ Report.Error (524, lexer.Location, "Interfaces can not declare structures");
+ }
+ | enum_declaration
+ {
+ Report.Error (524, lexer.Location, "Interfaces can not declare enumerations");
+ }
+ | interface_declaration
+ {
+ Report.Error (524, lexer.Location, "Interfaces can not declare interfaces");
+ }
;
opt_new
;
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
SEMICOLON
{
- $$ = new Method (current_container, (Expression) $3, (int) $2, true,
- (string) $4, (Parameters) $6, (Attributes) $1,
- lexer.Location);
+ MemberName name = (MemberName) $4;
+
+ $$ = new Method (current_class, (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
SEMICOLON
{
- $$ = new Method (current_container, TypeManager.system_void_expr, (int) $2,
- true, (string) $4, (Parameters) $6, (Attributes) $1,
- lexer.Location);
+ MemberName name = (MemberName) $4;
+
+ $$ = new Method (current_class, TypeManager.system_void_expr, (int) $2,
+ true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
+ if (RootContext.Documentation != null)
+ ((Method) $$).DocComment = Lexer.consume_doc_comment ();
}
;
{
InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
- $$ = new Property (current_container, (Expression) $3, (int) $2, true,
- (string) $4, (Attributes) $1, pinfo.Get, pinfo.Set,
- 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_accessors
- : opt_attributes GET SEMICOLON { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
- | opt_attributes SET SEMICOLON { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
- | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
- { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
- | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
- { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
+ : 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 EventField (current_container, (Expression) $4, (int) $2, true, (string) $5, null,
- (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);
{
InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
- $$ = new Indexer (current_container, (Expression) $3, null, (int) $2, true,
- (Parameters) $6, (Attributes) $1, info.Get, info.Set,
- 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 ();
}
;
{
OperatorDeclaration decl = (OperatorDeclaration) $3;
- Operator op = new Operator (decl.optype, decl.ret_type, (int) $2, decl.arg1type, decl.arg1name,
- decl.arg2type, decl.arg2name, (Block) $5, (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 = tmpComment;
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
if (SimpleIteratorContainer.Simple.Yields)
op.SetYields ();
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.NotAllowed;
+ }
+
+ $$ = 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.NotAllowed;
+ }
$$ = 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
;
current_local_parameters = new Parameters (pars, null, lexer.Location);
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.NotAllowed;
+ }
+
$$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, (string) $6,
null, null, lexer.Location);
}
current_local_parameters = new Parameters (pars, null, lexer.Location);
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.NotAllowed;
+ }
+
$$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, (string) $6,
null, null, lexer.Location);
}
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
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ : IDENTIFIER
{
- oob_stack.Push (lexer.Location);
-
- current_local_parameters = (Parameters) $3;
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ }
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS _mark_
+ {
+ current_local_parameters = (Parameters) $4;
}
opt_constructor_initializer
{
- Location l = (Location) oob_stack.Pop ();
- $$ = new Constructor (current_container, (string) $1, 0, (Parameters) $3,
- (ConstructorInitializer) $6, l);
+ $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
+ (ConstructorInitializer) $8, (Location) $6);
}
;
;
destructor_declaration
- : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+ : opt_attributes opt_finalizer TILDE
{
- if ((string) $4 != current_container.Basename){
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.NotAllowed;
+ }
+ }
+ IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+ {
+ 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;
}
Method d = new Destructor (
- current_container, TypeManager.system_void_expr, m, "Finalize",
+ 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 EventField (current_container, (Expression) $4, (int) $2, false, var.identifier,
- var.expression_or_array_initializer,
- (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
- OPEN_BRACE
+ EVENT type namespace_or_type_name
+ OPEN_BRACE _mark_
{
implicit_value_parameter_type = (Expression) $4;
lexer.EventParsing = true;
- oob_stack.Push (lexer.Location);
}
event_accessor_declarations
{
}
CLOSE_BRACE
{
- Location loc = (Location) oob_stack.Pop ();
+ Location loc = (Location) $7;
- if ($8 == null){
+ if ($9 == null){
Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
$$ = null;
} else {
- Pair pair = (Pair) $8;
-
- Event e = new EventProperty (current_container, (Expression) $4, (int) $2, false, (string) $5,
- null, (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
- loc);
+ Pair pair = (Pair) $9;
- CheckDef (current_container.AddEvent (e), e.Name, loc);
+ MemberName name = (MemberName) $5;
+
+ 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;
+ }
+
+ current_container.AddEvent (e);
implicit_value_parameter_type = null;
}
}
- | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
- string mn = (string) $5;
+ | 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.IndexOf ('.') != -1)
+ 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;
}
;
}
| 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 {
indexer_declaration
: opt_attributes opt_modifiers indexer_declarator
- OPEN_BRACE
+ OPEN_BRACE _mark_
{
IndexerDeclaration decl = (IndexerDeclaration) $3;
parsing_indexer = true;
indexer_parameters = decl.param_list;
- oob_stack.Push (lexer.Location);
}
accessor_declarations
{
{
// The signature is computed from the signature of the indexer. Look
// at section 3.6 on the spec
- Location loc = (Location) oob_stack.Pop ();
+ Location loc = (Location) $5;
Indexer indexer;
IndexerDeclaration decl = (IndexerDeclaration) $3;
- Pair pair = (Pair) $6;
+ Pair pair = (Pair) $7;
Accessor get_block = (Accessor) pair.First;
Accessor set_block = (Accessor) pair.Second;
- indexer = new Indexer (current_container, decl.type, decl.interface_type,
+ MemberName name;
+ if (decl.interface_type != null)
+ name = new MemberName (decl.interface_type,
+ TypeContainer.DefaultIndexerName);
+ 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;
Parameters pars = (Parameters) $4;
if (pars.HasArglist) {
// "__arglist is not valid in this context"
- Report.Error_T (1669, lexer.Location);
+ 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);
}
if (pars.HasArglist) {
// "__arglist is not valid in this context"
- Report.Error_T (1669, lexer.Location);
+ 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, $2.ToString (), pars);
+
+ MemberName name = (MemberName) $2;
+ $$ = 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
+ DELEGATE type member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
SEMICOLON
{
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);
}
| opt_attributes
opt_modifiers
- DELEGATE VOID
- IDENTIFIER OPEN_PARENS
- opt_formal_parameter_list
- CLOSE_PARENS
+ DELEGATE VOID member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
SEMICOLON
{
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);
}
;
-type_name
- : namespace_or_type_name
+namespace_or_type_name
+ : member_name
+ | namespace_or_type_name DOT IDENTIFIER {
+ $$ = new MemberName ((MemberName) $1, (string) $3);
+ }
;
-namespace_or_type_name
- : IDENTIFIER { $$ = new SimpleName ((string) $1, lexer.Location);}
- | namespace_or_type_name DOT IDENTIFIER {
- $$ = new MemberAccess ((Expression) $1, (string) $3, lexer.Location);
+member_name
+ : IDENTIFIER {
+ $$ = new MemberName ((string) $1);
}
;
* gets rid of a shift/reduce couple
*/
type
- : type_name { /* class_type */
- /*
- This does interfaces, delegates, struct_types, class_types,
- parent classes, and more! 4.2
- */
+ : 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
}
- | IDENTIFIER { $$ = new SimpleName ((string) $1, lexer.Location); }
+ | member_name
+ {
+ $$ = ((MemberName) $1).GetTypeExpression (lexer.Location);
+ }
| parenthesized_expression
| member_access
| invocation_expression
{
$$ = new InvocationOrCast ((Expression) $1, (Expression) $3, lexer.Location);
}
+ | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
+ {
+ ArrayList args = new ArrayList (1);
+ args.Add ($4);
+ $$ = new Invocation ((Expression) $1, args, lexer.Location);
+ }
+ | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
+ {
+ ArrayList args = ((ArrayList) $4);
+ args.Add ($6);
+ $$ = new Invocation ((Expression) $1, args, lexer.Location);
+ }
;
opt_argument_list
{
$$ = new Argument ((Expression) $1, Argument.AType.Expression);
}
- | REF variable_reference
+ | non_simple_argument
+ {
+ $$ = $1;
+ }
+ ;
+
+non_simple_argument
+ : REF variable_reference
{
$$ = new Argument ((Expression) $2, Argument.AType.Ref);
}
$$ = 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");
;
anonymous_method_expression
- : DELEGATE opt_anonymous_method_signature {
+ : DELEGATE opt_anonymous_method_signature _mark_
+ {
oob_stack.Push (current_local_parameters);
current_local_parameters = (Parameters)$2;
- create_toplevel_block = true;
- } block {
- if (true){
- Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
+
+ // Force the next block to be created as a ToplevelBlock
+ oob_stack.Push (current_block);
+ oob_stack.Push (top_current_block);
+ current_block = null;
+ }
+ block
+ {
+ Location loc = (Location) $3;
+ 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 {
- create_toplevel_block = false;
- 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 ();
+ } else {
+ ToplevelBlock anon_block = (ToplevelBlock) $5;
+
+ 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
;
;
opt_anonymous_method_parameter_list
- : /* empty */ { $$ = null; }
+ : /* empty */ { $$ = null; }
| anonymous_method_parameter_list { $$ = $1; }
;
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;
}
;
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);
- name = MakeName ((string) $4);
+ 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);
+ }
- 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);
+ current_container = current_class;
+ RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+ }
}
opt_class_base
- class_body
- opt_semicolon
{
- Class new_class = (Class) current_container;
-
- 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.");
+ 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.");
}
- new_class.Bases = (ArrayList) $6;
+ current_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 ();
+ }
+ 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
block
: OPEN_BRACE
{
- if (current_block == null || create_toplevel_block){
- current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
+ 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);
+ 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;
}
;
;
if_statement
- : if_statement_open if_statement_rest
- {
- $$ = $2;
- }
- ;
-
-if_statement_open
- : IF OPEN_PARENS
- {
- oob_stack.Push (lexer.Location);
- }
- ;
-
-if_statement_rest
- : boolean_expression CLOSE_PARENS
+ : IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS
embedded_statement
{
- Location l = (Location) oob_stack.Pop ();
+ Location l = (Location) $3;
- $$ = new If ((Expression) $1, (Statement) $3, l);
+ $$ = new If ((Expression) $4, (Statement) $6, l);
- if (RootContext.WarningLevel >= 3){
- if ($3 == EmptyStatement.Value)
- Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+ if (RootContext.WarningLevel >= 4){
+ if ($6 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
}
}
- | boolean_expression CLOSE_PARENS
+ | IF OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS
embedded_statement ELSE embedded_statement
{
- Location l = (Location) oob_stack.Pop ();
+ Location l = (Location) $3;
- $$ = new If ((Expression) $1, (Statement) $3, (Statement) $5, l);
+ $$ = new If ((Expression) $4, (Statement) $6, (Statement) $8, l);
}
;
switch_statement
- : SWITCH OPEN_PARENS
+ : SWITCH OPEN_PARENS _mark_
{
- oob_stack.Push (lexer.Location);
switch_stack.Push (current_block);
}
expression CLOSE_PARENS
switch_block
{
- $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) oob_stack.Pop ());
+ $$ = new Switch ((Expression) $5, (ArrayList) $7, (Location) $3);
current_block = (Block) switch_stack.Pop ();
}
;
;
while_statement
- : WHILE OPEN_PARENS
- {
- oob_stack.Push (lexer.Location);
- }
- boolean_expression CLOSE_PARENS embedded_statement
+ : WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS embedded_statement
{
- Location l = (Location) oob_stack.Pop ();
+ Location l = (Location) $3;
$$ = new While ((Expression) $4, (Statement) $6, l);
- if (RootContext.WarningLevel >= 3){
+ if (RootContext.WarningLevel >= 4){
if ($6 == EmptyStatement.Value)
- Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
}
}
;
do_statement
: DO embedded_statement
- WHILE OPEN_PARENS {
- oob_stack.Push (lexer.Location);
- }
- boolean_expression CLOSE_PARENS SEMICOLON
+ WHILE OPEN_PARENS _mark_ boolean_expression CLOSE_PARENS SEMICOLON
{
- Location l = (Location) oob_stack.Pop ();
+ Location l = (Location) $5;
$$ = new Do ((Statement) $2, (Expression) $6, l);
}
for_statement
: FOR OPEN_PARENS
- opt_for_initializer SEMICOLON
+ opt_for_initializer SEMICOLON _mark_
{
Block assign_block = new Block (current_block);
current_block = assign_block;
}
}
- $3 = null;
- }
- oob_stack.Push (lexer.Location);
+ // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
+ // This can be referred to as $6 below.
+ $$ = null;
+ } else {
+ $$ = $3;
+ }
}
opt_for_condition SEMICOLON
opt_for_iterator CLOSE_PARENS
embedded_statement
{
- Location l = (Location) oob_stack.Pop ();
+ Location l = (Location) $5;
- For f = new For ((Statement) $3, (Expression) $6, (Statement) $8, (Statement) $10, l);
+ For f = new For ((Statement) $6, (Expression) $7, (Statement) $9, (Statement) $11, l);
- if (RootContext.WarningLevel >= 3){
- if ($10 == EmptyStatement.Value)
- Report.Warning (642, lexer.Location, "Possibly mistaken empty statement");
+ if (RootContext.WarningLevel >= 4){
+ if ($11 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
}
current_block.AddStatement (f);
;
foreach_statement
- : FOREACH OPEN_PARENS type IDENTIFIER IN
- {
- oob_stack.Push (lexer.Location);
- }
+ : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
+ {
+ Report.Error (230, lexer.Location, "Type and identifier are both required in a foreach statement");
+ $$ = null;
+ }
+ | FOREACH OPEN_PARENS type IDENTIFIER IN _mark_
expression CLOSE_PARENS
{
- oob_stack.Push (current_block);
-
Block foreach_block = new Block (current_block);
- LocalVariableReference v = null;
+ current_block = foreach_block;
+
Location l = lexer.Location;
LocalInfo vi;
vi.ReadOnly = true;
// Get a writable reference to this read-only variable.
- v = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
+ //
+ // Note that the $$ here refers to the value of _this_ code block,
+ // not the value of the LHS non-terminal. This can be referred to as $9 below.
+ $$ = new LocalVariableReference (foreach_block, (string) $4, l, vi, false);
+ } else {
+ $$ = null;
}
- current_block = foreach_block;
-
- oob_stack.Push (v);
- oob_stack.Push (current_block);
}
embedded_statement
{
- Block foreach_block = (Block) oob_stack.Pop ();
- LocalVariableReference v = (LocalVariableReference) oob_stack.Pop ();
- Block prev_block = (Block) oob_stack.Pop ();
- Location l = (Location) oob_stack.Pop ();
-
- current_block = prev_block;
+ LocalVariableReference v = (LocalVariableReference) $9;
+ Location l = (Location) $6;
if (v != null) {
Foreach f = new Foreach ((Expression) $3, v, (Expression) $7, (Statement) $10, l);
- foreach_block.AddStatement (f);
+ current_block.AddStatement (f);
}
- $$ = foreach_block;
+ while (current_block.Implicit)
+ current_block = current_block.Parent;
+ $$ = current_block;
+ current_block = current_block.Parent;
}
;
Report.Error (1003, lexer.Location, "; expected");
$$ = null;
}
- if (!RootContext.V2){
- Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
+ if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
$$ = null;
}
if (iterator_container == null){
Report.Error (1003, lexer.Location, "; expected");
$$ = null;
}
- if (!RootContext.V2){
- Report.Error (-222, lexer.Location, "yield statement only available in C# 2.0 mode");
+ if (RootContext.Version == LanguageVersion.ISO_1){
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
$$ = null;
}
if (iterator_container == 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
{
one.Add (new VariableDeclaration (id, null, loc));
- $1 = current_block;
current_block = new Block (current_block);
Block b = declare_local_variables (type, one, loc);
current_block = b;
type = (Expression) cc.Key;
id = (string) cc.Value;
- if ($1 != null){
- //
- // FIXME: I can change this for an assignment.
- //
- while (current_block != (Block) $1)
+ if (id != null){
+ while (current_block.Implicit)
current_block = current_block.Parent;
+ current_block = current_block.Parent;
}
}
-
- $$ = new Catch (type, id , (Block) $4, lexer.Location);
+ $$ = new Catch (type, id, (Block) $4, ((Block) $4).loc);
}
;
fixed_statement
: FIXED OPEN_PARENS
type fixed_pointer_declarators
- CLOSE_PARENS
+ CLOSE_PARENS _mark_
{
- 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 ();
- oob_stack.Pop ();
+ Location l = (Location) $6;
+
+ Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $8, l);
- $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+ if (RootContext.WarningLevel >= 4){
+ if ($8 == EmptyStatement.Value)
+ Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
+ }
+
+ 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
;
using_statement
- : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
+ : USING OPEN_PARENS resource_acquisition CLOSE_PARENS _mark_
{
Block assign_block = new Block (current_block);
current_block = assign_block;
- oob_stack.Push (lexer.Location);
-
if ($3 is DictionaryEntry){
DictionaryEntry de = (DictionaryEntry) $3;
Location l = lexer.Location;
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);
}
// Assign a = new Assign (var, expr, decl.Location);
// assign_block.AddStatement (new StatementExpression (a, lexer.Location));
}
- $3 = new DictionaryEntry (type, vars);
+
+ // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
+ // It can be referred to as $6 below.
+ $$ = new DictionaryEntry (type, vars);
+ } else {
+ $$ = $3;
}
}
embedded_statement
{
- Using u = new Using ($3, (Statement) $6, (Location) oob_stack.Pop ());
+ Using u = new Using ($6, (Statement) $7, (Location) $5);
current_block.AddStatement (u);
while (current_block.Implicit)
current_block = current_block.Parent;
| expression
;
+// Utility rule to save location information
+_mark_
+ : /* empty */
+ { $$ = lexer.Location; }
+
%%
// <summary>
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)
{
public readonly Accessor Get, Set;
public InterfaceAccessorInfo (bool has_get, bool has_set,
- Attributes get_attrs, Attributes set_attrs)
+ 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, get_attrs);
+ Get = new Accessor (null, 0, get_attrs, get_loc);
if (has_set)
- Set = new Accessor (null, set_attrs);
+ Set = new Accessor (null, 0, set_attrs, set_loc);
}
+
}
// </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;
-}
-
-// <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;
+ } else {
+ return new MemberName (current_container.MemberName, class_name);
}
}
-void
-CheckDef (bool result, string name, Location l)
-{
- if (result)
- return;
- CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
-}
-
Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
{
Block implicit_block;
lexer = new Tokenizer (reader, file, defines);
}
-public override void parse ()
+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
+ //
+ // Removed for production use, use parser verbose to get the output.
//
- Console.WriteLine (e);
+ // Console.WriteLine (e);
Report.Error (-25, lexer.Location, "Parsing error");
- if (Driver.parser_verbose)
+ if (yacc_verbose_flag > 0)
Console.WriteLine (e);
}
}
CheckToken (1041, yyToken, "Identifier expected");
}
+string ConsumeStoredComment ()
+{
+ string s = tmpComment;
+ tmpComment = null;
+ Lexer.doc_state = XmlCommentState.Allowed;
+ return s;
+}
+
/* end end end */
}