// 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>
Delegate current_delegate;
- GenericMethod current_generic_method;
AnonymousMethodExpression current_anonymous_method;
/// <summary>
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
//
public Undo undo;
- // Stack<ToplevelBlock>
- Stack linq_clause_blocks;
+ Stack<Linq.QueryBlock> linq_clause_blocks;
// A counter to create new class names in interactive mode
static int class_count;
// share the bucket for very common constructs which can never
// be recursive
//
- static ArrayList parameters_bucket = new ArrayList (6);
- static ArrayList variables_bucket = new ArrayList (6);
+ static List<Parameter> parameters_bucket = new List<Parameter> (6);
+ static List<object> variables_bucket = new List<object> (6);
%}
%token EOF
: 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") {
{
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") {
attribute_list
: attribute
{
- $$ = new ArrayList (4) { $1 };
+ $$ = 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;
}
;
named_argument
- : IDENTIFIER COLON expression
+ : IDENTIFIER COLON opt_named_modifier 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) $3);
- }
- ;
-
+ $$ = 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);
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 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 ((Tokenizer.LocatedToken) $1, $4);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $4);
}
| IDENTIFIER
{
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 ((Tokenizer.LocatedToken) $1, $3);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
}
| IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
{
}
| 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 ((Tokenizer.LocatedToken) $1, $3);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
}
| IDENTIFIER
{
}
| 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 ());
}
- current_generic_method = null;
current_local_parameters = null;
if (RootContext.Documentation != null)
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);
-
- current_generic_method = generic;
+
+ 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 ());
+ }
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
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) {
method = new Method (current_class, generic, TypeManager.system_void_expr,
modifiers, name, current_local_parameters, (Attributes) $1);
- current_generic_method = generic;
-
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
{
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);
formal_parameter_list
: fixed_parameters
{
- ArrayList pars_list = (ArrayList) $1;
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (compiler, 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);
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add ((Parameter) $3);
- $$ = new ParametersCompiled (compiler, 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 (compiler, pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| 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");
-
- ArrayList pars_list = (ArrayList) $1;
- pars_list.Add (new ArglistParameter (GetLocation ($3)));
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
- $$ = new ParametersCompiled (compiler, pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| arglist_modifier COMMA error
{
| fixed_parameters COMMA ARGLIST COMMA error
{
Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
-
- ArrayList pars_list = (ArrayList) $1;
- pars_list.Add (new ArglistParameter (GetLocation ($3)));
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
- $$ = new ParametersCompiled (compiler, pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| parameter_array
{
}
| fixed_parameters COMMA fixed_parameter
{
- ArrayList pars = (ArrayList) $1;
+ var pars = (List<Parameter>) $1;
Parameter p = (Parameter) $3;
if (p != null) {
if (p.HasExtensionMethodModifier)
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, GetLocation ($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;
Report.Error (1007, GetLocation ($3), "Property accessor already defined");
break;
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, GetLocation ($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;
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);
opt_constructor_initializer
{
var lt = (Tokenizer.LocatedToken) $3;
- int mods = (int) $2;
+ 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 ());
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) {
{
MemberName name = (MemberName) $5;
- if (current_container.Kind == Kind.Interface) {
+ 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) {
$$ = null;
else {
Event e = new EventProperty (
- current_class, (FullNamedExpression) $4, (int) $2, name,
+ 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 ();
bool order = accessors != null ? accessors.declared_in_reverse : false;
Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
- (MemberName)$4, (int) $2, (ParametersCompiled) $7, (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)
}
| COLON error
{
- Error_TypeExpected (lexer.Location);
+ Error_TypeExpected (GetLocation ($1));
$$ = TypeManager.system_int32_expr;
}
;
;
opt_enum_member_declarations
- : /* empty */ { $$ = new ArrayList (0); }
+ : /* 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;
}
;
{
--lexer.parsing_block;
VariableDeclaration vd = new VariableDeclaration (
- (Tokenizer.LocatedToken) $2, $5, (Attributes) $1);
+ (Tokenizer.LocatedToken) $2, (Expression) $5, (Attributes) $1);
if (RootContext.Documentation != null)
vd.DocComment = ConsumeStoredComment ();
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) $11);
+ current_delegate.SetParameterInfo ((List<Constraints>) $11);
$$ = current_delegate;
current_delegate = null;
| type_expression rank_specifiers
{
string rank_specifiers = (string) $2;
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+ $$ = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
}
;
$$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
} else {
if (name.Left == null && name.Name == "var")
- $$ = current_array_type = new VarExpr (name.Location);
+ $$ = new VarExpr (name.Location);
else
$$ = name.GetTypeExpression ();
}
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;
}
;
| CHAR { $$ = TypeManager.system_char_expr; }
;
-predefined_type
- : builtin_types
- | VOID
- {
- $$ = TypeManager.system_void_expr;
- }
- ;
-
//
// Expressions, section 7.5
//
| IDENTIFIER opt_type_argument_list
{
var lt = (Tokenizer.LocatedToken) $1;
- $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
+ $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
}
| IDENTIFIER GENERATE_COMPLETION {
var lt = (Tokenizer.LocatedToken) $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
{
var lt = (Tokenizer.LocatedToken) $3;
$$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
}
- | predefined_type DOT IDENTIFIER opt_type_argument_list
+ | builtin_types DOT IDENTIFIER opt_type_argument_list
{
var lt = (Tokenizer.LocatedToken) $3;
// TODO: Location is wrong as some predefined types doesn't hold a location
var lt = (Tokenizer.LocatedToken) $3;
$$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
}
- | predefined_type DOT GENERATE_COMPLETION
+ | builtin_types DOT GENERATE_COMPLETION
{
// TODO: Location is wrong as some predefined types doesn't hold a location
$$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
}
- | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
+ | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
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, (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_list error {
+ Error_SyntaxError (yyToken);
+ $$ = $1;
+ }
;
member_initializer
}
| OPEN_BRACE expression_list CLOSE_BRACE
{
- $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
+ if ($2 == null)
+ $$ = null;
+ else
+ $$ = 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 COMMA
{
Report.Error (839, GetLocation ($2), "An argument is missing");
- $$ = null;
+ $$ = $1;
}
| COMMA argument_or_named_argument
{
Report.Error (839, GetLocation ($1), "An argument is missing");
- $$ = null;
+ $$ = $1;
}
;
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
}
- | ARGLIST open_parens_any argument_list CLOSE_PARENS
+ | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
{
$$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
}
- | ARGLIST open_parens_any CLOSE_PARENS
+ | ARGLIST OPEN_PARENS CLOSE_PARENS
{
$$ = new Argument (new Arglist (GetLocation ($1)));
}
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 error {
+ Error_SyntaxError (yyToken);
+ $$ = $1;
+ }
;
expression_list_arguments
this_access
: THIS
{
- $$ = new This (current_block, GetLocation ($1));
+ $$ = new This (GetLocation ($1));
}
;
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));
}
;
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
{
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
- $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
+ $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayInitializer) $3, GetLocation ($1));
}
| new_expr_start error
{
else if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
- $$ = new NewAnonymousType ((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;
}
;
}
| 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;
}
;
array_initializer
: OPEN_BRACE CLOSE_BRACE
{
- $$ = new ArrayList (0);
+ $$ = 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
$$ = new TypeOfVoid (GetLocation ($1));
else
$$ = new TypeOf (type, GetLocation ($1));
- current_array_type = pushed_current_array_type;
}
;
{
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
{
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
{
{
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
{
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);
}
;
: 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
;
{
$$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
}
- | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
+ | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
{
$$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
}
: 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
{
| 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));
}
;
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");
opt_lambda_parameter_list
: /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
| lambda_parameter_list {
- ArrayList pars_list = (ArrayList) $1;
- $$ = new ParametersCompiled (compiler, (Parameter[])pars_list.ToArray (typeof (Parameter)));
+ var pars_list = (List<Parameter>) $1;
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
;
}
| 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
non_assignment_expression
: conditional_expression
| lambda_expression
- | query_expression
+ | query_expression
;
constant_expression
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;
}
;
;
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 {
+ : WHERE IDENTIFIER COLON type_parameter_constraints
+ {
var lt = (Tokenizer.LocatedToken) $2;
- $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
+ $$ = 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));
}
;
empty_statement
: SEMICOLON
{
- $$ = EmptyStatement.Value;
+ $$ = new EmptyStatement (GetLocation ($1));
}
;
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")
- $$ = current_array_type = new VarExpr (sn.Location);
+ $$ = 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
{
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) {
- if (((VariableDeclaration)((ArrayList)$2) [0]).expression_or_array_initializer == null)
+ if (!((VariableDeclaration) ((List<object>)$2) [0]).HasInitializer)
ve.VariableInitializersCount = 0;
else
- ve.VariableInitializersCount = ((ArrayList)$2).Count;
+ 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;
}
| error
{
Error_SyntaxError (yyToken);
- $$ = null;
+ $$ = new EmptyStatement (GetLocation ($1));
}
;
: IF open_parens_any boolean_expression CLOSE_PARENS
embedded_statement
{
- Location l = GetLocation ($1);
-
- $$ = new If ((BooleanExpression) $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 = GetLocation ($1);
-
- $$ = new If ((BooleanExpression) $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, GetLocation ($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;
}
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_initializer
- : /* empty */ { $$ = EmptyStatement.Value; }
+ : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
| for_initializer
;
;
opt_for_iterator
- : /* empty */ { $$ = EmptyStatement.Value; }
+ : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
| for_iterator
;
try_statement
: TRY block catch_clauses
{
- $$ = new TryCatch ((Block) $2, (ArrayList) $3, GetLocation ($1), false);
+ $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
}
| TRY block FINALLY block
{
}
| TRY block catch_clauses FINALLY block
{
- $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
+ $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
}
| TRY block error
{
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;
+ var l = (List<Catch>) $1;
Catch c = (Catch) $2;
- if (((Catch) l [0]).IsGeneral) {
+ if (l [0].IsGeneral) {
Report.Error (1017, c.loc, "Try statement already has an empty catch block");
} else {
if (c.IsGeneral)
- l.Insert (0, $2);
+ l.Insert (0, c);
else
- l.Add ($2);
+ l.Add (c);
}
$$ = l;
catch_clause
: CATCH opt_catch_args
{
- Expression type = null;
-
if ($2 != null) {
- DictionaryEntry cc = (DictionaryEntry) $2;
- type = (Expression) cc.Key;
- var lt = (Tokenizer.LocatedToken) cc.Value;
+ var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
+ var lt = cc.Item2;
if (lt != null){
- ArrayList one = new ArrayList (2);
+ 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;
- var lt = (Tokenizer.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
{
type_and_void fixed_pointer_declarators
CLOSE_PARENS
{
- ArrayList list = (ArrayList) $4;
- Expression type = (Expression) $3;
- Location l = GetLocation ($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 = GetLocation ($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;
}
;
: IDENTIFIER ASSIGN expression
{
var lt = (Tokenizer.LocatedToken) $1;
- // FIXME: keep location
- $$ = new Pair (lt.Value, $3);
+ $$ = new KeyValuePair<Tokenizer.LocatedToken, Expression> (lt, (Expression) $3);
}
| IDENTIFIER
{
start_block (lexer.Location);
Block assign_block = current_block;
- DictionaryEntry de = (DictionaryEntry) $3;
+ var de = (Tuple<FullNamedExpression, List<object>>) $3;
Location l = GetLocation ($1);
- Expression type = (Expression) de.Key;
- ArrayList var_declarators = (ArrayList) de.Value;
+ var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
- Stack vars = new Stack ();
-
- 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;
+ 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);
// 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));
- var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
}
| FROM_FIRST type IDENTIFIER IN expression
{
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
var lt = (Tokenizer.LocatedToken) $3;
- $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ $$ = new Linq.QueryExpression (
+ new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ }
+ );
}
;
nested_from_clause
: FROM IDENTIFIER IN expression
{
- $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
- var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, 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 (compiler, current_block, lexer.Location);
+
var lt = (Tokenizer.LocatedToken) $3;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ $$ = new Linq.QueryExpression (
+ new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ }
+ );
}
;
from_clause
: FROM IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
var lt = (Tokenizer.LocatedToken) $2;
var sn = new SimpleMemberName (lt.Value, lt.Location);
- $$ = new Linq.SelectMany (current_block.Toplevel, sn, (Expression)$5);
+ $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
}
| FROM type IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
var lt = (Tokenizer.LocatedToken) $3;
var sn = new SimpleMemberName (lt.Value, lt.Location);
- FullNamedExpression type = (FullNamedExpression)$2;
-
- $$ = new Linq.SelectMany (current_block.Toplevel, sn, new Linq.Cast (type, (FullNamedExpression)$6));
+ $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ };
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (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
}
expression
{
- $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
+ $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
| GROUP
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
}
expression
{
}
BY expression
{
- $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
+ $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
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 (compiler, current_block, GetLocation ($1));
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression
{
var lt = (Tokenizer.LocatedToken) $2;
var sn = new SimpleMemberName (lt.Value, lt.Location);
- $$ = new Linq.Let (current_block.Toplevel, current_container, sn, (Expression)$5);
+ $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
}
;
}
boolean_expression
{
- $$ = new Linq.Where (current_block.Toplevel, (BooleanExpression)$3, GetLocation ($1));
+ $$ = new Linq.Where ((Linq.QueryBlock)current_block, (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<Linq.QueryBlock> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression ON
{
current_block = current_block.Parent;
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression EQUALS
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- var lt = (Tokenizer.LocatedToken) $2;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression opt_join_into
{
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 ();
+ var outer_selector = linq_clause_blocks.Pop ();
+ var block = linq_clause_blocks.Pop ();
if ($12 == null) {
- $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
+ $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
} else {
var lt2 = (Tokenizer.LocatedToken) $12;
sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
- $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, current_block.Toplevel,
+ $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block,
sn2, GetLocation ($1));
}
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- if (sn2 == null)
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
- else
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
}
| JOIN type IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression ON
{
current_block = current_block.Parent;
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- linq_clause_blocks.Push (current_block);
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression EQUALS
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- var lt = (Tokenizer.LocatedToken) $3;
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
}
expression opt_join_into
{
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 ();
+ var outer_selector = linq_clause_blocks.Pop ();
+ var block = linq_clause_blocks.Pop ();
- Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
if ($13 == null) {
- $$ = new Linq.Join (block, sn, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
+ $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ };
} else {
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));
+ $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, sn2, GetLocation ($1)) {
+ IdentifierType = (FullNamedExpression)$2
+ };
}
current_block.AddStatement (new ContextualReturn ((Expression) $12));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- if (sn2 == null)
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn);
- else
- ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2);
+ ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
}
;
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
}
then_by
{
- ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
+ ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
$$ = $1;
}
;
order_by
: expression
{
- $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression ASCENDING
{
- $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression DESCENDING
{
- $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
}
;
then_by
: expression
{
- $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression ASCENDING
{
- $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
}
| expression DESCENDING
{
- $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
+ $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
}
;
current_block.SetEndLocation (GetLocation ($1));
current_block = current_block.Parent;
-
- var lt = (Tokenizer.LocatedToken) $2;
+
+ current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
- current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
+ if (linq_clause_blocks == null)
+ linq_clause_blocks = new Stack<Linq.QueryBlock> ();
+
+ linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
query_body
{
- $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
+ var current_block = linq_clause_blocks.Pop ();
+ var lt = (Tokenizer.LocatedToken) $2;
+ $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
+ next = (Linq.AQueryClause)$4
+ };
}
;
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);
// </summary>
class VariableDeclaration {
public string identifier;
- public Expression expression_or_array_initializer;
+ Expression initializer;
public Location Location;
public Attributes OptAttributes;
public string DocComment;
- public VariableDeclaration (Tokenizer.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 (Tokenizer.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;
}
}
}
}
-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;
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;
LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
LocalVariableReference var;
var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
- Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, 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 (decl.HasInitializer){
Assign assign;
- Expression expr = decl.expression_or_array_initializer;
var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
- assign = new SimpleAssign (lvr, expr, decl.Location);
+ assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
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;
static CSharpParser ()
{
- oob_stack = new Stack ();
+ oob_stack = new Stack<object> ();
}
public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
if (obj is MemberName)
return ((MemberName) obj).Location;
+// if (obj is Expression)
+// return ((Expression) obj).Location;
+
return lexer.Location;
}
void start_block (Location loc)
{
if (current_block == null || parsing_anonymous_method) {
- current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, current_generic_method, loc);
+ current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, loc);
parsing_anonymous_method = false;
} else {
current_block = new ExplicitBlock (current_block, loc, Location.Null);
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++){