if (NamedArguments == null)
NamedArguments = new Arguments (1);
- var value = Constant.CreateConstant (rc, rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location);
+ var value = Constant.CreateConstant (rc.Module.PredefinedTypes.CharSet.TypeSpec, rc.Module.DefaultCharSet, Location);
NamedArguments.Add (new NamedArgument (dll_import_char_set, loc, value));
}
static bool IsValidArgumentType (TypeSpec t)
{
- if (t.IsArray)
- t = TypeManager.GetElementType (t);
+ if (t.IsArray) {
+ var ac = (ArrayContainer) t;
+ if (ac.Rank > 1)
+ return false;
+
+ t = ac.Element;
+ }
+
+ switch (t.BuildinType) {
+ case BuildinTypeSpec.Type.Int:
+ case BuildinTypeSpec.Type.UInt:
+ case BuildinTypeSpec.Type.Long:
+ case BuildinTypeSpec.Type.ULong:
+ case BuildinTypeSpec.Type.Float:
+ case BuildinTypeSpec.Type.Double:
+ case BuildinTypeSpec.Type.Char:
+ case BuildinTypeSpec.Type.Short:
+ case BuildinTypeSpec.Type.Bool:
+ case BuildinTypeSpec.Type.SByte:
+ case BuildinTypeSpec.Type.Byte:
+ case BuildinTypeSpec.Type.UShort:
+
+ case BuildinTypeSpec.Type.String:
+ case BuildinTypeSpec.Type.Object:
+ case BuildinTypeSpec.Type.Dynamic:
+ case BuildinTypeSpec.Type.Type:
+ return true;
+ }
- return t == TypeManager.string_type ||
- TypeManager.IsPrimitiveType (t) ||
- TypeManager.IsEnumType (t) ||
- t == TypeManager.object_type ||
- t == TypeManager.type_type;
+ return t.IsEnum;
}
// TODO: Don't use this ambiguous value
var cab = new CustomAttributeBuilder ((ConstructorInfo) ctor.GetMetaInfo (), values, prop, prop_values);
permissions.Add (cab);
#else
- Type orig_assembly_type = null;
-
- if (Type.MemberDefinition is TypeContainer) {
- if (!RootContext.StdLib) {
- orig_assembly_type = System.Type.GetType (Type.GetMetaInfo ().FullName);
- } else {
- string orig_version_path = Environment.GetEnvironmentVariable ("__SECURITY_BOOTSTRAP_DB");
- if (orig_version_path == null) {
- Error_AttributeEmitError ("security custom attributes can not be referenced from defining assembly");
- return;
- }
-
- if (orig_sec_assembly == null) {
- string file = Path.Combine (orig_version_path, Path.GetFileName (RootContext.OutputFile));
- orig_sec_assembly = Assembly.LoadFile (file);
- }
-
- orig_assembly_type = orig_sec_assembly.GetType (Type.GetMetaInfo ().FullName, true);
- if (orig_assembly_type == null) {
- Report.Warning (-112, 1, Location, "Self-referenced security attribute `{0}' " +
- "was not found in previous version of assembly");
- return;
- }
- }
- }
-
- SecurityAttribute sa;
- object[] args;
-
- // For all non-selfreferencing security attributes we can avoid all hacks
- if (orig_assembly_type == null) {
- args = new object[PosArguments.Count];
- for (int j = 0; j < args.Length; ++j) {
- args[j] = ((Constant) PosArguments[j].Expr).GetValue ();
- }
-
- sa = (SecurityAttribute) Activator.CreateInstance (Type.GetMetaInfo (), args);
-
- if (named_values != null) {
- for (int i = 0; i < named_values.Count; ++i) {
- PropertyInfo pi = ((PropertyExpr) named_values[i].Key).PropertyInfo.MetaInfo;
- pi.SetValue (sa, ((Constant) named_values [i].Value.Expr).GetValue (), null);
- }
- }
- } else {
- // HACK: All security attributes have same ctor syntax
- args = new object[] { GetSecurityActionValue () };
- sa = (SecurityAttribute) Activator.CreateInstance (orig_assembly_type, args);
-
- // All types are from newly created assembly but for invocation with old one we need to convert them
- if (named_values != null) {
- for (int i = 0; i < named_values.Count; ++i) {
- PropertyInfo emited_pi = ((PropertyExpr) named_values[i].Key).PropertyInfo.MetaInfo;
- // FIXME: We are missing return type filter
- // TODO: pi can be null
- PropertyInfo pi = orig_assembly_type.GetProperty (emited_pi.Name);
-
- pi.SetValue (sa, ((Constant) named_values[i].Value.Expr).GetValue (), null);
- }
- }
- }
-
- IPermission perm;
- perm = sa.CreatePermission ();
- SecurityAction action = (SecurityAction) args [0];
-
- // IS is correct because for corlib we are using an instance from old corlib
- if (!(perm is System.Security.CodeAccessPermission)) {
- switch (action) {
- case SecurityAction.Demand:
- action = (SecurityAction)13;
- break;
- case SecurityAction.LinkDemand:
- action = (SecurityAction)14;
- break;
- case SecurityAction.InheritanceDemand:
- action = (SecurityAction)15;
- break;
- }
- }
-
- if (permissions == null)
- permissions = new SecurityType ();
-
- PermissionSet ps;
- if (!permissions.TryGetValue (action, out ps)) {
- if (sa is PermissionSetAttribute)
- ps = new PermissionSet (sa.Unrestricted ? PermissionState.Unrestricted : PermissionState.None);
- else
- ps = new PermissionSet (PermissionState.None);
-
- permissions.Add (action, ps);
- } else if (!ps.IsUnrestricted () && (sa is PermissionSetAttribute) && sa.Unrestricted) {
- ps = ps.Union (new PermissionSet (PermissionState.Unrestricted));
- permissions [action] = ps;
- }
- ps.AddPermission (perm);
+ throw new NotSupportedException ();
#endif
}
if (string.IsNullOrEmpty (value))
Error_AttributeEmitError ("DllName cannot be empty");
}
- } else if (Type == predefined.MethodImpl && pt == TypeManager.short_type &&
+ } else if (Type == predefined.MethodImpl && pt.BuildinType == BuildinTypeSpec.Type.Short &&
!System.Enum.IsDefined (typeof (MethodImplOptions), ((Constant) arg_expr).GetValue ().ToString ())) {
Error_AttributeEmitError ("Incorrect argument value.");
return;
}
}
- if (!RootContext.VerifyClsCompliance)
+ if (!context.Module.Compiler.Settings.VerifyClsCompliance)
return;
// Here we are testing attribute arguments for array usage (error 3016)
public EncodedTypeProperties Encode (TypeSpec type)
{
- if (type == TypeManager.bool_type) {
+ switch (type.BuildinType) {
+ case BuildinTypeSpec.Type.Bool:
Encode ((byte) 0x02);
- } else if (type == TypeManager.char_type) {
+ break;
+ case BuildinTypeSpec.Type.Char:
Encode ((byte) 0x03);
- } else if (type == TypeManager.sbyte_type) {
+ break;
+ case BuildinTypeSpec.Type.SByte:
Encode ((byte) 0x04);
- } else if (type == TypeManager.byte_type) {
+ break;
+ case BuildinTypeSpec.Type.Byte:
Encode ((byte) 0x05);
- } else if (type == TypeManager.short_type) {
+ break;
+ case BuildinTypeSpec.Type.Short:
Encode ((byte) 0x06);
- } else if (type == TypeManager.ushort_type) {
+ break;
+ case BuildinTypeSpec.Type.UShort:
Encode ((byte) 0x07);
- } else if (type == TypeManager.int32_type) {
+ break;
+ case BuildinTypeSpec.Type.Int:
Encode ((byte) 0x08);
- } else if (type == TypeManager.uint32_type) {
+ break;
+ case BuildinTypeSpec.Type.UInt:
Encode ((byte) 0x09);
- } else if (type == TypeManager.int64_type) {
+ break;
+ case BuildinTypeSpec.Type.Long:
Encode ((byte) 0x0A);
- } else if (type == TypeManager.uint64_type) {
+ break;
+ case BuildinTypeSpec.Type.ULong:
Encode ((byte) 0x0B);
- } else if (type == TypeManager.float_type) {
+ break;
+ case BuildinTypeSpec.Type.Float:
Encode ((byte) 0x0C);
- } else if (type == TypeManager.double_type) {
+ break;
+ case BuildinTypeSpec.Type.Double:
Encode ((byte) 0x0D);
- } else if (type == TypeManager.string_type) {
+ break;
+ case BuildinTypeSpec.Type.String:
Encode ((byte) 0x0E);
- } else if (type == TypeManager.type_type) {
+ break;
+ case BuildinTypeSpec.Type.Type:
Encode ((byte) 0x50);
- } else if (type == TypeManager.object_type) {
+ break;
+ case BuildinTypeSpec.Type.Object:
Encode ((byte) 0x51);
- } else if (TypeManager.IsEnumType (type)) {
- Encode ((byte) 0x55);
- EncodeTypeName (type);
- } else if (type.IsArray) {
- Encode ((byte) 0x1D);
- return Encode (TypeManager.GetElementType (type));
- } else if (type == InternalType.Dynamic) {
+ break;
+ case BuildinTypeSpec.Type.Dynamic:
Encode ((byte) 0x51);
return EncodedTypeProperties.DynamicType;
+ default:
+ if (type.IsArray) {
+ Encode ((byte) 0x1D);
+ return Encode (TypeManager.GetElementType (type));
+ }
+
+ if (type.Kind == MemberKind.Enum) {
+ Encode ((byte) 0x55);
+ EncodeTypeName (type);
+ }
+
+ break;
}
return EncodedTypeProperties.None;
if (Resolve (loc) == null)
return;
- if (ctor == null && !ResolveConstructor (loc, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
+ if (ctor == null && !ResolveConstructor (loc, module.Compiler.BuildinTypes.Byte, module.Compiler.BuildinTypes.Byte,
+ module.Compiler.BuildinTypes.UInt, module.Compiler.BuildinTypes.UInt, module.Compiler.BuildinTypes.UInt))
return;
int[] bits = decimal.GetBits (value);
if (Resolve (loc) == null)
return;
- if (ctor == null && !ResolveConstructor (loc, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
+ if (ctor == null && !ResolveConstructor (loc, module.Compiler.BuildinTypes.Byte, module.Compiler.BuildinTypes.Byte,
+ module.Compiler.BuildinTypes.UInt, module.Compiler.BuildinTypes.UInt, module.Compiler.BuildinTypes.UInt))
return;
int[] bits = decimal.GetBits (value);
return transform.ToArray ();
}
- if (t == InternalType.Dynamic)
+ if (t.BuildinType == BuildinTypeSpec.Type.Dynamic)
return new bool[] { true };
return null;
if (Resolve (loc) == null)
return false;
- tctor = TypeManager.GetPredefinedConstructor (type, Location.Null, ArrayContainer.MakeType (TypeManager.bool_type));
+ tctor = TypeManager.GetPredefinedConstructor (type, Location.Null, ArrayContainer.MakeType (module, module.Compiler.BuildinTypes.Bool));
return tctor != null;
}
}