+2010-06-07 Marek Safar <marek.safar@gmail.com>
+
+ * typemanager.cs, eval.cs, iterators.cs, anonymous.cs, expression.cs
+ method.cs, class.cs, delegate.cs, cs-parser.jay, driver.cs, visit.cs
+ enum.cs: Hold location of predefined types.
+
2010-06-07 Marek Safar <marek.safar@gmail.com>
A fix for bug #610878
Location loc = Location;
- Method equals = new Method (this, null, TypeManager.system_boolean_expr,
+ Method equals = new Method (this, null, new TypeExpression (TypeManager.bool_type, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
Mono.CSharp.ParametersCompiled.CreateFullyResolved (new Parameter (null, "obj", 0, null, loc), TypeManager.object_type), null);
- Method tostring = new Method (this, null, TypeManager.system_string_expr,
+ Method tostring = new Method (this, null, new TypeExpression (TypeManager.string_type, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
//
// GetHashCode () override
//
- Method hashcode = new Method (this, null, TypeManager.system_int32_expr,
+ Method hashcode = new Method (this, null, new TypeExpression (TypeManager.int32_type, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("GetHashCode", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
Block hashcode_block = new Block (hashcode_top);
hashcode_top.AddStatement (new Unchecked (hashcode_block));
- hashcode_block.AddVariable (TypeManager.system_int32_expr, "hash", loc);
+ hashcode_block.AddVariable (new TypeExpression (TypeManager.int32_type, loc), "hash", loc);
LocalVariableReference hash_variable = new LocalVariableReference (hashcode_block, "hash", loc);
LocalVariableReference hash_variable_assign = new LocalVariableReference (hashcode_block, "hash", loc);
hashcode_block.AddStatement (new StatementExpression (
// This one is computed after we can distinguish interfaces
// from classes from the arraylist `type_bases'
//
- TypeExpr base_type;
+ protected TypeSpec base_type;
+ protected TypeExpr base_type_expr;
protected TypeExpr[] iface_exprs;
protected List<FullNamedExpression> type_bases;
}
}
- public virtual TypeSpec BaseType {
+ public TypeSpec BaseType {
get {
return spec.BaseType;
}
Report.Error (1965, Location, "Class `{0}' cannot derive from the dynamic type",
GetSignatureForError ());
else
- base_class = fne_resolved;
+ base_type = fne_resolved.Type;
+
+ base_class = fne_resolved;
continue;
}
return ifaces;
}
- TypeExpr[] GetNormalPartialBases (ref TypeExpr base_class)
+ TypeExpr[] GetNormalPartialBases ()
{
var ifaces = new List<TypeExpr> (0);
if (iface_exprs != null)
foreach (TypeContainer part in partial_parts) {
TypeExpr new_base_class;
TypeExpr[] new_ifaces = part.ResolveBaseTypes (out new_base_class);
- if (new_base_class != TypeManager.system_object_expr) {
- if (base_class == TypeManager.system_object_expr)
- base_class = new_base_class;
- else {
- if (new_base_class != null && !TypeManager.IsEqual (new_base_class.Type, base_class.Type)) {
- Report.SymbolRelatedToPreviousError (base_class.Location, "");
- Report.Error (263, part.Location,
- "Partial declarations of `{0}' must not specify different base classes",
- part.GetSignatureForError ());
-
- return null;
- }
+ if (new_base_class != null) {
+ if (base_type_expr != null && new_base_class.Type != base_type) {
+ Report.SymbolRelatedToPreviousError (new_base_class.Location, "");
+ Report.Error (263, part.Location,
+ "Partial declarations of `{0}' must not specify different base classes",
+ part.GetSignatureForError ());
+ } else {
+ base_type_expr = new_base_class;
+ base_type = base_type_expr.Type;
}
}
bool DefineBaseTypes ()
{
- iface_exprs = ResolveBaseTypes (out base_type);
+ iface_exprs = ResolveBaseTypes (out base_type_expr);
if (partial_parts != null) {
- iface_exprs = GetNormalPartialBases (ref base_type);
+ iface_exprs = GetNormalPartialBases ();
}
var cycle = CheckRecursiveDefinition (this);
return true;
}
- TypeSpec base_ts;
- if (base_type != null)
- base_ts = base_type.Type;
- else if (spec.IsStruct)
- base_ts = TypeManager.value_type;
- else if (spec.IsEnum)
- base_ts = TypeManager.enum_type;
- else if (spec.IsDelegate)
- base_ts = TypeManager.multicast_delegate_type;
- else
- base_ts = null;
-
- if (base_ts != null) {
- spec.BaseType = base_ts;
+ if (base_type != null) {
+ spec.BaseType = base_type;
// Set base type after type creation
- TypeBuilder.SetParent (base_ts.GetMetaInfo ());
+ TypeBuilder.SetParent (base_type.GetMetaInfo ());
}
return true;
InTransit = tc;
- if (base_type != null && base_type.Type != null) {
- var ptc = base_type.Type.MemberDefinition as TypeContainer;
+ if (base_type_expr != null) {
+ var ptc = base_type.MemberDefinition as TypeContainer;
if (ptc != null && ptc.CheckRecursiveDefinition (this) != null)
- return base_type.Type;
+ return base_type;
}
if (iface_exprs != null) {
}
}
- if (base_type != null) {
- ObsoleteAttribute obsolete_attr = base_type.Type.GetAttributeObsolete ();
+ if (base_type_expr != null) {
+ ObsoleteAttribute obsolete_attr = base_type.GetAttributeObsolete ();
if (obsolete_attr != null && !IsObsolete)
AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location, Report);
- var ct = base_type as GenericTypeExpr;
+ var ct = base_type_expr as GenericTypeExpr;
if (ct != null)
ct.CheckConstraints (this);
+ }
- var baseContainer = base_type.Type.MemberDefinition as ClassOrStruct;
+ if (base_type != null) {
+ var baseContainer = base_type.MemberDefinition as ClassOrStruct;
if (baseContainer != null) {
baseContainer.Define ();
if (base_class == null) {
if (spec != TypeManager.object_type)
- base_class = TypeManager.system_object_expr;
+ base_type = TypeManager.object_type;
} else {
- var base_type = base_class.Type;
-
if (base_type.IsGenericParameter){
Report.Error (689, base_class.Location, "`{0}': Cannot derive from type parameter `{1}'",
GetSignatureForError (), base_type.GetSignatureForError ());
Report.SymbolRelatedToPreviousError (base_class.Type);
Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
GetSignatureForError (), base_type.GetSignatureForError ());
- } else if (base_type.IsSealed){
+ } else if (base_type.IsSealed) {
Report.SymbolRelatedToPreviousError (base_class.Type);
Report.Error (509, Location, "`{0}': cannot derive from sealed type `{1}'",
GetSignatureForError (), base_type.GetSignatureForError ());
+ } else if (PartialContainer.IsStatic && base_class.Type != TypeManager.object_type) {
+ Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object",
+ GetSignatureForError (), base_class.GetSignatureForError ());
}
if (base_type is PredefinedTypeSpec && !(spec is PredefinedTypeSpec) &&
base_type == TypeManager.delegate_type || base_type == TypeManager.array_type)) {
Report.Error (644, Location, "`{0}' cannot derive from special class `{1}'",
GetSignatureForError (), base_type.GetSignatureForError ());
- base_class = TypeManager.system_object_expr;
+
+ base_type = TypeManager.object_type;
}
if (!IsAccessibleAs (base_type)) {
}
}
- if (PartialContainer.IsStatic) {
- if (base_class.Type != TypeManager.object_type) {
- Report.Error (713, Location, "Static class `{0}' cannot derive from type `{1}'. Static classes must derive from object",
- GetSignatureForError (), base_class.GetSignatureForError ());
- return ifaces;
- }
-
- if (ifaces != null) {
- foreach (TypeExpr t in ifaces)
- Report.SymbolRelatedToPreviousError (t.Type);
- Report.Error (714, Location, "Static class `{0}' cannot implement interfaces", GetSignatureForError ());
- }
+ if (PartialContainer.IsStatic && ifaces != null) {
+ foreach (TypeExpr t in ifaces)
+ Report.SymbolRelatedToPreviousError (t.Type);
+ Report.Error (714, Location, "Static class `{0}' cannot implement interfaces", GetSignatureForError ());
}
return ifaces;
protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
{
TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
- base_class = TypeManager.system_valuetype_expr;
+ base_type = TypeManager.value_type;
return ifaces;
}
SEMICOLON
{
FullNamedExpression type = (FullNamedExpression) $3;
- if (type == TypeManager.system_void_expr)
+ if (type.Type == TypeManager.void_type)
Report.Error (670, GetLocation ($3), "Fields cannot have void type");
var mod = (Modifiers) $2;
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
- TypeManager.system_void_expr, current_local_parameters);
+ new TypeExpression (TypeManager.void_type, GetLocation ($4)),
+ current_local_parameters);
generic.SetParameterInfo ((List<Constraints>) $11);
}
modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
- method = new Method (current_class, generic, TypeManager.system_void_expr,
+ method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
modifiers, name, current_local_parameters, (Attributes) $1);
if (RootContext.Documentation != null)
Report.Error (1585, name.Location,
"Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
- Method method = new Method (current_class, null, TypeManager.system_void_expr,
+ Method method = new Method (current_class, null, (FullNamedExpression) $3,
0, name, (ParametersCompiled) $7, (Attributes) $1);
current_local_parameters = (ParametersCompiled) $7;
prop = new Property (current_class, ptype, (Modifiers) $2,
name, (Attributes) $1, get_block, set_block, order, current_block);
- if (ptype == TypeManager.system_void_expr)
+ if (ptype.Type == TypeManager.void_type)
Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
if (accessors == null)
| VOID
{
Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
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;
+ var fne = (FullNamedExpression) $3;
- Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
+ Indexer indexer = new Indexer (current_class, fne,
(MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1,
get_block, set_block, order);
- if ($3 == TypeManager.system_void_expr)
+ if (fne.Type == TypeManager.void_type)
Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
if (accessors == null)
}
name = MakeName (name);
- Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (Modifiers) $2,
+ Enum e = new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2,
name, (Attributes) $1);
if (RootContext.Documentation != null)
EnumMember em = null;
foreach (VariableDeclaration ev in (IList<VariableDeclaration>) $7) {
em = new EnumMember (
- e, em, ev.identifier, ev.GetInitializer ((FullNamedExpression) $5),
+ e, em, ev.identifier, ev.GetInitializer (null),
ev.OptAttributes, ev.Location);
// if (RootContext.Documentation != null)
opt_enum_base
: /* empty */
- {
- $$ = TypeManager.system_int32_expr;
- }
| COLON type
{
- if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
- $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
- $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
- $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr) {
+ 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)) {
Enum.Error_1008 (GetLocation ($2), Report);
- $2 = TypeManager.system_int32_expr;
+ $$ = null;
+ } else {
+ $$ = $2;
}
-
- $$ = $2;
}
| COLON error
{
Error_TypeExpected (GetLocation ($1));
- $$ = TypeManager.system_int32_expr;
+ $$ = null;
}
;
: type_expression_or_array
| VOID
{
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
| VOID
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
| VOID
{
Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
// can't perform checks during this phase - we do it during
// semantic analysis.
//
- $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($2));
}
| VOID STAR
{
- $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1));
+ $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), "*", GetLocation ($2));
}
;
* simple types, but we need this to reuse it easily in variable_type
*/
builtin_types
- : OBJECT { $$ = TypeManager.system_object_expr; }
- | STRING { $$ = TypeManager.system_string_expr; }
- | BOOL { $$ = TypeManager.system_boolean_expr; }
- | DECIMAL { $$ = TypeManager.system_decimal_expr; }
- | FLOAT { $$ = TypeManager.system_single_expr; }
- | DOUBLE { $$ = TypeManager.system_double_expr; }
+ : 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)); }
| integral_type
;
integral_type
- : SBYTE { $$ = TypeManager.system_sbyte_expr; }
- | BYTE { $$ = TypeManager.system_byte_expr; }
- | SHORT { $$ = TypeManager.system_int16_expr; }
- | USHORT { $$ = TypeManager.system_uint16_expr; }
- | INT { $$ = TypeManager.system_int32_expr; }
- | UINT { $$ = TypeManager.system_uint32_expr; }
- | LONG { $$ = TypeManager.system_int64_expr; }
- | ULONG { $$ = TypeManager.system_uint64_expr; }
- | CHAR { $$ = TypeManager.system_char_expr; }
+ : 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)); }
;
//
$$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
} else {
Error_ExpectingTypeName (expr);
- $$ = TypeManager.system_object_expr;
+ $$ = null;
}
}
;
open_parens_any typeof_type_expression CLOSE_PARENS
{
lexer.TypeOfParsing = false;
- Expression type = (Expression)$4;
- if (type == TypeManager.system_void_expr)
- $$ = new TypeOfVoid (GetLocation ($1));
- else
- $$ = new TypeOf (type, GetLocation ($1));
+ $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
}
;
}
} else {
Error_ExpectingTypeName (expr);
- $$ = TypeManager.system_object_expr;
+ $$ = null;
}
}
| builtin_types opt_rank_specifier_or_nullable
| VOID opt_rank_specifier
{
Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
- $$ = TypeManager.system_void_expr;
+ $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
}
;
}
| VOID STAR
{
- $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1));
+ $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), "*", GetLocation ($2));
}
| local_variable_pointer_type STAR
{
- $$ = new ComposedCast ((FullNamedExpression) $1, "*");
+ $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($2));
}
;
// (ref object retval)
Parameter [] mpar = new Parameter [1];
- mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
+ mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
current_local_parameters = pars;
Method method = new Method (
current_class,
null, // generic
- TypeManager.system_void_expr,
+ new TypeExpression (TypeManager.void_type, Location.Null),
Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName ("Host"),
pars,
}
}
- public override TypeSpec BaseType {
- get {
- return TypeManager.multicast_delegate_type;
- }
- }
-
protected override bool DoDefineMembers ()
{
var ctor_parameters = ParametersCompiled.CreateFullyResolved (
base.Emit ();
}
+ protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
+ {
+ base_type = TypeManager.multicast_delegate_type;
+ base_class = null;
+ return null;
+ }
+
protected override TypeAttributes TypeAttr {
get {
return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) |
// TODO: Should be passed to parser as an argument
RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
var ctypes = TypeManager.InitCoreTypes ();
- TypeManager.InitExpressionTypes ();
Parse ();
if (Report.Errors > 0)
{
public static readonly string UnderlyingValueField = "value__";
- TypeExpr base_type;
-
const Modifiers AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.INTERNAL |
Modifiers.PRIVATE;
- public Enum (NamespaceEntry ns, DeclSpace parent, TypeExpr type,
+ public Enum (NamespaceEntry ns, DeclSpace parent, TypeExpression type,
Modifiers mod_flags, MemberName name, Attributes attrs)
: base (ns, parent, name, attrs, MemberKind.Enum)
{
- this.base_type = type;
+ base_type_expr = type;
var accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod_flags, accmods, Location, Report);
spec = new EnumSpec (null, this, null, null, ModFlags);
}
+ #region Properties
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Enum;
+ }
+ }
+
+ public TypeExpr BaseTypeExpression {
+ get {
+ return base_type_expr;
+ }
+ }
+
+ protected override TypeAttributes TypeAttr {
+ get {
+ return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) |
+ TypeAttributes.Class | TypeAttributes.Sealed | base.TypeAttr;
+ }
+ }
+
+ public TypeSpec UnderlyingType {
+ get {
+ return ((EnumSpec) spec).UnderlyingType;
+ }
+ }
+
+ #endregion
+
public void AddEnumMember (EnumMember em)
{
if (em.Name == UnderlyingValueField) {
public static void Error_1008 (Location loc, Report Report)
{
- Report.Error (1008, loc, "Type byte, sbyte, short, ushort, " +
- "int, uint, long or ulong expected");
+ Report.Error (1008, loc,
+ "Type byte, sbyte, short, ushort, int, uint, long or ulong expected");
}
protected override bool DefineNestedTypes ()
{
- if (!base.DefineNestedTypes ())
- return false;
-
- ((EnumSpec) spec).UnderlyingType = UnderlyingType;
+ ((EnumSpec) spec).UnderlyingType = base_type_expr == null ? TypeManager.int32_type : base_type_expr.Type;
TypeBuilder.DefineField (UnderlyingValueField, UnderlyingType.GetMetaInfo (),
FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
return true;
}
- public TypeSpec UnderlyingType {
- get {
- return base_type.Type;
- }
+ protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
+ {
+ base_type = TypeManager.enum_type;
+ base_class = base_type_expr;
+ return null;
}
protected override bool VerifyClsCompliance ()
return true;
}
-
- public override AttributeTargets AttributeTargets {
- get {
- return AttributeTargets.Enum;
- }
- }
-
- protected override TypeAttributes TypeAttr {
- get {
- return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) |
- TypeAttributes.Class | TypeAttributes.Sealed | base.TypeAttr;
- }
- }
}
class EnumSpec : TypeSpec
CompilerCallableEntryPoint.Reset ();
RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
/*var ctypes = */TypeManager.InitCoreTypes ();
- TypeManager.InitExpressionTypes ();
Import.Initialize ();
driver.LoadReferences ();
}
Arguments args = new Arguments (1);
- args.Add (new Argument (new TypeOf (source, Location)));
+ args.Add (new Argument (new TypeOf ((TypeExpr) clone, Location)));
source = new Invocation (new SimpleName ("Describe", Location), args).Resolve (ec);
}
Evaluator.SetPrinter (old_printer);
/// Implements the typeof operator
/// </summary>
public class TypeOf : Expression {
- Expression QueriedType;
- protected TypeSpec typearg;
+ FullNamedExpression QueriedType;
+ TypeSpec typearg;
- public TypeOf (Expression queried_type, Location l)
+ public TypeOf (FullNamedExpression queried_type, Location l)
{
QueriedType = queried_type;
loc = l;
}
+ #region Properties
+ public TypeSpec TypeArgument {
+ get {
+ return typearg;
+ }
+ }
+
+ public FullNamedExpression TypeExpression {
+ get {
+ return QueriedType;
+ }
+ }
+
+ #endregion
+
public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
if (tne != null && typearg.IsGeneric && !tne.HasTypeArguments)
typearg = typearg.GetDefinition ();
- if (typearg == TypeManager.void_type) {
+ if (typearg == TypeManager.void_type && !(QueriedType is TypeExpression)) {
ec.Report.Error (673, loc, "System.Void cannot be used from C#. Use typeof (void) to get the void type object");
} else if (typearg.IsPointer && !ec.IsUnsafe){
UnsafeError (ec, loc);
ec.Emit (OpCodes.Call, TypeManager.system_type_get_type_from_handle);
}
- public TypeSpec TypeArgument {
- get {
- return typearg;
- }
- }
-
protected override void CloneTo (CloneContext clonectx, Expression t)
{
TypeOf target = (TypeOf) t;
if (QueriedType != null)
- target.QueriedType = QueriedType.Clone (clonectx);
- }
- }
-
- /// <summary>
- /// Implements the `typeof (void)' operator
- /// </summary>
- public class TypeOfVoid : TypeOf {
- public TypeOfVoid (Location l) : base (null, l)
- {
- loc = l;
- }
-
- protected override Expression DoResolve (ResolveContext ec)
- {
- type = TypeManager.type_type;
- typearg = TypeManager.void_type;
-
- return DoResolveBase ();
+ target.QueriedType = (FullNamedExpression) QueriedType.Clone (clonectx);
}
}
}
public DisposeMethod (IteratorStorey host)
- : base (host, TypeManager.system_void_expr, Modifiers.PUBLIC, new MemberName ("Dispose", host.Location))
+ : base (host, new TypeExpression (TypeManager.void_type, host.Location), Modifiers.PUBLIC, new MemberName ("Dispose", host.Location))
{
host.AddMethod (this);
void DefineIteratorMembers ()
{
- pc_field = AddCompilerGeneratedField ("$PC", TypeManager.system_int32_expr);
+ pc_field = AddCompilerGeneratedField ("$PC", new TypeExpression (TypeManager.int32_type, Location));
current_field = AddCompilerGeneratedField ("$current", iterator_type_expr);
if (hoisted_params != null) {
type = iterator_type_expr;
} else {
name = new MemberName (name, "IEnumerator");
- type = TypeManager.system_object_expr;
+ type = new TypeExpression (TypeManager.object_type, Location);
}
name = new MemberName (name, "Current", Location);
void Define_Reset ()
{
Method reset = new Method (
- this, null, TypeManager.system_void_expr,
+ this, null, new TypeExpression (TypeManager.void_type, Location),
Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("Reset", Location),
ParametersCompiled.EmptyReadOnlyParameters, null);
protected override Expression DoResolve (ResolveContext ec)
{
method = new AnonymousMethodMethod (Storey,
- this, Storey, null, TypeManager.system_boolean_expr,
+ this, Storey, null, new TypeExpression (TypeManager.bool_type, loc),
Modifiers.PUBLIC, OriginalMethod.GetSignatureForError (),
new MemberName ("MoveNext", Location),
ParametersCompiled.EmptyReadOnlyParameters);
//
public override bool Define ()
{
- if (type_expr == TypeManager.system_void_expr && parameters.IsEmpty && Name == Destructor.MetadataName) {
+ if (type_expr.Type == TypeManager.void_type && parameters.IsEmpty && MemberName.Arity == 0 && MemberName.Name == Destructor.MetadataName) {
Report.Warning (465, 1, Location, "Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
}
public static readonly string MetadataName = "Finalize";
public Destructor (DeclSpace parent, Modifiers mod, ParametersCompiled parameters, Attributes attrs, Location l)
- : base (parent, null, TypeManager.system_void_expr, mod, AllowedModifiers,
+ : base (parent, null, null, mod, AllowedModifiers,
new MemberName (MetadataName, l), attrs, parameters)
{
ModFlags &= ~Modifiers.PRIVATE;
protected override bool CheckBase ()
{
- // Don't check base, the destructor has special syntax
+ // Don't check base, destructors have special syntax
+ return true;
+ }
+ public override void Emit()
+ {
var base_type = Parent.PartialContainer.BaseType;
- if (base_type == null)
- return true;
-
- if (Block != null) {
+ if (base_type != null && Block != null) {
MethodGroupExpr method_expr = Expression.MethodLookup (Parent.Module.Compiler, Parent.Definition, base_type, MemberKind.Destructor, MetadataName, 0, Location);
if (method_expr == null)
throw new NotImplementedException ();
block = new_block;
}
- return true;
+ base.Emit ();
}
public override string GetSignatureForError ()
return Parent.GetSignatureForError () + ".~" + Parent.MemberName.Name + "()";
}
+ protected override bool ResolveMemberType ()
+ {
+ member_type = TypeManager.void_type;
+ return true;
+ }
+
public override string[] ValidAttributeTargets {
get {
return attribute_targets;
public static TypeExpr binder_type;
public static TypeSpec binder_flags;
- //
- // Expressions representing the internal types. Used during declaration
- // definition.
- //
- static public TypeExpr system_object_expr, system_string_expr;
- static public TypeExpr system_boolean_expr, system_decimal_expr;
- static public TypeExpr system_single_expr, system_double_expr;
- static public TypeExpr system_sbyte_expr, system_byte_expr;
- static public TypeExpr system_int16_expr, system_uint16_expr;
- static public TypeExpr system_int32_expr, system_uint32_expr;
- static public TypeExpr system_int64_expr, system_uint64_expr;
- static public TypeExpr system_char_expr, system_void_expr;
- static public TypeExpr system_valuetype_expr;
public static TypeExpr expression_type_expr;
static Dictionary<Assembly, bool> assembly_internals_vis_attrs;
- //
- // These are expressions that represent some of the internal data types, used
- // elsewhere
- //
- public static void InitExpressionTypes ()
- {
- system_object_expr = new TypeLookupExpression (object_type);
- system_string_expr = new TypeLookupExpression (string_type);
- system_boolean_expr = new TypeLookupExpression (bool_type);
- system_decimal_expr = new TypeLookupExpression (decimal_type);
- system_single_expr = new TypeLookupExpression (float_type);
- system_double_expr = new TypeLookupExpression (double_type);
- system_sbyte_expr = new TypeLookupExpression (sbyte_type);
- system_byte_expr = new TypeLookupExpression (byte_type);
- system_int16_expr = new TypeLookupExpression (short_type);
- system_uint16_expr = new TypeLookupExpression (ushort_type);
- system_int32_expr = new TypeLookupExpression (int32_type);
- system_uint32_expr = new TypeLookupExpression (uint32_type);
- system_int64_expr = new TypeLookupExpression (int64_type);
- system_uint64_expr = new TypeLookupExpression (uint64_type);
- system_char_expr = new TypeLookupExpression (char_type);
- system_void_expr = new TypeLookupExpression (void_type);
- system_valuetype_expr = new TypeLookupExpression (value_type);
- }
-
static TypeManager ()
{
Reset ();
return null;
}
- public virtual object Visit (TypeLookupExpression typeLookupExpression)
- {
- return null;
- }
-
public virtual object Visit (LocalVariableReference localVariableReference)
{
return null;