X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fcs-parser.jay;h=5880df29440d1fc80d14ef9dad4e5bdd7ba5ed81;hb=29f95a7d2392761ca8aa5a0d45f598241b40f947;hp=5f9c9a5a15440d81f70929d31b847d86c3bd5cb0;hpb=071ba68d7889fb7d22fdd318b4b84d4fcfac9a64;p=mono.git diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index 5f9c9a5a154..5880df29440 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -1622,8 +1622,11 @@ interface_property_declaration type IDENTIFIER OPEN_BRACE { lexer.PropertyParsing = true; } - interface_accessors - { lexer.PropertyParsing = false; } + accessor_declarations + { + has_get = has_set = false; + lexer.PropertyParsing = false; + } CLOSE_BRACE { LocatedToken lt = (LocatedToken) $4; @@ -1634,22 +1637,37 @@ interface_property_declaration break; } + Property p = null; if ($7 == null) { - Property p = new Property (current_class, (Expression) $3, (int) $2, true, + p = new Property (current_class, (Expression) $3, (int) $2, true, name, (Attributes) $1, null, null); - Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ()); + Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ()); break; } - InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7; - - $$ = new Property (current_class, (Expression) $3, (int) $2, true, + Pair pair = (Pair) $7; + p = new Property (current_class, (Expression) $3, (int) $2, true, name, (Attributes) $1, - pinfo.Get, pinfo.Set); + (Accessor)pair.First, (Accessor)pair.Second); + + if (pair.First != null && ((Accessor)(pair.First)).Block != null) { + Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ()); + $$ = null; + break; + } + + if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) { + Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ()); + $$ = null; + break; + } + if (RootContext.Documentation != null) - ((Property) $$).DocComment = Lexer.consume_doc_comment (); + p.DocComment = Lexer.consume_doc_comment (); + + $$ = p; } | opt_attributes opt_new @@ -1659,33 +1677,6 @@ interface_property_declaration } ; -interface_accessors - : opt_attributes opt_modifiers GET SEMICOLON - { - $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, (Location) $3, (Location) $3); - } - | opt_attributes opt_modifiers GET OPEN_BRACE - { - Report.Error (531, (Location) $3, "`{0}': interface members cannot have a definition", ".get"); - $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, (Location) $3, (Location) $3); - } - | opt_attributes opt_modifiers SET SEMICOLON - { - $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, (Location) $3, (Location) $3); - } - | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON - { - $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, (Location) $3, (Location) $7); - } - | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON - { - $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, (Location) $3, (Location) $3); - } - | - { - $$ = null; - } - ; interface_event_declaration : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON @@ -1725,28 +1716,46 @@ interface_indexer_declaration OPEN_BRACKET formal_parameter_list CLOSE_BRACKET OPEN_BRACE { lexer.PropertyParsing = true; } - interface_accessors - { lexer.PropertyParsing = false; } + accessor_declarations + { + has_get = has_set = false; + lexer.PropertyParsing = false; + } CLOSE_BRACE { + Indexer i = null; if ($10 == null) { - Indexer i = new Indexer (current_class, (Expression) $3, - new MemberName (TypeContainer.DefaultIndexerName), + i = new Indexer (current_class, (Expression) $3, + new MemberName (TypeContainer.DefaultIndexerName, (Location) $4), (int) $2, true, (Parameters) $6, (Attributes) $1, null, null); - Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ()); + Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ()); break; } - InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10; - - $$ = new Indexer (current_class, (Expression) $3, + Pair pair = (Pair) $10; + i = new Indexer (current_class, (Expression) $3, new MemberName (TypeContainer.DefaultIndexerName, (Location) $4), (int) $2, true, (Parameters) $6, (Attributes) $1, - info.Get, info.Set); + (Accessor)pair.First, (Accessor)pair.Second); + + if (pair.First != null && ((Accessor)(pair.First)).Block != null) { + Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ()); + $$ = null; + break; + } + + if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) { + Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ()); + $$ = null; + break; + } + if (RootContext.Documentation != null) - ((Indexer) $$).DocComment = ConsumeStoredComment (); + i.DocComment = ConsumeStoredComment (); + + $$ = i; } ; @@ -2515,7 +2524,7 @@ pointer_type // can't perform checks during this phase - we do it during // semantic analysis. // - $$ = new ComposedCast ((Expression) $1, "*"); + $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location); } | VOID STAR { @@ -2644,15 +2653,15 @@ literal : boolean_literal | integer_literal | real_literal - | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value); } - | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value); } - | NULL { $$ = NullLiteral.Null; } + | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); } + | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); } + | NULL { $$ = new NullLiteral (lexer.Location); } ; real_literal - : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value); } - | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value); } - | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value); } + : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); } + | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); } + | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); } ; integer_literal @@ -2660,28 +2669,21 @@ integer_literal object v = lexer.Value; if (v is int){ - int i = (int) v; - - if (i == 0) - $$ = IntLiteral.Zero; - else if (i == 1) - $$ = IntLiteral.One; - else - $$ = new IntLiteral (i); + $$ = new IntLiteral ((int) v, lexer.Location); } else if (v is uint) - $$ = new UIntLiteral ((UInt32) v); + $$ = new UIntLiteral ((UInt32) v, lexer.Location); else if (v is long) - $$ = new LongLiteral ((Int64) v); + $$ = new LongLiteral ((Int64) v, lexer.Location); else if (v is ulong) - $$ = new ULongLiteral ((UInt64) v); + $$ = new ULongLiteral ((UInt64) v, lexer.Location); else Console.WriteLine ("OOPS. Unexpected result from scanner"); } ; boolean_literal - : TRUE { $$ = new BoolLiteral (true); } - | FALSE { $$ = new BoolLiteral (false); } + : TRUE { $$ = new BoolLiteral (true, lexer.Location); } + | FALSE { $$ = new BoolLiteral (false, lexer.Location); } ; parenthesized_expression_0 @@ -3176,7 +3178,8 @@ cast_expression : cast_list | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression { - $$ = new Cast ((Expression) $2, (Expression) $4); + // TODO: wrong location + $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location); } ; @@ -3737,7 +3740,7 @@ local_variable_type if ((string) $2 == "") $$ = $1; else - $$ = new ComposedCast ((Expression) $1, (string) $2); + $$ = new ComposedCast ((Expression) $1, (string) $2, lexer.Location); } ; @@ -4568,25 +4571,6 @@ public class VariableDeclaration { } } -/// -/// Used to pass around interface property information -/// -public class InterfaceAccessorInfo { - - public readonly Accessor Get, Set; - - public InterfaceAccessorInfo (bool has_get, bool has_set, - Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc) - { - if (has_get) - Get = new Accessor (null, get_mod, get_attrs, get_loc); - if (has_set) - Set = new Accessor (null, set_mod, set_attrs, set_loc); - } - -} - - // // A class used to hold info about an indexer declarator // @@ -4856,7 +4840,7 @@ public Tokenizer Lexer { } } -public CSharpParser (StreamReader reader, SourceFile file, ArrayList defines) +public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines) { current_namespace = new NamespaceEntry (null, file, null, Location.Null); this.name = file.Name;