// function aborts because it requires its argument to be of the same type
//
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
+
using System;
using System.Reflection;
bool in_transit = false;
public const int AllowedModifiers =
- Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.INTERNAL |
- Modifiers.PRIVATE;
+ Modifiers.PRIVATE |
+ Modifiers.SHADOWS;
public Const (Expression constant_type, string name, Expression expr, int mod_flags,
Attributes attrs, Location loc)
if (!TypeManager.IsBuiltinType (type) &&
(!type.IsSubclassOf (TypeManager.enum_type))) {
Report.Error (
- -3, Location,
+ 30424, Location,
"Constant type is not valid (only system types are allowed)");
return false;
}
+ // if no type is declared expicitely
+ // set the expression type as the type of constant
+ if (type == TypeManager.object_type){
+ if (Expr is IntLiteral)
+ type = TypeManager.int32_type;
+ else if (Expr is UIntLiteral)
+ type = TypeManager.uint32_type;
+ else if (Expr is LongLiteral)
+ type = TypeManager.int64_type;
+ else if (Expr is ULongLiteral)
+ type = TypeManager.uint64_type;
+ else if (Expr is FloatLiteral)
+ type = TypeManager.float_type;
+ else if (Expr is DoubleLiteral)
+ type = TypeManager.double_type;
+ else if (Expr is StringLiteral)
+ type = TypeManager.string_type;
+ else if (Expr is ShortLiteral)
+ type = TypeManager.short_type;
+ else if (Expr is UShortConstant)
+ type = TypeManager.ushort_type;
+ else if (Expr is SByteConstant)
+ type = TypeManager.sbyte_type;
+ else if (Expr is ByteConstant)
+ type = TypeManager.byte_type;
+ else if (Expr is CharConstant)
+ type = TypeManager.char_type;
+ else if (Expr is BoolConstant)
+ type = TypeManager.bool_type;
+ else if (Expr is DateConstant)
+ type = TypeManager.date_type;
+ }
Type ptype = parent.TypeBuilder.BaseType;
if (ptype != null) {
- MemberInfo [] mi = TypeContainer.FindMembers (
+ MemberList list = TypeContainer.FindMembers (
ptype, MemberTypes.Field, BindingFlags.Public,
Type.FilterName, Name);
- if (mi == null || mi.Length == 0)
- if ((ModFlags & Modifiers.NEW) != 0)
- WarningNotHiding (parent);
+ if ((list.Count > 0) && ((ModFlags & Modifiers.SHADOWS) == 0))
+ Report.Warning (
+ 40004, 2, Location,
+ "Const '" + Name + "' should be declared " +
+ "Shadows since the base type '" + ptype.Name +
+ "' has a Const with same name");
+ if (list.Count == 0) {
+ // if a member of module is not inherited from Object class
+ // can not be declared protected
+ if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+ Report.Error (30593, Location,
+ "'Const' inside a 'Module' can not be " +
+ "declared as 'Protected'");
+
+ /*if ((ModFlags & Modifiers.NEW) != 0)
+ WarningNotHiding (parent);*/
+ }
+ }
+ /*else if ((ModFlags & Modifiers.NEW) != 0)
+ WarningNotHiding (parent);*/
- } else if ((ModFlags & Modifiers.NEW) != 0)
- WarningNotHiding (parent);
+ if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+ Report.Error (30435, Location,
+ "'Const' inside a 'Structure' can not be " +
+ "declared as 'Protected'");
FieldBuilder = parent.TypeBuilder.DefineField (Name, type, FieldAttr);
if (Expr == null) {
if (errors == Report.Errors)
- Report.Error (150, Location, "A constant value is expected");
+ Report.Error (30059, Location, "A constant value is expected");
return null;
}
Expr = un_expr.Expr;
else if ((ch_expr != null) && (ch_expr.Expr is Constant))
Expr = ch_expr.Expr;
- else {
- Report.Error (150, Location, "A constant value is expected");
+ else \r
+ {
+ Report.Error (30059, Location, "A constant value is expected");
return null;
}
}
if (!TypeManager.RegisterFieldValue (FieldBuilder, ConstantValue))
return null;
-
+
return ConstantValue;
}
}
}
}
-
-