// 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
/// 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;
+ Block current_block, top_current_block;
Delegate current_delegate;
///
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.
///
SourceFile file;
+
+ ///
+ /// Temporary Xml documentation cache.
+ /// For enum types, we need one more temporary store.
+ ///
+ string tmpComment;
+ string enumTypeComment;
+
/// Current attribute target
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
// detach them
//
namespace_declaration
- : opt_attributes NAMESPACE namespace_name
+ : opt_attributes NAMESPACE namespace_or_type_name
{
if ($1 != null) {
Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
+ " Expected class, delegate, enum, interface, or struct");
}
- if (current_namespace.Parent != null && $3 is MemberAccess) {
- // Cannot use qualified namespace names in nested namespace declarations
- Report.Error (134, lexer.Location, "Cannot use qualified namespace names in nested namespace declarations");
+ 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, (string) $3, lexer.Location);
+ current_namespace, file, name.GetName (), lexer.Location);
}
namespace_body opt_semicolon
{
namespace_body
: OPEN_BRACE
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
opt_using_directives
opt_namespace_member_declarations
CLOSE_BRACE
}
opt_attributes
- : /* empty */
+ : /* empty */
{
global_attrs_enabled = false;
$$ = null;
global_attrs_enabled = false;
$$ = $1;
}
- ;
+ ;
attribute_sections
if (global_attrs_enabled) {
if (current_attr_target == "module") {
CodeGen.Module.AddAttributes (sect);
- $$ = null;
+ $$ = null;
} else if (current_attr_target == "assembly") {
CodeGen.Assembly.AddAttributes (sect);
- $$ = null;
+ $$ = 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
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;
}
$$ = args;
}
+ | named_argument_list COMMA expression
+ {
+ Report.Error (1016, lexer.Location, "Named attribute argument expected");
+ $$ = null;
+ }
;
named_argument
if ($7 != null)
current_class.Bases = (ArrayList) $7;
- CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
- current_class.Location);
+ 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
{
$$ = current_class;
;
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 (
current_class, (Expression) $4, (string) constant.identifier,
- (Expression) constant.expression_or_array_initializer, (int) $2,
+ (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);
}
}
;
{
ArrayList constants = new ArrayList (4);
if ($1 != null)
- constants.Add ($1);
+ constants.Add ($1);
$$ = constants;
}
| constant_declarators COMMA constant_declarator
{
if ($3 != null) {
- ArrayList constants = (ArrayList) $1;
- constants.Add ($3);
- }
+ ArrayList constants = (ArrayList) $1;
+ constants.Add ($3);
+ }
}
;
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;
}
;
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ generic.SetParameterInfo ((ArrayList) $9);
}
method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
current_local_parameters = (Parameters) $6;
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
$$ = method;
}
| opt_attributes
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
-
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+ generic.SetParameterInfo ((ArrayList) $9);
}
method = new Method (current_class, generic, TypeManager.system_void_expr,
current_local_parameters = (Parameters) $6;
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
$$ = method;
}
| opt_attributes
lexer.Location);
current_local_parameters = (Parameters) $6;
+
+ if (RootContext.Documentation != null)
+ method.DocComment = Lexer.consume_doc_comment ();
+
$$ = method;
}
;
{
$$ = 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;
property_declaration
: opt_attributes
opt_modifiers
- type namespace_or_type_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) $7;
MemberName name = (MemberName) $4;
+
if (name.TypeArguments != null)
syntax_error (lexer.Location, "a property can't have type arguments");
- Location loc = (Location) $6;
prop = new Property (current_container, (Expression) $3, (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;
}
;
if ($7 != null)
current_class.Bases = (ArrayList) $7;
- CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
- current_class.Name, current_class.Location);
+ current_class.SetParameterInfo ((ArrayList) $8);
+
+ if (RootContext.Documentation != null) {
+ current_class.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
current_class.Register ();
}
- interface_body opt_semicolon
+ interface_body
{
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+ opt_semicolon
+ {
$$ = current_class;
current_container = current_container.Parent;
{
Method m = (Method) $1;
- CheckDef (current_container.AddMethod (m), m.Name, m.Location);
+ current_container.AddMethod (m);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
| interface_property_declaration
{
Property p = (Property) $1;
- CheckDef (current_container.AddProperty (p), p.Name, p.Location);
- }
+ 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_container.AddEvent (e), e.Name, lexer.Location);
+ current_container.AddEvent (e);
}
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
| interface_indexer_declaration
{
Indexer i = (Indexer) $1;
current_container.AddIndexer (i);
+
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
;
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.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 namespace_or_type_name
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
generic = new GenericMethod (current_namespace, current_class,
name, lexer.Location);
- CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.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 ();
}
;
$$ = 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
$$ = 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_class, (Expression) $3, (int) $2, true,
- MemberName.Null, (Parameters) $6, (Attributes) $1,
+ $$ = 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;
+ 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, decl.arg1type,
- decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
- (Attributes) $1, decl.location);
+ 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 ();
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 (current_class, (string) $1, 0, (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;
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);
}
}
- | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
- string mn = (string) $5;
-
- if (mn.IndexOf ('.') != -1)
- Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
- else
- Report.Error (71, lexer.Location, "Event declaration should use property syntax");
- }
;
event_declaration
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);
+ 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
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");
+ 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;
+ }
- Event e = new EventProperty (current_class, (Expression) $4, (int) $2,
- false, name, null, (Attributes) $1,
- (Accessor) pair.First, (Accessor) pair.Second,
- loc);
-
- CheckDef (current_container.AddEvent (e), e.Name, loc);
- implicit_value_parameter_type = null;
+ 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;
}
;
}
| 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 {
MemberName name;
if (decl.interface_type != null)
- name = new MemberName (decl.interface_type, "", null);
+ name = new MemberName (decl.interface_type,
+ TypeContainer.DefaultIndexerName, null);
else
- name = MemberName.Null;
+ name = new MemberName (TypeContainer.DefaultIndexerName);
- indexer = new Indexer (current_class, decl.type, (int) $2, false,
- name, decl.param_list, (Attributes) $1,
+ 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;
} 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);
}
} else if (pars.FixedParameters == null && pars.ArrayParameter == null){
Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
}
+
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
{
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);
}
- string name = full_name.GetName (false);
- CheckDef (current_container.AddEnum (e), name, enum_location);
+ 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;
}
;
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
Location l = lexer.Location;
- Delegate del = new Delegate (
- current_namespace, current_container, (Expression) $4, (int) $2,
- MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
-
- CheckDef (current_container.AddDelegate (del), del.Name, l);
+ MemberName name = MakeName ((MemberName) $5);
+ Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
+ (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;
}
SEMICOLON
{
- CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+ current_delegate.SetParameterInfo ((ArrayList) $9);
current_delegate = null;
}
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 ((MemberName) $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;
}
SEMICOLON
{
- CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+ current_delegate.SetParameterInfo ((ArrayList) $9);
current_delegate = null;
}
| pointer_type
;
+
pointer_type
: type STAR
{
// Foo.Bar.Blah i;
// SimpleName is when you have
// Blah i;
-
+
Expression expr = (Expression) $1;
if (expr is ComposedCast){
$$ = new ComposedCast (expr, (string) $2, lexer.Location);
$$ = 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 void_pointer_expression CLOSE_PARENS
+ {
+ $$ = new TypeOf ((Expression) $3, lexer.Location);
+ }
| TYPEOF OPEN_PARENS
{
lexer.TypeOfParsing = true;
: DELEGATE opt_anonymous_method_signature {
oob_stack.Push (current_local_parameters);
current_local_parameters = (Parameters)$2;
- create_toplevel_block = true;
+
+ // 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 (true){
- Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
- $$ = null;
- } else {
- create_toplevel_block = false;
+ 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 ("anonymous methods");
+ Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
$$ = null;
- } else
- $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
+ } 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;
}
;
current_class.Bases = (ArrayList) $7;
}
- CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
- current_class.Name, current_class.Location);
+ current_class.SetParameterInfo ((ArrayList) $8);
+
+ if (RootContext.Documentation != null) {
+ current_class.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
current_class.Register ();
}
- class_body
+ class_body
+ {
+ if (RootContext.Documentation != null)
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
opt_semicolon
{
$$ = current_class;
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;
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
+ if (current_block == null)
+ top_current_block = null;
}
;
$$ = null;
}
if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotStandardized ("yield statement");
+ Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
$$ = null;
}
if (iterator_container == null){
$$ = null;
}
if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotStandardized ("yield statement");
+ 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
{
}
- $$ = 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;
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 ();
- $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+ 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");
+ }
+
+ 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);
+ ArrayList declarators = new ArrayList (4);
if ($1 != null)
- declarators.Add ($1);
+ declarators.Add ($1);
$$ = declarators;
}
| fixed_pointer_declarators COMMA fixed_pointer_declarator
{
ArrayList declarators = (ArrayList) $1;
if ($3 != null)
- declarators.Add ($3);
+ declarators.Add ($3);
$$ = declarators;
}
;
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>
-// 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)
-{
- current_container.CheckDef (result, name, l);
-}
-
-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;
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);
}
}
CheckToken (1041, yyToken, "Identifier expected");
}
+string ConsumeStoredComment ()
+{
+ string s = tmpComment;
+ tmpComment = null;
+ Lexer.doc_state = XmlCommentState.Allowed;
+ return s;
+}
+
/* end end end */
}