// 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;
TypeContainer current_container;
DeclSpace current_class;
- IAnonymousHost anonymous_host;
-
/// <summary>
/// Current block is used to add statements as we find
/// them.
Block current_block;
Delegate current_delegate;
-
+
+ GenericMethod current_generic_method;
AnonymousMethodExpression current_anonymous_method;
/// <summary>
/// This is used by the unary_expression code to resolve
/// a name against a parameter.
/// </summary>
+
+ // FIXME: This is very ugly and it's very hard to reset it correctly
+ // on all places, especially when some parameters are autogenerated.
Parameters current_local_parameters;
/// <summary>
/// value parameter that is passed to the "set" and "get"accesor
/// methods (properties and indexers).
/// </summary>
- Expression implicit_value_parameter_type;
+ FullNamedExpression implicit_value_parameter_type;
Parameters indexer_parameters;
/// <summary>
/// Hack to help create non-typed array initializer
/// </summary>
- public static Expression current_array_type;
- Expression pushed_current_array_type;
+ public static FullNamedExpression current_array_type;
+ FullNamedExpression pushed_current_array_type;
/// <summary>
/// Used to determine if we are parsing the get/set pair
///
Stack switch_stack;
+ ///
+ /// Controls the verbosity of the errors produced by the parser
+ ///
static public int yacc_verbose_flag;
- // Name of the file we are parsing
- public string name;
+ ///
+ /// Used by the interactive shell, flags whether EOF was reached
+ /// and an error was produced
+ ///
+ public bool UnexpectedEOF;
///
/// The current file.
///
- SourceFile file;
+ CompilationUnit file;
///
/// Temporary Xml documentation cache.
/// assembly and module attribute definitions are enabled
bool global_attrs_enabled = true;
bool has_get, has_set;
+ bool parameter_modifiers_not_allowed;
+ bool params_modifiers_not_allowed;
+ bool arglist_allowed;
+
+
+ /// When using the interactive parser, this holds the
+ /// resulting expression
+ public object InteractiveResult;
+ //
+ // Keeps track of global data changes to undo on parser error
+ //
+ public Undo undo;
+
+ // A counter to create new class names in interactive mode
+ static int class_count;
%}
%token EOF
%token VIRTUAL
%token VOID
%token VOLATILE
+%token WHERE
%token WHILE
%token ARGLIST
%token PARTIAL
%token ARROW
+%token QUERY_FIRST_TOKEN
+%token FROM
+%token JOIN
+%token ON
+%token EQUALS
+%token SELECT
+%token GROUP
+%token BY
+%token LET
+%token ORDERBY
+%token ASCENDING
+%token DESCENDING
+%token INTO
+%token QUERY_LAST_TOKEN
+%token INTERR_NULLABLE
/* C# keywords which are not really keywords */
-%token GET "get"
-%token SET "set"
+%token GET
+%token SET
%left LAST_KEYWORD
/* C# single character operators/punctuation. */
-%token OPEN_BRACE "{"
-%token CLOSE_BRACE "}"
-%token OPEN_BRACKET "["
-%token CLOSE_BRACKET "]"
-%token OPEN_PARENS "("
-%token CLOSE_PARENS ")"
-%token DOT "."
-%token COMMA ","
-%token COLON ":"
-%token SEMICOLON ";"
-%token TILDE "~"
-
-%token PLUS "+"
-%token MINUS "-"
-%token BANG "!"
-%token ASSIGN "="
-%token OP_LT "<"
-%token OP_GENERICS_LT "<"
-%token OP_GT ">"
-%token OP_GENERICS_GT ">"
-%token BITWISE_AND "&"
-%token BITWISE_OR "|"
-%token STAR "*"
-%token PERCENT "%"
-%token DIV "/"
-%token CARRET "^"
-%token INTERR "?"
+%token OPEN_BRACE
+%token CLOSE_BRACE
+%token OPEN_BRACKET
+%token CLOSE_BRACKET
+%token OPEN_PARENS
+%token CLOSE_PARENS
+%token DOT
+%token COMMA
+%token COLON
+%token SEMICOLON
+%token TILDE
+
+%token PLUS
+%token MINUS
+%token BANG
+%token ASSIGN
+%token OP_LT
+%token OP_GENERICS_LT
+%token OP_GENERICS_LT_DECL
+%token OP_GT
+%token OP_GENERICS_GT
+%token BITWISE_AND
+%token BITWISE_OR
+%token STAR
+%token PERCENT
+%token DIV
+%token CARRET
+%token INTERR
/* C# multi-character operators. */
-%token DOUBLE_COLON "::"
-%token OP_INC "++"
-%token OP_DEC "--"
-%token OP_SHIFT_LEFT "<<"
-%token OP_SHIFT_RIGHT ">>"
-%token OP_LE "<="
-%token OP_GE ">="
-%token OP_EQ "=="
-%token OP_NE "!="
-%token OP_AND "&&"
-%token OP_OR "||"
-%token OP_MULT_ASSIGN "*="
-%token OP_DIV_ASSIGN "/="
-%token OP_MOD_ASSIGN "%="
-%token OP_ADD_ASSIGN "+="
-%token OP_SUB_ASSIGN "-="
-%token OP_SHIFT_LEFT_ASSIGN "<<="
-%token OP_SHIFT_RIGHT_ASSIGN ">>="
-%token OP_AND_ASSIGN "&="
-%token OP_XOR_ASSIGN "^="
-%token OP_OR_ASSIGN "|="
-%token OP_PTR "->"
+%token DOUBLE_COLON
+%token OP_INC
+%token OP_DEC
+%token OP_SHIFT_LEFT
+%token OP_SHIFT_RIGHT
+%token OP_LE
+%token OP_GE
+%token OP_EQ
+%token OP_NE
+%token OP_AND
+%token OP_OR
+%token OP_MULT_ASSIGN
+%token OP_DIV_ASSIGN
+%token OP_MOD_ASSIGN
+%token OP_ADD_ASSIGN
+%token OP_SUB_ASSIGN
+%token OP_SHIFT_LEFT_ASSIGN
+%token OP_SHIFT_RIGHT_ASSIGN
+%token OP_AND_ASSIGN
+%token OP_XOR_ASSIGN
+%token OP_OR_ASSIGN
+%token OP_PTR
+%token OP_COALESCING
/* Numbers */
-%token LITERAL_INTEGER "int literal"
-%token LITERAL_FLOAT "float literal"
-%token LITERAL_DOUBLE "double literal"
-%token LITERAL_DECIMAL "decimal literal"
-%token LITERAL_CHARACTER "character literal"
-%token LITERAL_STRING "string literal"
+%token LITERAL_INTEGER
+%token LITERAL_FLOAT
+%token LITERAL_DOUBLE
+%token LITERAL_DECIMAL
+%token LITERAL_CHARACTER
+%token LITERAL_STRING
%token IDENTIFIER
%token OPEN_PARENS_LAMBDA
%token CLOSE_PARENS_NO_CAST
%token CLOSE_PARENS_OPEN_PARENS
%token CLOSE_PARENS_MINUS
+%token DEFAULT_OPEN_PARENS
+%token GENERIC_DIMENSION
+%token DEFAULT_COLON
+
+// Make the parser go into eval mode parsing (statements and compilation units).
+%token EVAL_STATEMENT_PARSER
+%token EVAL_COMPILATION_UNIT_PARSER
+%token EVAL_USING_DECLARATIONS_UNIT_PARSER
/* Add precedence rules to solve dangling else s/r conflict */
%nonassoc LOWPREC
| outer_declarations global_attributes opt_EOF
| global_attributes opt_EOF
| opt_EOF /* allow empty files */
- ;
-
+ | interactive_parsing opt_EOF
+ ;
+
opt_EOF
: /* empty */
{
;
outer_declarations
- : outer_declaration
- | outer_declarations outer_declaration
- ;
+ : outer_declaration
+ | outer_declarations outer_declaration
+ ;
outer_declaration
: extern_alias_directive
- | using_directive
- | namespace_member_declaration
- ;
+ | using_directive
+ | namespace_member_declaration
+ ;
extern_alias_directives
: extern_alias_directive
- | extern_alias_directives extern_alias_directive;
+ | extern_alias_directives extern_alias_directive
+ ;
extern_alias_directive
: EXTERN IDENTIFIER IDENTIFIER SEMICOLON
Report.FeatureIsNotAvailable (lt.Location, "external alias");
} else {
lt = (LocatedToken) $3;
- current_namespace.UsingExternalAlias (lt.Value, lt.Location);
+ current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
}
}
;
;
using_alias_directive
- : USING IDENTIFIER ASSIGN
- namespace_or_type_name SEMICOLON
+ : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
{
LocatedToken lt = (LocatedToken) $2;
- current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
+ current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
}
| USING error {
CheckIdentifierToken (yyToken, GetLocation ($2));
+ $$ = null;
}
;
using_namespace_directive
: USING namespace_name SEMICOLON
{
- current_namespace.Using ((MemberName) $2, (Location) $1);
- }
+ current_namespace.AddUsing ((MemberName) $2, (Location) $1);
+ }
;
//
// detach them
//
namespace_declaration
- : opt_attributes NAMESPACE namespace_or_type_name
+ : opt_attributes NAMESPACE qualified_identifier
{
MemberName name = (MemberName) $3;
}
;
+qualified_identifier
+ : IDENTIFIER
+ {
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new MemberName (lt.Value, lt.Location);
+ }
+ | qualified_identifier DOT IDENTIFIER
+ {
+ LocatedToken lt = (LocatedToken) $3;
+ $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
+ }
+ | error
+ {
+ syntax_error (lexer.Location, "`.' expected");
+ }
+ ;
+
opt_semicolon
: /* empty */
| SEMICOLON
namespace_name
: namespace_or_type_name
+ {
+ MemberName name = (MemberName) $1;
+
+ if (name.TypeArguments != null)
+ syntax_error (lexer.Location, "namespace name expected");
+
+ $$ = name;
+ }
;
namespace_body
global_attributes
: attribute_sections
-{
- if ($1 != null) {
- Attributes attrs = (Attributes)$1;
- if (global_attrs_enabled) {
- CodeGen.Assembly.AddAttributes (attrs.Attrs);
- } 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");
+ {
+ if ($1 != null) {
+ Attributes attrs = (Attributes)$1;
+ if (global_attrs_enabled) {
+ CodeGen.Assembly.AddAttributes (attrs.Attrs);
+ } 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");
+ }
}
}
- }
-
- $$ = $1;
-}
+ $$ = $1;
+ }
+ ;
opt_attributes
: /* empty */
{
$$ = $3;
}
- | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
+ | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
{
$$ = $2;
}
| RETURN { $$ = "return"; }
| error
{
- string name = yyNames [yyToken].ToLower ();
+ string name = GetTokenName (yyToken);
$$ = CheckAttributeTarget (name, GetLocation ($1));
}
;
;
attribute
- : attribute_name opt_attribute_arguments
+ : attribute_name
+ {
+ ++lexer.parsing_block;
+ }
+ opt_attribute_arguments
{
+ --lexer.parsing_block;
MemberName mname = (MemberName) $1;
- object[] arguments = (object[]) $2;
+ if (mname.IsGeneric) {
+ Report.Error (404, lexer.Location,
+ "'<' unexpected: attributes cannot be generic");
+ }
+
+ object [] arguments = (object []) $3;
MemberName left = mname.Left;
string identifier = mname.Name;
opt_partial
STRUCT
{
+ lexer.ConstraintsParsing = true;
}
- type_name
+ type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
}
opt_class_base
+ opt_type_parameter_constraints_clauses
{
+ lexer.ConstraintsParsing = false;
+
+ current_class.SetParameterInfo ((ArrayList) $9);
+
if (RootContext.Documentation != null)
current_container.DocComment = Lexer.consume_doc_comment ();
}
}
Const c = new Const (
- current_class, (Expression) $4, (string) constant.identifier,
+ current_class, (FullNamedExpression) $4, (string) constant.identifier,
(Expression) constant.expression_or_array_initializer, modflags,
(Attributes) $1, l);
;
constant_declarator
- : IDENTIFIER ASSIGN constant_expression
+ : IDENTIFIER ASSIGN
{
- $$ = new VariableDeclaration ((LocatedToken) $1, $3);
+ ++lexer.parsing_block;
+ }
+ constant_initializer
+ {
+ --lexer.parsing_block;
+ $$ = new VariableDeclaration ((LocatedToken) $1, $4);
}
| IDENTIFIER
{
$$ = null;
}
;
+
+constant_initializer
+ : constant_expression
+ | array_initializer
+ ;
field_declaration
: opt_attributes
opt_modifiers
- type
+ member_type
variable_declarators
SEMICOLON
{
- Expression type = (Expression) $3;
+ FullNamedExpression type = (FullNamedExpression) $3;
+ if (type == TypeManager.system_void_expr)
+ Report.Error (670, GetLocation ($3), "Fields cannot have void type");
+
int mod = (int) $2;
current_array_type = null;
- foreach (VariableDeclaration var in (ArrayList) $4){
- Field field = new Field (current_class, type, mod, var.identifier,
- (Attributes) $1, var.Location);
+ foreach (VariableMemberDeclaration var in (ArrayList) $4){
+ Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
field.Initializer = var.expression_or_array_initializer;
| opt_attributes
opt_modifiers
FIXED
- type
+ member_type
fixed_variable_declarators
SEMICOLON
{
- Expression type = (Expression) $4;
+ FullNamedExpression type = (FullNamedExpression) $4;
+
int mod = (int) $2;
current_array_type = null;
| opt_attributes
opt_modifiers
FIXED
- type
+ member_type
error
{
Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
}
- | opt_attributes
- opt_modifiers
- VOID
- variable_declarators
- SEMICOLON {
- current_array_type = null;
- Report.Error (670, (Location) $3, "Fields cannot have void type");
- }
;
fixed_variable_declarators
$$ = new VariableDeclaration ((LocatedToken) $1, null);
}
;
-
-variable_declarators
- : variable_declarator
+
+
+local_variable_declarators
+ : local_variable_declarator
{
ArrayList decl = new ArrayList (4);
if ($1 != null)
decl.Add ($1);
$$ = decl;
}
- | variable_declarators COMMA variable_declarator
+ | local_variable_declarators COMMA local_variable_declarator
{
ArrayList decls = (ArrayList) $1;
decls.Add ($3);
$$ = $1;
}
;
-
-variable_declarator
- : IDENTIFIER ASSIGN variable_initializer
+
+local_variable_declarator
+ : IDENTIFIER ASSIGN local_variable_initializer
{
$$ = new VariableDeclaration ((LocatedToken) $1, $3);
}
}
;
-variable_initializer
+local_variable_initializer
: expression
- {
- $$ = $1;
- }
| array_initializer
- {
- $$ = $1;
- }
- | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
+ | STACKALLOC type_expression OPEN_BRACKET expression CLOSE_BRACKET
{
$$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
}
}
;
+
+variable_declarators
+ : variable_declarator
+ {
+ ArrayList decl = new ArrayList (4);
+ if ($1 != null)
+ decl.Add ($1);
+ $$ = decl;
+ }
+ | variable_declarators COMMA variable_declarator
+ {
+ ArrayList decls = (ArrayList) $1;
+ decls.Add ($3);
+ $$ = $1;
+ }
+ ;
+
+variable_declarator
+ : member_declaration_name ASSIGN
+ {
+ ++lexer.parsing_block;
+ lexer.parsing_generic_declaration = false;
+ }
+ variable_initializer
+ {
+ --lexer.parsing_block;
+ $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
+ }
+ | member_declaration_name
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = new VariableMemberDeclaration ((MemberName) $1, null);
+ }
+ | member_declaration_name OPEN_BRACKET opt_expression CLOSE_BRACKET
+ {
+ lexer.parsing_generic_declaration = false;
+ Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
+ "To declare a fixed size buffer field, use the fixed keyword before the field type");
+ $$ = null;
+ }
+ ;
+
+variable_initializer
+ : expression
+ | array_initializer
+ ;
+
method_declaration
: method_header {
- anonymous_host = (IAnonymousHost) $1;
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.NotAllowed;
}
Method method = (Method) $1;
method.Block = (ToplevelBlock) $3;
current_container.AddMethod (method);
+
+ if (current_container.Kind == Kind.Interface && method.Block != null) {
+ Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
+ }
- anonymous_host = null;
+ current_generic_method = null;
current_local_parameters = null;
if (RootContext.Documentation != null)
}
;
-opt_error_modifier
- : /* empty */
- | modifiers
- {
- int m = (int) $1;
- int i = 1;
-
- while (m != 0){
- if ((i & m) != 0){
- Report.Error (1585, lexer.Location,
- "Member modifier `{0}' must precede the member type and name",
- Modifiers.Name (i));
- }
- m &= ~i;
- i = i << 1;
- }
- }
- ;
-
- //
- // This rule is used to handle the cases where OPEN_PARENS_LAMBDA
- // is returned (type followed by an identifier), these are the
- // declarations (methods, overloads, constructors, etc) and a handful
- // of expressions ("using", "fixed") or "catch".
- //
-open_parens
- : OPEN_PARENS
- | OPEN_PARENS_LAMBDA
- ;
-
method_header
: opt_attributes
opt_modifiers
- type namespace_or_type_name
- open_parens opt_formal_parameter_list CLOSE_PARENS
+ member_type
+ method_declaration_name OPEN_PARENS
+ {
+ arglist_allowed = true;
+ }
+ opt_formal_parameter_list CLOSE_PARENS
+ {
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
{
+ lexer.ConstraintsParsing = false;
+ arglist_allowed = false;
MemberName name = (MemberName) $4;
+ current_local_parameters = (Parameters) $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);
- Method method = new Method (current_class, null, (Expression) $3, (int) $2,
- false, name, (Parameters) $6, (Attributes) $1);
+ generic.SetParameterInfo ((ArrayList) $10);
+ }
+
+ method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
+ name, current_local_parameters, (Attributes) $1);
- anonymous_host = method;
- current_local_parameters = (Parameters) $6;
+ current_generic_method = generic;
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
}
| opt_attributes
opt_modifiers
- VOID namespace_or_type_name
- open_parens opt_formal_parameter_list CLOSE_PARENS
+ PARTIAL
+ VOID method_declaration_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
- MemberName name = (MemberName) $4;
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
- Method method = new Method (current_class, null, TypeManager.system_void_expr,
- (int) $2, false, name, (Parameters) $6,
- (Attributes) $1);
+ MemberName name = (MemberName) $5;
+ current_local_parameters = (Parameters) $7;
+
+ if ($9 != 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,
+ TypeManager.system_void_expr, current_local_parameters);
+
+ generic.SetParameterInfo ((ArrayList) $10);
+ }
+
+ int modifiers = (int) $2;
+
+
+ const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
+ Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
+
+ if ((modifiers & invalid_partial_mod) != 0) {
+ Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
+ "any of abstract, extern, new, override, sealed, or virtual modifiers");
+ modifiers &= ~invalid_partial_mod;
+ }
+
+ if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
+ Report.Error (751, name.Location, "A partial method must be declared within a " +
+ "partial class or partial struct");
+ }
+
+ modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
+
+ method = new Method (current_class, generic, TypeManager.system_void_expr,
+ modifiers, name, current_local_parameters, (Attributes) $1);
- anonymous_host = method;
- current_local_parameters = (Parameters) $6;
+ current_generic_method = generic;
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
}
| opt_attributes
opt_modifiers
- type
- modifiers namespace_or_type_name open_parens opt_formal_parameter_list CLOSE_PARENS
+ member_type
+ modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
MemberName name = (MemberName) $5;
Report.Error (1585, name.Location,
"Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
Method method = new Method (current_class, null, TypeManager.system_void_expr,
- 0, false, name, (Parameters) $7, (Attributes) $1);
+ 0, name, (Parameters) $7, (Attributes) $1);
current_local_parameters = (Parameters) $7;
: /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
| formal_parameter_list
;
+
+opt_parameter_list_no_mod
+ : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
+ |
+ {
+ parameter_modifiers_not_allowed = true;
+ }
+ formal_parameter_list
+ {
+ parameter_modifiers_not_allowed = false;
+ $$ = $2;
+ }
+ ;
formal_parameter_list
: fixed_parameters
$$ = new Parameters (pars);
}
- | fixed_parameters COMMA ARGLIST
+ | fixed_parameters COMMA arglist_modifier
{
ArrayList pars_list = (ArrayList) $1;
- //pars_list.Add (new ArglistParameter (GetLocation ($3)));
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
Parameter [] pars = new Parameter [pars_list.Count];
pars_list.CopyTo (pars);
Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
$$ = null;
}
- | ARGLIST COMMA error
+ | arglist_modifier COMMA error
{
Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
$$ = null;
{
$$ = new Parameters (new Parameter[] { (Parameter) $1 } );
}
- | ARGLIST
+ | arglist_modifier
{
- $$ = new Parameters (new Parameter[0], true);
+ $$ = new Parameters (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
}
;
| fixed_parameters COMMA fixed_parameter
{
ArrayList pars = (ArrayList) $1;
-
- pars.Add ($3);
+ Parameter p = (Parameter)$3;
+ if (p != null) {
+ if (p.HasExtensionMethodModifier)
+ Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
+ pars.Add (p);
+ }
$$ = $1;
}
;
IDENTIFIER
{
LocatedToken lt = (LocatedToken) $4;
- $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
+ $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
}
| opt_attributes
opt_parameter_modifier
if (((Parameter.Modifier)$1 & p2) == p2) {
Error_DuplicateParameterModifier (lexer.Location, p2);
} else {
- Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
+ switch (mod & ~Parameter.Modifier.This) {
+ case Parameter.Modifier.REF:
+ Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
+ break;
+ case Parameter.Modifier.OUT:
+ Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
+ break;
+ default:
+ Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
+ break;
+ }
}
$$ = mod;
}
;
parameter_modifier
- : REF { $$ = Parameter.Modifier.REF; }
- | OUT { $$ = Parameter.Modifier.OUT; }
- | THIS { $$ = Parameter.Modifier.This; }
+ : REF
+ {
+ if (parameter_modifiers_not_allowed)
+ Error_ParameterModifierNotValid ("ref", (Location)$1);
+
+ $$ = Parameter.Modifier.REF;
+ }
+ | OUT
+ {
+ if (parameter_modifiers_not_allowed)
+ Error_ParameterModifierNotValid ("out", (Location)$1);
+
+ $$ = Parameter.Modifier.OUT;
+ }
+ | THIS
+ {
+ if (parameter_modifiers_not_allowed)
+ Error_ParameterModifierNotValid ("this", (Location)$1);
+
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
+
+ $$ = Parameter.Modifier.This;
+ }
;
parameter_array
- : opt_attributes PARAMS type IDENTIFIER
+ : opt_attributes params_modifier type IDENTIFIER
{
LocatedToken lt = (LocatedToken) $4;
- $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
+ $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
}
- | opt_attributes PARAMS PARAMS type IDENTIFIER
- {
- Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
+ | opt_attributes params_modifier type error {
+ CheckIdentifierToken (yyToken, GetLocation ($4));
$$ = null;
}
- | opt_attributes PARAMS parameter_modifier type IDENTIFIER
+ ;
+
+params_modifier
+ : PARAMS
+ {
+ if (params_modifiers_not_allowed)
+ Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
+ }
+ | PARAMS parameter_modifier
{
- Parameter.Modifier mod = (Parameter.Modifier)$3;
+ Parameter.Modifier mod = (Parameter.Modifier)$2;
if ((mod & Parameter.Modifier.This) != 0) {
- Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
+ Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
} else {
- Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
- }
- $$ = null;
+ Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
+ }
}
- | opt_attributes PARAMS type error {
- CheckIdentifierToken (yyToken, GetLocation ($4));
- $$ = null;
+ | PARAMS params_modifier
+ {
+ Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
}
;
-
+
+arglist_modifier
+ : ARGLIST
+ {
+ if (!arglist_allowed)
+ Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
+ }
+ ;
+
property_declaration
: opt_attributes
opt_modifiers
- type
- namespace_or_type_name
+ member_type
+ member_declaration_name
{
if (RootContext.Documentation != null)
tmpComment = Lexer.consume_doc_comment ();
}
OPEN_BRACE
{
- implicit_value_parameter_type = (Expression) $3;
-
+ implicit_value_parameter_type = (FullNamedExpression) $3;
lexer.PropertyParsing = true;
}
accessor_declarations
}
CLOSE_BRACE
{
- if ($8 == null)
- break;
-
Property prop;
Accessors accessors = (Accessors) $8;
- Accessor get_block = accessors.get_or_add;
- Accessor set_block = accessors.set_or_remove;
+ 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;
MemberName name = (MemberName) $4;
+ FullNamedExpression ptype = (FullNamedExpression) $3;
+
+ prop = new Property (current_class, ptype, (int) $2,
+ name, (Attributes) $1, get_block, set_block, order, current_block);
+
+ if (ptype == TypeManager.system_void_expr)
+ Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
+
+ 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 (prop.Get.Block != null)
+ Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
+
+ if (prop.Set.Block != null)
+ Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
+ }
- prop = new Property (current_class, (Expression) $3, (int) $2,
- false, name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse);
-
current_container.AddProperty (prop);
implicit_value_parameter_type = null;
else
current_local_parameters = indexer_parameters;
lexer.PropertyParsing = false;
-
- anonymous_host = SimpleAnonymousHost.GetSimple ();
}
- accessor_body
+ accessor_body
{
if (has_get) {
Report.Error (1007, (Location) $3, "Property accessor already defined");
break;
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
+ Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
has_get = true;
current_local_parameters = null;
lexer.PropertyParsing = true;
- SimpleAnonymousHost.Simple.Propagate (accessor);
- anonymous_host = null;
-
if (RootContext.Documentation != null)
if (Lexer.doc_state == XmlCommentState.Error)
Lexer.doc_state = XmlCommentState.NotAllowed;
set_accessor_declaration
: opt_attributes opt_modifiers SET
{
- Parameter [] args;
Parameter implicit_value_parameter = new Parameter (
implicit_value_parameter_type, "value",
Parameter.Modifier.NONE, null, (Location) $3);
- if (parsing_indexer == false) {
- args = new Parameter [1];
- args [0] = implicit_value_parameter;
- current_local_parameters = new Parameters (args);
+ if (!parsing_indexer) {
+ current_local_parameters = new Parameters (new Parameter [] { implicit_value_parameter });
} else {
- Parameter [] fpars = indexer_parameters.FixedParameters;
-
- if (fpars != null){
- int count = fpars.Length;
-
- args = new Parameter [count + 1];
- fpars.CopyTo (args, 0);
- args [count] = implicit_value_parameter;
- } else
- args = null;
- current_local_parameters = new Parameters (
- args);
+ current_local_parameters = Parameters.MergeGenerated (
+ indexer_parameters, true, implicit_value_parameter, null);
}
lexer.PropertyParsing = false;
-
- anonymous_host = SimpleAnonymousHost.GetSimple ();
}
accessor_body
{
Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
break;
}
- Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
+ Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
has_set = true;
current_local_parameters = null;
lexer.PropertyParsing = true;
- SimpleAnonymousHost.Simple.Propagate (accessor);
- anonymous_host = null;
-
if (RootContext.Documentation != null
&& Lexer.doc_state == XmlCommentState.Error)
Lexer.doc_state = XmlCommentState.NotAllowed;
opt_partial
INTERFACE
{
+ lexer.ConstraintsParsing = true;
}
- type_name
+ type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
}
opt_class_base
+ opt_type_parameter_constraints_clauses
{
+ lexer.ConstraintsParsing = false;
+
+ current_class.SetParameterInfo ((ArrayList) $9);
+
if (RootContext.Documentation != null) {
current_container.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
;
interface_member_declaration
- : interface_method_declaration
- {
- if ($1 == null)
- break;
-
- Method m = (Method) $1;
-
- if (m.IsExplicitImpl)
- Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
- m.GetSignatureForError ());
-
- current_container.AddMethod (m);
-
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
+ : constant_declaration
+ {
+ Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
}
- | interface_property_declaration
- {
- if ($1 == null)
- break;
-
- Property p = (Property) $1;
-
- if (p.IsExplicitImpl)
- Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
- p.GetSignatureForError ());
-
- current_container.AddProperty (p);
-
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
+ | field_declaration
+ {
+ Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
}
- | interface_event_declaration
- {
- if ($1 != null){
- Event e = (Event) $1;
-
- if (e.IsExplicitImpl)
- Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
- e.GetSignatureForError ());
-
- current_container.AddEvent (e);
- }
-
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- | interface_indexer_declaration
- {
- if ($1 == null)
- break;
-
- Indexer i = (Indexer) $1;
-
- if (i.IsExplicitImpl)
- Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
- i.GetSignatureForError ());
-
- current_container.AddIndexer (i);
-
- if (RootContext.Documentation != null)
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- | delegate_declaration
- {
- if ($1 != null) {
- Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
- ((MemberCore)$1).GetSignatureForError ());
- }
- }
- | class_declaration
- {
- if ($1 != null) {
- Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
- ((MemberCore)$1).GetSignatureForError ());
- }
- }
- | struct_declaration
- {
- if ($1 != null) {
- Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
- ((MemberCore)$1).GetSignatureForError ());
- }
- }
- | enum_declaration
- {
- if ($1 != null) {
- Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
- ((MemberCore)$1).GetSignatureForError ());
- }
- }
- | interface_declaration
- {
- if ($1 != null) {
- Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
- ((MemberCore)$1).GetSignatureForError ());
- }
- }
- | constant_declaration
- {
- Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
- }
- ;
-
-opt_new
- : opt_modifiers
- {
- int val = (int) $1;
- val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
- $$ = val;
- }
- ;
-
-interface_method_declaration
- : opt_attributes opt_new type namespace_or_type_name
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
- SEMICOLON
- {
- $$ = new Method (current_class, null, (Expression) $3, (int) $2, true,
- (MemberName) $4, (Parameters) $6, (Attributes) $1);
- if (RootContext.Documentation != null)
- ((Method) $$).DocComment = Lexer.consume_doc_comment ();
- }
- | opt_attributes opt_new type namespace_or_type_name
- OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
- OPEN_BRACE opt_statement_list CLOSE_BRACE
- {
- $$ = new Method (current_class, null, (Expression) $3, (int) $2, true,
- (MemberName) $4, (Parameters) $6, (Attributes) $1);
-
- Report.Error (531, lexer.Location, "`{0}': interface members cannot have a definition",
- ((Method)$$).GetSignatureForError ());
- }
- ;
-
-interface_property_declaration
- : opt_attributes
- opt_new
- type IDENTIFIER
- OPEN_BRACE
- {
- lexer.PropertyParsing = true;
- implicit_value_parameter_type = (Expression)$3;
- }
- accessor_declarations
- {
- has_get = has_set = false;
- lexer.PropertyParsing = false;
- implicit_value_parameter_type = null;
- }
- CLOSE_BRACE
- {
- LocatedToken lt = (LocatedToken) $4;
- MemberName name = new MemberName (lt.Value, lt.Location);
-
- if ($3 == TypeManager.system_void_expr) {
- Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
- break;
- }
-
- Property p = null;
- if ($7 == null) {
- p = new Property (current_class, (Expression) $3, (int) $2, true,
- name, (Attributes) $1,
- null, null, false);
-
- Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
- break;
- }
-
- Accessors accessor = (Accessors) $7;
- p = new Property (current_class, (Expression) $3, (int) $2, true,
- name, (Attributes) $1,
- accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
-
- if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
- Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
- $$ = null;
- break;
- }
-
- if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
- Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
- $$ = null;
- break;
- }
-
- if (RootContext.Documentation != null)
- p.DocComment = Lexer.consume_doc_comment ();
-
- $$ = p;
- }
- | opt_attributes
- opt_new
- type error {
- CheckIdentifierToken (yyToken, GetLocation ($4));
- $$ = null;
- }
- ;
-
-
-interface_event_declaration
- : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
+ | method_declaration
+ | property_declaration
+ | event_declaration
+ | indexer_declaration
+ | operator_declaration
{
- LocatedToken lt = (LocatedToken) $5;
- $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
- new MemberName (lt.Value, lt.Location),
- (Attributes) $1);
- if (RootContext.Documentation != null)
- ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
+ Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
}
- | opt_attributes opt_new EVENT type error {
- CheckIdentifierToken (yyToken, GetLocation ($5));
- $$ = null;
- }
- | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
- LocatedToken lt = (LocatedToken) $5;
- Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
- $$ = null;
- }
- | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
+ | constructor_declaration
{
- implicit_value_parameter_type = (Expression) $4;
- lexer.EventParsing = true;
+ Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
}
- event_accessor_declarations
+ | type_declaration
{
- lexer.EventParsing = false;
- implicit_value_parameter_type = null;
- }
- CLOSE_BRACE {
- Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
- $$ = null;
- }
- ;
-
-interface_indexer_declaration
- : opt_attributes opt_new type THIS
- OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
- OPEN_BRACE
- {
- lexer.PropertyParsing = true;
- implicit_value_parameter_type = (Expression)$3;
- }
- accessor_declarations
- {
- has_get = has_set = false;
- lexer.PropertyParsing = false;
- implicit_value_parameter_type = null;
- }
- CLOSE_BRACE
- {
- Indexer i = null;
- if ($10 == null) {
- i = new Indexer (current_class, (Expression) $3,
- new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
- (int) $2, true, (Parameters) $6, (Attributes) $1,
- null, null, false);
-
- Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
- break;
- }
-
- Accessors accessors = (Accessors) $10;
- i = new Indexer (current_class, (Expression) $3,
- new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
- (int) $2, true, (Parameters) $6, (Attributes) $1,
- accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
-
- if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
- Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
- $$ = null;
- break;
- }
-
- if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
- Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
- $$ = null;
- break;
- }
-
- if (RootContext.Documentation != null)
- i.DocComment = ConsumeStoredComment ();
-
- $$ = i;
+ Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
}
;
operator_declaration
: opt_attributes opt_modifiers operator_declarator
{
- anonymous_host = SimpleAnonymousHost.GetSimple ();
}
operator_body
{
break;
OperatorDeclaration decl = (OperatorDeclaration) $3;
-
- Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
-
- param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
- if (decl.arg2type != null)
- param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
-
Operator op = new Operator (
current_class, decl.optype, decl.ret_type, (int) $2,
- new Parameters (param_list),
+ current_local_parameters,
(ToplevelBlock) $5, (Attributes) $1, decl.location);
if (RootContext.Documentation != null) {
Lexer.doc_state = XmlCommentState.Allowed;
}
- SimpleAnonymousHost.Simple.Propagate (op);
- anonymous_host = null;
-
// Note again, checking is done in semantic analysis
current_container.AddOperator (op);
: block
| SEMICOLON { $$ = null; }
;
-operator_declarator
- : type OPERATOR overloadable_operator
- open_parens opt_attributes opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
- {
- // TODO: wrong location
- if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE)
- Error_ParameterModifierNotValid ((Location) $2);
-
- LocatedToken lt = (LocatedToken) $8;
- Operator.OpType op = (Operator.OpType) $3;
- CheckUnaryOperator (op, lt.Location);
-
- if (op == Operator.OpType.Addition)
- op = Operator.OpType.UnaryPlus;
- if (op == Operator.OpType.Subtraction)
- op = Operator.OpType.UnaryNegation;
-
- Parameter [] pars = new Parameter [1];
- Expression type = (Expression) $7;
-
- pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, (Attributes) $5, lt.Location);
+operator_type
+ : type_expression_or_array
+ | VOID
+ {
+ Report.Error (590, lexer.Location, "User-defined operators cannot return void");
+ $$ = TypeManager.system_void_expr;
+ }
+ ;
- current_local_parameters = new Parameters (pars);
+operator_declarator
+ : operator_type OPERATOR overloadable_operator OPEN_PARENS
+ {
+ params_modifiers_not_allowed = true;
+ }
+ opt_parameter_list_no_mod CLOSE_PARENS
+ {
+ params_modifiers_not_allowed = false;
+ Location loc = (Location) $2;
+ Operator.OpType op = (Operator.OpType) $3;
+ current_local_parameters = (Parameters)$6;
+
+ int p_count = current_local_parameters.Count;
+ if (p_count == 1) {
+ if (op == Operator.OpType.Addition)
+ op = Operator.OpType.UnaryPlus;
+ else if (op == Operator.OpType.Subtraction)
+ op = Operator.OpType.UnaryNegation;
+ }
+
+ if (IsUnaryOperator (op)) {
+ if (p_count == 2) {
+ Report.Error (1020, loc, "Overloadable binary operator expected");
+ } else if (p_count != 1) {
+ Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
+ Operator.GetName (op));
+ }
+ } else {
+ if (p_count > 2) {
+ Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
+ Operator.GetName (op));
+ } else if (p_count != 2) {
+ Report.Error (1019, loc, "Overloadable unary operator expected");
+ }
+ }
+
if (RootContext.Documentation != null) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
- $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
- null, null, (Location) $2);
+ $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
}
- | type OPERATOR overloadable_operator
- open_parens
- opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
- opt_attributes opt_parameter_modifier type IDENTIFIER
- CLOSE_PARENS
- {
- // TODO: wrong location
- if ((Parameter.Modifier)$6 != Parameter.Modifier.NONE || (Parameter.Modifier)$11 != Parameter.Modifier.NONE)
- Error_ParameterModifierNotValid ((Location) $2);
-
- LocatedToken ltParam1 = (LocatedToken) $8;
- LocatedToken ltParam2 = (LocatedToken) $13;
- CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
-
- Parameter [] pars = new Parameter [2];
-
- Expression typeL = (Expression) $7;
- Expression typeR = (Expression) $12;
-
- pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, (Attributes) $5, ltParam1.Location);
- pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, (Attributes) $10, ltParam2.Location);
-
- current_local_parameters = new Parameters (pars);
-
- if (RootContext.Documentation != null) {
- tmpComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.NotAllowed;
- }
-
- $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
- typeL, ltParam1.Value,
- typeR, ltParam2.Value, (Location) $2);
- }
| conversion_operator_declarator
- | type OPERATOR overloadable_operator
- open_parens
- opt_attributes opt_parameter_modifier type IDENTIFIER COMMA
- opt_attributes opt_parameter_modifier type IDENTIFIER COMMA error
- {
- Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
- Operator.GetName ((Operator.OpType) $3));
- $$ = null;
- }
- | type OPERATOR overloadable_operator
- open_parens CLOSE_PARENS
- {
- Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
- Operator.GetName ((Operator.OpType) $3));
- $$ = null;
- }
;
overloadable_operator
;
conversion_operator_declarator
- : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
+ : IMPLICIT OPERATOR type OPEN_PARENS
{
- // TODO: wrong location
- if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
- Error_ParameterModifierNotValid (GetLocation ($4));
-
- LocatedToken lt = (LocatedToken) $7;
- Parameter [] pars = new Parameter [1];
-
- pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
+ params_modifiers_not_allowed = true;
+ }
+ opt_parameter_list_no_mod CLOSE_PARENS
+ {
+ params_modifiers_not_allowed = false;
- current_local_parameters = new Parameters (pars);
+ Location loc = (Location) $2;
+ current_local_parameters = (Parameters)$6;
if (RootContext.Documentation != null) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
- $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
- null, null, (Location) $2);
+ $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
}
- | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
+ | EXPLICIT OPERATOR type OPEN_PARENS
{
- // TODO: wrong location
- if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
- Error_ParameterModifierNotValid (GetLocation ($4));
-
- LocatedToken lt = (LocatedToken) $7;
- Parameter [] pars = new Parameter [1];
-
- pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
-
- current_local_parameters = new Parameters (pars);
+ params_modifiers_not_allowed = true;
+ }
+ opt_parameter_list_no_mod CLOSE_PARENS
+ {
+ params_modifiers_not_allowed = false;
+
+ Location loc = (Location) $2;
+ current_local_parameters = (Parameters)$6;
if (RootContext.Documentation != null) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
- $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
- null, null, (Location) $2);
+ $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
}
| IMPLICIT error
{
;
constructor_declaration
- : opt_attributes
- opt_modifiers
- constructor_declarator
+ : constructor_declarator
constructor_body
{
- Constructor c = (Constructor) $3;
- c.Block = (ToplevelBlock) $4;
- c.OptAttributes = (Attributes) $1;
- int yield_method = c.ModFlags & Modifiers.METHOD_YIELDS;
- c.ModFlags = (int) $2;
-
+ Constructor c = (Constructor) $1;
+ c.Block = (ToplevelBlock) $2;
+
if (RootContext.Documentation != null)
c.DocComment = ConsumeStoredComment ();
- if (c.Name == current_container.Basename){
- if ((c.ModFlags & Modifiers.STATIC) != 0){
- if ((c.ModFlags & Modifiers.Accessibility) != 0){
- Report.Error (515, c.Location,
- "`{0}': access modifiers are not allowed on static constructors",
- c.GetSignatureForError ());
- }
-
- c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
-
- if (c.Initializer != null){
- Report.Error (514, c.Location,
- "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
- c.GetSignatureForError ());
- }
- } else {
- c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
- }
- } else {
- // We let another layer check the validity of the constructor.
- //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
- }
-
- c.ModFlags |= yield_method;
current_container.AddConstructor (c);
current_local_parameters = null;
;
constructor_declarator
- : constructor_header
- {
- $$ = $1;
- }
- | constructor_header constructor_initializer
- {
- ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
- $$ = $1;
- }
- ;
-
-constructor_header
- : IDENTIFIER
+ : opt_attributes
+ opt_modifiers
+ IDENTIFIER
{
if (RootContext.Documentation != null) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
}
- open_parens opt_formal_parameter_list CLOSE_PARENS
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
- LocatedToken lt = (LocatedToken) $1;
- current_local_parameters = (Parameters) $4;
- current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
-
- $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
- null, lt.Location);
+ current_local_parameters = (Parameters) $6;
+
+ //
+ // start block here, so possible anonymous methods inside
+ // constructor initializer can get correct parent block
+ //
+ start_block (lexer.Location);
+ }
+ opt_constructor_initializer
+ {
+ LocatedToken lt = (LocatedToken) $3;
+ int mods = (int) $2;
+ ConstructorInitializer ci = (ConstructorInitializer) $9;
- anonymous_host = (IAnonymousHost) $$;
+ Constructor c = new Constructor (current_class, lt.Value, mods,
+ (Attributes) $1, current_local_parameters, ci, lt.Location);
+
+ 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){
+ Report.Error (515, c.Location,
+ "`{0}': static constructor cannot have an access modifier",
+ c.GetSignatureForError ());
+ }
+ if (ci != null) {
+ Report.Error (514, c.Location,
+ "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
+ c.GetSignatureForError ());
+
+ }
+ }
+
+ $$ = c;
}
;
| SEMICOLON { current_block = null; $$ = null; }
;
+opt_constructor_initializer
+ : /* Empty */
+ | constructor_initializer
+ ;
+
constructor_initializer
- : COLON BASE open_parens opt_argument_list CLOSE_PARENS
+ : COLON BASE OPEN_PARENS
{
- $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
+ ++lexer.parsing_block;
}
- | COLON THIS open_parens opt_argument_list CLOSE_PARENS
+ opt_argument_list CLOSE_PARENS
{
- $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
+ --lexer.parsing_block;
+ $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
+ }
+ | COLON THIS OPEN_PARENS
+ {
+ ++lexer.parsing_block;
+ }
+ opt_argument_list CLOSE_PARENS
+ {
+ --lexer.parsing_block;
+ $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
}
| COLON error {
Report.Error (1018, (Location) $1, "Keyword this or base expected");
}
;
-opt_finalizer
- : /* EMPTY */ { $$ = 0; }
- | UNSAFE { $$ = Modifiers.UNSAFE; }
- | EXTERN { $$ = Modifiers.EXTERN; }
- ;
-
destructor_declaration
- : opt_attributes opt_finalizer TILDE
+ : opt_attributes opt_modifiers TILDE
{
if (RootContext.Documentation != null) {
tmpComment = Lexer.consume_doc_comment ();
IDENTIFIER OPEN_PARENS CLOSE_PARENS block
{
LocatedToken lt = (LocatedToken) $5;
- if (lt.Value != current_container.Basename){
+ 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){
Report.Error (575, lt.Location, "Only class types can contain destructor");
} else {
- Location l = lt.Location;
-
- int m = (int) $2;
- if (!RootContext.StdLib && current_container.Name == "System.Object")
- m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
- else
- m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
-
Method d = new Destructor (
- current_class, TypeManager.system_void_expr, m, "Finalize",
- Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
+ current_class, TypeManager.system_void_expr, (int) $2, "Finalize",
+ Parameters.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
if (RootContext.Documentation != null)
d.DocComment = ConsumeStoredComment ();
EVENT type variable_declarators SEMICOLON
{
current_array_type = null;
- foreach (VariableDeclaration var in (ArrayList) $5) {
-
- MemberName name = new MemberName (var.identifier,
- var.Location);
+ foreach (VariableMemberDeclaration var in (ArrayList) $5) {
EventField e = new EventField (
- current_class, (Expression) $4, (int) $2, false, name,
- (Attributes) $1);
+ current_class, (FullNamedExpression) $4, (int) $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.expression_or_array_initializer;
+ }
+
+ if (var.MemberName.Left != null) {
+ Report.Error (71, e.Location,
+ "`{0}': An explicit interface implementation of an event must use property syntax",
+ e.GetSignatureForError ());
+ }
current_container.AddEvent (e);
}
| opt_attributes
opt_modifiers
- EVENT type namespace_or_type_name
+ EVENT type member_declaration_name
OPEN_BRACE
{
- implicit_value_parameter_type = (Expression) $4;
+ implicit_value_parameter_type = (FullNamedExpression) $4;
+ current_local_parameters = new Parameters (
+ new Parameter (implicit_value_parameter_type, "value",
+ Parameter.Modifier.NONE, null, GetLocation ($3)));
+
lexer.EventParsing = true;
}
event_accessor_declarations
CLOSE_BRACE
{
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 ($8 == null){
Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
- current_container.Name, name.ToString ());
+ current_container.Name, name.GetSignatureForError ());
$$ = 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, (Expression) $4, (int) $2, false, name,
+ 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 ();
implicit_value_parameter_type = null;
}
}
+ current_local_parameters = null;
}
- | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
+ | opt_attributes opt_modifiers EVENT type member_declaration_name error
+ {
MemberName mn = (MemberName) $5;
-
if (mn.Left != null)
Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
- else
- Report.Error (71, mn.Location, "Event declaration should use property syntax");
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
+
+ Report.Error (1002, GetLocation ($6), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
+ $$ = null;
}
;
add_accessor_declaration
: opt_attributes ADD
{
- Parameter [] args = new Parameter [1];
- Parameter implicit_value_parameter = new Parameter (
- implicit_value_parameter_type, "value",
- Parameter.Modifier.NONE, null, (Location) $2);
-
- args [0] = implicit_value_parameter;
-
- current_local_parameters = new Parameters (args);
lexer.EventParsing = false;
-
- anonymous_host = SimpleAnonymousHost.GetSimple ();
}
block
{
- Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
+ Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
lexer.EventParsing = true;
-
- current_local_parameters = null;
- SimpleAnonymousHost.Simple.Propagate (accessor);
- anonymous_host = null;
-
$$ = accessor;
}
| opt_attributes ADD error {
remove_accessor_declaration
: opt_attributes REMOVE
{
- Parameter [] args = new Parameter [1];
- Parameter implicit_value_parameter = new Parameter (
- implicit_value_parameter_type, "value",
- Parameter.Modifier.NONE, null, (Location) $2);
-
- args [0] = implicit_value_parameter;
-
- current_local_parameters = new Parameters (args);
lexer.EventParsing = false;
}
- block
+ block
{
- $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
+ $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
lexer.EventParsing = true;
}
| opt_attributes REMOVE error {
;
indexer_declaration
- : opt_attributes opt_modifiers indexer_declarator
+ : opt_attributes opt_modifiers
+ member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
OPEN_BRACE
{
- IndexerDeclaration decl = (IndexerDeclaration) $3;
-
- implicit_value_parameter_type = decl.type;
+ implicit_value_parameter_type = (FullNamedExpression) $3;
+ indexer_parameters = (Parameters) $6;
+ if (indexer_parameters.IsEmpty)
+ Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
+
+ if (RootContext.Documentation != null) {
+ tmpComment = Lexer.consume_doc_comment ();
+ Lexer.doc_state = XmlCommentState.Allowed;
+ }
+
lexer.PropertyParsing = true;
parsing_indexer = true;
- indexer_parameters = decl.param_list;
- anonymous_host = SimpleAnonymousHost.GetSimple ();
}
- accessor_declarations
+ accessor_declarations
{
lexer.PropertyParsing = false;
has_get = has_set = false;
}
CLOSE_BRACE
{
- if ($6 == null)
- break;
+ Accessors accessors = (Accessors) $10;
+ 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, (Parameters) $6, (Attributes) $1,
+ get_block, set_block, order);
+
+ if ($3 == TypeManager.system_void_expr)
+ Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
+
+ if (accessors == null)
+ Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
- // The signature is computed from the signature of the indexer. Look
- // at section 3.6 on the spec
- Indexer indexer;
- IndexerDeclaration decl = (IndexerDeclaration) $3;
- Location loc = decl.location;
- Accessors accessors = (Accessors) $6;
- Accessor get_block = accessors.get_or_add;
- Accessor set_block = accessors.set_or_remove;
-
- MemberName name;
- if (decl.interface_type != null)
- name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
- else
- name = new MemberName (TypeContainer.DefaultIndexerName, loc);
+ if (current_container.Kind == Kind.Interface) {
+ if (indexer.Get.Block != null)
+ Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
- indexer = new Indexer (current_class, decl.type, name,
- (int) $2, false, decl.param_list, (Attributes) $1,
- get_block, set_block, accessors.declared_in_reverse);
+ if (indexer.Set.Block != null)
+ Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
+ }
if (RootContext.Documentation != null)
indexer.DocComment = ConsumeStoredComment ();
}
;
-indexer_declarator
- : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
- {
- Parameters pars = (Parameters) $4;
- if (pars.HasArglist) {
- // "__arglist is not valid in this context"
- Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
- } else if (pars.Empty){
- Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
- }
- if (RootContext.Documentation != null) {
- tmpComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
-
- $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
- }
- | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
- {
- Parameters pars = (Parameters) $6;
-
- if (pars.HasArglist) {
- // "__arglist is not valid in this context"
- Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
- } else if (pars.Empty){
- Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
- }
-
- MemberName name = (MemberName) $2;
- $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
-
- if (RootContext.Documentation != null) {
- tmpComment = Lexer.consume_doc_comment ();
- Lexer.doc_state = XmlCommentState.Allowed;
- }
- }
- ;
-
enum_declaration
: opt_attributes
opt_modifiers
- ENUM IDENTIFIER
+ ENUM type_declaration_name
opt_enum_base {
if (RootContext.Documentation != null)
enumTypeComment = Lexer.consume_doc_comment ();
enum_body
opt_semicolon
{
- LocatedToken lt = (LocatedToken) $4;
- Location enum_location = lt.Location;
+ MemberName name = (MemberName) $4;
+ if (name.IsGeneric) {
+ Report.Error (1675, name.Location, "Enums cannot have type parameters");
+ }
- MemberName name = MakeName (new MemberName (lt.Value, enum_location));
- Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
+ name = MakeName (name);
+ Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
name, (Attributes) $1);
if (RootContext.Documentation != null)
e.AddEnumMember (em);
}
+ if (RootContext.EvalMode)
+ undo.AddTypeContainer (current_container, e);
current_container.AddTypeContainer (e);
+
$$ = e;
}
opt_enum_base
: /* empty */ { $$ = TypeManager.system_int32_expr; }
- | COLON type { $$ = $2; }
+ | 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;
+ }
+ | COLON error
+ {
+ Error_TypeExpected (lexer.Location);
+ }
;
enum_body
Lexer.doc_state = XmlCommentState.NotAllowed;
}
}
- ASSIGN expression
+ ASSIGN constant_expression
{
VariableDeclaration vd = new VariableDeclaration (
(LocatedToken) $2, $5, (Attributes) $1);
: opt_attributes
opt_modifiers
DELEGATE
+ member_type type_declaration_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
- }
- type type_name
- open_parens opt_formal_parameter_list CLOSE_PARENS
- {
- MemberName name = MakeName ((MemberName) $6);
- Parameters p = (Parameters) $8;
- if (p.HasArglist) {
- // TODO: wrong location
- Report.Error (1669, name.Location, "__arglist is not valid in this context");
- }
+ MemberName name = MakeName ((MemberName) $5);
+ Parameters p = (Parameters) $7;
- Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
+ Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
(int) $2, name, p, (Attributes) $1);
if (RootContext.Documentation != null) {
current_container.AddDelegate (del);
current_delegate = del;
+ lexer.ConstraintsParsing = true;
+ }
+ opt_type_parameter_constraints_clauses
+ {
+ lexer.ConstraintsParsing = false;
}
SEMICOLON
{
+ current_delegate.SetParameterInfo ((ArrayList) $10);
$$ = current_delegate;
current_delegate = null;
}
;
+opt_nullable
+ : /* empty */
+ {
+ $$ = null;
+ }
+ | INTERR_NULLABLE
+ {
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
+
+ $$ = this;
+ }
+ ;
+
namespace_or_type_name
: member_name
- | IDENTIFIER DOUBLE_COLON IDENTIFIER {
+ | qualified_alias_member IDENTIFIER opt_type_argument_list
+ {
LocatedToken lt1 = (LocatedToken) $1;
- LocatedToken lt2 = (LocatedToken) $3;
- $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
+ LocatedToken lt2 = (LocatedToken) $2;
+
+ $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
}
- | namespace_or_type_name DOT IDENTIFIER {
+ ;
+
+member_name
+ : type_name
+ | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
+ {
LocatedToken lt = (LocatedToken) $3;
- $$ = new MemberName ((MemberName) $1, lt.Value);
+ $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
}
;
-member_name
- : IDENTIFIER {
+type_name
+ : IDENTIFIER opt_type_argument_list
+ {
LocatedToken lt = (LocatedToken) $1;
- $$ = new MemberName (lt.Value, lt.Location);
+ $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
+ }
+ ;
+
+//
+// Generics arguments (any type, without attributes)
+//
+opt_type_argument_list
+ : /* empty */ { $$ = null; }
+ | OP_GENERICS_LT type_arguments OP_GENERICS_GT
+ {
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+
+ $$ = $2;
+ }
+ | OP_GENERICS_LT error
+ {
+ Error_TypeExpected (lexer.Location);
+ $$ = new TypeParameterName ("", null, lexer.Location);
}
;
-type_name
- : member_name
+type_arguments
+ : type
+ {
+ TypeArguments type_args = new TypeArguments (lexer.Location);
+ type_args.Add ((Expression) $1);
+ $$ = type_args;
+ }
+ | type_arguments COMMA type
+ {
+ TypeArguments type_args = (TypeArguments) $1;
+ type_args.Add ((Expression) $3);
+ $$ = type_args;
+ }
;
-/*
- * Before you think of adding a return_type, notice that we have been
- * using two rules in the places where it matters (one rule using type
- * and another identical one that uses VOID as the return type). This
- * gets rid of a shift/reduce couple
- */
-type
- : namespace_or_type_name
+//
+// Generics parameters (identifiers only, with attributes), used in type or method declarations
+//
+type_declaration_name
+ : IDENTIFIER
{
- MemberName name = (MemberName) $1;
- $$ = name.GetTypeExpression ();
+ lexer.parsing_generic_declaration = true;
}
- | builtin_types
- | array_type
- | pointer_type
+ opt_type_parameter_list
+ {
+ lexer.parsing_generic_declaration = false;
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
+ }
+ ;
+
+member_declaration_name
+ : method_declaration_name
+ {
+ MemberName mn = (MemberName)$1;
+ if (mn.TypeArguments != null)
+ syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
+ mn.GetSignatureForError ()));
+ }
+ ;
+
+method_declaration_name
+ : type_declaration_name
+ | explicit_interface IDENTIFIER opt_type_parameter_list
+ {
+ lexer.parsing_generic_declaration = false;
+ LocatedToken lt = (LocatedToken) $2;
+ $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+ }
+ ;
+
+indexer_declaration_name
+ : THIS
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
+ }
+ | explicit_interface THIS
+ {
+ lexer.parsing_generic_declaration = false;
+ $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
+ }
+ ;
+
+explicit_interface
+ : IDENTIFIER opt_type_argument_list DOT
+ {
+ LocatedToken lt = (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;
+
+ $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
+ }
+ | explicit_interface IDENTIFIER opt_type_argument_list DOT
+ {
+ LocatedToken lt = (LocatedToken) $2;
+ $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
+ }
+ ;
+
+opt_type_parameter_list
+ : /* empty */ { $$ = null; }
+ | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
+ {
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+
+ $$ = $2;
+ }
+ ;
+
+type_parameters
+ : type_parameter
+ {
+ TypeArguments type_args = new TypeArguments (lexer.Location);
+ type_args.Add ((Expression)$1);
+ $$ = type_args;
+ }
+ | type_parameters COMMA type_parameter
+ {
+ TypeArguments type_args = (TypeArguments) $1;
+ type_args.Add ((Expression)$3);
+ $$ = type_args;
+ }
+ ;
+
+type_parameter
+ : opt_attributes IDENTIFIER
+ {
+ LocatedToken lt = (LocatedToken)$2;
+ $$ = new TypeParameterName (lt.Value, (Attributes)$1, lt.Location);
+ }
+ | error
+ {
+ if (GetTokenName (yyToken) == "<type>")
+ Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
+ else
+ Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
+
+ $$ = new TypeParameterName ("", null, lexer.Location);
+ }
+ ;
+
+//
+// All types where void is allowed
+//
+type_and_void
+ : type_expression_or_array
+ | VOID
+ {
+ $$ = TypeManager.system_void_expr;
+ }
+ ;
+
+member_type
+ : type_and_void
+ {
+ lexer.parsing_generic_declaration = true;
+ }
+ ;
+
+//
+// A type which does not allow `void' to be used
+//
+type
+ : type_expression_or_array
+ | VOID
+ {
+ Expression.Error_VoidInvalidInTheContext (lexer.Location);
+ $$ = TypeManager.system_void_expr;
+ }
;
+type_expression_or_array
+ : type_expression
+ | array_type
+ ;
+
+type_expression
+ : namespace_or_type_name opt_nullable
+ {
+ MemberName name = (MemberName) $1;
-pointer_type
- : type STAR
+ if ($2 != null) {
+ $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
+ } else {
+ if (name.Left == null && name.Name == "var" &&
+ (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
+ $$ = current_array_type = new VarExpr (name.Location);
+ else
+ $$ = name.GetTypeExpression ();
+ }
+ }
+ | builtin_types opt_nullable
+ {
+ if ($2 != null)
+ $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
+ }
+ | type_expression STAR
{
//
// Note that here only unmanaged types are allowed but we
// can't perform checks during this phase - we do it during
// semantic analysis.
//
- $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
}
| VOID STAR
{
$$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
- }
+ }
;
non_expression_type
- : builtin_types
- | non_expression_type rank_specifier
+ : builtin_types opt_nullable
+ {
+ if ($2 != null)
+ $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
+ }
+ | VOID
+ {
+ $$ = TypeManager.system_void_expr;
+ }
+ | non_expression_type rank_specifiers
{
Location loc = GetLocation ($1);
if (loc.IsNull)
loc = lexer.Location;
- $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
}
| non_expression_type STAR
{
Location loc = GetLocation ($1);
if (loc.IsNull)
loc = lexer.Location;
- $$ = new ComposedCast ((Expression) $1, "*", loc);
- }
- | expression rank_specifiers
- {
- $$ = new ComposedCast ((Expression) $1, (string) $2);
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
}
- | expression STAR
- {
- $$ = new ComposedCast ((Expression) $1, "*");
- }
-
//
// We need this because the parser will happily go and reduce IDENTIFIER STAR
// through this different path
//
| multiplicative_expression STAR
{
- $$ = new ComposedCast ((Expression) $1, "*");
+ FullNamedExpression e = $1 as FullNamedExpression;
+ if (e != null)
+ $$ = new ComposedCast (e, "*");
+ else
+ Error_TypeExpected (GetLocation ($1));
}
;
type_list
- : type
+ : base_type_name
{
- ArrayList types = new ArrayList (4);
-
+ ArrayList types = new ArrayList (2);
types.Add ($1);
$$ = types;
}
- | type_list COMMA type
+ | type_list COMMA base_type_name
{
ArrayList types = (ArrayList) $1;
-
types.Add ($3);
$$ = types;
}
;
+base_type_name
+ : type
+ {
+ if ($1 is ComposedCast)
+ Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
+ $$ = $1;
+ }
+ | error
+ {
+ Error_TypeExpected (lexer.Location);
+ }
+ ;
+
/*
* replaces all the productions for isolating the various
* simple types, but we need this to reuse it easily in local_variable_type
| LONG { $$ = TypeManager.system_int64_expr; }
| ULONG { $$ = TypeManager.system_uint64_expr; }
| CHAR { $$ = TypeManager.system_char_expr; }
- | VOID { $$ = TypeManager.system_void_expr; }
;
array_type
- : type rank_specifiers
+ : type_expression rank_specifiers
+ {
+ string rank_specifiers = (string) $2;
+ $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+ }
+ ;
+
+predefined_type
+ : builtin_types
+ | VOID
{
- $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2);
+ $$ = TypeManager.system_void_expr;
}
;
//
// Expressions, section 7.5
//
+
+
primary_expression
+ : primary_expression_no_array_creation
+ | array_creation_expression
+ ;
+
+primary_expression_no_array_creation
: literal
+ | IDENTIFIER opt_type_argument_list
{
- // 7.5.1: Literals
- }
- | member_name
- {
- MemberName mn = (MemberName) $1;
- $$ = mn.GetTypeExpression ();
- }
- | IDENTIFIER DOUBLE_COLON IDENTIFIER
- {
- LocatedToken lt1 = (LocatedToken) $1;
- LocatedToken lt2 = (LocatedToken) $3;
- $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
}
| parenthesized_expression
+ | default_value_expression
| member_access
| invocation_expression
| element_access
| base_access
| post_increment_expression
| post_decrement_expression
- | new_expression
+ | object_or_delegate_creation_expression
+ | anonymous_type_expression
| typeof_expression
| sizeof_expression
| checked_expression
| parenthesized_expression_0 CLOSE_PARENS
{
$$ = $1;
- }
+ }
| parenthesized_expression_0 CLOSE_PARENS_MINUS
{
// If a parenthesized expression is followed by a minus, we need to wrap
;
member_access
- : primary_expression DOT IDENTIFIER
+ : primary_expression DOT IDENTIFIER opt_type_argument_list
{
LocatedToken lt = (LocatedToken) $3;
- $$ = new MemberAccess ((Expression) $1, lt.Value);
+ $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
}
- | predefined_type DOT IDENTIFIER
+ | predefined_type DOT IDENTIFIER opt_type_argument_list
{
LocatedToken lt = (LocatedToken) $3;
// TODO: Location is wrong as some predefined types doesn't hold a location
- $$ = new MemberAccess ((Expression) $1, lt.Value, lt.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;
-predefined_type
- : builtin_types
+ $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
+ }
;
invocation_expression
}
;
+opt_object_or_collection_initializer
+ : /* empty */ { $$ = null; }
+ | object_or_collection_initializer
+ ;
+
+object_or_collection_initializer
+ : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
+ {
+ if ($2 == null)
+ $$ = CollectionOrObjectInitializers.Empty;
+ else
+ $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+ }
+ | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
+ {
+ $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+ }
+ ;
+
+opt_member_initializer_list
+ : /* empty */ { $$ = null; }
+ | member_initializer_list
+ {
+ $$ = $1;
+ }
+ ;
+
+member_initializer_list
+ : member_initializer
+ {
+ ArrayList a = new ArrayList ();
+ a.Add ($1);
+ $$ = a;
+ }
+ | member_initializer_list COMMA member_initializer
+ {
+ ArrayList a = (ArrayList)$1;
+ a.Add ($3);
+ $$ = a;
+ }
+ ;
+
+member_initializer
+ : IDENTIFIER ASSIGN initializer_value
+ {
+ LocatedToken lt = $1 as LocatedToken;
+ $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
+ }
+ | non_assignment_expression
+ {
+ $$ = new CollectionElementInitializer ((Expression)$1);
+ }
+ | OPEN_BRACE expression_list CLOSE_BRACE
+ {
+ $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
+ }
+ | OPEN_BRACE CLOSE_BRACE
+ {
+ Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
+ }
+ ;
+
+initializer_value
+ : expression
+ | object_or_collection_initializer
+ ;
+
opt_argument_list
: /* empty */ { $$ = null; }
| argument_list
list.Add ($3);
$$ = list;
}
- | argument_list error {
- CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
- $$ = null;
+ | argument_list COMMA
+ {
+ Report.Error (839, GetLocation ($2), "An argument is missing");
+ $$ = null;
+ }
+ | COMMA argument
+ {
+ Report.Error (839, GetLocation ($1), "An argument is missing");
+ $$ = null;
}
;
;
element_access
- : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
+ : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
{
$$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
}
- | primary_expression rank_specifiers
+ | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
+ {
+ // LAMESPEC: Not allowed according to specification
+ $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
+ }
+ | primary_expression_no_array_creation rank_specifiers
{
// So the super-trick is that primary_expression
// can only be either a SimpleName or a MemberAccess.
Expression expr = (Expression) $1;
if (expr is ComposedCast){
- $$ = new ComposedCast (expr, (string) $2);
- } else if (!(expr is SimpleName || expr is MemberAccess || expr is QualifiedAliasMember)){
- Error_ExpectingTypeName (expr);
- $$ = TypeManager.system_object_expr;
- } else {
+ $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
+ } else if (expr is ATypeNameExpression){
//
// So we extract the string corresponding to the SimpleName
// or MemberAccess
//
- $$ = new ComposedCast (expr, (string) $2);
+ $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
+ } else {
+ Error_ExpectingTypeName (expr);
+ $$ = TypeManager.system_object_expr;
}
- current_array_type = (Expression)$$;
+
+ current_array_type = (FullNamedExpression)$$;
}
;
;
base_access
- : BASE DOT IDENTIFIER
+ : BASE DOT IDENTIFIER opt_type_argument_list
{
LocatedToken lt = (LocatedToken) $3;
- $$ = new BaseAccess (lt.Value, lt.Location);
+ $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
}
| BASE OPEN_BRACKET expression_list CLOSE_BRACKET
{
}
;
-new_expression
- : object_or_delegate_creation_expression
- | array_creation_expression
- ;
-
object_or_delegate_creation_expression
- : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
+ : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
+ {
+ if ($6 != null) {
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
+
+ $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
+ }
+ else
+ $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
+ }
+ | NEW type object_or_collection_initializer
{
- $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
+
+ $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
}
;
array_creation_expression
- : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
+ : NEW type_expression OPEN_BRACKET expression_list CLOSE_BRACKET
opt_rank_specifier
opt_array_initializer
{
- $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
+ $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
}
- | NEW type rank_specifiers array_initializer
+ | NEW type_expression rank_specifiers array_initializer
{
- $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
+ $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
+ }
+ | NEW rank_specifiers array_initializer
+ {
+ $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
}
| NEW error
{
Report.Error (1031, (Location) $1, "Type expected");
- $$ = null;
+ $$ = null;
}
- | NEW type error
+ | NEW type_expression error
{
Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
$$ = null;
}
;
+anonymous_type_expression
+ : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
+ {
+ if (RootContext.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
+
+ $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
+ }
+ ;
+
+anonymous_type_parameters_opt_comma
+ : anonymous_type_parameters_opt
+ | anonymous_type_parameters COMMA
+ ;
+
+anonymous_type_parameters_opt
+ : { $$ = null; }
+ | anonymous_type_parameters
+ ;
+
+anonymous_type_parameters
+ : anonymous_type_parameter
+ {
+ ArrayList a = new ArrayList (4);
+ a.Add ($1);
+ $$ = a;
+ }
+ | anonymous_type_parameters COMMA anonymous_type_parameter
+ {
+ ArrayList a = (ArrayList) $1;
+ a.Add ($3);
+ $$ = a;
+ }
+ ;
+
+anonymous_type_parameter
+ : IDENTIFIER ASSIGN variable_initializer
+ {
+ LocatedToken lt = (LocatedToken)$1;
+ $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
+ }
+ | IDENTIFIER
+ {
+ LocatedToken lt = (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;
+ BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
+ $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
+ }
+ | member_access
+ {
+ MemberAccess ma = (MemberAccess) $1;
+ $$ = new AnonymousTypeParameter (ma, ma.Name, ma.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");
+ }
+ ;
+
opt_rank_specifier
: /* empty */
{
}
;
+opt_rank_specifier_or_nullable
+ : opt_nullable
+ {
+ if ($1 != null)
+ $$ = "?";
+ else
+ $$ = string.Empty;
+ }
+ | opt_nullable rank_specifiers
+ {
+ if ($1 != null)
+ $$ = "?" + (string) $2;
+ else
+ $$ = $2;
+ }
+ ;
+
rank_specifiers
: rank_specifier opt_rank_specifier
{
- $$ = (string) $2 + (string) $1;
+ $$ = (string) $2 + (string) $1;
}
- ;
+ ;
rank_specifier
: OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
{
$$ = null;
}
- | array_initializer
+ | array_initializer
{
$$ = $1;
}
: TYPEOF
{
pushed_current_array_type = current_array_type;
+ lexer.TypeOfParsing = true;
}
- OPEN_PARENS type CLOSE_PARENS
+ OPEN_PARENS typeof_type_expression CLOSE_PARENS
{
+ lexer.TypeOfParsing = false;
Expression type = (Expression)$4;
if (type == TypeManager.system_void_expr)
$$ = new TypeOfVoid ((Location) $1);
current_array_type = pushed_current_array_type;
}
;
+
+typeof_type_expression
+ : type_and_void
+ {
+ $$ = $1;
+ }
+ | unbound_type_name
+ {
+ $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
+ }
+ | error
+ {
+ Error_TypeExpected (lexer.Location);
+ $$ = null;
+ }
+ ;
+
+unbound_type_name
+ : IDENTIFIER generic_dimension
+ {
+ LocatedToken lt = (LocatedToken) $1;
+ TypeArguments ta = (TypeArguments)$2;
+
+ $$ = new MemberName (lt.Value, ta, lt.Location);
+ }
+ | qualified_alias_member IDENTIFIER generic_dimension
+ {
+ LocatedToken lt1 = (LocatedToken) $1;
+ LocatedToken lt2 = (LocatedToken) $2;
+ TypeArguments ta = (TypeArguments)$3;
+
+ $$ = new MemberName (new MemberName (lt1.Value, lt1.Location), lt2.Value, ta, lt2.Location);
+ }
+ | unbound_type_name DOT IDENTIFIER generic_dimension
+ {
+ LocatedToken lt = (LocatedToken) $3;
+ TypeArguments ta = (TypeArguments)$4;
+
+ $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
+ }
+ | namespace_or_type_name DOT IDENTIFIER generic_dimension
+ {
+ LocatedToken lt = (LocatedToken) $3;
+ TypeArguments ta = (TypeArguments)$4;
+
+ $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
+ }
+ ;
+
+generic_dimension
+ : GENERIC_DIMENSION
+ {
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (lexer.Location, "generics");
+
+ $$ = new TypeArguments ((int)$1, lexer.Location);
+ }
+ ;
+
+qualified_alias_member
+ : IDENTIFIER DOUBLE_COLON
+ {
+ LocatedToken lt = (LocatedToken) $1;
+ if (RootContext.Version == LanguageVersion.ISO_1)
+ Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
+
+ $$ = lt;
+ }
+ ;
sizeof_expression
: SIZEOF OPEN_PARENS type CLOSE_PARENS {
Expression deref;
LocatedToken lt = (LocatedToken) $3;
- deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
+ deref = new Indirection ((Expression) $1, lt.Location);
$$ = new MemberAccess (deref, lt.Value);
}
;
block
{
$$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
- }
+ }
;
opt_anonymous_method_signature
;
anonymous_method_signature
- : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS
+ : OPEN_PARENS
{
- if ($2 == null)
- $$ = Parameters.EmptyReadOnlyParameters;
- else {
- ArrayList par_list = (ArrayList) $2;
- Parameter [] pars = new Parameter [par_list.Count];
- par_list.CopyTo (pars);
- $$ = new Parameters (pars);
- }
+ params_modifiers_not_allowed = true;
}
- ;
-
-opt_anonymous_method_parameter_list
- : /* empty */ { $$ = null; }
- | anonymous_method_parameter_list { $$ = $1; }
- ;
-
-anonymous_method_parameter_list
- : anonymous_method_parameter
+ opt_formal_parameter_list CLOSE_PARENS
{
- ArrayList a = new ArrayList (4);
- a.Add ($1);
- $$ = a;
+ params_modifiers_not_allowed = false;
+ $$ = $3;
}
- | anonymous_method_parameter_list COMMA anonymous_method_parameter
+ ;
+
+default_value_expression
+ : DEFAULT_OPEN_PARENS type CLOSE_PARENS
{
- ArrayList a = (ArrayList) $1;
- a.Add ($3);
- $$ = a;
- }
- ;
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
-anonymous_method_parameter
- : opt_parameter_modifier type IDENTIFIER {
- LocatedToken lt = (LocatedToken) $3;
- $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
- }
- | PARAMS type IDENTIFIER {
- Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
- $$ = null;
+ $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
}
;
{
$$ = new Cast ((Expression) $1, (Expression) $3);
}
+ | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
+ {
+ $$ = new Cast ((Expression) $1, (Expression) $3);
+ }
| parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
{
$$ = new Cast ((Expression) $1, (Expression) $3);
: cast_list
| OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
{
+ if ($2 == TypeManager.system_void_expr)
+ Expression.Error_VoidInvalidInTheContext (GetLocation ($2));
+
// TODO: wrong location
$$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
}
}
| STAR prefixed_unary_expression
{
- $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
+ $$ = new Indirection ((Expression) $2, (Location) $1);
}
| BITWISE_AND prefixed_unary_expression
{
}
;
-pre_increment_expression
- : OP_INC prefixed_unary_expression
- {
- $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
- (Expression) $2, (Location) $1);
- }
- ;
-
-pre_decrement_expression
- : OP_DEC prefixed_unary_expression
- {
- $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
- (Expression) $2, (Location) $1);
- }
- ;
-
multiplicative_expression
: prefixed_unary_expression
| multiplicative_expression STAR prefixed_unary_expression
$$ = new Binary (Binary.Operator.Subtraction,
(Expression) $1, (Expression) $3);
}
+ | additive_expression AS type
+ {
+ $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
+ }
+ | additive_expression IS type
+ {
+ $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
+ }
;
shift_expression
$$ = new Binary (Binary.Operator.GreaterThanOrEqual,
(Expression) $1, (Expression) $3);
}
- | relational_expression IS type
- {
- $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
- }
- | relational_expression AS type
- {
- $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
- }
;
equality_expression
{
$$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
}
+ | conditional_or_expression OP_COALESCING expression
+ {
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
+
+ $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
+ }
+ | primary_expression INTERR_NULLABLE opt_rank_specifier
+ {
+ //
+ // TODO: Is this the best place to handle `= (foo?)a;' ?
+ //
+ if (RootContext.Version < LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
+
+ $$ = new ComposedCast ((FullNamedExpression) $1, "?" + (string)$3, lexer.Location);
+ }
;
assignment_expression
: prefixed_unary_expression ASSIGN expression
{
- $$ = new Assign ((Expression) $1, (Expression) $3);
+ $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
}
| prefixed_unary_expression OP_MULT_ASSIGN expression
{
}
;
-implicitly_typed_lambda_parameter_list
- : IDENTIFIER {
- LocatedToken lt = (LocatedToken) $1;
- ArrayList a = new ArrayList (4);
-
- a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
- $$ = a;
- }
- | implicitly_typed_lambda_parameter_list COMMA IDENTIFIER {
- LocatedToken lt = (LocatedToken) $3;
- ArrayList a = (ArrayList) $1;
- a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
- $$ = a;
- }
- ;
-
-explicitly_typed_lambda_parameter_list
- : explicitly_typed_lambda_parameter
+lambda_parameter_list
+ : lambda_parameter
{
ArrayList pars = new ArrayList (4);
pars.Add ($1);
$$ = pars;
}
- | explicitly_typed_lambda_parameter_list COMMA explicitly_typed_lambda_parameter
+ | lambda_parameter_list COMMA lambda_parameter
{
ArrayList pars = (ArrayList) $1;
- pars.Add ($3);
-
+ 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");
+ }
+
+ pars.Add (p);
$$ = pars;
}
;
-explicitly_typed_lambda_parameter
+lambda_parameter
: parameter_modifier type IDENTIFIER
{
LocatedToken lt = (LocatedToken) $3;
- $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
+ $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
}
| type IDENTIFIER
{
LocatedToken lt = (LocatedToken) $2;
- $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
+ $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
+ }
+ | IDENTIFIER
+ {
+ LocatedToken lt = (LocatedToken) $1;
+ $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
}
- ;
-
-lambda_parameter_list
- : implicitly_typed_lambda_parameter_list { $$ = $1; }
- | explicitly_typed_lambda_parameter_list { $$ = $1; }
;
opt_lambda_parameter_list
- : /* empty */ { $$ = null; }
+ : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
| lambda_parameter_list {
ArrayList pars_list = (ArrayList) $1;
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
- $$ = new Parameters (pars);
+ $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
}
;
lambda_expression
: IDENTIFIER ARROW
{
- Parameter [] pars = new Parameter [1];
LocatedToken lt = (LocatedToken) $1;
- pars [0] = new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
-
- Parameters parameters = new Parameters (pars);
-
- start_anonymous (true, parameters, (Location) $2);
+ Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
+ start_anonymous (true, new Parameters (p), (Location) $2);
}
lambda_expression_body
{
;
expression
+ : assignment_expression
+ | non_assignment_expression
+ ;
+
+non_assignment_expression
: conditional_expression
- | assignment_expression
| lambda_expression
+ | query_expression
;
constant_expression
opt_partial
CLASS
{
+ lexer.ConstraintsParsing = true;
}
- type_name
+ type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
}
opt_class_base
+ opt_type_parameter_constraints_clauses
{
+ lexer.ConstraintsParsing = false;
+
+ current_class.SetParameterInfo ((ArrayList) $9);
+
if (RootContext.Documentation != null) {
current_container.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
;
modifier
- : NEW { $$ = Modifiers.NEW; }
+ : NEW
+ {
+ $$ = Modifiers.NEW;
+ if (current_container == RootContext.ToplevelTypes)
+ Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
+ }
| PUBLIC { $$ = Modifiers.PUBLIC; }
| PROTECTED { $$ = Modifiers.PROTECTED; }
| INTERNAL { $$ = Modifiers.INTERNAL; }
: COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
;
+opt_type_parameter_constraints_clauses
+ : /* empty */ { $$ = null; }
+ | type_parameter_constraints_clauses
+ { $$ = $1; }
+ ;
+
+type_parameter_constraints_clauses
+ : type_parameter_constraints_clause {
+ ArrayList constraints = new ArrayList (1);
+ constraints.Add ($1);
+ $$ = constraints;
+ }
+ | type_parameter_constraints_clauses type_parameter_constraints_clause {
+ ArrayList constraints = (ArrayList) $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);
+ }
+ }
+
+ constraints.Add (new_constraint);
+ $$ = constraints;
+ }
+ ;
+
+type_parameter_constraints_clause
+ : WHERE IDENTIFIER COLON type_parameter_constraints {
+ LocatedToken lt = (LocatedToken) $2;
+ $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
+ }
+ ;
+
+type_parameter_constraints
+ : type_parameter_constraint {
+ ArrayList constraints = new ArrayList (1);
+ constraints.Add ($1);
+ $$ = constraints;
+ }
+ | type_parameter_constraints COMMA type_parameter_constraint {
+ ArrayList constraints = (ArrayList) $1;
+
+ constraints.Add ($3);
+ $$ = constraints;
+ }
+ ;
+
+type_parameter_constraint
+ : type
+ | NEW OPEN_PARENS CLOSE_PARENS {
+ $$ = SpecialConstraint.Constructor;
+ }
+ | CLASS {
+ $$ = SpecialConstraint.ReferenceType;
+ }
+ | STRUCT {
+ $$ = SpecialConstraint.ValueType;
+ }
+ ;
+
//
// Statements (8.2)
//
: OPEN_BRACE
{
++lexer.parsing_block;
+ current_block.StartLocation = GetLocation ($1);
}
opt_statement_list CLOSE_BRACE
{
| labeled_statement
;
+//
+// The interactive_statement and its derivatives are only
+// used to provide a special version of `expression_statement'
+// that has a side effect of assigning the expression to
+// $retval
+//
+interactive_statement_list
+ : interactive_statement
+ | interactive_statement_list interactive_statement
+ ;
+
+interactive_statement
+ : declaration_statement
+ {
+ if ($1 != null && (Block) $1 != current_block){
+ current_block.AddStatement ((Statement) $1);
+ current_block = (Block) $1;
+ }
+ }
+ | interactive_valid_declaration_statement
+ {
+ current_block.AddStatement ((Statement) $1);
+ }
+ | labeled_statement
+ ;
+
valid_declaration_statement
: block
| empty_statement
| fixed_statement
;
+interactive_valid_declaration_statement
+ : block
+ | empty_statement
+ | interactive_expression_statement
+ | selection_statement
+ | iteration_statement
+ | jump_statement
+ | try_statement
+ | checked_statement
+ | unchecked_statement
+ | lock_statement
+ | using_statement
+ | unsafe_statement
+ | fixed_statement
+ ;
+
embedded_statement
: valid_declaration_statement
| declaration_statement
* > The expressions are converted into types during semantic analysis.
*/
local_variable_type
- : primary_expression opt_rank_specifier
+ : primary_expression_no_array_creation opt_rank_specifier_or_nullable
{
// FIXME: Do something smart here regarding the composition of the type.
// Foo.Bar.Blah i;
// SimpleName is when you have
// Blah i;
-
- Expression expr = (Expression) $1;
- if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is QualifiedAliasMember)) {
- Error_ExpectingTypeName (expr);
- $$ = null;
- } else {
+
+ Expression expr = (Expression) $1;
+ string rank_or_nullable = (string) $2;
+
+ if (expr is ComposedCast){
+ $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
+ } else if (expr is ATypeNameExpression){
//
// So we extract the string corresponding to the SimpleName
// or MemberAccess
- //
-
- if ((string) $2 == "")
- $$ = $1;
- else
- $$ = new ComposedCast ((Expression) $1, (string) $2);
+ //
+ if (rank_or_nullable.Length == 0) {
+ SimpleName sn = expr as SimpleName;
+ if (sn != null && sn.Name == "var" &&
+ (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
+ $$ = current_array_type = new VarExpr (sn.Location);
+ else
+ $$ = $1;
+ } else {
+ $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
+ }
+ } else {
+ Error_ExpectingTypeName (expr);
+ $$ = TypeManager.system_object_expr;
}
}
- | builtin_types opt_rank_specifier
+ | builtin_types opt_rank_specifier_or_nullable
{
if ((string) $2 == "")
$$ = $1;
else
- $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
+ $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
}
- ;
+ | VOID opt_rank_specifier
+ {
+ Expression.Error_VoidInvalidInTheContext (lexer.Location);
+ $$ = TypeManager.system_void_expr;
+ }
+ ;
local_variable_pointer_type
- : primary_expression STAR
+ : primary_expression_no_array_creation STAR
{
- Expression expr = (Expression) $1;
-
- if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is QualifiedAliasMember)) {
- Error_ExpectingTypeName (expr);
+ ATypeNameExpression expr = $1 as ATypeNameExpression;
- $$ = null;
- } else
- $$ = new ComposedCast ((Expression) $1, "*");
+ if (expr != null) {
+ $$ = new ComposedCast (expr, "*");
+ } else {
+ Error_ExpectingTypeName ((Expression)$1);
+ $$ = expr;
+ }
}
- | builtin_types STAR
+ | builtin_types STAR
{
- $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
}
- | VOID STAR
+ | VOID STAR
{
$$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
}
| local_variable_pointer_type STAR
- {
- $$ = new ComposedCast ((Expression) $1, "*");
+ {
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*");
}
- ;
+ ;
local_variable_declaration
- : local_variable_type variable_declarators
+ : local_variable_type local_variable_declarators
{
- if ($1 != null)
+ if ($1 != null) {
+ VarExpr ve = $1 as VarExpr;
+ if (ve != null)
+ ve.VariableInitializer = (ArrayList)$2;
+
$$ = new DictionaryEntry ($1, $2);
- else
+ } else
$$ = null;
}
- | local_variable_pointer_type opt_rank_specifier variable_declarators
+ | local_variable_pointer_type opt_rank_specifier local_variable_declarators
{
if ($1 != null){
Expression t;
if ((string) $2 == "")
t = (Expression) $1;
else
- t = new ComposedCast ((Expression) $1, (string) $2);
+ t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
$$ = new DictionaryEntry (t, $3);
} else
$$ = null;
: statement_expression SEMICOLON { $$ = $1; }
;
+interactive_expression_statement
+ : interactive_statement_expression SEMICOLON { $$ = $1; }
+ ;
+
//
// We have to do the wrapping here and not in the case above,
// because statement_expression is used for example in for_statement
: expression
{
Expression expr = (Expression) $1;
- ExpressionStatement s = expr as ExpressionStatement;
+ ExpressionStatement s;
+
+ s = expr as ExpressionStatement;
+
if (s == null) {
expr.Error_InvalidExpressionStatement ();
$$ = null;
+ } else {
+ $$ = new StatementExpression (s);
}
- $$ = new StatementExpression (s);
}
| error
{
- Report.Error (1002, GetLocation ($1), "Expecting `;'");
+ Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
$$ = null;
}
;
-object_creation_expression
- : object_or_delegate_creation_expression
- { note ("complain if this is a delegate maybe?"); }
- ;
+interactive_statement_expression
+ : expression
+ {
+ Expression expr = (Expression) $1;
+ ExpressionStatement s;
+ s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
+ $$ = new StatementExpression (s);
+ }
+ | error
+ {
+ Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
+ $$ = null;
+ }
+ ;
+
selection_statement
: if_statement
| switch_statement
;
switch_label
- : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
- | DEFAULT COLON { $$ = new SwitchLabel (null, (Location) $1); }
- | error {
- Report.Error (
- 1523, GetLocation ($1),
- "The keyword case or default must precede code in switch block");
+ : CASE constant_expression COLON
+ {
+ $$ = new SwitchLabel ((Expression) $2, (Location) $1);
+ }
+ | DEFAULT_COLON
+ {
+ $$ = new SwitchLabel (null, (Location) $1);
}
;
;
for_statement
- : FOR open_parens
+ : FOR OPEN_PARENS
opt_for_initializer SEMICOLON
{
Location l = lexer.Location;
var = new LocalVariableReference (assign_block, decl.identifier, l);
if (expr != null) {
- Assign a = new Assign (var, expr, decl.Location);
+ Assign a = new SimpleAssign (var, expr, decl.Location);
assign_block.AddStatement (new StatementExpression (a));
}
;
foreach_statement
- : FOREACH open_parens type IN expression CLOSE_PARENS
+ : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
{
Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
$$ = null;
}
- | FOREACH open_parens type IDENTIFIER IN
+ | FOREACH OPEN_PARENS type IDENTIFIER IN
expression CLOSE_PARENS
{
start_block (lexer.Location);
Report.FeatureIsNotAvailable (lt.Location, "yield statement");
$$ = null;
}
- if (anonymous_host == null){
- Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
- $$ = null;
- } else {
- anonymous_host.SetYields ();
- $$ = new Yield ((Expression) $3, lt.Location);
- }
+ current_block.Toplevel.IsIterator = true;
+ $$ = new Yield ((Expression) $3, lt.Location);
}
| IDENTIFIER RETURN SEMICOLON
{
Report.FeatureIsNotAvailable (lt.Location, "yield statement");
$$ = null;
}
- if (anonymous_host == null){
- Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
- $$ = null;
- } else {
- anonymous_host.SetYields ();
- $$ = new YieldBreak (lt.Location);
- }
+
+ current_block.Toplevel.IsIterator = true;
+ $$ = new YieldBreak (lt.Location);
}
;
;
try_statement
- : TRY block catch_clauses
+ : TRY block catch_clauses
{
- Catch g = null;
-
- ArrayList c = (ArrayList)$3;
- for (int i = 0; i < c.Count; ++i) {
- Catch cc = (Catch) c [i];
- if (cc.IsGeneral) {
- if (i != c.Count - 1)
- Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
- g = cc;
- c.RemoveAt (i);
- i--;
- }
- }
-
- // Now s contains the list of specific catch clauses
- // and g contains the general one.
-
- $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
+ $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
}
- | TRY block opt_catch_clauses FINALLY block
+ | TRY block FINALLY block
{
- Catch g = null;
- ArrayList s = new ArrayList (4);
- ArrayList catch_list = (ArrayList) $3;
-
- if (catch_list != null){
- foreach (Catch cc in catch_list) {
- if (cc.IsGeneral)
- g = cc;
- else
- s.Add (cc);
- }
- }
-
- $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
+ $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
+ }
+ | TRY block catch_clauses FINALLY block
+ {
+ $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
}
| TRY block error
{
}
;
-opt_catch_clauses
- : /* empty */ { $$ = null; }
- | catch_clauses
- ;
-
catch_clauses
: catch_clause
{
opt_catch_args
: /* empty */ { $$ = null; }
- | catch_args
+ | catch_args
;
catch_args
- : open_parens type opt_identifier CLOSE_PARENS
- {
+ : OPEN_PARENS type opt_identifier CLOSE_PARENS
+ {
$$ = new DictionaryEntry ($2, $3);
}
- ;
-
-
-checked_statement
- : CHECKED block
+ | OPEN_PARENS CLOSE_PARENS
+ {
+ Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
+ }
+ ;
+
+checked_statement
+ : CHECKED block
+ {
+ $$ = new Checked ((Block) $2);
+ }
+ ;
+
+unchecked_statement
+ : UNCHECKED block
+ {
+ $$ = new Unchecked ((Block) $2);
+ }
+ ;
+
+unsafe_statement
+ : UNSAFE
+ {
+ RootContext.CheckUnsafeOption ((Location) $1);
+ } block {
+ $$ = new Unsafe ((Block) $3);
+ }
+ ;
+
+fixed_statement
+ : FIXED OPEN_PARENS
+ 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);
+
+ current_block.AddStatement (f);
+
+ $$ = end_block (lexer.Location);
+ }
+ ;
+
+fixed_pointer_declarators
+ : fixed_pointer_declarator {
+ ArrayList declarators = new ArrayList (4);
+ if ($1 != null)
+ declarators.Add ($1);
+ $$ = declarators;
+ }
+ | fixed_pointer_declarators COMMA fixed_pointer_declarator
+ {
+ ArrayList declarators = (ArrayList) $1;
+ if ($3 != null)
+ declarators.Add ($3);
+ $$ = declarators;
+ }
+ ;
+
+fixed_pointer_declarator
+ : IDENTIFIER ASSIGN expression
+ {
+ LocatedToken lt = (LocatedToken) $1;
+ // FIXME: keep location
+ $$ = new Pair (lt.Value, $3);
+ }
+ | IDENTIFIER
+ {
+ Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
+ $$ = null;
+ }
+ ;
+
+lock_statement
+ : LOCK OPEN_PARENS expression CLOSE_PARENS
+ {
+ //
+ }
+ embedded_statement
+ {
+ $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
+ }
+ ;
+
+using_statement
+ : USING OPEN_PARENS local_variable_declaration CLOSE_PARENS
+ {
+ 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;
+
+ Stack vars = new Stack ();
+
+ foreach (VariableDeclaration decl in var_declarators) {
+ LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
+ if (vi == null)
+ continue;
+ vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
+
+ Expression expr = decl.expression_or_array_initializer;
+ if (expr == null) {
+ Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
+ continue;
+ }
+ LocalVariableReference var;
+
+ // Get a writable reference to this read-only variable.
+ var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
+
+ // This is so that it is not a warning on using variables
+ vi.Used = true;
+
+ vars.Push (new DictionaryEntry (var, expr));
+
+ // Assign a = new SimpleAssign (var, expr, decl.Location);
+ // assign_block.AddStatement (new StatementExpression (a));
+ }
+
+ // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
+ // It can be referred to as $5 below.
+ $$ = vars;
+ }
+ embedded_statement
+ {
+ Statement stmt = (Statement) $6;
+ Stack vars = (Stack) $5;
+ Location l = (Location) $1;
+
+ while (vars.Count > 0) {
+ DictionaryEntry de = (DictionaryEntry) vars.Pop ();
+ stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
+ }
+ current_block.AddStatement (stmt);
+ $$ = end_block (lexer.Location);
+ }
+ | USING OPEN_PARENS expression CLOSE_PARENS
+ {
+ start_block (lexer.Location);
+ }
+ embedded_statement
+ {
+ current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
+ $$ = end_block (lexer.Location);
+ }
+ ;
+
+
+// LINQ
+
+query_expression
+ : first_from_clause
+ {
+ ++lexer.query_parsing;
+ }
+ query_body
+ {
+ if (--lexer.query_parsing == 1)
+ lexer.query_parsing = 0;
+
+ Linq.AQueryClause from = $1 as Linq.AQueryClause;
+
+ from.Tail.Next = (Linq.AQueryClause)$3;
+ $$ = from;
+
+ current_block.SetEndLocation (lexer.Location);
+ current_block = current_block.Parent;
+ }
+ ;
+
+first_from_clause
+ : FROM IDENTIFIER IN expression
+ {
+ current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+ LocatedToken lt = (LocatedToken) $2;
+
+ current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
+ $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
+ }
+ | FROM type IDENTIFIER IN expression
+ {
+ current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+ LocatedToken lt = (LocatedToken) $3;
+
+ Expression type = (Expression)$2;
+ current_block.AddVariable (type, lt.Value, lt.Location);
+ $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
+ }
+ ;
+
+from_clause
+ : FROM IDENTIFIER IN expression
+ {
+ LocatedToken lt = (LocatedToken) $2;
+
+ current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+ lt.Value, lt.Location);
+
+ $$ = new Linq.SelectMany (lt, (Expression)$4);
+ }
+ | FROM type IDENTIFIER IN expression
+ {
+ LocatedToken lt = (LocatedToken) $3;
+
+ Expression type = (Expression)$2;
+ current_block.AddVariable (type, lt.Value, lt.Location);
+ $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
+ }
+ ;
+
+query_body
+ : opt_query_body_clauses select_or_group_clause opt_query_continuation
+ {
+ Linq.AQueryClause head = (Linq.AQueryClause)$2;
+
+ if ($3 != null)
+ head.Next = (Linq.AQueryClause)$3;
+
+ if ($1 != null) {
+ Linq.AQueryClause clause = (Linq.AQueryClause)$1;
+ clause.Tail.Next = head;
+ head = clause;
+ }
+
+ $$ = head;
+ }
+ ;
+
+select_or_group_clause
+ : SELECT expression
{
- $$ = new Checked ((Block) $2);
+ $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
+ }
+ | GROUP expression BY expression
+ {
+ $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
}
;
-
-unchecked_statement
- : UNCHECKED block
+
+opt_query_body_clauses
+ : /* empty */
+ | query_body_clauses
+ ;
+
+query_body_clauses
+ : query_body_clause
+ | query_body_clauses query_body_clause
{
- $$ = new Unchecked ((Block) $2);
+ ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
+ $$ = $1;
}
;
-
-unsafe_statement
- : UNSAFE
+
+query_body_clause
+ : from_clause
+ | let_clause
+ | where_clause
+ | join_clause
+ | orderby_clause
+ ;
+
+let_clause
+ : LET IDENTIFIER ASSIGN expression
{
- RootContext.CheckUnsafeOption ((Location) $1);
- } block {
- $$ = new Unsafe ((Block) $3);
+ LocatedToken lt = (LocatedToken) $2;
+ current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+ lt.Value, lt.Location);
+ $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
}
;
-fixed_statement
- : FIXED open_parens
- type fixed_pointer_declarators
- CLOSE_PARENS
+where_clause
+ : WHERE boolean_expression
{
- 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;
+ $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
+ }
+ ;
+
+join_clause
+ : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
+ {
+ Location loc = GetLocation ($1);
+ LocatedToken lt = (LocatedToken) $2;
+ current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+ lt.Value, lt.Location);
+
+ if ($9 == null) {
+ $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
+ (Expression)$8, loc);
+ } else {
+ LocatedToken lt_into = (LocatedToken) $9;
+ $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
+ (Expression)$8, lt_into, loc);
}
}
- embedded_statement
+ | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
{
- Location l = (Location) $1;
-
- Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
-
- current_block.AddStatement (f);
-
- $$ = end_block (lexer.Location);
+ Location loc = GetLocation ($1);
+ LocatedToken lt = (LocatedToken) $3;
+ current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
+
+ Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
+ if ($10 == null) {
+ $$ = new Linq.Join (lt, cast, (Expression)$7,
+ (Expression)$9, loc);
+ } else {
+ LocatedToken lt_into = (LocatedToken) $10;
+ $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
+ (Expression)$9, lt_into, loc);
+ }
}
;
-
-fixed_pointer_declarators
- : fixed_pointer_declarator {
- ArrayList declarators = new ArrayList (4);
- if ($1 != null)
- declarators.Add ($1);
- $$ = declarators;
- }
- | fixed_pointer_declarators COMMA fixed_pointer_declarator
+
+opt_join_into
+ : /* empty */
+ | INTO IDENTIFIER
{
- ArrayList declarators = (ArrayList) $1;
- if ($3 != null)
- declarators.Add ($3);
- $$ = declarators;
+ $$ = $2;
}
;
-
-fixed_pointer_declarator
- : IDENTIFIER ASSIGN expression
+
+orderby_clause
+ : ORDERBY orderings
{
- LocatedToken lt = (LocatedToken) $1;
- // FIXME: keep location
- $$ = new Pair (lt.Value, $3);
+ $$ = $2;
}
- | IDENTIFIER
+ ;
+
+orderings
+ : order_by
+ | order_by COMMA orderings_then_by
{
- Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
- $$ = null;
+ ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
+ $$ = $1;
}
;
-
-lock_statement
- : LOCK OPEN_PARENS expression CLOSE_PARENS
+
+orderings_then_by
+ : then_by
{
- //
- }
- embedded_statement
+ $$ = $1;
+ }
+ | orderings_then_by COMMA then_by
{
- $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
+ ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
+ $$ = $1;
+ }
+ ;
+
+order_by
+ : expression
+ {
+ $$ = new Linq.OrderByAscending ((Expression)$1);
+ }
+ | expression ASCENDING
+ {
+ $$ = new Linq.OrderByAscending ((Expression)$1);
+ }
+ | expression DESCENDING
+ {
+ $$ = new Linq.OrderByDescending ((Expression)$1);
}
;
-using_statement
- : USING open_parens resource_acquisition CLOSE_PARENS
+then_by
+ : expression
{
- start_block (lexer.Location);
- Block assign_block = current_block;
-
- if ($3 is DictionaryEntry){
- DictionaryEntry de = (DictionaryEntry) $3;
- Location l = (Location) $1;
-
- Expression type = (Expression) de.Key;
- ArrayList var_declarators = (ArrayList) de.Value;
-
- ArrayList vars = new ArrayList (4);
-
- foreach (VariableDeclaration decl in var_declarators){
-
- LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
- if (vi == null)
- continue;
- vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
-
- Expression expr = decl.expression_or_array_initializer;
- if (expr == null) {
- Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
- }
+ $$ = new Linq.ThenByAscending ((Expression)$1);
+ }
+ | expression ASCENDING
+ {
+ $$ = new Linq.ThenByAscending ((Expression)$1);
+ }
+ | expression DESCENDING
+ {
+ $$ = new Linq.ThenByDescending ((Expression)$1);
+ }
+ ;
- LocalVariableReference var;
- // Get a writable reference to this read-only variable.
- var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
+opt_query_continuation
+ : /* empty */
+ | INTO IDENTIFIER
+ {
+ // query continuation block is not linked with query block but with block
+ // before. This means each query can use same range variable names for
+ // different identifiers.
- // This is so that it is not a warning on using variables
- vi.Used = true;
+ current_block.SetEndLocation (GetLocation ($1));
+ current_block = current_block.Parent;
+ current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
+
+ LocatedToken lt = (LocatedToken) $2;
+ current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
+ lt.Value, lt.Location);
+ }
+ query_body
+ {
+ $$ = new Linq.QueryExpression ((LocatedToken) $2,
+ (Linq.AQueryClause)$4);
+ }
+ ;
+
+//
+// Support for using the compiler as an interactive parser
+//
+// The INTERACTIVE_PARSER token is first sent to parse our
+// productions; If the result is a Statement, the parsing
+// is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
+// to setup the blocks in advance.
+//
+// This setup is here so that in the future we can add
+// support for other constructs (type parsing, namespaces, etc)
+// that do not require a block to be setup in advance
+//
- vars.Add (new DictionaryEntry (var, expr));
+interactive_parsing
+ : EVAL_STATEMENT_PARSER EOF
+ | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
+ | EVAL_STATEMENT_PARSER {
+ Evaluator.LoadAliases (current_namespace);
+
+ push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
+ Modifiers.PUBLIC, null), null);
+
+ ArrayList baseclass_list = new ArrayList ();
+ baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
+ current_container.AddBasesForPart (current_class, baseclass_list);
+
+ // (ref object retval)
+ Parameter [] mpar = new Parameter [1];
+ mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
+
+ Parameters pars = new Parameters (mpar);
+ current_local_parameters = pars;
+ Method method = new Method (
+ current_class,
+ null, // generic
+ TypeManager.system_void_expr,
+ Modifiers.PUBLIC | Modifiers.STATIC,
+ new MemberName ("Host"),
+ pars,
+ null /* attributes */);
+
+ oob_stack.Push (method);
+ ++lexer.parsing_block;
+ start_block (lexer.Location);
+ }
+ interactive_statement_list
+ {
+ --lexer.parsing_block;
+ Method method = (Method) oob_stack.Pop ();
- // Assign a = new Assign (var, expr, decl.Location);
- // assign_block.AddStatement (new StatementExpression (a));
- }
+ method.Block = (ToplevelBlock) end_block(lexer.Location);
+ current_container.AddMethod (method);
- // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
- // It can be referred to as $5 below.
- $$ = new DictionaryEntry (type, vars);
- } else {
- $$ = $3;
- }
+ InteractiveResult = pop_current_class ();
+ current_local_parameters = null;
}
- embedded_statement
- {
- Using u = new Using ($5, (Statement) $6, (Location) $1);
- current_block.AddStatement (u);
- $$ = end_block (lexer.Location);
+ | EVAL_COMPILATION_UNIT_PARSER {
+ Evaluator.LoadAliases (current_namespace);
}
- ;
-
-resource_acquisition
- : local_variable_declaration
- | expression
+ interactive_compilation_unit
;
+interactive_compilation_unit
+ : outer_declarations
+ | outer_declarations global_attributes
+ | global_attributes
+ | /* nothing */
+ ;
%%
// <summary>
{
this.identifier = lt.Value;
if (eoai is ArrayList) {
- if (CSharpParser.current_array_type == null)
- Report.Error (622, lt.Location,
- "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
} else {
this.expression_or_array_initializer = (Expression)eoai;
}
}
-// <summary>
-// A class used to hold info about an indexer declarator
-// </summary>
-public class IndexerDeclaration {
- public Expression type;
- public MemberName interface_type;
- public Parameters param_list;
- public Location location;
-
- public IndexerDeclaration (Expression type, MemberName interface_type,
- Parameters param_list, Location loc)
- {
- this.type = type;
- this.interface_type = interface_type;
- this.param_list = param_list;
- this.location = loc;
- }
-}
-
-//
-// We use this when we do not have an object in advance that is an IAnonymousHost
-//
-public class SimpleAnonymousHost : IAnonymousHost {
- public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
-
- bool yields;
- ArrayList anonymous_methods;
-
- public static SimpleAnonymousHost GetSimple () {
- Simple.yields = false;
- Simple.anonymous_methods = null;
- return Simple;
- }
-
- public void SetYields ()
- {
- yields = true;
- }
-
- public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
- {
- if (anonymous_methods == null)
- anonymous_methods = new ArrayList ();
- anonymous_methods.Add (anonymous);
- }
-
- public void Propagate (IAnonymousHost real_host)
+class VariableMemberDeclaration
+{
+ public readonly MemberName MemberName;
+ public Expression expression_or_array_initializer;
+
+ public VariableMemberDeclaration (MemberName mn, object initializer)
{
- if (yields)
- real_host.SetYields ();
- if (anonymous_methods != null) {
- foreach (AnonymousMethodExpression ame in anonymous_methods)
- real_host.AddAnonymousMethod (ame);
+ 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;
}
}
}
+
// <summary>
// A class used to hold info about an operator declarator
// </summary>
-public class OperatorDeclaration {
- public Operator.OpType optype;
- public Expression ret_type, arg1type, arg2type;
- public string arg1name, arg2name;
- public Location location;
-
- public OperatorDeclaration (Operator.OpType op, Expression ret_type,
- Expression arg1type, string arg1name,
- Expression arg2type, string arg2name, Location location)
+struct OperatorDeclaration {
+ public readonly Operator.OpType optype;
+ public readonly FullNamedExpression ret_type;
+ public readonly Location location;
+
+ public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
{
optype = op;
this.ret_type = ret_type;
- this.arg1type = arg1type;
- this.arg1name = arg1name;
- this.arg2type = arg2type;
- this.arg2name = arg2name;
this.location = location;
}
-
}
void Error_ExpectingTypeName (Expression expr)
}
}
-public static void Error_ParameterModifierNotValid (Location loc)
+static void Error_ParameterModifierNotValid (string modifier, Location loc)
{
- Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
+ Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
+ modifier);
}
static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
Parameter.GetModifierSignature (mod));
}
+static void Error_TypeExpected (Location loc)
+{
+ Report.Error (1031, loc, "Type expected");
+}
+
void push_current_class (TypeContainer tc, object partial_token)
{
+ if (RootContext.EvalMode){
+ tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
+ undo.AddTypeContainer (current_container, tc);
+ }
+
if (partial_token != null)
current_container = current_container.AddPartial (tc);
else
current_container = current_container.AddTypeContainer (tc);
+
+
current_class = tc;
}
{
Namespace ns = current_namespace.NS;
- if (current_container.Name.Length == 0){
+ if (current_container == RootContext.ToplevelTypes) {
if (ns.Name.Length != 0)
return new MemberName (ns.MemberName, class_name);
else
Block implicit_block;
ArrayList inits = null;
+ //
+ // If we are doing interactive editing, we want variable declarations
+ // that are in the top block to be added instead to the class as
+ // static variables
+ //
+ if (RootContext.StatementMode){
+ bool hoist = true;
+
+ for (Block b = current_block; b != null; b = b.Parent){
+ if (b is ExplicitBlock && !(b is ToplevelBlock)){
+ // There has been an explicit block, we cant add to the class
+ hoist = false;
+ break;
+ }
+ }
+ if (hoist){
+ //
+ // We can use "current_block" since we know there are no explicit blocks
+ //
+ 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){
+ string id = "$" + decl.identifier;
+ current_block.AddVariable (type, id, decl.Location);
+
+ 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);
+ current_block.AddStatement (new StatementExpression (assign));
+ assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
+ current_block.AddStatement (new StatementExpression (assign));
+ } else {
+ Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
+ new MemberName (decl.identifier, loc), null);
+ current_container.AddField (f);
+
+ // Register the field to be visible later as a global variable
+ Evaluator.QueueField (f);
+ }
+ }
+
+ return current_block;
+ }
+ }
+
//
// We use the `Used' property to check whether statements
// have been added to the current block. If so, we need
// int j = 1; int k = j + 1;
//
if (current_block.Used)
- implicit_block = new Block (current_block, loc, Location.Null);
+ implicit_block = new Block (current_block, loc, lexer.Location);
else
implicit_block = current_block;
LocalVariableReference var;
var = new LocalVariableReference (implicit_block, decl.identifier, loc);
- assign = new Assign (var, expr, decl.Location);
+ assign = new SimpleAssign (var, expr, decl.Location);
implicit_block.AddStatement (new StatementExpression (assign));
}
return string.Empty;
}
-void CheckUnaryOperator (Operator.OpType op, Location l)
+static bool IsUnaryOperator (Operator.OpType op)
{
switch (op) {
case Operator.OpType.Decrement:
case Operator.OpType.True:
case Operator.OpType.False:
- case Operator.OpType.Addition:
- case Operator.OpType.Subtraction:
-
- break;
-
- default :
- Report.Error (1019, l, "Overloadable unary operator expected");
- break;
-
+ case Operator.OpType.UnaryPlus:
+ case Operator.OpType.UnaryNegation:
+ return true;
}
-}
-
-void CheckBinaryOperator (Operator.OpType op, Location l)
-{
- switch (op) {
-
- case Operator.OpType.Addition:
- case Operator.OpType.Subtraction:
- case Operator.OpType.Multiply:
- case Operator.OpType.Division:
- case Operator.OpType.Modulus:
- case Operator.OpType.BitwiseAnd:
- case Operator.OpType.BitwiseOr:
- case Operator.OpType.ExclusiveOr:
- case Operator.OpType.LeftShift:
- case Operator.OpType.RightShift:
- case Operator.OpType.Equality:
- case Operator.OpType.Inequality:
- case Operator.OpType.GreaterThan:
- case Operator.OpType.LessThan:
- case Operator.OpType.GreaterThanOrEqual:
- case Operator.OpType.LessThanOrEqual:
- break;
-
- default :
- Report.Error (1020, l, "Overloadable binary operator expected");
- break;
- }
-
+ return false;
}
void syntax_error (Location l, string msg)
oob_stack = new Stack ();
}
-public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
{
- this.name = file.Name;
+ if (RootContext.EvalMode)
+ undo = new Undo ();
+
this.file = file;
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, defines);
+ lexer = new Tokenizer (reader, file);
}
public void parse ()
{
- int errors = Report.Errors;
+ eof_token = Token.EOF;
+
try {
if (yacc_verbose_flag > 1)
yyparse (lexer, new yydebug.yyDebugSimple ());
else
yyparse (lexer);
- Tokenizer tokenizer = lexer as Tokenizer;
- tokenizer.cleanup ();
} catch (Exception e){
- //
- // Removed for production use, use parser verbose to get the output.
- //
- // Console.WriteLine (e);
- if (Report.Errors == errors)
+ 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");
- if (yacc_verbose_flag > 0)
- Console.WriteLine (e);
+ else
+ Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
}
+ 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)
{
if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
- Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
+ Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
else
Report.Error (error, loc, msg);
}
return lexer.Location;
}
-static GenericMethod current_generic_method = null;
-
void start_block (Location loc)
{
if (current_block == null || parsing_anonymous_method) {
current_local_parameters = parameters;
- ToplevelBlock top_current_block = current_block == null ? null : current_block.Toplevel;
-
current_anonymous_method = lambda
- ? new LambdaExpression (
- current_anonymous_method, current_generic_method, current_container,
- parameters, top_current_block, loc)
- : new AnonymousMethodExpression (
- current_anonymous_method, current_generic_method, current_container,
- parameters, top_current_block, loc);
+ ? new LambdaExpression (parameters, loc)
+ : new AnonymousMethodExpression (parameters, loc);
// Force the next block to be created as a ToplevelBlock
parsing_anonymous_method = true;
* Completes the anonymous method processing, if lambda_expr is null, this
* means that we have a Statement instead of an Expression embedded
*/
-AnonymousMethodExpression
-end_anonymous (ToplevelBlock anon_block, Location loc)
+AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
{
AnonymousMethodExpression retval;
retval = null;
} else {
current_anonymous_method.Block = anon_block;
- if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
- anonymous_host.AddAnonymousMethod (current_anonymous_method);
-
retval = current_anonymous_method;
}
return retval;
}
+public NamespaceEntry CurrentNamespace {
+ get {
+ return current_namespace;
+ }
+}
+
+public string GetExpecting ()
+{
+ int [] tokens = yyExpectingTokens (yyExpectingState);
+ if (tokens.Length == 1)
+ return "`" + GetTokenName (tokens [0]) + "'";
+
+ StringBuilder sb = new StringBuilder ();
+ ArrayList names = new ArrayList ();
+ for (int i = 0; i < tokens.Length; i++){
+ string name = GetTokenName (tokens [i]);
+ if (name == "<internal>")
+ continue;
+ if (names.Contains (name))
+ continue;
+
+ names.Add (name);
+ }
+
+ names.Sort ();
+ int count = names.Count;
+ for (int i = 0; i < count; i++){
+ bool last = i + 1 == count;
+ if (last)
+ sb.Append ("or ");
+ sb.Append ('`');
+ sb.Append (names [i]);
+ sb.Append (last ? "'" : "', ");
+ }
+ return sb.ToString ();
+}
+
+static public string GetTokenName (int token)
+{
+ switch (token){
+ case Token.ABSTRACT:
+ return "abstract";
+ case Token.AS:
+ return "as";
+ case Token.ADD:
+ return "add";
+ case Token.ASSEMBLY:
+ return "assembly";
+ case Token.BASE:
+ return "base";
+ case Token.BREAK:
+ return "break";
+ case Token.CASE:
+ return "case";
+ case Token.CATCH:
+ return "catch";
+ case Token.CHECKED:
+ return "checked";
+ case Token.CLASS:
+ return "class";
+ case Token.CONST:
+ return "const";
+ case Token.CONTINUE:
+ return "continue";
+ case Token.DEFAULT:
+ return "default";
+ case Token.DELEGATE:
+ return "delegate";
+ case Token.DO:
+ return "do";
+ case Token.ELSE:
+ return "else";
+ case Token.ENUM:
+ return "enum";
+ case Token.EVENT:
+ return "event";
+ case Token.EXPLICIT:
+ return "explicit";
+ case Token.EXTERN:
+ return "extern";
+ case Token.FALSE:
+ return "false";
+ case Token.FINALLY:
+ return "finally";
+ case Token.FIXED:
+ return "fixed";
+ case Token.FOR:
+ return "for";
+ case Token.FOREACH:
+ return "foreach";
+ case Token.GOTO:
+ return "goto";
+ case Token.IF:
+ return "if";
+ case Token.IMPLICIT:
+ return "implicit";
+ case Token.IN:
+ return "in";
+ case Token.INTERFACE:
+ return "interface";
+ case Token.INTERNAL:
+ return "internal";
+ case Token.IS:
+ return "is";
+ case Token.LOCK:
+ return "lock";
+ case Token.NAMESPACE:
+ return "namespace";
+ case Token.NEW:
+ return "new";
+ case Token.NULL:
+ return "null";
+ case Token.OBJECT:
+ return "object";
+ case Token.OPERATOR:
+ return "operator";
+ case Token.OUT:
+ return "out";
+ case Token.OVERRIDE:
+ return "override";
+ case Token.PARAMS:
+ return "params";
+ case Token.PRIVATE:
+ return "private";
+ case Token.PROTECTED:
+ return "protected";
+ case Token.PUBLIC:
+ return "public";
+ case Token.READONLY:
+ return "readonly";
+ case Token.REF:
+ return "ref";
+ case Token.RETURN:
+ return "return";
+ case Token.REMOVE:
+ return "remove";
+ case Token.SEALED:
+ return "sealed";
+ case Token.SIZEOF:
+ return "sizeof";
+ case Token.STACKALLOC:
+ return "stackalloc";
+ case Token.STATIC:
+ return "static";
+ case Token.STRUCT:
+ return "struct";
+ case Token.SWITCH:
+ return "switch";
+ case Token.THIS:
+ return "this";
+ case Token.THROW:
+ return "throw";
+ case Token.TRUE:
+ return "true";
+ case Token.TRY:
+ return "try";
+ case Token.TYPEOF:
+ return "typeof";
+ case Token.UNCHECKED:
+ return "unchecked";
+ case Token.UNSAFE:
+ return "unsafe";
+ case Token.USING:
+ return "using";
+ case Token.VIRTUAL:
+ return "virtual";
+ case Token.VOLATILE:
+ return "volatile";
+ case Token.WHERE:
+ return "where";
+ case Token.WHILE:
+ return "while";
+ case Token.ARGLIST:
+ return "arglist";
+ case Token.PARTIAL:
+ return "partial";
+ case Token.ARROW:
+ return "=>";
+ case Token.FROM:
+ return "from";
+ case Token.JOIN:
+ return "join";
+ case Token.ON:
+ return "on";
+ case Token.EQUALS:
+ return "equals";
+ case Token.SELECT:
+ return "select";
+ case Token.GROUP:
+ return "group";
+ case Token.BY:
+ return "by";
+ case Token.LET:
+ return "let";
+ case Token.ORDERBY:
+ return "orderby";
+ case Token.ASCENDING:
+ return "ascending";
+ case Token.DESCENDING:
+ return "descending";
+ case Token.INTO:
+ return "into";
+ case Token.GET:
+ return "get";
+ case Token.SET:
+ return "set";
+ case Token.OPEN_BRACE:
+ return "{";
+ case Token.CLOSE_BRACE:
+ return "}";
+ case Token.OPEN_BRACKET:
+ return "[";
+ case Token.CLOSE_BRACKET:
+ return "]";
+ case Token.DEFAULT_OPEN_PARENS:
+ case Token.OPEN_PARENS_LAMBDA:
+ case Token.OPEN_PARENS:
+ return "(";
+ case Token.CLOSE_PARENS_CAST:
+ case Token.CLOSE_PARENS_NO_CAST:
+ case Token.CLOSE_PARENS_OPEN_PARENS:
+ case Token.CLOSE_PARENS_MINUS:
+ case Token.CLOSE_PARENS:
+ return ")";
+ case Token.DOT:
+ return ".";
+ case Token.COMMA:
+ return ",";
+ case Token.DEFAULT_COLON:
+ return "default:";
+ case Token.COLON:
+ return ":";
+ case Token.SEMICOLON:
+ return ";";
+ case Token.TILDE:
+ return "~";
+
+ case Token.PLUS:
+ case Token.UMINUS:
+ case Token.MINUS:
+ case Token.BANG:
+ case Token.OP_LT:
+ case Token.OP_GT:
+ case Token.BITWISE_AND:
+ case Token.BITWISE_OR:
+ case Token.STAR:
+ case Token.PERCENT:
+ case Token.DIV:
+ case Token.CARRET:
+ case Token.OP_INC:
+ case Token.OP_DEC:
+ case Token.OP_SHIFT_LEFT:
+ case Token.OP_SHIFT_RIGHT:
+ case Token.OP_LE:
+ case Token.OP_GE:
+ case Token.OP_EQ:
+ case Token.OP_NE:
+ case Token.OP_AND:
+ case Token.OP_OR:
+ case Token.OP_PTR:
+ case Token.OP_COALESCING:
+ return "<operator>";
+
+ case Token.OP_MULT_ASSIGN:
+ case Token.OP_DIV_ASSIGN:
+ case Token.OP_MOD_ASSIGN:
+ case Token.OP_ADD_ASSIGN:
+ case Token.OP_SUB_ASSIGN:
+ case Token.OP_SHIFT_LEFT_ASSIGN:
+ case Token.OP_SHIFT_RIGHT_ASSIGN:
+ case Token.OP_AND_ASSIGN:
+ case Token.OP_XOR_ASSIGN:
+ case Token.OP_OR_ASSIGN:
+ return "<operator>";
+
+ case Token.BOOL:
+ case Token.BYTE:
+ case Token.CHAR:
+ case Token.VOID:
+ case Token.DECIMAL:
+ case Token.DOUBLE:
+ case Token.FLOAT:
+ case Token.INT:
+ case Token.LONG:
+ case Token.SBYTE:
+ case Token.SHORT:
+ case Token.STRING:
+ case Token.UINT:
+ case Token.ULONG:
+ case Token.USHORT:
+ return "<type>";
+
+ case Token.ASSIGN:
+ return "=";
+ case Token.OP_GENERICS_LT:
+ case Token.GENERIC_DIMENSION:
+ return "<";
+ case Token.OP_GENERICS_GT:
+ return ">";
+ case Token.INTERR:
+ case Token.INTERR_NULLABLE:
+ 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:
+ return "value";
+ case Token.IDENTIFIER:
+ return "identifier";
+
+ // All of these are internal.
+ case Token.NONE:
+ case Token.ERROR:
+ case Token.FIRST_KEYWORD:
+ case Token.EOF:
+ case Token.EVAL_COMPILATION_UNIT_PARSER:
+ case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
+ case Token.EVAL_STATEMENT_PARSER:
+ case Token.LOWPREC:
+ case Token.QUERY_LAST_TOKEN:
+ case Token.QUERY_FIRST_TOKEN:
+ case Token.LAST_KEYWORD:
+ return "<internal>";
+
+ // A bit more robust.
+ default:
+ return yyNames [token];
+ }
+}
+
/* end end end */
}