// Ravi Pratap (ravi@ximian.com)
// Marek Safar (marek.safar@gmail.com)
//
-// Licensed under the terms of the GNU GPL
+// Dual Licensed under the terms of the GNU GPL and the MIT X11 license
//
// (C) 2001 Ximian, Inc (http://www.ximian.com)
// (C) 2004 Novell, Inc
// great spot to put an `error' because you can reproduce it with this input:
// "public X { }"
//
-// Possible optimization:
-// Run memory profiler with parsing only, and consider dropping
-// arraylists where not needed. Some pieces can use linked lists.
-
using System.Text;
using System.IO;
using System;
+using System.Collections.Generic;
namespace Mono.CSharp
{
- using System.Collections;
-
/// <summary>
/// The C# Parser
/// </summary>
- public class CSharpParser {
+ public class CSharpParser
+ {
+ [Flags]
+ enum ParameterModifierType
+ {
+ Ref = 1 << 1,
+ Out = 1 << 2,
+ This = 1 << 3,
+ Params = 1 << 4,
+ Arglist = 1 << 5,
+ DefaultValue = 1 << 6,
+
+ All = Ref | Out | This | Params | Arglist | DefaultValue
+ }
+
NamespaceEntry current_namespace;
TypeContainer current_container;
DeclSpace current_class;
FullNamedExpression implicit_value_parameter_type;
ParametersCompiled indexer_parameters;
- /// <summary>
- /// Hack to help create non-typed array initializer
- /// </summary>
- public static FullNamedExpression current_array_type;
- FullNamedExpression pushed_current_array_type;
-
/// <summary>
/// Used to determine if we are parsing the get/set pair
/// of an indexer or a property
///
/// An out-of-band stack.
///
- static Stack oob_stack;
+ static Stack<object> oob_stack;
///
/// Switch stack.
///
- Stack switch_stack;
+ Stack<Block> switch_stack;
///
/// Controls the verbosity of the errors produced by the parser
/// assembly and module attribute definitions are enabled
bool global_attrs_enabled = true;
bool has_get, has_set;
- bool parameter_modifiers_not_allowed;
- bool complex_parameters_modifiers_not_allowed;
- bool arglist_allowed;
+
+ ParameterModifierType valid_param_mod;
+
bool default_parameter_used;
/// When using the interactive parser, this holds the
//
public Undo undo;
- // Stack<ToplevelBlock>
- Stack linq_clause_blocks;
+ Stack<Block> linq_clause_blocks;
// A counter to create new class names in interactive mode
static int class_count;
+
+ CompilerContext compiler;
+
+ //
+ // Instead of allocating carrier array everytime we
+ // share the bucket for very common constructs which can never
+ // be recursive
+ //
+ static List<Parameter> parameters_bucket = new List<Parameter> (6);
+ static List<object> variables_bucket = new List<object> (6);
%}
%token EOF
%token OP_PTR
%token OP_COALESCING
-/* Numbers */
-%token LITERAL_INTEGER
-%token LITERAL_FLOAT
-%token LITERAL_DOUBLE
-%token LITERAL_DECIMAL
-%token LITERAL_CHARACTER
-%token LITERAL_STRING
+%token LITERAL
%token IDENTIFIER
%token OPEN_PARENS_LAMBDA
extern_alias_directive
: EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
{
- LocatedToken lt = (LocatedToken) $2;
+ var lt = (Tokenizer.LocatedToken) $2;
string s = lt.Value;
if (s != "alias"){
syntax_error (lt.Location, "`alias' expected");
} else if (RootContext.Version == LanguageVersion.ISO_1) {
Report.FeatureIsNotAvailable (lt.Location, "external alias");
} else {
- lt = (LocatedToken) $3;
- current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
+ lt = (Tokenizer.LocatedToken) $3;
+ current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
}
}
| EXTERN_ALIAS error
using_alias_directive
: USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
{
- LocatedToken lt = (LocatedToken) $2;
- current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
+ var lt = (Tokenizer.LocatedToken) $2;
+ current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
}
| USING error {
CheckIdentifierToken (yyToken, GetLocation ($2));
using_namespace_directive
: USING namespace_name SEMICOLON
{
- current_namespace.AddUsing ((MemberName) $2, (Location) $1);
+ current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
}
;
qualified_identifier
: IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, lt.Location);
}
| qualified_identifier DOT IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
}
| error
{
syntax_error (lexer.Location, "`.' expected");
+ $$ = new MemberName ("<invalid>", lexer.Location);
}
;
if ($1 != null) {
Attributes attrs = (Attributes)$1;
if (global_attrs_enabled) {
- CodeGen.Assembly.AddAttributes (attrs.Attrs);
+ CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
} else {
foreach (Attribute a in attrs.Attrs) {
Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
: attribute_section
{
if (current_attr_target != String.Empty) {
- ArrayList sect = (ArrayList) $1;
+ var sect = (List<Attribute>) $1;
if (global_attrs_enabled) {
if (current_attr_target == "module") {
- current_container.Module.AddAttributes (sect);
+ current_container.Module.Compiled.AddAttributes (sect);
$$ = null;
} else if (current_attr_target != null && current_attr_target.Length > 0) {
- CodeGen.Assembly.AddAttributes (sect);
+ CodeGen.Assembly.AddAttributes (sect, current_namespace);
$$ = null;
} else {
$$ = new Attributes (sect);
{
if (current_attr_target != String.Empty) {
Attributes attrs = $1 as Attributes;
- ArrayList sect = (ArrayList) $2;
+ var sect = (List<Attribute>) $2;
if (global_attrs_enabled) {
if (current_attr_target == "module") {
- current_container.Module.AddAttributes (sect);
+ current_container.Module.Compiled.AddAttributes (sect);
$$ = null;
} else if (current_attr_target == "assembly") {
- CodeGen.Assembly.AddAttributes (sect);
+ CodeGen.Assembly.AddAttributes (sect, current_namespace);
$$ = null;
} else {
if (attrs == null)
attribute_target
: IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = CheckAttributeTarget (lt.Value, lt.Location);
}
| EVENT { $$ = "event"; }
attribute_list
: attribute
{
- ArrayList attrs = new ArrayList (4);
- attrs.Add ($1);
-
- $$ = attrs;
-
+ $$ = new List<Attribute> (4) { (Attribute) $1 };
}
| attribute_list COMMA attribute
{
- ArrayList attrs = (ArrayList) $1;
- attrs.Add ($3);
+ var attrs = (List<Attribute>) $1;
+ attrs.Add ((Attribute) $3);
$$ = attrs;
}
{
++lexer.parsing_block;
}
- opt_attribute_arguments
+ opt_attribute_arguments
{
--lexer.parsing_block;
MemberName mname = (MemberName) $1;
"'<' unexpected: attributes cannot be generic");
}
- object [] arguments = (object []) $3;
- MemberName left = mname.Left;
- string identifier = mname.Name;
-
- Expression left_expr = left == null ? null : left.GetTypeExpression ();
+ Arguments [] arguments = (Arguments []) $3;
+ ATypeNameExpression expr = mname.GetTypeExpression ();
if (current_attr_target == String.Empty)
$$ = null;
else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
// FIXME: supply "nameEscaped" parameter here.
$$ = new GlobalAttribute (current_namespace, current_attr_target,
- left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
+ expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
else
- $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
+ $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
}
;
attribute_arguments
- : opt_positional_argument_list
+ : /* empty */ { $$ = null; }
+ | positional_or_named_argument
{
- if ($1 == null)
- $$ = null;
- else {
- $$ = new object [] { $1, null };
- }
+ Arguments a = new Arguments (4);
+ a.Add ((Argument) $1);
+ $$ = new Arguments [] { a, null };
}
- | positional_argument_list COMMA named_argument_list
+ | named_attribute_argument
{
- $$ = new object[] { $1, $3 };
+ Arguments a = new Arguments (4);
+ a.Add ((Argument) $1);
+ $$ = new Arguments [] { null, a };
}
- | named_argument_list
+ | attribute_arguments COMMA positional_or_named_argument
{
- $$ = new object [] { null, $1 };
+ Arguments[] o = (Arguments[]) $1;
+ if (o [1] != null) {
+ Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
+ o [0] = new Arguments (4);
+ }
+
+ Arguments args = ((Arguments) o [0]);
+ if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
+ Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
+
+ args.Add ((Argument) $3);
}
- ;
-
-
-opt_positional_argument_list
- : /* empty */ { $$ = null; }
- | positional_argument_list
- ;
-
-positional_argument_list
- : expression
+ | attribute_arguments COMMA named_attribute_argument
{
- ArrayList args = new ArrayList (4);
- args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
+ Arguments[] o = (Arguments[]) $1;
+ if (o [1] == null) {
+ o [1] = new Arguments (4);
+ }
- $$ = args;
+ ((Arguments) o [1]).Add ((Argument) $3);
}
- | positional_argument_list COMMA expression
- {
- ArrayList args = (ArrayList) $1;
- args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
-
- $$ = args;
- }
- ;
+ ;
-named_argument_list
- : named_argument
+positional_or_named_argument
+ : expression
{
- ArrayList args = new ArrayList (4);
- args.Add ($1);
-
- $$ = args;
+ $$ = new Argument ((Expression) $1);
}
- | named_argument_list COMMA named_argument
- {
- ArrayList args = (ArrayList) $1;
- args.Add ($3);
+ | named_argument
+ ;
- $$ = args;
- }
- | named_argument_list COMMA expression
+named_attribute_argument
+ : IDENTIFIER ASSIGN expression
{
- Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
- $$ = null;
+ var lt = (Tokenizer.LocatedToken) $1;
+ $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
}
;
-
+
named_argument
- : IDENTIFIER ASSIGN expression
+ : IDENTIFIER COLON opt_named_modifier expression
{
- // FIXME: keep location
- $$ = new DictionaryEntry (
- ((LocatedToken) $1).Value,
- new Argument ((Expression) $3, Argument.AType.Expression));
+ if (RootContext.Version <= LanguageVersion.V_3)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
+
+ // Avoid boxing in common case (no modifier)
+ var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
+
+ var lt = (Tokenizer.LocatedToken) $1;
+ $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
+ }
+ ;
+
+opt_named_modifier
+ : /* empty */ { $$ = null; }
+ | REF
+ {
+ $$ = Argument.AType.Ref;
+ }
+ | OUT
+ {
+ $$ = Argument.AType.Out;
}
;
-
class_body
: OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
- push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
+ push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
}
opt_class_base
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- current_class.SetParameterInfo ((ArrayList) $9);
+ current_class.SetParameterInfo ((List<Constraints>) $9);
if (RootContext.Documentation != null)
current_container.DocComment = Lexer.consume_doc_comment ();
constant_declarators
SEMICOLON
{
- int modflags = (int) $2;
- foreach (VariableDeclaration constant in (ArrayList) $5){
+ var modflags = (Modifiers) $2;
+ foreach (VariableDeclaration constant in (List<object>) $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);
+ Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + "." + (string) constant.identifier);
continue;
}
Const c = new Const (
current_class, (FullNamedExpression) $4, (string) constant.identifier,
- (Expression) constant.expression_or_array_initializer, modflags,
+ constant.GetInitializer ((FullNamedExpression) $4), modflags,
(Attributes) $1, l);
if (RootContext.Documentation != null) {
constant_declarators
: constant_declarator
{
- ArrayList constants = new ArrayList (4);
+ variables_bucket.Clear ();
if ($1 != null)
- constants.Add ($1);
- $$ = constants;
+ variables_bucket.Add ($1);
+ $$ = variables_bucket;
}
| constant_declarators COMMA constant_declarator
{
if ($3 != null) {
- ArrayList constants = (ArrayList) $1;
+ var constants = (List<object>) $1;
constants.Add ($3);
}
}
constant_initializer
{
--lexer.parsing_block;
- $$ = new VariableDeclaration ((LocatedToken) $1, $4);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $4);
}
| IDENTIFIER
{
// A const field requires a value to be provided
- Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
+ Report.Error (145, GetLocation ($1), "A const field requires a value to be provided");
$$ = null;
}
;
if (type == TypeManager.system_void_expr)
Report.Error (670, GetLocation ($3), "Fields cannot have void type");
- int mod = (int) $2;
-
- current_array_type = null;
+ var mod = (Modifiers) $2;
- foreach (VariableMemberDeclaration var in (ArrayList) $4){
+ foreach (VariableMemberDeclaration var in (List<object>) $4){
Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
- field.Initializer = var.expression_or_array_initializer;
+ field.Initializer = var.GetInitializer (type);
if (RootContext.Documentation != null) {
field.DocComment = Lexer.consume_doc_comment ();
{
FullNamedExpression type = (FullNamedExpression) $4;
- int mod = (int) $2;
-
- current_array_type = null;
+ var mod = (Modifiers) $2;
- foreach (VariableDeclaration var in (ArrayList) $5) {
+ foreach (VariableDeclaration var in (List<VariableDeclaration>) $5) {
FixedField field = new FixedField (current_class, type, mod, var.identifier,
- (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
+ var.GetInitializer (type), (Attributes) $1, var.Location);
+
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
if (RootContext.Documentation != null) {
field.DocComment = Lexer.consume_doc_comment ();
fixed_variable_declarators
: fixed_variable_declarator
{
- ArrayList decl = new ArrayList (2);
- decl.Add ($1);
+ var decl = new List<VariableDeclaration> (2);
+ decl.Add ((VariableDeclaration)$1);
$$ = decl;
}
| fixed_variable_declarators COMMA fixed_variable_declarator
{
- ArrayList decls = (ArrayList) $1;
- decls.Add ($3);
+ var decls = (List<VariableDeclaration>) $1;
+ decls.Add ((VariableDeclaration)$3);
$$ = $1;
}
;
fixed_variable_declarator
: IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
{
- $$ = new VariableDeclaration ((LocatedToken) $1, $3);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
}
| IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
{
Report.Error (443, lexer.Location, "Value or constant expected");
- $$ = new VariableDeclaration ((LocatedToken) $1, null);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null);
}
;
local_variable_declarators
: local_variable_declarator
{
- ArrayList decl = new ArrayList (4);
+ variables_bucket.Clear ();
if ($1 != null)
- decl.Add ($1);
- $$ = decl;
+ variables_bucket.Add ($1);
+ $$ = variables_bucket;
}
| local_variable_declarators COMMA local_variable_declarator
{
- ArrayList decls = (ArrayList) $1;
+ var decls = (List<object>) $1;
decls.Add ($3);
$$ = $1;
}
local_variable_declarator
: IDENTIFIER ASSIGN local_variable_initializer
{
- $$ = new VariableDeclaration ((LocatedToken) $1, $3);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
}
| IDENTIFIER
{
- $$ = new VariableDeclaration ((LocatedToken) $1, null);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null);
}
| IDENTIFIER variable_bad_array
{
| array_initializer
| STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
{
- $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
+ $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
}
| ARGLIST
{
- $$ = new ArglistAccess ((Location) $1);
+ $$ = new ArglistAccess (GetLocation ($1));
}
| STACKALLOC simple_type
{
- Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
- $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
+ Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
+ $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
}
;
variable_declarators
: variable_declarator
{
- ArrayList decl = new ArrayList (4);
+ variables_bucket.Clear ();
if ($1 != null)
- decl.Add ($1);
- $$ = decl;
+ variables_bucket.Add ($1);
+ $$ = variables_bucket;
}
| variable_declarators COMMA variable_declarator
{
- ArrayList decls = (ArrayList) $1;
+ var decls = (List<object>) $1;
decls.Add ($3);
$$ = $1;
}
variable_initializer
{
--lexer.parsing_block;
- $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
+ $$ = new VariableMemberDeclaration ((MemberName) $1, (Expression) $4);
}
| member_declaration_name
{
method.Block = (ToplevelBlock) $3;
current_container.AddMethod (method);
- if (current_container.Kind == Kind.Interface && method.Block != null) {
+ if (current_container.Kind == MemberKind.Interface && method.Block != null) {
Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
}
member_type
method_declaration_name OPEN_PARENS
{
- arglist_allowed = true;
+ valid_param_mod = ParameterModifierType.All;
}
- opt_formal_parameter_list CLOSE_PARENS
+ opt_formal_parameter_list CLOSE_PARENS
{
lexer.ConstraintsParsing = true;
}
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- arglist_allowed = false;
+ valid_param_mod = 0;
MemberName name = (MemberName) $4;
current_local_parameters = (ParametersCompiled) $7;
- if ($10 != null && name.TypeArguments == null)
- Report.Error (80, lexer.Location,
- "Constraints are not allowed on non-generic declarations");
-
- Method method;
-
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
(FullNamedExpression) $3, current_local_parameters);
- generic.SetParameterInfo ((ArrayList) $10);
+ generic.SetParameterInfo ((List<Constraints>) $10);
+ } else if ($10 != null) {
+ Report.Error (80, GetLocation ($10),
+ "Constraints are not allowed on non-generic declarations");
}
- method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
+ Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
name, current_local_parameters, (Attributes) $1);
+
+ if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
+ Report.Error (460, method.Location,
+ "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
+ method.GetSignatureForError ());
+ }
current_generic_method = generic;
VOID method_declaration_name
OPEN_PARENS
{
- arglist_allowed = true;
+ valid_param_mod = ParameterModifierType.All;
}
opt_formal_parameter_list CLOSE_PARENS
{
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- arglist_allowed = false;
+ valid_param_mod = 0;
MemberName name = (MemberName) $5;
current_local_parameters = (ParametersCompiled) $8;
generic = new GenericMethod (current_namespace, current_class, name,
TypeManager.system_void_expr, current_local_parameters);
- generic.SetParameterInfo ((ArrayList) $11);
+ generic.SetParameterInfo ((List<Constraints>) $11);
}
- int modifiers = (int) $2;
+ var modifiers = (Modifiers) $2;
- const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
+ const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
if ((modifiers & invalid_partial_mod) != 0) {
{
MemberName name = (MemberName) $5;
Report.Error (1585, name.Location,
- "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
+ "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
Method method = new Method (current_class, null, TypeManager.system_void_expr,
0, name, (ParametersCompiled) $7, (Attributes) $1);
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
- $$ = null;
+ $$ = method;
}
;
| formal_parameter_list
;
-opt_parameter_list_no_mod
- : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
- |
- {
- parameter_modifiers_not_allowed = true;
- }
- formal_parameter_list
- {
- parameter_modifiers_not_allowed = false;
- $$ = $2;
- }
- ;
-
formal_parameter_list
: fixed_parameters
{
- ArrayList pars_list = (ArrayList) $1;
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (pars);
+ var pars_list = (List<Parameter>) $1;
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
| fixed_parameters COMMA parameter_array
{
- ArrayList pars_list = (ArrayList) $1;
- pars_list.Add ($3);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add ((Parameter) $3);
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (pars);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
| fixed_parameters COMMA arglist_modifier
{
- ArrayList pars_list = (ArrayList) $1;
+ var pars_list = (List<Parameter>) $1;
pars_list.Add (new ArglistParameter (GetLocation ($3)));
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| parameter_array COMMA error
{
if ($1 != null)
Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
- $$ = null;
+
+ $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
}
| fixed_parameters COMMA parameter_array COMMA error
{
if ($3 != null)
Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
- $$ = null;
+
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
+
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| arglist_modifier COMMA error
{
- Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
- $$ = null;
+ Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
+
+ $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
}
| fixed_parameters COMMA ARGLIST COMMA error
{
- Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
- $$ = null;
+ Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
+
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
+
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| parameter_array
{
- $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
+ $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
}
| arglist_modifier
{
- $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
+ $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
}
;
fixed_parameters
: fixed_parameter
{
- ArrayList pars = new ArrayList (4);
+ parameters_bucket.Clear ();
Parameter p = (Parameter) $1;
- pars.Add (p);
+ parameters_bucket.Add (p);
default_parameter_used = p.HasDefaultValue;
- $$ = pars;
+ $$ = parameters_bucket;
}
| fixed_parameters COMMA fixed_parameter
{
- ArrayList pars = (ArrayList) $1;
+ var pars = (List<Parameter>) $1;
Parameter p = (Parameter) $3;
if (p != null) {
if (p.HasExtensionMethodModifier)
fixed_parameter
: opt_attributes
opt_parameter_modifier
- type
+ parameter_type
IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $4;
+ var lt = (Tokenizer.LocatedToken) $4;
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
}
| opt_attributes
opt_parameter_modifier
- type
+ parameter_type
IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
{
- LocatedToken lt = (LocatedToken) $4;
+ var lt = (Tokenizer.LocatedToken) $4;
Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
- $$ = null;
+ $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
}
| opt_attributes
opt_parameter_modifier
- type
+ parameter_type
error
{
Location l = GetLocation ($4);
}
| opt_attributes
opt_parameter_modifier
- type
+ parameter_type
IDENTIFIER
ASSIGN
constant_expression
mod = Parameter.Modifier.NONE;
}
- if (complex_parameters_modifiers_not_allowed)
+ if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
- LocatedToken lt = (LocatedToken) $4;
+ var lt = (Tokenizer.LocatedToken) $4;
$$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
if ($6 != null)
((Parameter) $$).DefaultValue = (Expression) $6;
parameter_modifier
: REF
{
- if (parameter_modifiers_not_allowed)
- Error_ParameterModifierNotValid ("ref", (Location)$1);
+ if ((valid_param_mod & ParameterModifierType.Ref) == 0)
+ Error_ParameterModifierNotValid ("ref", GetLocation ($1));
$$ = Parameter.Modifier.REF;
}
| OUT
{
- if (parameter_modifiers_not_allowed)
- Error_ParameterModifierNotValid ("out", (Location)$1);
+ if ((valid_param_mod & ParameterModifierType.Out) == 0)
+ Error_ParameterModifierNotValid ("out", GetLocation ($1));
$$ = Parameter.Modifier.OUT;
}
| THIS
{
- if (parameter_modifiers_not_allowed)
- Error_ParameterModifierNotValid ("this", (Location)$1);
+ if ((valid_param_mod & ParameterModifierType.This) == 0)
+ Error_ParameterModifierNotValid ("this", GetLocation ($1));
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
parameter_array
: opt_attributes params_modifier type IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $4;
+ var lt = (Tokenizer.LocatedToken) $4;
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
}
| opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
{
Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
- LocatedToken lt = (LocatedToken) $4;
+ var lt = (Tokenizer.LocatedToken) $4;
$$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
}
| opt_attributes params_modifier type error {
params_modifier
: PARAMS
{
- if (complex_parameters_modifiers_not_allowed)
- Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
+ if ((valid_param_mod & ParameterModifierType.Params) == 0)
+ Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
}
| PARAMS parameter_modifier
{
Parameter.Modifier mod = (Parameter.Modifier)$2;
if ((mod & Parameter.Modifier.This) != 0) {
- Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
+ Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
} else {
- Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
+ Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
}
}
| PARAMS params_modifier
{
- Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
+ Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
}
;
arglist_modifier
: ARGLIST
{
- if (!arglist_allowed)
- Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
+ if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
+ Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
}
;
MemberName name = (MemberName) $4;
FullNamedExpression ptype = (FullNamedExpression) $3;
- prop = new Property (current_class, ptype, (int) $2,
+ prop = new Property (current_class, ptype, (Modifiers) $2,
name, (Attributes) $1, get_block, set_block, order, current_block);
if (ptype == TypeManager.system_void_expr)
if (accessors == null)
Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
- if (current_container.Kind == Kind.Interface) {
+ if (current_container.Kind == MemberKind.Interface) {
if (prop.Get.Block != null)
Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
Report.Error (1007, GetLocation ($3), "Property accessor already defined");
break;
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
+ Accessor accessor = new Accessor ((ToplevelBlock) $5, (Modifiers) $2, (Attributes) $1, current_local_parameters, GetLocation ($3));
has_get = true;
current_local_parameters = null;
lexer.PropertyParsing = true;
{
Parameter implicit_value_parameter = new Parameter (
implicit_value_parameter_type, "value",
- Parameter.Modifier.NONE, null, (Location) $3);
+ Parameter.Modifier.NONE, null, GetLocation ($3));
if (!parsing_indexer) {
- current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter });
+ current_local_parameters = new ParametersCompiled (compiler, new Parameter [] { implicit_value_parameter });
} else {
- current_local_parameters = ParametersCompiled.MergeGenerated (
+ current_local_parameters = ParametersCompiled.MergeGenerated (compiler,
indexer_parameters, true, implicit_value_parameter, null);
}
Report.Error (1007, GetLocation ($3), "Property accessor already defined");
break;
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
+ Accessor accessor = new Accessor ((ToplevelBlock) $5, (Modifiers) $2, (Attributes) $1, current_local_parameters, GetLocation ($3));
has_set = true;
current_local_parameters = null;
lexer.PropertyParsing = true;
}
| error
{
- Error_SyntaxError (1043, yyToken);
+ Error_SyntaxError (1043, yyToken, "Invalid accessor body");
$$ = null;
}
;
type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
- push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
+ push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
}
opt_class_base
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- current_class.SetParameterInfo ((ArrayList) $9);
+ current_class.SetParameterInfo ((List<Constraints>) $9);
if (RootContext.Documentation != null) {
current_container.DocComment = Lexer.consume_doc_comment ();
OperatorDeclaration decl = (OperatorDeclaration) $3;
Operator op = new Operator (
- current_class, decl.optype, decl.ret_type, (int) $2,
+ current_class, decl.optype, decl.ret_type, (Modifiers) $2,
current_local_parameters,
(ToplevelBlock) $5, (Attributes) $1, decl.location);
: type_expression_or_array
| VOID
{
- Report.Error (590, lexer.Location, "User-defined operators cannot return void");
+ Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
$$ = TypeManager.system_void_expr;
}
;
operator_declarator
: operator_type OPERATOR overloadable_operator OPEN_PARENS
{
- complex_parameters_modifiers_not_allowed = true;
+ valid_param_mod = ParameterModifierType.DefaultValue;
}
- opt_parameter_list_no_mod CLOSE_PARENS
+ opt_formal_parameter_list CLOSE_PARENS
{
- complex_parameters_modifiers_not_allowed = false;
+ valid_param_mod = 0;
- Location loc = (Location) $2;
+ Location loc = GetLocation ($2);
Operator.OpType op = (Operator.OpType) $3;
current_local_parameters = (ParametersCompiled)$6;
conversion_operator_declarator
: IMPLICIT OPERATOR type OPEN_PARENS
{
- complex_parameters_modifiers_not_allowed = true;
+ valid_param_mod = ParameterModifierType.DefaultValue;
}
- opt_parameter_list_no_mod CLOSE_PARENS
+ opt_formal_parameter_list CLOSE_PARENS
{
- complex_parameters_modifiers_not_allowed = false;
+ valid_param_mod = 0;
- Location loc = (Location) $2;
+ Location loc = GetLocation ($2);
current_local_parameters = (ParametersCompiled)$6;
if (RootContext.Documentation != null) {
}
| EXPLICIT OPERATOR type OPEN_PARENS
{
- complex_parameters_modifiers_not_allowed = true;
+ valid_param_mod = ParameterModifierType.DefaultValue;
}
- opt_parameter_list_no_mod CLOSE_PARENS
+ opt_formal_parameter_list CLOSE_PARENS
{
- complex_parameters_modifiers_not_allowed = false;
+ valid_param_mod = 0;
- Location loc = (Location) $2;
+ Location loc = GetLocation ($2);
current_local_parameters = (ParametersCompiled)$6;
if (RootContext.Documentation != null) {
| IMPLICIT error
{
Error_SyntaxError (yyToken);
+ current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
$$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
}
| EXPLICIT error
{
Error_SyntaxError (yyToken);
+ current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
$$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
}
;
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
- arglist_allowed = true;
+
+ valid_param_mod = ParameterModifierType.All;
}
OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
- arglist_allowed = false;
+ valid_param_mod = 0;
current_local_parameters = (ParametersCompiled) $6;
//
}
opt_constructor_initializer
{
- LocatedToken lt = (LocatedToken) $3;
- int mods = (int) $2;
+ var lt = (Tokenizer.LocatedToken) $3;
+ var mods = (Modifiers) $2;
ConstructorInitializer ci = (ConstructorInitializer) $9;
Constructor c = new Constructor (current_class, lt.Value, mods,
if (lt.Value != current_container.MemberName.Name) {
Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
} else if ((mods & Modifiers.STATIC) != 0) {
- if ((mods & Modifiers.Accessibility) != 0){
+ if ((mods & Modifiers.AccessibilityMask) != 0){
Report.Error (515, c.Location,
"`{0}': static constructor cannot have an access modifier",
c.GetSignatureForError ());
opt_argument_list CLOSE_PARENS
{
--lexer.parsing_block;
- $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
+ $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
}
| COLON THIS OPEN_PARENS
{
opt_argument_list CLOSE_PARENS
{
--lexer.parsing_block;
- $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
+ $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
}
| COLON error {
Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
}
IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
{
- LocatedToken lt = (LocatedToken) $5;
+ var lt = (Tokenizer.LocatedToken) $5;
if (lt.Value != current_container.MemberName.Name){
Report.Error (574, lt.Location, "Name of destructor must match name of class");
- } else if (current_container.Kind != Kind.Class){
+ } else if (current_container.Kind != MemberKind.Class){
Report.Error (575, lt.Location, "Only class types can contain destructor");
} else {
- Destructor d = new Destructor (current_class, (int) $2,
+ Destructor d = new Destructor (current_class, (Modifiers) $2,
ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
if (RootContext.Documentation != null)
d.DocComment = ConsumeStoredComment ();
opt_modifiers
EVENT type variable_declarators SEMICOLON
{
- current_array_type = null;
- foreach (VariableMemberDeclaration var in (ArrayList) $5) {
+ foreach (VariableMemberDeclaration var in (List<object>) $5) {
EventField e = new EventField (
- current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
+ current_class, (FullNamedExpression) $4, (Modifiers) $2, var.MemberName, (Attributes) $1);
- if (var.expression_or_array_initializer != null) {
- if (current_container.Kind == Kind.Interface) {
- Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
- }
-
- e.Initializer = var.expression_or_array_initializer;
+ e.Initializer = var.GetInitializer ((FullNamedExpression) $4);
+ if (current_container.Kind == MemberKind.Interface && e.Initializer != null) {
+ Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
}
if (var.MemberName.Left != null) {
OPEN_BRACE
{
implicit_value_parameter_type = (FullNamedExpression) $4;
- current_local_parameters = new ParametersCompiled (
+ current_local_parameters = new ParametersCompiled (compiler,
new Parameter (implicit_value_parameter_type, "value",
Parameter.Modifier.NONE, null, GetLocation ($3)));
{
MemberName name = (MemberName) $5;
- if (current_container.Kind == Kind.Interface) {
- Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
+ if (current_container.Kind == MemberKind.Interface) {
+ Report.Error (69, GetLocation ($3), "Event in interface cannot have add or remove accessors");
+ $8 = new Accessors (null, null);
+ } else if ($8 == null) {
+ Report.Error (65, GetLocation ($3), "`{0}.{1}': event property must have both add and remove accessors",
+ current_container.GetSignatureForError (), name.GetSignatureForError ());
+ $8 = new Accessors (null, null);
}
+
+ Accessors accessors = (Accessors) $8;
- if ($8 == null){
- Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
- current_container.Name, name.GetSignatureForError ());
+ if (accessors.get_or_add == null || accessors.set_or_remove == null)
+ // CS0073 is already reported, so no CS0065 here.
$$ = null;
- } else {
- Accessors accessors = (Accessors) $8;
-
- if (accessors.get_or_add == null || accessors.set_or_remove == null)
- // CS0073 is already reported, so no CS0065 here.
- $$ = null;
- else {
- Event e = new EventProperty (
- current_class, (FullNamedExpression) $4, (int) $2, name,
- (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
- if (RootContext.Documentation != null) {
- e.DocComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
-
- current_container.AddEvent (e);
- implicit_value_parameter_type = null;
+ else {
+ Event e = new EventProperty (
+ current_class, (FullNamedExpression) $4, (Modifiers) $2, name,
+ (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
+ if (RootContext.Documentation != null) {
+ e.DocComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
}
+
+ current_container.AddEvent (e);
+ implicit_value_parameter_type = null;
}
current_local_parameters = null;
}
}
block
{
- Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
+ Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2));
lexer.EventParsing = true;
$$ = accessor;
}
| opt_attributes ADD error {
- Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
+ Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body");
$$ = null;
}
| opt_attributes modifiers ADD {
- Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
+ Report.Error (1609, GetLocation ($3), "Modifiers cannot be placed on event accessor declarations");
$$ = null;
}
;
}
block
{
- $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
+ $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2));
lexer.EventParsing = true;
}
| opt_attributes REMOVE error {
- Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
+ Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body");
$$ = null;
}
| opt_attributes modifiers REMOVE {
- Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
+ Report.Error (1609, GetLocation ($3), "Modifiers cannot be placed on event accessor declarations");
$$ = null;
}
;
indexer_declaration
: opt_attributes opt_modifiers
- member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
+ member_type indexer_declaration_name OPEN_BRACKET
+ {
+ valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
+ }
+ opt_formal_parameter_list CLOSE_BRACKET
OPEN_BRACE
{
+ valid_param_mod = 0;
implicit_value_parameter_type = (FullNamedExpression) $3;
- indexer_parameters = (ParametersCompiled) $6;
+ indexer_parameters = (ParametersCompiled) $7;
if (indexer_parameters.IsEmpty) {
Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
- } else if (indexer_parameters.Count == 1) {
- Parameter p = indexer_parameters [0];
- if (p.HasDefaultValue)
- p.Warning_UselessOptionalParameter ();
}
if (RootContext.Documentation != null) {
}
CLOSE_BRACE
{
- Accessors accessors = (Accessors) $10;
+ Accessors accessors = (Accessors) $11;
Accessor get_block = accessors != null ? accessors.get_or_add : null;
Accessor set_block = accessors != null ? accessors.set_or_remove : null;
bool order = accessors != null ? accessors.declared_in_reverse : false;
Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
- (MemberName)$4, (int) $2, (ParametersCompiled) $6, (Attributes) $1,
+ (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1,
get_block, set_block, order);
if ($3 == TypeManager.system_void_expr)
if (accessors == null)
Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
- if (current_container.Kind == Kind.Interface) {
+ if (current_container.Kind == MemberKind.Interface) {
if (indexer.Get.Block != null)
Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
}
name = MakeName (name);
- Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
+ Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (Modifiers) $2,
name, (Attributes) $1);
if (RootContext.Documentation != null)
EnumMember em = null;
- foreach (VariableDeclaration ev in (ArrayList) $7) {
+ foreach (VariableDeclaration ev in (IList<VariableDeclaration>) $7) {
em = new EnumMember (
- e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
+ e, em, ev.identifier, ev.GetInitializer ((FullNamedExpression) $5),
ev.OptAttributes, ev.Location);
// if (RootContext.Documentation != null)
;
opt_enum_base
- : /* empty */ { $$ = TypeManager.system_int32_expr; }
+ : /* empty */
+ {
+ $$ = TypeManager.system_int32_expr;
+ }
| COLON type
{
if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
$2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
$2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
- $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
- Enum.Error_1008 (GetLocation ($2));
+ $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr) {
+ Enum.Error_1008 (GetLocation ($2), Report);
+ $2 = TypeManager.system_int32_expr;
+ }
$$ = $2;
}
| COLON error
{
- Error_TypeExpected (lexer.Location);
+ Error_TypeExpected (GetLocation ($1));
+ $$ = TypeManager.system_int32_expr;
}
;
;
opt_enum_member_declarations
- : /* empty */ { $$ = new ArrayList (4); }
+ : /* empty */ { $$ = new VariableDeclaration [0]; }
| enum_member_declarations opt_comma { $$ = $1; }
;
enum_member_declarations
: enum_member_declaration
{
- ArrayList l = new ArrayList (4);
-
- l.Add ($1);
+ var l = new List<VariableDeclaration> (4);
+ l.Add ((VariableDeclaration) $1);
$$ = l;
}
| enum_member_declarations COMMA enum_member_declaration
{
- ArrayList l = (ArrayList) $1;
-
- l.Add ($3);
-
+ var l = (List<VariableDeclaration>) $1;
+ l.Add ((VariableDeclaration) $3);
$$ = l;
}
;
: opt_attributes IDENTIFIER
{
VariableDeclaration vd = new VariableDeclaration (
- (LocatedToken) $2, null, (Attributes) $1);
+ (Tokenizer.LocatedToken) $2, null, (Attributes) $1);
if (RootContext.Documentation != null) {
vd.DocComment = Lexer.consume_doc_comment ();
{
--lexer.parsing_block;
VariableDeclaration vd = new VariableDeclaration (
- (LocatedToken) $2, $5, (Attributes) $1);
+ (Tokenizer.LocatedToken) $2, (Expression) $5, (Attributes) $1);
if (RootContext.Documentation != null)
vd.DocComment = ConsumeStoredComment ();
opt_modifiers
DELEGATE
member_type type_declaration_name
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ OPEN_PARENS
{
+ valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
+ }
+ opt_formal_parameter_list CLOSE_PARENS
+ {
+ valid_param_mod = 0;
+
MemberName name = MakeName ((MemberName) $5);
- ParametersCompiled p = (ParametersCompiled) $7;
+ ParametersCompiled p = (ParametersCompiled) $8;
Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
- (int) $2, name, p, (Attributes) $1);
+ (Modifiers) $2, name, p, (Attributes) $1);
if (RootContext.Documentation != null) {
del.DocComment = Lexer.consume_doc_comment ();
}
SEMICOLON
{
- current_delegate.SetParameterInfo ((ArrayList) $10);
+ current_delegate.SetParameterInfo ((List<Constraints>) $11);
$$ = current_delegate;
current_delegate = null;
| INTERR_NULLABLE
{
if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
- Report.FeatureIsNotSupported (lexer.Location, "nullable types");
+ Report.FeatureIsNotSupported (GetLocation ($1), "nullable types");
else if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
+ Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
$$ = this;
}
: member_name
| qualified_alias_member IDENTIFIER opt_type_argument_list
{
- LocatedToken lt1 = (LocatedToken) $1;
- LocatedToken lt2 = (LocatedToken) $2;
+ var lt1 = (Tokenizer.LocatedToken) $1;
+ var lt2 = (Tokenizer.LocatedToken) $2;
$$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
}
: type_name
| namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
}
;
type_name
: IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
}
;
| OP_GENERICS_LT type_arguments OP_GENERICS_GT
{
if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
- Report.FeatureIsNotSupported (lexer.Location, "generics");
+ Report.FeatureIsNotSupported (GetLocation ($1), "generics");
else if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
opt_type_parameter_list
{
lexer.parsing_generic_declaration = false;
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
}
;
| explicit_interface IDENTIFIER opt_type_parameter_list
{
lexer.parsing_generic_declaration = false;
- LocatedToken lt = (LocatedToken) $2;
+ var lt = (Tokenizer.LocatedToken) $2;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
}
;
explicit_interface
: IDENTIFIER opt_type_argument_list DOT
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
}
| qualified_alias_member IDENTIFIER opt_type_argument_list DOT
{
- LocatedToken lt1 = (LocatedToken) $1;
- LocatedToken lt2 = (LocatedToken) $2;
+ var lt1 = (Tokenizer.LocatedToken) $1;
+ var lt2 = (Tokenizer.LocatedToken) $2;
$$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
}
| explicit_interface IDENTIFIER opt_type_argument_list DOT
{
- LocatedToken lt = (LocatedToken) $2;
+ var lt = (Tokenizer.LocatedToken) $2;
$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
}
;
| OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
{
if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
- Report.FeatureIsNotSupported (lexer.Location, "generics");
+ Report.FeatureIsNotSupported (GetLocation ($1), "generics");
else if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
type_parameter
: opt_attributes opt_type_parameter_variance IDENTIFIER
{
- LocatedToken lt = (LocatedToken)$3;
+ var lt = (Tokenizer.LocatedToken)$3;
$$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
}
| error
: type_expression_or_array
| VOID
{
- Expression.Error_VoidInvalidInTheContext (lexer.Location);
+ Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
$$ = TypeManager.system_void_expr;
}
;
: type_expression
| VOID
{
- Expression.Error_VoidInvalidInTheContext (lexer.Location);
+ Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
+ $$ = TypeManager.system_void_expr;
+ }
+ ;
+
+parameter_type
+ : type_expression_or_array
+ | VOID
+ {
+ Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
$$ = TypeManager.system_void_expr;
}
- ;
+ ;
type_expression_or_array
: type_expression
| type_expression rank_specifiers
{
string rank_specifiers = (string) $2;
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+ $$ = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
}
;
if ($2 != null) {
$$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
} else {
- if (name.Left == null && name.Name == "var" && RootContext.Version > LanguageVersion.ISO_2)
- $$ = current_array_type = new VarExpr (name.Location);
+ if (name.Left == null && name.Name == "var")
+ $$ = new VarExpr (name.Location);
else
$$ = name.GetTypeExpression ();
}
}
| VOID STAR
{
- $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
+ $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1));
}
;
type_list
: base_type_name
{
- ArrayList types = new ArrayList (2);
- types.Add ($1);
+ var types = new List<FullNamedExpression> (2);
+ types.Add ((FullNamedExpression) $1);
$$ = types;
}
| type_list COMMA base_type_name
{
- ArrayList types = (ArrayList) $1;
- types.Add ($3);
+ var types = (List<FullNamedExpression>) $1;
+ types.Add ((FullNamedExpression) $3);
$$ = types;
}
;
base_type_name
: type
{
- if ($1 is ComposedCast)
+ if ($1 is ComposedCast) {
Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+ }
$$ = $1;
}
| error
{
Error_TypeExpected (lexer.Location);
+ $$ = null;
}
;
: literal
| IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $1;
- $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
+ var lt = (Tokenizer.LocatedToken) $1;
+ $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
}
| IDENTIFIER GENERATE_COMPLETION {
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
}
| parenthesized_expression
literal
: boolean_literal
- | integer_literal
- | real_literal
- | 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, lexer.Location); }
- | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
- | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
- ;
-
-integer_literal
- : LITERAL_INTEGER {
- object v = lexer.Value;
-
- if (v is int){
- $$ = new IntLiteral ((int) v, lexer.Location);
- } else if (v is uint)
- $$ = new UIntLiteral ((UInt32) v, lexer.Location);
- else if (v is long)
- $$ = new LongLiteral ((Int64) v, lexer.Location);
- else if (v is ulong)
- $$ = new ULongLiteral ((UInt64) v, lexer.Location);
- else
- Console.WriteLine ("OOPS. Unexpected result from scanner");
- }
+ | LITERAL
+ | NULL { $$ = new NullLiteral (GetLocation ($1)); }
;
boolean_literal
- : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
- | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
+ : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
+ | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
;
open_parens_any
: OPEN_PARENS
| OPEN_PARENS_CAST
- | OPEN_PARENS_LAMBDA
;
+//
+// Use this production to accept closing parenthesis or
+// performing completion
+//
+close_parens
+ : CLOSE_PARENS
+ | COMPLETE_COMPLETION
+ ;
+
+
parenthesized_expression
: OPEN_PARENS expression CLOSE_PARENS
{
member_access
: primary_expression DOT IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
}
| predefined_type DOT IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
// TODO: Location is wrong as some predefined types doesn't hold a location
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
}
| qualified_alias_member IDENTIFIER opt_type_argument_list
{
- LocatedToken lt1 = (LocatedToken) $1;
- LocatedToken lt2 = (LocatedToken) $2;
+ var lt1 = (Tokenizer.LocatedToken) $1;
+ var lt2 = (Tokenizer.LocatedToken) $2;
$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
}
$$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
}
| primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
}
| predefined_type DOT GENERATE_COMPLETION
$$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
}
| predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
}
;
invocation_expression
- : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
+ : primary_expression open_parens_any opt_argument_list close_parens
{
- $$ = new Invocation ((Expression) $1, (ArrayList) $3);
+ $$ = new Invocation ((Expression) $1, (Arguments) $3);
}
;
if ($2 == null)
$$ = CollectionOrObjectInitializers.Empty;
else
- $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+ $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
}
| OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
{
- $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+ $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
}
;
;
member_initializer_list
- : member_initializer
+ : member_initializer
{
- ArrayList a = new ArrayList ();
- a.Add ($1);
+ var a = new List<Expression> ();
+ a.Add ((Expression) $1);
$$ = a;
}
| member_initializer_list COMMA member_initializer
{
- ArrayList a = (ArrayList)$1;
- a.Add ($3);
+ var a = (List<Expression>)$1;
+ a.Add ((Expression) $3);
$$ = a;
}
;
member_initializer
: IDENTIFIER ASSIGN initializer_value
{
- LocatedToken lt = $1 as LocatedToken;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
}
| GENERATE_COMPLETION
}
| OPEN_BRACE expression_list CLOSE_BRACE
{
- $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
+ $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
}
| OPEN_BRACE CLOSE_BRACE
{
Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
+ $$ = null;
}
;
;
argument_list
- : argument
+ : argument_or_named_argument
{
- ArrayList list = new ArrayList (4);
- list.Add ($1);
+ Arguments list = new Arguments (4);
+ list.Add ((Argument) $1);
$$ = list;
}
| argument_list COMMA argument
{
- ArrayList list = (ArrayList) $1;
- list.Add ($3);
+ Arguments list = (Arguments) $1;
+ if (list [list.Count - 1] is NamedArgument)
+ Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
+
+ list.Add ((Argument) $3);
+ $$ = list;
+ }
+ | argument_list COMMA named_argument
+ {
+ Arguments list = (Arguments) $1;
+ NamedArgument a = (NamedArgument) $3;
+ for (int i = 0; i < list.Count; ++i) {
+ NamedArgument na = list [i] as NamedArgument;
+ if (na != null && na.Name == a.Name)
+ Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
+ na.Name);
+ }
+
+ list.Add (a);
$$ = list;
}
| argument_list COMMA
Report.Error (839, GetLocation ($2), "An argument is missing");
$$ = null;
}
- | COMMA argument
+ | COMMA argument_or_named_argument
{
Report.Error (839, GetLocation ($1), "An argument is missing");
$$ = null;
argument
: expression
{
- $$ = new Argument ((Expression) $1, Argument.AType.Expression);
+ $$ = new Argument ((Expression) $1);
}
| non_simple_argument
- {
- $$ = $1;
- }
+ ;
+
+argument_or_named_argument
+ : argument
+ | named_argument
;
non_simple_argument
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
}
- | ARGLIST open_parens_any argument_list CLOSE_PARENS
+ | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
{
- ArrayList list = (ArrayList) $3;
- Argument[] args = new Argument [list.Count];
- list.CopyTo (args, 0);
-
- Expression expr = new Arglist (args, (Location) $1);
- $$ = new Argument (expr, Argument.AType.Expression);
+ $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
}
- | ARGLIST open_parens_any CLOSE_PARENS
+ | ARGLIST OPEN_PARENS CLOSE_PARENS
{
- $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
+ $$ = new Argument (new Arglist (GetLocation ($1)));
}
| ARGLIST
{
- $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
+ $$ = new Argument (new ArglistAccess (GetLocation ($1)));
}
;
variable_reference
- : expression { note ("section 5.4"); $$ = $1; }
+ : expression
;
element_access
- : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
+ : primary_expression_no_array_creation OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
{
- $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
+ $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
}
- | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
+ | array_creation_expression OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
{
// LAMESPEC: Not allowed according to specification
- $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
+ $$ = new ElementAccess ((Expression) $1, (Arguments) $3);
}
| primary_expression_no_array_creation rank_specifiers
{
Error_ExpectingTypeName (expr);
$$ = TypeManager.system_object_expr;
}
-
- current_array_type = (FullNamedExpression)$$;
}
;
expression_list
: expression
{
- ArrayList list = new ArrayList (4);
- list.Add ($1);
+ var list = new List<Expression> (4);
+ list.Add ((Expression) $1);
$$ = list;
}
| expression_list COMMA expression
{
- ArrayList list = (ArrayList) $1;
- list.Add ($3);
+ var list = (List<Expression>) $1;
+ list.Add ((Expression) $3);
$$ = list;
}
;
+
+expression_list_arguments
+ : expression_list_argument
+ {
+ Arguments args = new Arguments (4);
+ args.Add ((Argument) $1);
+ $$ = args;
+ }
+ | expression_list_arguments COMMA expression_list_argument
+ {
+ Arguments args = (Arguments) $1;
+ args.Add ((Argument) $3);
+ $$ = args;
+ }
+ ;
+
+expression_list_argument
+ : expression
+ {
+ $$ = new Argument ((Expression) $1);
+ }
+ | named_argument
+ ;
this_access
: THIS
{
- $$ = new This (current_block, (Location) $1);
+ $$ = new This (current_block, GetLocation ($1));
}
;
base_access
: BASE DOT IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
}
- | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
+ | BASE OPEN_BRACKET expression_list_arguments CLOSE_BRACKET
{
- $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
+ $$ = new BaseIndexerAccess ((Arguments) $3, GetLocation ($1));
}
- | BASE error {
- Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
- $$ = null;
+ | BASE error
+ {
+ Error_SyntaxError (yyToken);
+ $$ = new BaseAccess (null, GetLocation ($2));
}
;
post_increment_expression
: primary_expression OP_INC
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
}
;
post_decrement_expression
: primary_expression OP_DEC
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
}
;
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
- $$ = new NewInitialize ((Expression) $1, (ArrayList) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
+ $$ = new NewInitialize ((Expression) $1, (Arguments) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
}
else
- $$ = new New ((Expression) $1, (ArrayList) $3, GetLocation ($1));
+ $$ = new New ((Expression) $1, (Arguments) $3, GetLocation ($1));
}
| new_expr_start object_or_collection_initializer
{
opt_rank_specifier // shift/reduce on OPEN_BRACE
opt_array_initializer
{
- $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
+ $$ = new ArrayCreation ((FullNamedExpression) $1, (List<Expression>) $3, (string) $5, (ArrayInitializer) $6, GetLocation ($1));
}
| new_expr_start rank_specifiers opt_array_initializer
{
if ($3 == null)
Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
- $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
+ $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayInitializer) $3, GetLocation ($1));
}
| NEW rank_specifiers array_initializer
{
- $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
+
+ $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayInitializer) $3, GetLocation ($1));
}
| new_expr_start error
{
Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
- $$ = null;
+ $$ = new ArrayCreation ((FullNamedExpression) $1, "[]", null, GetLocation ($1));
}
;
: NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
{
if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
- Report.FeatureIsNotSupported (lexer.Location, "anonymous types");
+ Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types");
else if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
- $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
+ $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
}
;
anonymous_type_parameters
: anonymous_type_parameter
{
- ArrayList a = new ArrayList (4);
- a.Add ($1);
+ var a = new List<AnonymousTypeParameter> (4);
+ a.Add ((AnonymousTypeParameter) $1);
$$ = a;
}
| anonymous_type_parameters COMMA anonymous_type_parameter
{
- ArrayList a = (ArrayList) $1;
- a.Add ($3);
+ var a = (List<AnonymousTypeParameter>) $1;
+ a.Add ((AnonymousTypeParameter) $3);
$$ = a;
}
;
anonymous_type_parameter
: IDENTIFIER ASSIGN variable_initializer
{
- LocatedToken lt = (LocatedToken)$1;
+ var lt = (Tokenizer.LocatedToken)$1;
$$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
}
| IDENTIFIER
{
- LocatedToken lt = (LocatedToken)$1;
+ var lt = (Tokenizer.LocatedToken)$1;
$$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
lt.Value, lt.Location);
}
| BASE DOT IDENTIFIER opt_type_argument_list
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
$$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
}
}
| error
{
- Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
- "Anonymous type members must be a member assignment, simple name or member access expression");
+ Report.Error (746, lexer.Location,
+ "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
+ $$ = null;
}
;
: rank_specifier
| rank_specifier rank_specifiers
{
- $$ = (string) $2 + (string) $1;
+ $$ = (string) $1 + (string) $2;
}
;
{
$$ = "[" + (string) $2 + "]";
}
- | OPEN_BRACKET error CLOSE_BRACKET
+ | OPEN_BRACKET error
{
- ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
+ Error_SyntaxError (178, yyToken, "Invalid rank specifier");
$$ = "[]";
}
;
array_initializer
: OPEN_BRACE CLOSE_BRACE
{
- ArrayList list = new ArrayList (4);
- $$ = list;
+ $$ = new ArrayInitializer (0, GetLocation ($1));
}
| OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
{
- $$ = (ArrayList) $2;
+ $$ = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
}
;
variable_initializer_list
: variable_initializer
{
- ArrayList list = new ArrayList (4);
- list.Add ($1);
+ var list = new List<Expression> (4);
+ list.Add ((Expression) $1);
$$ = list;
}
| variable_initializer_list COMMA variable_initializer
{
- ArrayList list = (ArrayList) $1;
- list.Add ($3);
+ var list = (List<Expression>) $1;
+ list.Add ((Expression) $3);
$$ = list;
}
| error
{
Error_SyntaxError (yyToken);
- $$ = new ArrayList ();
+ $$ = new List<Expression> ();
}
;
typeof_expression
: TYPEOF
{
- pushed_current_array_type = current_array_type;
lexer.TypeOfParsing = true;
}
open_parens_any typeof_type_expression CLOSE_PARENS
lexer.TypeOfParsing = false;
Expression type = (Expression)$4;
if (type == TypeManager.system_void_expr)
- $$ = new TypeOfVoid ((Location) $1);
+ $$ = new TypeOfVoid (GetLocation ($1));
else
- $$ = new TypeOf (type, (Location) $1);
- current_array_type = pushed_current_array_type;
+ $$ = new TypeOf (type, GetLocation ($1));
}
;
unbound_type_name
: IDENTIFIER generic_dimension
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
- $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
+ $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
}
| qualified_alias_member IDENTIFIER generic_dimension
{
- LocatedToken lt1 = (LocatedToken) $1;
- LocatedToken lt2 = (LocatedToken) $2;
+ var lt1 = (Tokenizer.LocatedToken) $1;
+ var lt2 = (Tokenizer.LocatedToken) $2;
- $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
+ $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
}
| unbound_type_name DOT IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
}
| unbound_type_name DOT IDENTIFIER generic_dimension
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
- $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
+ $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
}
| namespace_or_type_name DOT IDENTIFIER generic_dimension
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
MemberName name = (MemberName) $1;
- $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
+ $$ = new MemberAccess (name.GetTypeExpression (), lt.Value, (int) $4, lt.Location);
}
;
: GENERIC_DIMENSION
{
if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
- Report.FeatureIsNotSupported (lexer.Location, "generics");
+ Report.FeatureIsNotSupported (GetLocation ($1), "generics");
else if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (lexer.Location, "generics");
+ Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $1;
}
qualified_alias_member
: IDENTIFIER DOUBLE_COLON
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
if (RootContext.Version == LanguageVersion.ISO_1)
Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
sizeof_expression
: SIZEOF open_parens_any type CLOSE_PARENS {
- $$ = new SizeOf ((Expression) $3, (Location) $1);
+ $$ = new SizeOf ((Expression) $3, GetLocation ($1));
}
;
checked_expression
: CHECKED open_parens_any expression CLOSE_PARENS
{
- $$ = new CheckedExpr ((Expression) $3, (Location) $1);
+ $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
}
;
unchecked_expression
: UNCHECKED open_parens_any expression CLOSE_PARENS
{
- $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
+ $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
}
;
: primary_expression OP_PTR IDENTIFIER
{
Expression deref;
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
deref = new Indirection ((Expression) $1, lt.Location);
$$ = new MemberAccess (deref, lt.Value);
anonymous_method_expression
: DELEGATE opt_anonymous_method_signature
{
- start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
+ start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
}
block
{
anonymous_method_signature
: OPEN_PARENS
{
- complex_parameters_modifiers_not_allowed = true;
+ valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
}
opt_formal_parameter_list CLOSE_PARENS
{
- complex_parameters_modifiers_not_allowed = false;
+ valid_param_mod = 0;
$$ = $3;
}
;
: DEFAULT open_parens_any type CLOSE_PARENS
{
if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
+ Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
$$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
}
: primary_expression
| BANG prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
+ $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
}
| TILDE prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
+ $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
}
| cast_expression
;
: unary_expression
| PLUS prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
+ $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
}
| MINUS prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
+ $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
}
| OP_INC prefixed_unary_expression
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
}
| OP_DEC prefixed_unary_expression
{
- $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
+ $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
}
| STAR prefixed_unary_expression
{
}
| BITWISE_AND prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
+ $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
}
;
| multiplicative_expression STAR prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Multiply,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| multiplicative_expression DIV prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Division,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| multiplicative_expression PERCENT prefixed_unary_expression
{
$$ = new Binary (Binary.Operator.Modulus,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| additive_expression PLUS multiplicative_expression
{
$$ = new Binary (Binary.Operator.Addition,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| additive_expression MINUS multiplicative_expression
{
- $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+ $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| parenthesized_expression MINUS multiplicative_expression
{
// Shift/Reduce conflict
- $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
+ $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
}
| additive_expression AS type
{
- $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
+ $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
}
| additive_expression IS type
{
- $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
+ $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| shift_expression OP_SHIFT_LEFT additive_expression
{
$$ = new Binary (Binary.Operator.LeftShift,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| shift_expression OP_SHIFT_RIGHT additive_expression
{
$$ = new Binary (Binary.Operator.RightShift,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| relational_expression OP_LT shift_expression
{
$$ = new Binary (Binary.Operator.LessThan,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| relational_expression OP_GT shift_expression
{
$$ = new Binary (Binary.Operator.GreaterThan,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| relational_expression OP_LE shift_expression
{
$$ = new Binary (Binary.Operator.LessThanOrEqual,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| relational_expression OP_GE shift_expression
{
$$ = new Binary (Binary.Operator.GreaterThanOrEqual,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| equality_expression OP_EQ relational_expression
{
$$ = new Binary (Binary.Operator.Equality,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
| equality_expression OP_NE relational_expression
{
$$ = new Binary (Binary.Operator.Inequality,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| and_expression BITWISE_AND equality_expression
{
$$ = new Binary (Binary.Operator.BitwiseAnd,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| exclusive_or_expression CARRET and_expression
{
$$ = new Binary (Binary.Operator.ExclusiveOr,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| inclusive_or_expression BITWISE_OR exclusive_or_expression
{
$$ = new Binary (Binary.Operator.BitwiseOr,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| conditional_and_expression OP_AND inclusive_or_expression
{
$$ = new Binary (Binary.Operator.LogicalAnd,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
| conditional_or_expression OP_OR conditional_and_expression
{
$$ = new Binary (Binary.Operator.LogicalOr,
- (Expression) $1, (Expression) $3);
+ (Expression) $1, (Expression) $3, GetLocation ($2));
}
;
if (RootContext.Version < LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
- $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
+ $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
}
;
: null_coalescing_expression
| null_coalescing_expression INTERR expression COLON expression
{
- $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
+ $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5);
}
;
lambda_parameter_list
: lambda_parameter
{
- ArrayList pars = new ArrayList (4);
- pars.Add ($1);
+ var pars = new List<Parameter> (4);
+ pars.Add ((Parameter) $1);
$$ = pars;
}
| lambda_parameter_list COMMA lambda_parameter
{
- ArrayList pars = (ArrayList) $1;
+ var pars = (List<Parameter>) $1;
Parameter p = (Parameter)$3;
if (pars[0].GetType () != p.GetType ()) {
Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
;
lambda_parameter
- : parameter_modifier type IDENTIFIER
+ : parameter_modifier parameter_type IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
}
- | type IDENTIFIER
+ | parameter_type IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $2;
+ var lt = (Tokenizer.LocatedToken) $2;
$$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
}
| IDENTIFIER
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
$$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
}
;
opt_lambda_parameter_list
: /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
| lambda_parameter_list {
- ArrayList pars_list = (ArrayList) $1;
- $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter)));
+ var pars_list = (List<Parameter>) $1;
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
;
lambda_expression
: IDENTIFIER ARROW
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
- start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
+ start_anonymous (true, new ParametersCompiled (compiler, p), GetLocation ($1));
}
lambda_expression_body
{
$$ = end_anonymous ((ToplevelBlock) $4);
}
- | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
+ | OPEN_PARENS_LAMBDA
+ {
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
+
+ valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
+ }
+ opt_lambda_parameter_list CLOSE_PARENS ARROW
{
- start_anonymous (true, (ParametersCompiled) $2, GetLocation ($1));
+ valid_param_mod = 0;
+ start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
}
lambda_expression_body
{
- $$ = end_anonymous ((ToplevelBlock) $6);
+ $$ = end_anonymous ((ToplevelBlock) $7);
}
;
non_assignment_expression
: conditional_expression
| lambda_expression
- | query_expression
+ | query_expression
;
constant_expression
boolean_expression
: expression
+ {
+ $$ = new BooleanExpression ((Expression) $1);
+ }
;
//
type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
- push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
+ push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
}
opt_class_base
opt_type_parameter_constraints_clauses
{
lexer.ConstraintsParsing = false;
- current_class.SetParameterInfo ((ArrayList) $9);
+ current_class.SetParameterInfo ((List<Constraints>) $9);
if (RootContext.Documentation != null) {
current_container.DocComment = Lexer.consume_doc_comment ();
: modifier
| modifiers modifier
{
- int m1 = (int) $1;
- int m2 = (int) $2;
+ var m1 = (Modifiers) $1;
+ var m2 = (Modifiers) $2;
if ((m1 & m2) != 0) {
Location l = lexer.Location;
- Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
+ Report.Error (1004, l, "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
}
- $$ = (int) (m1 | m2);
+ $$ = m1 | m2;
}
;
{
$$ = Modifiers.NEW;
if (current_container == RootContext.ToplevelTypes)
- Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
+ Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
}
| PUBLIC { $$ = Modifiers.PUBLIC; }
| PROTECTED { $$ = Modifiers.PROTECTED; }
;
class_base
- : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
+ : COLON type_list
+ {
+ current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
+ }
;
opt_type_parameter_constraints_clauses
: /* empty */ { $$ = null; }
| type_parameter_constraints_clauses
- { $$ = $1; }
+ {
+ $$ = $1;
+ }
;
type_parameter_constraints_clauses
- : type_parameter_constraints_clause {
- ArrayList constraints = new ArrayList (1);
- constraints.Add ($1);
+ : type_parameter_constraints_clause
+ {
+ var constraints = new List<Constraints> (1);
+ constraints.Add ((Constraints) $1);
$$ = constraints;
}
- | type_parameter_constraints_clauses type_parameter_constraints_clause {
- ArrayList constraints = (ArrayList) $1;
+ | type_parameter_constraints_clauses type_parameter_constraints_clause
+ {
+ var constraints = (List<Constraints>) $1;
Constraints new_constraint = (Constraints)$2;
foreach (Constraints c in constraints) {
- if (new_constraint.TypeParameter == c.TypeParameter) {
- Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
- new_constraint.TypeParameter);
+ if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
+ Report.Error (409, new_constraint.Location,
+ "A constraint clause has already been specified for type parameter `{0}'",
+ new_constraint.TypeParameter.Value);
}
}
;
type_parameter_constraints_clause
- : WHERE IDENTIFIER COLON type_parameter_constraints {
- LocatedToken lt = (LocatedToken) $2;
- $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
+ : WHERE IDENTIFIER COLON type_parameter_constraints
+ {
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
}
;
type_parameter_constraints
- : type_parameter_constraint {
- ArrayList constraints = new ArrayList (1);
- constraints.Add ($1);
+ : type_parameter_constraint
+ {
+ var constraints = new List<FullNamedExpression> (1);
+ constraints.Add ((FullNamedExpression) $1);
$$ = constraints;
}
- | type_parameter_constraints COMMA type_parameter_constraint {
- ArrayList constraints = (ArrayList) $1;
+ | type_parameter_constraints COMMA type_parameter_constraint
+ {
+ var constraints = (List<FullNamedExpression>) $1;
+ var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
+ if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
+ Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
+ }
+
+ prev = $3 as SpecialContraintExpr;
+ if (prev != null) {
+ if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
+ Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
+ } else {
+ prev = constraints [0] as SpecialContraintExpr;
+ if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
+ Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
+ }
+ }
+ }
- constraints.Add ($3);
+ constraints.Add ((FullNamedExpression) $3);
$$ = constraints;
}
;
type_parameter_constraint
: type
- | NEW OPEN_PARENS CLOSE_PARENS {
- $$ = SpecialConstraint.Constructor;
+ {
+ if ($1 is ComposedCast)
+ Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+
+ $$ = $1;
+ }
+ | NEW OPEN_PARENS CLOSE_PARENS
+ {
+ $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
}
- | CLASS {
- $$ = SpecialConstraint.ReferenceType;
+ | CLASS
+ {
+ $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
}
- | STRUCT {
- $$ = SpecialConstraint.ValueType;
+ | STRUCT
+ {
+ $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
}
;
: OPEN_BRACE
{
++lexer.parsing_block;
- start_block ((Location) $1);
+ start_block (GetLocation ($1));
}
opt_statement_list block_end
{
$$ = $4;
- }
+ }
;
block_end
: CLOSE_BRACE
{
--lexer.parsing_block;
- $$ = end_block ((Location) $1);
+ $$ = end_block (GetLocation ($1));
}
| COMPLETE_COMPLETION
{
opt_statement_list CLOSE_BRACE
{
--lexer.parsing_block;
- $$ = end_block ((Location) $4);
+ $$ = end_block (GetLocation ($4));
}
;
empty_statement
: SEMICOLON
{
- $$ = EmptyStatement.Value;
+ $$ = new EmptyStatement (GetLocation ($1));
}
;
labeled_statement
: IDENTIFIER COLON
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
if (current_block.AddLabel (labeled))
declaration_statement
: local_variable_declaration SEMICOLON
{
- current_array_type = null;
if ($1 != null){
- DictionaryEntry de = (DictionaryEntry) $1;
- Expression e = (Expression) de.Key;
-
- $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
+ var de = (Tuple<FullNamedExpression, List<object>>) $1;
+ $$ = declare_local_variables (de.Item1, de.Item2, de.Item1.Location);
}
}
| local_constant_declaration SEMICOLON
{
- current_array_type = null;
if ($1 != null){
- DictionaryEntry de = (DictionaryEntry) $1;
+ var de = (Tuple<FullNamedExpression, List<object>>) $1;
- $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
+ $$ = declare_local_constants (de.Item1, de.Item2);
}
}
;
//
if (rank_or_nullable.Length == 0) {
SimpleName sn = expr as SimpleName;
- if (sn != null && sn.Name == "var" && RootContext.Version > LanguageVersion.ISO_2)
- $$ = current_array_type = new VarExpr (sn.Location);
+ if (sn != null && sn.Name == "var")
+ $$ = new VarExpr (sn.Location);
else
$$ = $1;
} else {
if ((string) $2 == "")
$$ = $1;
else
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
}
| VOID opt_rank_specifier
{
- Expression.Error_VoidInvalidInTheContext (lexer.Location);
+ Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
$$ = TypeManager.system_void_expr;
}
;
}
| VOID STAR
{
- $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
+ $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1));
}
| local_variable_pointer_type STAR
{
if (rank == "")
$$ = $1;
else
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
+ $$ = new ComposedCast ((FullNamedExpression) $1, rank);
} else {
$$ = null;
}
{
if ($1 != null) {
VarExpr ve = $1 as VarExpr;
- if (ve != null)
- ve.VariableInitializer = (ArrayList)$2;
+ if (ve != null) {
+ if (!((VariableDeclaration) ((List<object>)$2) [0]).HasInitializer)
+ ve.VariableInitializersCount = 0;
+ else
+ ve.VariableInitializersCount = ((List<object>)$2).Count;
+ }
- $$ = new DictionaryEntry ($1, $2);
+ $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $1, (List<object>) $2);
} else
$$ = null;
}
: CONST variable_type constant_declarators
{
if ($2 != null)
- $$ = new DictionaryEntry ($2, $3);
+ $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $2, (List<object>) $3);
else
$$ = null;
}
{
ExpressionStatement s = $1 as ExpressionStatement;
if (s == null) {
- ((Expression) $1).Error_InvalidExpressionStatement ();
+ Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
s = EmptyExpressionStatement.Instance;
}
| error
{
Error_SyntaxError (yyToken);
- $$ = null;
+ $$ = new EmptyStatement (GetLocation ($1));
}
;
: IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement
{
- Location l = (Location) $1;
-
- $$ = new If ((Expression) $3, (Statement) $5, l);
-
- // FIXME: location for warning should be loc property of $5.
- if ($5 == EmptyStatement.Value)
- Report.Warning (642, 3, l, "Possible mistaken empty statement");
-
+ if ($5 is EmptyStatement)
+ Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
+
+ $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
}
| IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement ELSE embedded_statement
{
- Location l = (Location) $1;
-
- $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
+ $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
- // FIXME: location for warning should be loc property of $5 and $7.
- if ($5 == EmptyStatement.Value)
- Report.Warning (642, 3, l, "Possible mistaken empty statement");
- if ($7 == EmptyStatement.Value)
- Report.Warning (642, 3, l, "Possible mistaken empty statement");
+ if ($5 is EmptyStatement)
+ Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
+ if ($7 is EmptyStatement)
+ Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
}
;
: SWITCH open_parens_any
{
if (switch_stack == null)
- switch_stack = new Stack (2);
+ switch_stack = new Stack<Block> (2);
switch_stack.Push (current_block);
}
expression CLOSE_PARENS
switch_block
{
- $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
+ $$ = new Switch ((Expression) $4, (List<SwitchSection>) $6, GetLocation ($1));
current_block = (Block) switch_stack.Pop ();
}
;
: /* empty */
{
Report.Warning (1522, 1, lexer.Location, "Empty switch block");
- $$ = new ArrayList ();
+ $$ = new List<SwitchSection> ();
}
| switch_sections
;
switch_sections
: switch_section
{
- ArrayList sections = new ArrayList (4);
+ var sections = new List<SwitchSection> (4);
- sections.Add ($1);
+ sections.Add ((SwitchSection) $1);
$$ = sections;
}
| switch_sections switch_section
{
- ArrayList sections = (ArrayList) $1;
+ var sections = (List<SwitchSection>) $1;
- sections.Add ($2);
+ sections.Add ((SwitchSection) $2);
$$ = sections;
}
;
}
statement_list
{
- $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
+ $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block.Explicit);
}
;
switch_labels
: switch_label
{
- ArrayList labels = new ArrayList (4);
+ var labels = new List<SwitchLabel> (4);
- labels.Add ($1);
+ labels.Add ((SwitchLabel) $1);
$$ = labels;
}
| switch_labels switch_label
{
- ArrayList labels = (ArrayList) ($1);
- labels.Add ($2);
+ var labels = (List<SwitchLabel>) ($1);
+ labels.Add ((SwitchLabel) $2);
$$ = labels;
}
switch_label
: CASE constant_expression COLON
{
- $$ = new SwitchLabel ((Expression) $2, (Location) $1);
+ $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
}
| DEFAULT_COLON
{
- $$ = new SwitchLabel (null, (Location) $1);
+ $$ = new SwitchLabel (null, GetLocation ($1));
}
;
while_statement
: WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
{
- Location l = (Location) $1;
- $$ = new While ((Expression) $3, (Statement) $5, l);
+ Location l = GetLocation ($1);
+ $$ = new While ((BooleanExpression) $3, (Statement) $5, l);
}
;
: DO embedded_statement
WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
{
- Location l = (Location) $1;
+ Location l = GetLocation ($1);
- $$ = new Do ((Statement) $2, (Expression) $5, l);
+ $$ = new Do ((Statement) $2, (BooleanExpression) $5, l);
}
;
start_block (l);
Block assign_block = current_block;
- if ($3 is DictionaryEntry){
- DictionaryEntry de = (DictionaryEntry) $3;
+ if ($3 is Tuple<FullNamedExpression, List<object>>){
+ var de = (Tuple<FullNamedExpression, List<object>>) $3;
- Expression type = (Expression) de.Key;
- ArrayList var_declarators = (ArrayList) de.Value;
+ var type = de.Item1;
- foreach (VariableDeclaration decl in var_declarators){
+ foreach (VariableDeclaration decl in de.Item2){
LocalInfo vi;
if (vi == null)
continue;
- Expression expr = decl.expression_or_array_initializer;
+ Expression expr = decl.GetInitializer (type);
LocalVariableReference var;
var = new LocalVariableReference (assign_block, decl.identifier, l);
opt_for_iterator CLOSE_PARENS
embedded_statement
{
- Location l = (Location) $1;
+ Location l = GetLocation ($1);
- For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
+ For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, l);
current_block.AddStatement (f);
;
opt_for_initializer
- : /* empty */ { $$ = EmptyStatement.Value; }
+ : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
| for_initializer
;
;
opt_for_iterator
- : /* empty */ { $$ = EmptyStatement.Value; }
+ : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
| for_iterator
;
foreach_statement
: FOREACH open_parens_any type IN expression CLOSE_PARENS
{
- Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
+ Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
$$ = null;
}
| FOREACH open_parens_any type IDENTIFIER IN
start_block (lexer.Location);
Block foreach_block = current_block;
- LocatedToken lt = (LocatedToken) $4;
+ var lt = (Tokenizer.LocatedToken) $4;
Location l = lt.Location;
LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
if (vi != null) {
embedded_statement
{
LocalVariableReference v = (LocalVariableReference) $8;
- Location l = (Location) $1;
+ Location l = GetLocation ($1);
if (v != null) {
Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
break_statement
: BREAK SEMICOLON
{
- $$ = new Break ((Location) $1);
+ $$ = new Break (GetLocation ($1));
}
;
continue_statement
: CONTINUE SEMICOLON
{
- $$ = new Continue ((Location) $1);
+ $$ = new Continue (GetLocation ($1));
}
;
goto_statement
: GOTO IDENTIFIER SEMICOLON
{
- LocatedToken lt = (LocatedToken) $2;
+ var lt = (Tokenizer.LocatedToken) $2;
$$ = new Goto (lt.Value, lt.Location);
}
| GOTO CASE constant_expression SEMICOLON
{
- $$ = new GotoCase ((Expression) $3, (Location) $1);
+ $$ = new GotoCase ((Expression) $3, GetLocation ($1));
}
| GOTO DEFAULT SEMICOLON
{
- $$ = new GotoDefault ((Location) $1);
+ $$ = new GotoDefault (GetLocation ($1));
}
;
return_statement
: RETURN opt_expression SEMICOLON
{
- $$ = new Return ((Expression) $2, (Location) $1);
+ $$ = new Return ((Expression) $2, GetLocation ($1));
}
;
throw_statement
: THROW opt_expression SEMICOLON
{
- $$ = new Throw ((Expression) $2, (Location) $1);
+ $$ = new Throw ((Expression) $2, GetLocation ($1));
}
;
yield_statement
: IDENTIFIER RETURN expression SEMICOLON
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
string s = lt.Value;
if (s != "yield"){
Report.Error (1003, lt.Location, "; expected");
}
| IDENTIFIER RETURN SEMICOLON
{
- Report.Error (1627, (Location) $2, "Expression expected after yield return");
+ Report.Error (1627, GetLocation ($2), "Expression expected after yield return");
$$ = null;
}
| IDENTIFIER BREAK SEMICOLON
{
- LocatedToken lt = (LocatedToken) $1;
+ var lt = (Tokenizer.LocatedToken) $1;
string s = lt.Value;
if (s != "yield"){
Report.Error (1003, lt.Location, "; expected");
try_statement
: TRY block catch_clauses
{
- $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
+ $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
}
| TRY block FINALLY block
{
- $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
+ $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
}
| TRY block catch_clauses FINALLY block
{
- $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
+ $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
}
| TRY block error
{
- Report.Error (1524, (Location) $1, "Expected catch or finally");
+ Report.Error (1524, GetLocation ($1), "Expected catch or finally");
$$ = null;
}
;
catch_clauses
: catch_clause
{
- ArrayList l = new ArrayList (4);
+ var l = new List<Catch> (2);
- l.Add ($1);
+ l.Add ((Catch) $1);
$$ = l;
}
| catch_clauses catch_clause
{
- ArrayList l = (ArrayList) $1;
-
- l.Add ($2);
+ var l = (List<Catch>) $1;
+
+ Catch c = (Catch) $2;
+ if (l [0].IsGeneral) {
+ Report.Error (1017, c.loc, "Try statement already has an empty catch block");
+ } else {
+ if (c.IsGeneral)
+ l.Insert (0, c);
+ else
+ l.Add (c);
+ }
+
$$ = l;
}
;
catch_clause
: CATCH opt_catch_args
{
- Expression type = null;
-
if ($2 != null) {
- DictionaryEntry cc = (DictionaryEntry) $2;
- type = (Expression) cc.Key;
- LocatedToken lt = (LocatedToken) cc.Value;
+ var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
+ var lt = cc.Item2;
if (lt != null){
- ArrayList one = new ArrayList (4);
+ List<object> one = new List<object> (1);
one.Add (new VariableDeclaration (lt, null));
start_block (lexer.Location);
- current_block = declare_local_variables (type, one, lt.Location);
+ current_block = declare_local_variables (cc.Item1, one, lt.Location);
}
}
} block {
Block var_block = null;
if ($2 != null){
- DictionaryEntry cc = (DictionaryEntry) $2;
- type = (Expression) cc.Key;
- LocatedToken lt = (LocatedToken) cc.Value;
+ var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
+ type = cc.Item1;
+ var lt = cc.Item2;
if (lt != null){
id = lt.Value;
catch_args
: open_parens_any type opt_identifier CLOSE_PARENS
{
- $$ = new DictionaryEntry ($2, $3);
+ $$ = new Tuple<FullNamedExpression, Tokenizer.LocatedToken> ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3);
}
| open_parens_any CLOSE_PARENS
{
Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
+ $$ = null;
}
;
unsafe_statement
: UNSAFE
{
- RootContext.CheckUnsafeOption ((Location) $1);
+ RootContext.CheckUnsafeOption (GetLocation ($1), Report);
} block {
$$ = new Unsafe ((Block) $3);
}
type_and_void fixed_pointer_declarators
CLOSE_PARENS
{
- ArrayList list = (ArrayList) $4;
- Expression type = (Expression) $3;
- Location l = (Location) $1;
- int top = list.Count;
-
start_block (lexer.Location);
-
- for (int i = 0; i < top; i++){
- Pair p = (Pair) list [i];
- LocalInfo v;
-
- v = current_block.AddVariable (type, (string) p.First, l);
- if (v == null)
- continue;
-
- v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
- v.Pinned = true;
- p.First = v;
- list [i] = p;
- }
}
embedded_statement
{
- Location l = (Location) $1;
-
- Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+ Expression type = (Expression) $3;
+ var list = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $4;
+ Fixed f = new Fixed (type,
+ list.ConvertAll (i => {
+ var v = new KeyValuePair<LocalInfo, Expression> (current_block.AddVariable (type, i.Key.Value, i.Key.Location), i.Value);
+ if (v.Key != null) {
+ v.Key.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
+ v.Key.Pinned = true;
+ }
+ return v;
+ }), (Statement) $7, GetLocation ($1));
current_block.AddStatement (f);
fixed_pointer_declarators
: fixed_pointer_declarator {
- ArrayList declarators = new ArrayList (4);
+ var declarators = new List<KeyValuePair<Tokenizer.LocatedToken, Expression>> (2);
if ($1 != null)
- declarators.Add ($1);
+ declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$1);
$$ = declarators;
}
| fixed_pointer_declarators COMMA fixed_pointer_declarator
{
- ArrayList declarators = (ArrayList) $1;
+ var declarators = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $1;
if ($3 != null)
- declarators.Add ($3);
+ declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$3);
$$ = declarators;
}
;
fixed_pointer_declarator
: IDENTIFIER ASSIGN expression
{
- LocatedToken lt = (LocatedToken) $1;
- // FIXME: keep location
- $$ = new Pair (lt.Value, $3);
+ var lt = (Tokenizer.LocatedToken) $1;
+ $$ = new KeyValuePair<Tokenizer.LocatedToken, Expression> (lt, (Expression) $3);
}
| IDENTIFIER
{
- Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
+ Report.Error (210, ((Tokenizer.LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
$$ = null;
}
;
}
embedded_statement
{
- $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
+ $$ = new Lock ((Expression) $3, (Statement) $6, GetLocation ($1));
}
;
start_block (lexer.Location);
Block assign_block = current_block;
- DictionaryEntry de = (DictionaryEntry) $3;
- Location l = (Location) $1;
-
- Expression type = (Expression) de.Key;
- ArrayList var_declarators = (ArrayList) de.Value;
+ var de = (Tuple<FullNamedExpression, List<object>>) $3;
+ Location l = GetLocation ($1);
- Stack vars = new Stack ();
+ var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
- foreach (VariableDeclaration decl in var_declarators) {
- LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
+ foreach (VariableDeclaration decl in de.Item2) {
+ LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location);
if (vi == null)
continue;
vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
- Expression expr = decl.expression_or_array_initializer;
+ Expression expr = decl.GetInitializer (de.Item1);
if (expr == null) {
Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
continue;
// This is so that it is not a warning on using variables
vi.Used = true;
- vars.Push (new DictionaryEntry (var, expr));
+ vars.Push (new Tuple<LocalVariableReference, Expression> (var, expr));
// Assign a = new SimpleAssign (var, expr, decl.Location);
// assign_block.AddStatement (new StatementExpression (a));
embedded_statement
{
Statement stmt = (Statement) $6;
- Stack vars = (Stack) $5;
- Location l = (Location) $1;
+ var vars = (Stack<Tuple<LocalVariableReference, Expression>>) $5;
+ Location l = GetLocation ($1);
while (vars.Count > 0) {
- DictionaryEntry de = (DictionaryEntry) vars.Pop ();
- stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
+ var de = vars.Pop ();
+ stmt = new Using (de.Item1, de.Item2, stmt, l);
}
current_block.AddStatement (stmt);
$$ = end_block (lexer.Location);
}
embedded_statement
{
- current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
+ current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1)));
$$ = end_block (lexer.Location);
}
;
// LINQ
query_expression
- : first_from_clause query_body
+ : first_from_clause query_body
{
lexer.query_parsing = false;
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
}
+
+ // Bubble up COMPLETE_COMPLETION productions
+ | first_from_clause COMPLETE_COMPLETION {
+ lexer.query_parsing = false;
+ $$ = $1;
+
+ current_block.SetEndLocation (lexer.Location);
+ current_block = current_block.Parent;
+ }
+ | nested_from_clause COMPLETE_COMPLETION {
+ $$ = $1;
+ current_block.SetEndLocation (lexer.Location);
+ current_block = current_block.Parent;
+ }
;
first_from_clause
: FROM_FIRST IDENTIFIER IN expression
{
$$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
+ var lt = (Tokenizer.LocatedToken) $2;
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
}
| FROM_FIRST type IDENTIFIER IN expression
{
+ var lt = (Tokenizer.LocatedToken) $3;
$$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
}
;
: FROM IDENTIFIER IN expression
{
$$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
+ var lt = (Tokenizer.LocatedToken) $2;
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
}
| FROM type IDENTIFIER IN expression
{
$$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
+ var lt = (Tokenizer.LocatedToken) $3;
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
}
;
from_clause
: FROM IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
}
expression
{
- LocatedToken lt = (LocatedToken) $2;
- $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
+ var lt = (Tokenizer.LocatedToken) $2;
+ var sn = new SimpleMemberName (lt.Value, lt.Location);
+ $$ = new Linq.SelectMany (current_block.Toplevel, sn, (Expression)$5);
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
}
| FROM type IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
}
expression
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
+ var sn = new SimpleMemberName (lt.Value, lt.Location);
+
FullNamedExpression type = (FullNamedExpression)$2;
- $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
+ $$ = new Linq.SelectMany (current_block.Toplevel, sn, new Linq.Cast (type, (FullNamedExpression)$6));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
}
;
query_body
- : opt_query_body_clauses select_or_group_clause opt_query_continuation
+ : opt_query_body_clauses select_or_group_clause opt_query_continuation
{
Linq.AQueryClause head = (Linq.AQueryClause)$2;
$$ = head;
}
+ | opt_query_body_clauses COMPLETE_COMPLETION
;
select_or_group_clause
: SELECT
{
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
| GROUP
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Block> ();
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
}
expression
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
BY expression
{
query_body_clause
: from_clause
- | let_clause
+ | let_clause
| where_clause
| join_clause
| orderby_clause
let_clause
: LET IDENTIFIER ASSIGN
{
- current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
}
expression
{
- LocatedToken lt = (LocatedToken) $2;
- $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
+ var lt = (Tokenizer.LocatedToken) $2;
+ var sn = new SimpleMemberName (lt.Value, lt.Location);
+ $$ = new Linq.Let (current_block.Toplevel, current_container, sn, (Expression)$5);
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
}
;
where_clause
: WHERE
{
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
boolean_expression
{
- $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1));
+ $$ = new Linq.Where (current_block.Toplevel, (BooleanExpression)$3, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
: JOIN IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Block> ();
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
}
expression ON
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
}
expression EQUALS
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location);
+ var lt = (Tokenizer.LocatedToken) $2;
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
}
expression opt_join_into
{
- LocatedToken lt = (LocatedToken) $2;
+ var lt = (Tokenizer.LocatedToken) $2;
+ var sn = new SimpleMemberName (lt.Value, lt.Location);
+ SimpleMemberName sn2 = null;
ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
if ($12 == null) {
- $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
+ $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
} else {
- $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
- (LocatedToken) $12, GetLocation ($1));
+ var lt2 = (Tokenizer.LocatedToken) $12;
+ sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
+ $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, current_block.Toplevel,
+ sn2, GetLocation ($1));
}
current_block.AddStatement (new ContextualReturn ((Expression) $11));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- if ($12 == null)
- ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
+ if (sn2 == null)
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
else
- ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12);
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
}
| JOIN type IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Block> ();
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
}
expression ON
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
}
expression EQUALS
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location);
+ var lt = (Tokenizer.LocatedToken) $3;
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
}
expression opt_join_into
{
- LocatedToken lt = (LocatedToken) $3;
+ var lt = (Tokenizer.LocatedToken) $3;
+ var sn = new SimpleMemberName (lt.Value, lt.Location);
+ SimpleMemberName sn2 = null;
ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
if ($13 == null) {
- $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
+ $$ = new Linq.Join (block, sn, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
} else {
- $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
- (LocatedToken) $13, GetLocation ($1));
+ var lt2 = (Tokenizer.LocatedToken) $13;
+ sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
+ $$ = new Linq.GroupJoin (block, sn, cast, outer_selector, current_block.Toplevel,
+ sn2, GetLocation ($1));
}
current_block.AddStatement (new ContextualReturn ((Expression) $12));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- if ($13 == null)
- ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
+ if (sn2 == null)
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
else
- ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13);
+ ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
}
;
orderby_clause
: ORDERBY
{
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
orderings
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
orderings_then_by
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
then_by
{
current_block.SetEndLocation (GetLocation ($1));
current_block = current_block.Parent;
+
+ var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
}
query_body
{
push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
Modifiers.PUBLIC, null), null);
- ArrayList baseclass_list = new ArrayList ();
+ var baseclass_list = new List<FullNamedExpression> ();
baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
current_container.AddBasesForPart (current_class, baseclass_list);
Parameter [] mpar = new Parameter [1];
mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
- ParametersCompiled pars = new ParametersCompiled (mpar);
+ ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
current_local_parameters = pars;
Method method = new Method (
current_class,
// <summary>
// A class used to pass around variable declarations and constants
// </summary>
-public class VariableDeclaration {
+class VariableDeclaration {
public string identifier;
- public Expression expression_or_array_initializer;
+ Expression initializer;
public Location Location;
public Attributes OptAttributes;
public string DocComment;
- public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
+ public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer, Attributes opt_attrs)
{
this.identifier = lt.Value;
- if (eoai is ArrayList) {
- this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
- } else {
- this.expression_or_array_initializer = (Expression)eoai;
- }
+ this.initializer = initializer;
this.Location = lt.Location;
this.OptAttributes = opt_attrs;
}
- public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
+ public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
+ : this (lt, initializer, null)
{
}
+
+ public Expression GetInitializer (FullNamedExpression type)
+ {
+ if (initializer is ArrayInitializer)
+ return new ArrayCreation (type, "", (ArrayInitializer)initializer, Location);
+
+ return initializer;
+ }
+
+ public bool HasInitializer {
+ get { return initializer != null; }
+ }
}
class VariableMemberDeclaration
{
public readonly MemberName MemberName;
- public Expression expression_or_array_initializer;
+ Expression initializer;
- public VariableMemberDeclaration (MemberName mn, object initializer)
+ public VariableMemberDeclaration (MemberName mn, Expression initializer)
{
MemberName = mn;
-
- if (initializer is ArrayList) {
- this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
- } else {
- this.expression_or_array_initializer = (Expression)initializer;
- }
+ this.initializer = initializer;
+ }
+
+ public Expression GetInitializer (FullNamedExpression type)
+ {
+ if (initializer is ArrayInitializer)
+ return new ArrayCreation (type, "", (ArrayInitializer)initializer, MemberName.Location);
+
+ return initializer;
}
}
if (expr is Invocation){
Report.Error (1002, expr.Location, "Expecting `;'");
} else {
- expr.Error_InvalidExpressionStatement ();
+ Expression.Error_InvalidExpressionStatement (Report, expr.Location);
}
}
-static void Error_ParameterModifierNotValid (string modifier, Location loc)
+void Error_ParameterModifierNotValid (string modifier, Location loc)
{
Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
modifier);
}
-static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
+void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
{
Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
Parameter.GetModifierSignature (mod));
}
-static void Error_TypeExpected (Location loc)
+void Error_TypeExpected (Location loc)
{
Report.Error (1031, loc, "Type expected");
}
+void Error_NamedArgumentExpected (NamedArgument a)
+{
+ Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
+}
+
void push_current_class (TypeContainer tc, object partial_token)
{
if (RootContext.EvalMode){
}
}
-Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
+Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
{
Block implicit_block;
- ArrayList inits = null;
//
// If we are doing interactive editing, we want variable declarations
foreach (VariableDeclaration decl in variable_declarators){
// We can not use the super-handy f.Initializer, because
// multiple lines would force code to be executed out of sync
- if (decl.expression_or_array_initializer != null){
+ var init = decl.GetInitializer (type);
+ if (init != null){
string id = "$" + decl.identifier;
- current_block.AddVariable (type, id, decl.Location);
+ LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
+
+ // Avoid warning about this variable not being used.
+ vi.Used = true;
LocalVariableReference var;
- var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
- Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
+ var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
+ Assign assign = new SimpleAssign (var, init, decl.Location);
current_block.AddStatement (new StatementExpression (assign));
assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
current_block.AddStatement (new StatementExpression (assign));
foreach (VariableDeclaration decl in variable_declarators){
if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
- if (decl.expression_or_array_initializer != null){
- if (inits == null)
- inits = new ArrayList (4);
- inits.Add (decl);
- }
- }
- }
-
- if (inits == null)
- return implicit_block;
-
- foreach (VariableDeclaration decl in inits){
- Assign assign;
- Expression expr = decl.expression_or_array_initializer;
-
- LocalVariableReference var;
- var = new LocalVariableReference (implicit_block, decl.identifier, loc);
+ if (decl.HasInitializer){
+ Assign assign;
+
+ var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
- assign = new SimpleAssign (var, expr, decl.Location);
+ assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
- implicit_block.AddStatement (new StatementExpression (assign));
+ implicit_block.AddStatement (new StatementExpression (assign));
+ }
+ }
}
return implicit_block;
}
-Block declare_local_constants (Expression type, ArrayList declarators)
+Block declare_local_constants (FullNamedExpression type, List<object> declarators)
{
Block implicit_block;
implicit_block = current_block;
foreach (VariableDeclaration decl in declarators){
- implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
+ implicit_block.AddConstant (type, decl.identifier, decl.GetInitializer (type), decl.Location);
}
return implicit_block;
Report.Error (1003, l, "Syntax error, " + msg);
}
-void note (string s)
-{
- // Used to put annotations
-}
-
Tokenizer lexer;
public Tokenizer Lexer {
static CSharpParser ()
{
- oob_stack = new Stack ();
+ oob_stack = new Stack<object> ();
}
-public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
{
if (RootContext.EvalMode)
undo = new Undo ();
this.file = file;
+ this.compiler = ctx;
current_namespace = new NamespaceEntry (null, file, null);
current_class = current_namespace.SlaveDeclSpace;
current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
oob_stack.Clear ();
- lexer = new Tokenizer (reader, file);
+ lexer = new Tokenizer (reader, file, ctx);
+
+ use_global_stacks = true;
}
public void parse ()
{
eof_token = Token.EOF;
-
+ Tokenizer.LocatedToken.Initialize ();
+
try {
if (yacc_verbose_flag > 1)
yyparse (lexer, new yydebug.yyDebugSimple ());
else
yyparse (lexer);
+
+ Tokenizer tokenizer = lexer as Tokenizer;
+ tokenizer.cleanup ();
} catch (Exception e){
if (e is yyParser.yyUnexpectedEof)
UnexpectedEOF = true;
- else if (yacc_verbose_flag > 0)
- Console.WriteLine (e);
+
if (e is yyParser.yyException)
Report.Error (-25, lexer.Location, "Parsing error");
+ else if (yacc_verbose_flag > 0)
+ throw; // Used by compiler-tester to test internal errors
else
- Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
+ Report.Error (589, lexer.Location, "Internal compiler error during parsing");
}
- Tokenizer tokenizer = lexer as Tokenizer;
- tokenizer.cleanup ();
if (RootContext.ToplevelTypes.NamespaceEntry != null)
throw new InternalErrorException ("who set it?");
}
-static void CheckToken (int error, int yyToken, string msg, Location loc)
+void CheckToken (int error, int yyToken, string msg, Location loc)
{
if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
Location GetLocation (object obj)
{
- if (obj is MemberCore)
- return ((MemberCore) obj).Location;
+ if (obj is Tokenizer.LocatedToken)
+ return ((Tokenizer.LocatedToken) obj).Location;
if (obj is MemberName)
return ((MemberName) obj).Location;
- if (obj is LocatedToken)
- return ((LocatedToken) obj).Location;
- if (obj is Location)
- return (Location) obj;
+
+// if (obj is Expression)
+// return ((Expression) obj).Location;
+
return lexer.Location;
}
+Report Report {
+ get { return compiler.Report; }
+}
+
void start_block (Location loc)
{
if (current_block == null || parsing_anonymous_method) {
- current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
+ current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, current_generic_method, loc);
parsing_anonymous_method = false;
} else {
current_block = new ExplicitBlock (current_block, loc, Location.Null);
void Error_SyntaxError (int token)
{
- Error_SyntaxError (0, token);
+ Error_SyntaxError (0, token, "Unexpected symbol");
}
-void Error_SyntaxError (int error_code, int token)
+void Error_SyntaxError (int error_code, int token, string msg)
{
string symbol = GetSymbolName (token);
string expecting = GetExpecting ();
}
if (expecting != null)
- Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
- symbol, expecting);
+ Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}",
+ symbol, expecting, msg);
else
- Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
+ Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
}
string GetExpecting ()
{
int [] tokens = yyExpectingTokens (yyExpectingState);
- ArrayList names = new ArrayList (tokens.Length);
+ var names = new List<string> (tokens.Length);
bool has_type = false;
bool has_identifier = false;
for (int i = 0; i < tokens.Length; i++){
sb.Append ("or ");
sb.Append ('`');
sb.Append (names [i]);
- sb.Append (last ? "'" : "', ");
+ sb.Append (last ? "'" : count < 3 ? "' " : "', ");
}
return sb.ToString ();
}
string GetSymbolName (int token)
{
switch (token){
- case Token.LITERAL_FLOAT:
- case Token.LITERAL_INTEGER:
- case Token.LITERAL_DOUBLE:
- case Token.LITERAL_DECIMAL:
- case Token.LITERAL_CHARACTER:
- case Token.LITERAL_STRING:
- return lexer.Value.ToString ();
+ case Token.LITERAL:
+ return ((Constant)lexer.Value).GetValue ().ToString ();
case Token.IDENTIFIER:
- return ((LocatedToken)lexer.Value).Value;
+ return ((Tokenizer.LocatedToken)lexer.Value).Value;
case Token.BOOL:
return "bool";
return "?";
case Token.DOUBLE_COLON:
return "::";
- case Token.LITERAL_FLOAT:
- case Token.LITERAL_INTEGER:
- case Token.LITERAL_DOUBLE:
- case Token.LITERAL_DECIMAL:
- case Token.LITERAL_CHARACTER:
- case Token.LITERAL_STRING:
+ case Token.LITERAL:
return "value";
case Token.IDENTIFIER:
return "identifier";