/// When using the interactive parser, this holds the
/// resulting expression
- public object InteractiveResult;
+ public Class InteractiveResult;
//
// Keeps track of global data changes to undo on parser error
Stack<Linq.QueryBlock> linq_clause_blocks;
- // A counter to create new class names in interactive mode
- static int class_count;
-
ModuleContainer module;
- CompilerContext compiler;
+ readonly CompilerContext compiler;
+ readonly LanguageVersion lang_version;
+ readonly bool doc_support;
+ readonly CompilerSettings settings;
//
// Instead of allocating carrier array everytime we
string s = lt.Value;
if (s != "alias"){
syntax_error (lt.Location, "`alias' expected");
- } else if (RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotAvailable (lt.Location, "external alias");
+ } else if (lang_version == LanguageVersion.ISO_1) {
+ FeatureIsNotAvailable (lt.Location, "external alias");
} else {
lt = (Tokenizer.LocatedToken) $3;
current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
using_directive
: using_alias_directive
{
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
| using_namespace_directive
{
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
;
: USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
{
var lt = (Tokenizer.LocatedToken) $2;
+ if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
+ Report.Warning (440, 2, lt.Location,
+ "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
+ }
+
current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
}
| USING error
namespace_body
: OPEN_BRACE
{
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_extern_alias_directives
$$ = new Attributes (sect);
}
if ($$ == null) {
- if (RootContext.Documentation != null) {
+ if (doc_support) {
Lexer.check_incorrect_doc_comment ();
Lexer.doc_state =
XmlCommentState.Allowed;
named_argument
: IDENTIFIER COLON opt_named_modifier expression
{
- if (RootContext.Version <= LanguageVersion.V_3)
- Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
+ if (lang_version <= LanguageVersion.V_3)
+ FeatureIsNotAvailable (GetLocation ($1), "named argument");
// Avoid boxing in common case (no modifier)
var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
current_class.SetParameterInfo ((List<Constraints>) $9);
- if (RootContext.Documentation != null)
+ if (doc_support)
current_container.DocComment = Lexer.consume_doc_comment ();
lbag.AddMember (current_class, mod_locations, GetLocation ($4));
struct_body
{
--lexer.parsing_declaration;
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_semicolon
struct_body
: OPEN_BRACE
{
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_struct_member_declarations CLOSE_BRACE
}
constant_initializer opt_constant_declarators SEMICOLON
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_field.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
lexer.parsing_generic_declaration = false;
FullNamedExpression type = (FullNamedExpression) $3;
- if (type.Type == TypeManager.void_type)
+ if (type.Type != null && type.Type.Kind == MemberKind.Void)
Report.Error (670, GetLocation ($3), "Fields cannot have void type");
var lt = (Tokenizer.LocatedToken) $4;
opt_field_declarators
SEMICOLON
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_field.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_modifiers
FIXED simple_type IDENTIFIER
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
var lt = (Tokenizer.LocatedToken) $5;
current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
}
fixed_field_size opt_fixed_field_declarators SEMICOLON
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_field.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
method_declaration
: method_header
{
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.NotAllowed;
// Add it early in the case of body being eof for full aot
current_local_parameters = null;
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
;
method.GetSignatureForError ());
}
- if (RootContext.Documentation != null)
+ if (doc_support)
method.DocComment = Lexer.consume_doc_comment ();
lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
- new TypeExpression (TypeManager.void_type, GetLocation ($4)),
+ new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($4)),
current_local_parameters);
generic.SetParameterInfo ((List<Constraints>) $11);
modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
- method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
+ method = new Method (current_class, generic, new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($4)),
modifiers, name, current_local_parameters, (Attributes) $1);
- if (RootContext.Documentation != null)
+ if (doc_support)
method.DocComment = Lexer.consume_doc_comment ();
// TODO: lbag, push void
current_local_parameters = (ParametersCompiled) $7;
- if (RootContext.Documentation != null)
+ if (doc_support)
method.DocComment = Lexer.consume_doc_comment ();
$$ = method;
constant_expression
{
--lexer.parsing_block;
- if (RootContext.Version <= LanguageVersion.V_3) {
- Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
+ if (lang_version <= LanguageVersion.V_3) {
+ FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
}
Parameter.Modifier mod = (Parameter.Modifier) $2;
if ((valid_param_mod & ParameterModifierType.This) == 0)
Error_ParameterModifierNotValid ("this", GetLocation ($1));
- if (RootContext.Version <= LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
+ if (lang_version <= LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "extension methods");
$$ = Parameter.Modifier.This;
}
member_type
member_declaration_name
{
- if (RootContext.Documentation != null)
+ if (doc_support)
tmpComment = Lexer.consume_doc_comment ();
}
OPEN_BRACE
{
- current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
+ var type = (FullNamedExpression) $3;
+ current_property = new Property (current_class, type, (Modifiers) $2,
(MemberName) $4, (Attributes) $1);
- if (current_property.TypeExpression.Type == TypeManager.void_type)
+ if (type.Type != null && type.Type.Kind == MemberKind.Void)
Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
current_container.AddProperty ((Property)current_property);
{
lexer.PropertyParsing = false;
- if (RootContext.Documentation != null)
+ if (doc_support)
current_property.DocComment = ConsumeStoredComment ();
}
CLOSE_BRACE
opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
{
valid_param_mod = 0;
-
- Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+ var type = (FullNamedExpression) $3;
+ Indexer indexer = new Indexer (current_class, type,
(MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
current_property = indexer;
current_container.AddIndexer (indexer);
lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
- if (indexer.TypeExpression.Type == TypeManager.void_type)
+ if (type.Type != null && type.Type.Kind == MemberKind.Void)
Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
if (indexer.Parameters.IsEmpty) {
Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
}
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
}
CLOSE_BRACE
{
- if (RootContext.Documentation != null)
+ if (doc_support)
current_property.DocComment = ConsumeStoredComment ();
lbag.AppendToMember (current_property, GetLocation ($12));
get_accessor_declaration
: opt_attributes opt_modifiers GET
{
- if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+ if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
+ FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
}
if (current_property.Get != null) {
current_local_parameters = null;
lexer.PropertyParsing = true;
- if (RootContext.Documentation != null)
+ if (doc_support)
if (Lexer.doc_state == XmlCommentState.Error)
Lexer.doc_state = XmlCommentState.NotAllowed;
}
set_accessor_declaration
: opt_attributes opt_modifiers SET
{
- if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
+ if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
+ FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
}
if (current_property.Set != null) {
current_local_parameters = null;
lexer.PropertyParsing = true;
- if (RootContext.Documentation != null
+ if (doc_support
&& Lexer.doc_state == XmlCommentState.Error)
Lexer.doc_state = XmlCommentState.NotAllowed;
}
current_class.SetParameterInfo ((List<Constraints>) $9);
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_container.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
{
--lexer.parsing_declaration;
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_semicolon
current_local_parameters,
(ToplevelBlock) $5, (Attributes) $1, decl.location);
- if (RootContext.Documentation != null) {
+ if (doc_support) {
op.DocComment = tmpComment;
Lexer.doc_state = XmlCommentState.Allowed;
}
| VOID
{
Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
- $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+ $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
}
;
}
}
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
Location loc = GetLocation ($2);
current_local_parameters = (ParametersCompiled)$6;
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
Location loc = GetLocation ($2);
current_local_parameters = (ParametersCompiled)$6;
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
Constructor c = (Constructor) $1;
c.Block = (ToplevelBlock) $2;
- if (RootContext.Documentation != null)
+ if (doc_support)
c.DocComment = ConsumeStoredComment ();
current_container.AddConstructor (c);
current_local_parameters = null;
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
;
opt_modifiers
IDENTIFIER
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
destructor_declaration
: opt_attributes opt_modifiers TILDE
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
Destructor d = new Destructor (current_class, (Modifiers) $2,
ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
- if (RootContext.Documentation != null)
+ if (doc_support)
d.DocComment = ConsumeStoredComment ();
d.Block = (ToplevelBlock) $8;
opt_event_declarators
SEMICOLON
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_event_field.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
}
CLOSE_BRACE
{
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_event.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
ENUM type_declaration_name
opt_enum_base
{
- if (RootContext.Documentation != null)
+ if (doc_support)
enumTypeComment = Lexer.consume_doc_comment ();
}
OPEN_BRACE
{
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
MemberName name = (MemberName) $4;
opt_enum_member_declarations
{
// here will be evaluated after CLOSE_BLACE is consumed.
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
CLOSE_BRACE opt_semicolon
{
- if (RootContext.Documentation != null)
+ if (doc_support)
current_class.DocComment = enumTypeComment;
--lexer.parsing_declaration;
-// if (RootContext.Documentation != null)
+// if (doc_support)
// em.DocComment = ev.DocComment;
lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
| COLON type
{
var te = $2 as TypeExpression;
- if (te == null ||
- (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
- te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
- te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
- te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
+ if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
Enum.Error_1008 (GetLocation ($2), Report);
$$ = null;
} else {
var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
((Enum) current_class).AddEnumMember (em);
- if (RootContext.Documentation != null) {
+ if (doc_support) {
em.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
| opt_attributes IDENTIFIER
{
++lexer.parsing_block;
- if (RootContext.Documentation != null) {
+ if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
((Enum) current_class).AddEnumMember (em);
- if (RootContext.Documentation != null)
+ if (doc_support)
em.DocComment = ConsumeStoredComment ();
$$ = em;
Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
(Modifiers) $2, name, p, (Attributes) $1);
- if (RootContext.Documentation != null) {
+ if (doc_support) {
del.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
: /* empty */
| INTERR_NULLABLE
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "nullable types");
$$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
}
: /* empty */
| OP_GENERICS_LT type_arguments OP_GENERICS_GT
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $2;
}
: /* empty */
| OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $2;
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
: type_expression_or_array
| VOID
{
- $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+ $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
}
;
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+ $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
}
;
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+ $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
}
;
| VOID
{
Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
- $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+ $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
}
;
}
| VOID pointer_stars
{
- $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
+ $$ = new ComposedCast (new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
}
;
* simple types, but we need this to reuse it easily in variable_type
*/
builtin_types
- : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
- | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
- | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
- | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
- | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
- | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
+ : OBJECT { $$ = new TypeExpression (compiler.BuildinTypes.Object, GetLocation ($1)); }
+ | STRING { $$ = new TypeExpression (compiler.BuildinTypes.String, GetLocation ($1)); }
+ | BOOL { $$ = new TypeExpression (compiler.BuildinTypes.Bool, GetLocation ($1)); }
+ | DECIMAL { $$ = new TypeExpression (compiler.BuildinTypes.Decimal, GetLocation ($1)); }
+ | FLOAT { $$ = new TypeExpression (compiler.BuildinTypes.Float, GetLocation ($1)); }
+ | DOUBLE { $$ = new TypeExpression (compiler.BuildinTypes.Double, GetLocation ($1)); }
| integral_type
;
integral_type
- : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
- | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
- | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
- | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
- | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
- | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
- | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
- | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
- | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
+ : SBYTE { $$ = new TypeExpression (compiler.BuildinTypes.SByte, GetLocation ($1)); }
+ | BYTE { $$ = new TypeExpression (compiler.BuildinTypes.Byte, GetLocation ($1)); }
+ | SHORT { $$ = new TypeExpression (compiler.BuildinTypes.Short, GetLocation ($1)); }
+ | USHORT { $$ = new TypeExpression (compiler.BuildinTypes.UShort, GetLocation ($1)); }
+ | INT { $$ = new TypeExpression (compiler.BuildinTypes.Int, GetLocation ($1)); }
+ | UINT { $$ = new TypeExpression (compiler.BuildinTypes.UInt, GetLocation ($1)); }
+ | LONG { $$ = new TypeExpression (compiler.BuildinTypes.Long, GetLocation ($1)); }
+ | ULONG { $$ = new TypeExpression (compiler.BuildinTypes.ULong, GetLocation ($1)); }
+ | CHAR { $$ = new TypeExpression (compiler.BuildinTypes.Char, GetLocation ($1)); }
;
//
;
boolean_literal
- : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
- | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
+ : TRUE { $$ = new BoolLiteral (compiler.BuildinTypes, true, GetLocation ($1)); }
+ | FALSE { $$ = new BoolLiteral (compiler.BuildinTypes, false, GetLocation ($1)); }
;
: NEW new_expr_type open_parens_any 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");
+ if (lang_version <= LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "object initializers");
$$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
} else {
}
| NEW new_expr_type object_or_collection_initializer
{
- if (RootContext.Version <= LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
+ if (lang_version <= LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
$$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
}
}
| NEW rank_specifier array_initializer
{
- if (RootContext.Version <= LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
+ if (lang_version <= LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
$$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
}
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");
+ if (lang_version <= LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
$$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
: OPEN_BRACKET CLOSE_BRACKET
{
$$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($2));
}
| OPEN_BRACKET dim_separators CLOSE_BRACKET
{
$$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
+ lbag.AddLocation ($$, GetLocation ($3));
}
;
{
var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
ai.VariableDeclaration = current_variable;
- lbag.AddLocation (ai, GetLocation ($3));
+ if ($3 != null) {
+ lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
+ } else {
+ lbag.AddLocation (ai, GetLocation ($4));
+ }
$$ = ai;
}
;
generic_dimension
: GENERIC_DIMENSION
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "generics");
$$ = $1;
}
: IDENTIFIER DOUBLE_COLON
{
var lt = (Tokenizer.LocatedToken) $1;
- if (RootContext.Version == LanguageVersion.ISO_1)
- Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
+ if (lang_version == LanguageVersion.ISO_1)
+ FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
$$ = lt;
}
default_value_expression
: DEFAULT open_parens_any type CLOSE_PARENS
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "default value expression");
$$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
: conditional_or_expression
| conditional_or_expression OP_COALESCING null_coalescing_expression
{
- if (RootContext.Version < LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
+ if (lang_version < LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
$$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
}
}
| OPEN_PARENS_LAMBDA
{
- if (RootContext.Version <= LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
+ if (lang_version <= LanguageVersion.ISO_2)
+ FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
}
lambda_expression_body
{
$$ = end_anonymous ((ParametersBlock) $7);
- lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
+ lbag.AddLocation ($$, GetLocation ($4), GetLocation ($5));
}
;
type_declaration_name
{
MemberName name = MakeName ((MemberName) $6);
- push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
+ Class c = new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1);
+ if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
+ FeatureIsNotAvailable (c.Location, "static classes");
+ }
+
+ push_current_class (c, $3);
}
opt_class_base
opt_type_parameter_constraints_clauses
current_class.SetParameterInfo ((List<Constraints>) $9);
lbag.AddMember (current_class, mod_locations, GetLocation ($4));
- if (RootContext.Documentation != null) {
+ if (doc_support) {
current_container.DocComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.Allowed;
}
OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
{
--lexer.parsing_declaration;
- if (RootContext.Documentation != null)
+ if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
}
opt_semicolon
{
$$ = Modifiers.UNSAFE;
StoreModifierLocation ($$, GetLocation ($1));
- if (!RootContext.Unsafe)
+ if (!settings.Unsafe)
Error_UnsafeCodeNotAllowed (GetLocation ($1));
}
| ASYNC
}
| type_parameter_variance
{
- if (RootContext.Version <= LanguageVersion.V_3)
- Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
+ if (lang_version <= LanguageVersion.V_3)
+ FeatureIsNotAvailable (lexer.Location, "generic type variance");
$$ = $1;
}
}
| VOID pointer_stars
{
- $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
+ $$ = new ComposedCast (new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
}
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
+ $$ = new TypeExpression (compiler.BuildinTypes.Void, GetLocation ($1));
}
;
switch_labels
: switch_label
{
- var labels = new List<SwitchLabel> (4);
+ var labels = new List<SwitchLabel> (2);
labels.Add ((SwitchLabel) $1);
$$ = labels;
Report.Error (1003, lt.Location, "; expected");
} else if ($3 == null) {
Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
- } else if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotAvailable (lt.Location, "iterators");
+ } else if (lang_version == LanguageVersion.ISO_1){
+ FeatureIsNotAvailable (lt.Location, "iterators");
}
current_block.ParametersBlock.TopBlock.IsIterator = true;
string s = lt.Value;
if (s != "yield"){
Report.Error (1003, lt.Location, "; expected");
- } else if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotAvailable (lt.Location, "iterators");
+ } else if (lang_version == LanguageVersion.ISO_1){
+ FeatureIsNotAvailable (lt.Location, "iterators");
}
current_block.ParametersBlock.TopBlock.IsIterator = true;
unsafe_statement
: UNSAFE
{
- if (!RootContext.Unsafe)
+ if (!settings.Unsafe)
Error_UnsafeCodeNotAllowed (GetLocation ($1));
} block {
$$ = new Unsafe ((Block) $3, GetLocation ($1));
{
start_block (GetLocation ($2));
+ current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li);
{
start_block (GetLocation ($2));
+ current_block.IsCompilerGenerated = true;
var lt = (Tokenizer.LocatedToken) $4;
var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
current_block.AddLocalName (li);
first_from_clause
: FROM_FIRST IDENTIFIER IN expression
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $2;
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
}
| FROM_FIRST type IDENTIFIER IN expression
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $3;
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
nested_from_clause
: FROM IDENTIFIER IN expression
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $2;
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
}
| FROM type IDENTIFIER IN expression
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
var lt = (Tokenizer.LocatedToken) $3;
var rv = new Linq.RangeVariable (lt.Value, lt.Location);
from_clause
: FROM IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
expression
{
}
| FROM type IDENTIFIER IN
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
expression
{
select_or_group_clause
: SELECT
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
expression
{
if (linq_clause_blocks == null)
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
}
expression
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
BY expression
{
let_clause
: LET IDENTIFIER ASSIGN
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
expression
{
where_clause
: WHERE
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
- boolean_expression
+ expression
{
- $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
+ $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
if (linq_clause_blocks == null)
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression ON
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression EQUALS
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
expression opt_join_into
{
if (linq_clause_blocks == null)
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression ON
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
}
expression EQUALS
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
expression opt_join_into
{
orderby_clause
: ORDERBY
{
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
orderings
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
}
orderings_then_by
{
current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
+ current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
}
then_by
{
current_block.SetEndLocation (GetLocation ($1));
current_block = current_block.Parent;
- current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
+ current_block = new Linq.QueryBlock (current_block, lexer.Location);
if (linq_clause_blocks == null)
linq_clause_blocks = new Stack<Linq.QueryBlock> ();
interactive_parsing
: EVAL_STATEMENT_PARSER EOF
| EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
- | 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);
-
- var baseclass_list = new List<FullNamedExpression> ();
- baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
- current_container.AddBasesForPart (current_class, baseclass_list);
+ | EVAL_STATEMENT_PARSER
+ {
+ current_container = new Class (current_namespace, current_class, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
+ current_class = current_container;
// (ref object retval)
Parameter [] mpar = new Parameter [1];
- mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
+ mpar [0] = new Parameter (new TypeExpression (compiler.BuildinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
ParametersCompiled pars = new ParametersCompiled (mpar);
+ var mods = Modifiers.PUBLIC | Modifiers.STATIC;
+ if (settings.Unsafe)
+ mods |= Modifiers.UNSAFE;
+
current_local_parameters = pars;
Method method = new Method (
current_class,
null, // generic
- new TypeExpression (TypeManager.void_type, Location.Null),
- Modifiers.PUBLIC | Modifiers.STATIC,
+ new TypeExpression (compiler.BuildinTypes.Void, Location.Null),
+ mods,
new MemberName ("Host"),
pars,
null /* attributes */);
+
+ current_container.AddMethod (method);
oob_stack.Push (method);
- ++lexer.parsing_block;
+ ++lexer.parsing_block;
start_block (lexer.Location);
}
interactive_statement_list opt_COMPLETE_COMPLETION
Method method = (Method) oob_stack.Pop ();
method.Block = (ToplevelBlock) end_block(lexer.Location);
- current_container.AddMethod (method);
- --lexer.parsing_declaration;
- InteractiveResult = pop_current_class ();
+ InteractiveResult = (Class) pop_current_class ();
current_local_parameters = null;
}
- | EVAL_COMPILATION_UNIT_PARSER {
- Evaluator.LoadAliases (current_namespace);
- }
- interactive_compilation_unit
+ | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
;
interactive_compilation_unit
void push_current_class (TypeContainer tc, object partial_token)
{
- if (RootContext.EvalMode){
- tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
+ if (module.Evaluator != null){
+ tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
+ if (undo == null)
+ undo = new Undo ();
undo.AddTypeContainer (current_container, tc);
}
}
public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
+ : this (reader, file, module, new NamespaceEntry (module, null, file, null))
{
- if (RootContext.EvalMode)
- undo = new Undo ();
+}
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module, NamespaceEntry ns)
+{
this.file = file;
this.module = module;
this.compiler = module.Compiler;
- current_namespace = new NamespaceEntry (module, null, file, null);
+ this.settings = compiler.Settings;
+ lang_version = settings.Version;
+ doc_support = settings.Documentation != null;
+ current_namespace = ns;
current_class = current_namespace.SlaveDeclSpace;
current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
oob_stack.Clear ();
return s;
}
+void FeatureIsNotAvailable (Location loc, string feature)
+{
+ compiler.Report.FeatureIsNotAvailable (compiler, loc, feature);
+}
+
Location GetLocation (object obj)
{
var lt = obj as Tokenizer.LocatedToken;
void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
{
- if (RootContext.Version == LanguageVersion.ISO_1){
- Report.FeatureIsNotAvailable (loc, "anonymous methods");
+ if (lang_version == LanguageVersion.ISO_1){
+ FeatureIsNotAvailable (loc, "anonymous methods");
}
oob_stack.Push (current_anonymous_method);