+2004-10-07 Raja R Harinath <rharinath@novell.com>
+
+ More DeclSpace.ResolveType avoidance.
+ * decl.cs (MemberCore.InUnsafe): New property.
+ * class.cs (MemberBase.DoDefine): Use ResolveAsTypeTerminal
+ with newly created EmitContext.
+ (FieldMember.Define): Likewise.
+ * delegate.cs (Delegate.Define): Likewise.
+ * ecore.cs (SimpleName.ResolveAsTypeStep): Lookup with alias
+ only if normal name-lookup fails.
+ (TypeExpr.DoResolve): Enable error-checking.
+ * expression.cs (ArrayCreation.DoResolve): Use ResolveAsTypeTerminal.
+ (SizeOf.DoResolve): Likewise.
+ (ComposedCast.DoResolveAsTypeStep): Likewise.
+ (StackAlloc.DoResolve): Likewise.
+ * statement.cs (Block.Flags): Add new flag 'Unsafe'.
+ (Block.Unsafe): New property.
+ (Block.EmitMeta): Set ec.InUnsafe as appropriate.
+ (Unsafe): Set 'unsafe' flag of contained block.
+ (LocalInfo.Resolve): Use ResolveAsTypeTerminal.
+ (Fixed.Resolve): Likewise.
+ (Catch.Resolve): Likewise.
+ (Using.ResolveLocalVariableDecls): Likewise.
+ (Foreach.Resolve): Likewise.
+
+2004-10-05 John Luke <john.luke@gmail.com>
+
+ * cs-parser.jay: add location to error CS0175
+
2004-10-04 Miguel de Icaza <miguel@ximian.com>
* ecore.cs (Expression.Constantity): Add support for turning null
protected virtual bool DoDefineBase ()
{
+ EmitContext ec = new EmitContext (Parent, Location, null, null, 0);
+ ec.InUnsafe = InUnsafe;
+
if (Name == null)
throw new InternalErrorException ();
protected virtual bool DoDefine (DeclSpace decl)
{
+ EmitContext ec = new EmitContext (Parent, Location, null, null, 0);
+ ec.InUnsafe = InUnsafe;
+
// Lookup Type, verify validity
MemberType = decl.ResolveType (Type, false, Location);
if (MemberType == null)
return false;
if (IsExplicitImpl) {
- Expression iface_expr = ExplicitInterfaceName.GetTypeExpression (Location);
-
- InterfaceType = Parent.ResolveType (iface_expr, false, Location);
- if (InterfaceType == null)
+ Expression expr = ExplicitInterfaceName.GetTypeExpression (Location);
+ expr = expr.ResolveAsTypeTerminal (ec, false);
+ if (expr == null)
return false;
+ InterfaceType = expr.Type;
+
if (InterfaceType.IsClass) {
Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
return false;
public override bool Define()
{
- MemberType = Parent.ResolveType (Type, false, Location);
+ EmitContext ec = new EmitContext (Parent, Location, null, null, 0);
+ ec.InUnsafe = InUnsafe;
- if (MemberType == null)
+ Type = Type.ResolveAsTypeTerminal (ec, false);
+ if (Type == null)
return false;
+ MemberType = Type.Type;
+
if (!CheckBase ())
return false;
$$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
}
| BASE error {
- Report.Error (175, "Use of keyword `base' is not valid in this context");
+ Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
$$ = null;
}
;
VerifyClsCompliance (Parent);
}
+ public bool InUnsafe {
+ get {
+ return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
+ }
+ }
+
//
// Whehter is it ok to use an unsafe pointer in this type container
//
}
// <summary>
- // Looks up the type, as parsed into the expression `e'
+ // Looks up the type, as parsed into the expression `e'.
// </summary>
+ //[Obsolete ("This method is going away soon")]
public Type ResolveType (Expression e, bool silent, Location loc)
{
TypeExpr d = ResolveTypeExpr (e, silent, loc);
// <summary>
// Resolves the expression `e' for a type, and will recursively define
- // types.
+ // types. This should only be used for resolving base types.
// </summary>
public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
{
return false;
}
- ReturnType = ResolveTypeExpr (ReturnType, false, Location);
+ ReturnType = ReturnType.ResolveAsTypeTerminal (ec, false);
if (ReturnType == null)
return false;
}
}
- //
- // First, the using aliases
- //
- if (alias_value != null){
+ if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
+ return t;
+
+ if (alias_value != null) {
if (alias_value.IsType)
return alias_value.Type;
if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
return new SimpleName (alias_value.Name, loc);
}
- //
- // Stage 2: Lookup up if we are an alias to a type
- // or a namespace.
- //
-
- if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
- return t;
-
// No match, maybe our parent can compose us
// into something meaningful.
return this;
override public Expression DoResolve (EmitContext ec)
{
- return ResolveAsTypeTerminal (ec, true);
+ return ResolveAsTypeTerminal (ec, false);
}
override public void Emit (EmitContext ec)
//
Expression array_type_expr;
array_type_expr = new ComposedCast (requested_base_type, array_qualifier.ToString (), loc);
- type = ec.DeclSpace.ResolveType (array_type_expr, false, loc);
-
- if (type == null)
+ array_type_expr = array_type_expr.ResolveAsTypeTerminal (ec, false);
+ if (array_type_expr == null)
return false;
+ type = array_type_expr.Type;
+
if (!type.IsArray) {
Error (622, "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
return false;
return null;
}
- QueriedType = ec.DeclSpace.ResolveTypeExpr (QueriedType, false, loc);
- if (QueriedType == null || QueriedType.Type == null)
+ QueriedType = QueriedType.ResolveAsTypeTerminal (ec, false);
+ if (QueriedType == null)
return null;
if (QueriedType is TypeParameterExpr){
}
type_queried = QueriedType.Type;
- if (type_queried == null)
- return null;
CheckObsoleteAttribute (type_queried);
public override TypeExpr DoResolveAsTypeStep (EmitContext ec)
{
- Type ltype = ec.DeclSpace.ResolveType (left, false, loc);
- if (ltype == null)
+ left = left.ResolveAsTypeTerminal (ec, false);
+ if (left == null)
return null;
+ Type ltype = left.Type;
+
if ((ltype == TypeManager.void_type) && (dim != "*")) {
Report.Error (1547, Location,
"Keyword 'void' cannot be used in this context");
return null;
}
- otype = ec.DeclSpace.ResolveType (t, false, loc);
-
- if (otype == null)
+ t = t.ResolveAsTypeTerminal (ec, false);
+ if (t == null)
return null;
+ otype = t.Type;
+
if (!TypeManager.VerifyUnManaged (otype, loc))
return null;
public bool Resolve (EmitContext ec)
{
- if (VariableType == null)
- VariableType = ec.DeclSpace.ResolveType (Type, false, Location);
+ if (VariableType == null) {
+ Type = Type.ResolveAsTypeTerminal (ec, false);
+
+ if (Type == null)
+ return false;
+
+ VariableType = Type.Type;
+ }
if (VariableType == TypeManager.void_type) {
Report.Error (1547, Location,
return false;
}
- if (VariableType == null)
- return false;
-
if (VariableType.IsAbstract && VariableType.IsSealed) {
Report.Error (723, Location, "Cannot declare variable of static type '{0}'", TypeManager.CSharpName (VariableType));
return false;
VariablesInitialized = 8,
HasRet = 16,
IsDestructor = 32,
- HasVarargs = 64
+ HasVarargs = 64,
+ Unsafe = 128,
}
Flags flags;
}
}
+ public bool Unsafe {
+ get {
+ return (flags & Flags.Unsafe) != 0;
+ }
+ set {
+ flags |= Flags.Unsafe;
+ }
+ }
+
public bool HasVarargs {
get {
if (Parent != null)
{
ILGenerator ig = ec.ig;
+ bool old_unsafe = ec.InUnsafe;
+
+ // If some parent block was unsafe, we remain unsafe even if this block
+ // isn't explicitly marked as such.
+ ec.InUnsafe |= Unsafe;
+
//
// Compute the VariableMap's.
//
foreach (Block b in children)
b.EmitMeta (ec, ip);
}
+
+ ec.InUnsafe = old_unsafe;
}
void UsageWarning (FlowBranching.UsageVector vector)
public Unsafe (Block b)
{
Block = b;
+ Block.Unsafe = true;
}
public override bool Resolve (EmitContext ec)
return false;
}
- expr_type = ec.DeclSpace.ResolveType (type, false, loc);
- if (expr_type == null)
+ type = type.ResolveAsTypeTerminal (ec, false);
+ if (type == null)
return false;
+ expr_type = type.Type;
+
CheckObsolete (expr_type);
if (ec.RemapToProxy){
public override bool Resolve (EmitContext ec)
{
if (type_expr != null) {
- type = ec.DeclSpace.ResolveType (type_expr, false, loc);
- if (type == null)
+ TypeExpr te = type_expr.ResolveAsTypeTerminal (ec, false);
+ if (te == null)
return false;
+ type = te.Type;
+
CheckObsolete (type);
if (type != TypeManager.exception_type && !type.IsSubclassOf (TypeManager.exception_type)){
//
bool ResolveLocalVariableDecls (EmitContext ec)
{
- expr_type = ec.DeclSpace.ResolveType (expr, false, loc);
int i = 0;
- if (expr_type == null)
+ expr = expr.ResolveAsTypeTerminal (ec, false);
+ if (expr == null)
return false;
+ expr_type = expr.Type;
+
//
// The type must be an IDisposable or an implicit conversion
// must exist.
if (expr == null)
return false;
- var_type = ec.DeclSpace.ResolveType (type, false, loc);
- if (var_type == null)
+ type = type.ResolveAsTypeTerminal (ec, false);
+ if (type == null)
return false;
+
+ var_type = type.Type;
//
// We need an instance variable. Not sure this is the best