var domain = AppDomain.CurrentDomain;
temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
- var importer = new Compiler.ReflectionImporter (cc.BuildinTypes) {
+ var importer = new Compiler.ReflectionImporter (module, cc.BuildinTypes) {
IgnorePrivateMembers = false
};
// A copy is not enough, inflate any type parameter constraints
// using a new type parameters
- var inflator = new TypeParameterInflator (null, src, dst);
+ var inflator = new TypeParameterInflator (this, null, src, dst);
for (int i = 0; i < type_params.Length; ++i) {
src[i].InflateConstraints (inflator, dst[i]);
}
// Inflated type instance has to be updated manually
if (Instance.Type is InflatedTypeSpec) {
- var inflator = new TypeParameterInflator (Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+ var inflator = new TypeParameterInflator (this, Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
Instance.Type.MemberCache.AddMember (f.Spec.InflateMember (inflator));
- inflator = new TypeParameterInflator (f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+ inflator = new TypeParameterInflator (this, f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
f.Parent.CurrentType.MemberCache.AddMember (f.Spec.InflateMember (inflator));
}
}
ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
} else {
if (delegate_method.IsGeneric)
- delegate_method = delegate_method.MakeGenericMethod (method.TypeParameters);
+ delegate_method = delegate_method.MakeGenericMethod (ec.MemberContext, method.TypeParameters);
ec.Emit (OpCodes.Ldftn, delegate_method);
}
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, TypeManager.bool_type));
return tctor != null;
}
}
// Switch to inflated version as it's used by all expressions
//
var targs = CurrentTypeParameters == null ? TypeSpec.EmptyTypes : CurrentTypeParameters.Select (l => l.Type).ToArray ();
- current_type = spec.MakeGenericType (targs);
+ current_type = spec.MakeGenericType (this, targs);
} else {
current_type = spec;
}
// Implemented by elements which can act as independent contexts
// during resolve phase. Used mostly for lookups.
//
- public interface IMemberContext
+ public interface IMemberContext : IModuleContext
{
//
// A scope type context, it can be inflated for generic types
bool IsUnsafe { get; }
bool IsStatic { get; }
bool HasUnresolvedConstraints { get; }
- ModuleContainer Module { get; }
string GetSignatureForError ();
FullNamedExpression LookupNamespaceAlias (string name);
}
+ public interface IModuleContext
+ {
+ ModuleContainer Module { get; }
+ }
+
//
// Block or statement resolving context
//
}
TypeSpec t = FindDocumentedTypeNonArray (mc, identifier, ds, cref, r);
if (t != null && is_array)
- t = ArrayContainer.MakeType (t);
+ t = ArrayContainer.MakeType (mc.Module, t);
return t;
}
return 1;
}
- public static string GetPackageFlags (string packages, bool fatal, Report report)
+ public static string GetPackageFlags (string packages, Report report)
{
ProcessStartInfo pi = new ProcessStartInfo ();
pi.FileName = "pkg-config";
try {
p = Process.Start (pi);
} catch (Exception e) {
+ if (report == null)
+ throw;
+
report.Error (-27, "Couldn't run pkg-config: " + e.Message);
- if (fatal)
- Environment.Exit (1);
- p.Close ();
return null;
}
- if (p.StandardOutput == null){
+ if (p.StandardOutput == null) {
+ if (report == null)
+ throw new ApplicationException ("Specified package did not return any information");
+
report.Warning (-27, 1, "Specified package did not return any information");
p.Close ();
return null;
}
+
string pkgout = p.StandardOutput.ReadToEnd ();
p.WaitForExit ();
if (p.ExitCode != 0) {
+ if (report == null)
+ throw new ApplicationException (pkgout);
+
report.Error (-27, "Error running pkg-config. Check the above output.");
- if (fatal)
- Environment.Exit (1);
p.Close ();
return null;
}
- p.Close ();
+ p.Close ();
return pkgout;
}
}
#if STATIC
- var importer = new StaticImporter ();
+ var importer = new StaticImporter (module);
var references_loader = new StaticLoader (importer, ctx);
tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
- var importer = new ReflectionImporter (ctx.BuildinTypes);
+ var importer = new ReflectionImporter (module, ctx.BuildinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
RootContext.Reset (full_flag);
TypeManager.Reset ();
- ArrayContainer.Reset ();
ReferenceContainer.Reset ();
PointerContainer.Reset ();
Parameter.Reset ();
// Inflated type instance has to be updated manually
if (instance_type is InflatedTypeSpec) {
- var inflator = new TypeParameterInflator (instance_type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+ var inflator = new TypeParameterInflator (this, instance_type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
inflated = (TypeSpec) d.CurrentType.InflateMember (inflator);
instance_type.MemberCache.AddMember (inflated);
//
// Inflate the field, no need to keep it in MemberCache as it's accessed only once
//
- var inflator = new TypeParameterInflator (instance_type, spec.MemberDefinition.TypeParameters, instance_type.TypeArguments);
+ var inflator = new TypeParameterInflator (this, instance_type, spec.MemberDefinition.TypeParameters, instance_type.TypeArguments);
fs = (FieldSpec) fs.InflateMember (inflator);
}
{
instance_type = spec;
if (mutator != null)
- instance_type = instance_type.MakeGenericType (mutator.MethodTypeParameters.Select (l => l.Type).ToArray ());
+ instance_type = instance_type.MakeGenericType (this, mutator.MethodTypeParameters.Select (l => l.Type).ToArray ());
return true;
}
}
if (targs != null)
- method = method.MakeGenericMethod (targs);
+ method = method.MakeGenericMethod (rc, targs);
}
//
if (g_args_count != type_arguments.Count)
return int.MaxValue - 20000 + System.Math.Abs (type_arguments.Count - g_args_count);
- ms = ms.MakeGenericMethod (type_arguments.Arguments);
+ ms = ms.MakeGenericMethod (ec, type_arguments.Arguments);
} else {
// TODO: It should not be here (we don't know yet whether any argument is lambda) but
// for now it simplifies things. I should probably add a callback to ResolveContext
return ti.InferenceScore - 20000;
if (i_args.Length != 0) {
- ms = ms.MakeGenericMethod (i_args);
+ ms = ms.MakeGenericMethod (ec, i_args);
}
cc.IgnoreInferredDynamic = true;
//
if (candidate != pm) {
MethodSpec override_ms = (MethodSpec) pm;
- var inflator = new TypeParameterInflator (ms.DeclaringType, override_ms.GenericDefinition.TypeParameters, ms.TypeArguments);
+ var inflator = new TypeParameterInflator (ec, ms.DeclaringType, override_ms.GenericDefinition.TypeParameters, ms.TypeArguments);
returnType = inflator.Inflate (returnType);
} else {
returnType = ms.ReturnType;
static Dictionary<string, Tuple<FieldSpec, FieldInfo>> fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
static TypeSpec interactive_base_class;
- static Driver driver;
static bool inited;
static CompilerContext ctx;
static DynamicLoader loader;
static NamespaceEntry ns;
+ static ModuleContainer module;
public static TextWriter MessageOutput = Console.Out;
IsEvalutor = true
};
- RootContext.ToplevelTypes = new ModuleContainer (ctx);
+ RootContext.ToplevelTypes = module = new ModuleContainer (ctx);
var startup_files = new List<string> ();
foreach (CompilationUnit file in Location.SourceFiles)
CompilerCallableEntryPoint.PartialReset ();
- var importer = new ReflectionImporter (ctx.BuildinTypes);
+ var importer = new ReflectionImporter (module, ctx.BuildinTypes);
loader = new DynamicLoader (importer, ctx);
- RootContext.ToplevelTypes.SetDeclaringAssembly (new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp"));
+ module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "temp"));
- loader.LoadReferences (RootContext.ToplevelTypes);
- ctx.BuildinTypes.CheckDefinitions (RootContext.ToplevelTypes);
- RootContext.ToplevelTypes.InitializePredefinedTypes ();
+ loader.LoadReferences (module);
+ ctx.BuildinTypes.CheckDefinitions (module);
+ module.InitializePredefinedTypes ();
inited = true;
else
ctx.Report.Printer.Reset ();
- // RootContext.ToplevelTypes = new ModuleContainer (ctx);
-
bool partial_input;
CSharpParser parser = ParseString (ParseMode.Silent, input, out partial_input);
if (parser == null){
Class parser_result = parser.InteractiveResult;
try {
- var a = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp");
+ var a = new AssemblyDefinitionDynamic (module, "temp");
a.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run);
- RootContext.ToplevelTypes.SetDeclaringAssembly (a);
- RootContext.ToplevelTypes.CreateType ();
- RootContext.ToplevelTypes.Define ();
+ module.SetDeclaringAssembly (a);
+ module.CreateType ();
+ module.Define ();
parser_result.CreateType ();
parser_result.Define ();
seekable.Position = 0;
if (ns == null)
- ns = new NamespaceEntry (RootContext.ToplevelTypes, null, Location.SourceFiles[0], null);
+ ns = new NamespaceEntry (module, null, Location.SourceFiles[0], null);
- CSharpParser parser = new CSharpParser (seekable, Location.SourceFiles [0], RootContext.ToplevelTypes, ns);
+ CSharpParser parser = new CSharpParser (seekable, Location.SourceFiles [0], module, ns);
if (kind == InputKind.StatementOrExpression){
parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
access = AssemblyBuilderAccess.RunAndSave;
- assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name, current_debug_name);
+ assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
assembly.Importer = loader.Importer;
} else {
#if NET_4_0
#else
access = AssemblyBuilderAccess.Run;
#endif
- assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name);
+ assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
}
assembly.Create (AppDomain.CurrentDomain, access);
host.Define ();
}
- RootContext.ToplevelTypes.CreateType ();
- RootContext.ToplevelTypes.Define ();
+ module.CreateType ();
+ module.Define ();
if (Report.Errors != 0){
if (undo != null)
host.EmitType ();
}
- RootContext.ToplevelTypes.Emit ();
+ module.Emit ();
if (Report.Errors != 0){
if (undo != null)
undo.ExecuteUndo ();
return null;
}
- RootContext.ToplevelTypes.CloseType ();
+ module.CloseType ();
if (host != null)
host.CloseType ();
lock (evaluator_lock){
var a = loader.LoadAssemblyFile (file);
if (a != null)
- loader.Importer.ImportAssembly (a, RootContext.ToplevelTypes.GlobalRootNamespace);
+ loader.Importer.ImportAssembly (a, module.GlobalRootNamespace);
}
}
static public void ReferenceAssembly (Assembly a)
{
lock (evaluator_lock){
- loader.Importer.ImportAssembly (a, RootContext.ToplevelTypes.GlobalRootNamespace);
+ loader.Importer.ImportAssembly (a, module.GlobalRootNamespace);
}
}
return;
}
- string pkgout = Driver.GetPackageFlags (pkg, false, RootContext.ToplevelTypes.Compiler.Report);
- if (pkgout == null)
- return;
+ string pkgout = Driver.GetPackageFlags (pkg, null);
string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
Split (new Char [] { ' ', '\t'});
t, MemberFilter.Method ("CreateInstance", 1, ParametersCompiled.EmptyReadOnlyParameters, null), loc);
}
- var ctor_factory = TypeManager.activator_create_instance.MakeGenericMethod (type);
+ var ctor_factory = TypeManager.activator_create_instance.MakeGenericMethod (ec.MemberContext, type);
var tparam = (TypeParameterSpec) type;
if (tparam.IsReferenceType) {
//
UnifyInitializerElement (ec);
- type = ArrayContainer.MakeType (array_element_type, dimensions);
+ type = ArrayContainer.MakeType (ec.Module, array_element_type, dimensions);
eclass = ExprClass.Value;
return this;
}
ec.Module.Compiler.Report.Error (719, loc, "Array elements cannot be of static type `{0}'",
type.GetSignatureForError ());
} else {
- MakeArray (single_spec);
+ MakeArray (ec.Module, single_spec);
}
}
return this;
}
- void MakeArray (ComposedTypeSpecifier spec)
+ void MakeArray (ModuleContainer module, ComposedTypeSpecifier spec)
{
if (spec.Next != null)
- MakeArray (spec.Next);
+ MakeArray (module, spec.Next);
- type = ArrayContainer.MakeType (type, spec.Dimension);
+ type = ArrayContainer.MakeType (module, type, spec.Dimension);
}
public override string GetSignatureForError ()
readonly TypeSpec type;
readonly TypeParameterSpec[] tparams;
readonly TypeSpec[] targs;
+ readonly IModuleContext context;
public TypeParameterInflator (TypeParameterInflator nested, TypeSpec type)
- : this (type, nested.tparams, nested.targs)
+ : this (nested.context, type, nested.tparams, nested.targs)
{
}
- public TypeParameterInflator (TypeSpec type, TypeParameterSpec[] tparams, TypeSpec[] targs)
+ public TypeParameterInflator (IModuleContext context, TypeSpec type, TypeParameterSpec[] tparams, TypeSpec[] targs)
{
if (tparams.Length != targs.Length)
throw new ArgumentException ("Invalid arguments");
+ this.context = context;
this.tparams = tparams;
this.targs = targs;
this.type = type;
#region Properties
+ public IModuleContext Context {
+ get {
+ return context;
+ }
+ }
+
public TypeSpec TypeInstance {
- get { return type; }
+ get {
+ return type;
+ }
}
//
if (ac != null) {
var et = Inflate (ac.Element);
if (et != ac.Element)
- return ArrayContainer.MakeType (et, ac.Rank);
+ return ArrayContainer.MakeType (context.Module, et, ac.Rank);
return ac;
}
for (; i < targs.Length; ++i)
inflated_targs[i] = Inflate (targs[i]);
- type = type.MakeGenericType (inflated_targs);
+ type = type.MakeGenericType (context, inflated_targs);
}
return type;
targs[i++] = Inflate (ds_tp);
}
- return type.MakeGenericType (targs);
+ return type.MakeGenericType (context, targs);
}
public TypeSpec Inflate (TypeParameterSpec tp)
TypeSpec[] targs;
TypeParameterSpec[] constraints;
readonly TypeSpec open_type;
+ readonly IModuleContext context;
- public InflatedTypeSpec (TypeSpec openType, TypeSpec declaringType, TypeSpec[] targs)
+ public InflatedTypeSpec (IModuleContext context, TypeSpec openType, TypeSpec declaringType, TypeSpec[] targs)
: base (openType.Kind, declaringType, openType.MemberDefinition, null, openType.Modifiers)
{
if (targs == null)
throw new ArgumentNullException ("targs");
// this.state = openType.state;
+ this.context = context;
this.open_type = openType;
this.targs = targs;
public TypeParameterSpec[] Constraints {
get {
if (constraints == null) {
- constraints = TypeParameterSpec.InflateConstraints (MemberDefinition.TypeParameters, l => l.CreateLocalInflator (), this);
+ constraints = TypeParameterSpec.InflateConstraints (MemberDefinition.TypeParameters, l => l.CreateLocalInflator (context), this);
}
return constraints;
return false;
}
- TypeParameterInflator CreateLocalInflator ()
+ TypeParameterInflator CreateLocalInflator (IModuleContext context)
{
TypeParameterSpec[] tparams_full;
TypeSpec[] targs_full = targs;
tparams_full = open_type.MemberDefinition.TypeParameters;
}
- return new TypeParameterInflator (this, tparams_full, targs_full);
+ return new TypeParameterInflator (context, this, tparams_full, targs_full);
}
MetaType CreateMetaInfo (TypeParameterMutator mutator)
if (cache == null)
cache = new MemberCache (onlyTypes ? open_type.MemberCacheTypes : open_type.MemberCache);
- var inflator = CreateLocalInflator ();
+ var inflator = CreateLocalInflator (context);
//
// Two stage inflate due to possible nested types recursive
//
// Now bind the parameters
//
- type = open_type.MakeGenericType (atypes);
+ type = open_type.MakeGenericType (ec, atypes);
//
// Check constraints when context is not method/base type
// Uses inferred or partially infered types to inflate delegate type argument. Returns
// null when type parameter has not been fixed
//
- public TypeSpec InflateGenericArgument (TypeSpec parameter)
+ public TypeSpec InflateGenericArgument (IModuleContext context, TypeSpec parameter)
{
var tp = parameter as TypeParameterSpec;
if (tp != null) {
if (gt != null) {
var inflated_targs = new TypeSpec [gt.TypeArguments.Length];
for (int ii = 0; ii < inflated_targs.Length; ++ii) {
- var inflated = InflateGenericArgument (gt.TypeArguments [ii]);
+ var inflated = InflateGenericArgument (context, gt.TypeArguments [ii]);
if (inflated == null)
return null;
inflated_targs[ii] = inflated;
}
- return gt.GetDefinition ().MakeGenericType (inflated_targs);
+ return gt.GetDefinition ().MakeGenericType (context, inflated_targs);
}
return parameter;
// if all delegate generic arguments are fixed.
TypeSpec[] param_types = new TypeSpec [invoke.Parameters.Count];
for (int i = 0; i < param_types.Length; ++i) {
- var inflated = InflateGenericArgument (invoke.Parameters.Types[i]);
+ var inflated = InflateGenericArgument (ec, invoke.Parameters.Types[i]);
if (inflated == null)
return 0;
sealed class StaticImporter : MetadataImporter
{
- public StaticImporter ()
+ public StaticImporter (ModuleContainer module)
+ : base (module)
{
}
protected readonly Dictionary<MetaType, TypeSpec> import_cache;
protected readonly Dictionary<MetaType, TypeSpec> compiled_types;
protected readonly Dictionary<Assembly, IAssemblyDefinition> assembly_2_definition;
+ readonly ModuleContainer module;
public static readonly string CompilerServicesNamespace = "System.Runtime.CompilerServices";
- protected MetadataImporter ()
+ protected MetadataImporter (ModuleContainer module)
{
+ this.module = module;
+
import_cache = new Dictionary<MetaType, TypeSpec> (1024, ReferenceEquality<MetaType>.Default);
compiled_types = new Dictionary<MetaType, TypeSpec> (40, ReferenceEquality<MetaType>.Default);
assembly_2_definition = new Dictionary<Assembly, IAssemblyDefinition> (ReferenceEquality<Assembly>.Default);
throw new NotImplementedException ("Unknown element type " + type.ToString ());
}
- spec = ArrayContainer.MakeType (spec, type.GetArrayRank ());
+ spec = ArrayContainer.MakeType (module, spec, type.GetArrayRank ());
} else {
spec = CreateType (type, dtype, true);
//
if (!IsMissingType (type) && type.IsGenericTypeDefinition) {
var targs = CreateGenericArguments (0, type.GetGenericArguments (), dtype);
- spec = spec.MakeGenericType (targs);
+ spec = spec.MakeGenericType (module, targs);
}
}
if (declaringType == null) {
// Simple case, no nesting
spec = CreateType (type_def, null, new DynamicTypeReader (), canImportBaseType);
- spec = spec.MakeGenericType (targs);
+ spec = spec.MakeGenericType (module, targs);
} else {
//
// Nested type case, converting .NET types like
int targs_pos = 0;
if (declaringType.Arity > 0) {
- spec = declaringType.MakeGenericType (targs.Skip (targs_pos).Take (declaringType.Arity).ToArray ());
+ spec = declaringType.MakeGenericType (module, targs.Skip (targs_pos).Take (declaringType.Arity).ToArray ());
targs_pos = spec.Arity;
} else {
spec = declaringType;
var t = nested_hierarchy [i - 1];
spec = MemberCache.FindNestedType (spec, t.Name, t.Arity);
if (t.Arity > 0) {
- spec = spec.MakeGenericType (targs.Skip (targs_pos).Take (spec.Arity).ToArray ());
+ spec = spec.MakeGenericType (module, targs.Skip (targs_pos).Take (spec.Arity).ToArray ());
targs_pos += t.Arity;
}
}
spec = MemberCache.FindNestedType (spec, name, targs.Length - targs_pos);
if (spec.Arity > 0) {
- spec = spec.MakeGenericType (targs.Skip (targs_pos).ToArray ());
+ spec = spec.MakeGenericType (module, targs.Skip (targs_pos).ToArray ());
}
}
var spec = ImportType (element, dtype);
if (type.IsArray)
- return ArrayContainer.MakeType (spec, type.GetArrayRank ());
+ return ArrayContainer.MakeType (module, spec, type.GetArrayRank ());
if (type.IsByRef)
return ReferenceContainer.MakeType (spec);
if (type.IsPointer)
// When type inference context exists try to apply inferred type arguments
//
if (tic != null) {
- d_param = tic.InflateGenericArgument (d_param);
+ d_param = tic.InflateGenericArgument (ec, d_param);
}
ptypes [i] = d_param;
TypeInferenceContext tic = new TypeInferenceContext (source_type.TypeArguments);
tic.OutputTypeInference (rc, a.Expr, source_type);
if (tic.FixAllTypes (rc)) {
- source_type = source_type.GetDefinition ().MakeGenericType (tic.InferredTypeArguments);
+ source_type = source_type.GetDefinition ().MakeGenericType (rc, tic.InferredTypeArguments);
}
}
return ms;
}
- public MethodSpec MakeGenericMethod (params TypeSpec[] targs)
+ public MethodSpec MakeGenericMethod (IMemberContext context, params TypeSpec[] targs)
{
if (targs == null)
throw new ArgumentNullException ();
//if (generic_intances == null)
// generic_intances = new Dictionary<TypeSpec[], Method> (TypeSpecArrayComparer.Default);
- var inflator = new TypeParameterInflator (DeclaringType, GenericDefinition.TypeParameters, targs);
+ var inflator = new TypeParameterInflator (context, DeclaringType, GenericDefinition.TypeParameters, targs);
var inflated = (MethodSpec) MemberwiseClone ();
inflated.declaringType = inflator.TypeInstance;
var local_tparam = tp.Type;
local_tparam.SpecialConstraint = base_tparam.SpecialConstraint;
- var inflator = new TypeParameterInflator (CurrentType, base_decl_tparams, base_targs);
+ var inflator = new TypeParameterInflator (this, CurrentType, base_decl_tparams, base_targs);
base_tparam.InflateConstraints (inflator, local_tparam);
//
#if STATIC
public class ReflectionImporter
{
- public ReflectionImporter (BuildinTypes buildin)
+ public ReflectionImporter (ModuleContainer module, BuildinTypes buildin)
{
throw new NotSupportedException ();
}
#else
public sealed class ReflectionImporter : MetadataImporter
{
- public ReflectionImporter (BuildinTypes buildin)
+ public ReflectionImporter (ModuleContainer module, BuildinTypes buildin)
+ : base (module)
{
Initialize (buildin);
}
return ParseResult.Error;
}
packages = String.Join (" ", value.Split (new Char[] { ';', ',', '\n', '\r' }));
- string pkgout = Driver.GetPackageFlags (packages, true, report);
+ string pkgout = Driver.GetPackageFlags (packages, report);
- if (pkgout != null) {
- string[] xargs = pkgout.Trim (new Char[] { ' ', '\n', '\r', '\t' }).
- Split (new Char[] { ' ', '\t' });
- args = AddArgs (args, xargs);
- }
+ if (pkgout == null)
+ return ParseResult.Error;
+ string[] xargs = pkgout.Trim (new Char[] { ' ', '\n', '\r', '\t' }).Split (new Char[] { ' ', '\t' });
+ args = AddArgs (args, xargs);
return ParseResult.Success;
}
public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
Dictionary<int, List<AnonymousTypeClass>> anonymous_types;
+ Dictionary<ArrayContainer.TypeRankPair, ArrayContainer> arrays;
AssemblyDefinition assembly;
readonly CompilerContext context;
anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
global_ns = new GlobalRootNamespace ();
alias_ns = new Dictionary<string, RootNamespace> ();
+ arrays = new Dictionary<ArrayContainer.TypeRankPair, ArrayContainer> ();
}
#region Properties
+ public Dictionary<ArrayContainer.TypeRankPair, ArrayContainer> ArraysCache {
+ get {
+ return arrays;
+ }
+ }
+
public override AttributeTargets AttributeTargets {
get {
return AttributeTargets.Assembly;
string ns;
int arity;
MemberKind kind;
- ModuleContainer module;
+ protected readonly ModuleContainer module;
protected TypeSpec type;
public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
// because type parameters are same for all nested types
//
if (DeclaringType == inflator.TypeInstance) {
- return MakeGenericType (targs);
+ return MakeGenericType (inflator.Context, targs);
}
- return new InflatedTypeSpec (this, inflator.TypeInstance, targs);
+ return new InflatedTypeSpec (inflator.Context, this, inflator.TypeInstance, targs);
}
- public InflatedTypeSpec MakeGenericType (TypeSpec[] targs)
+ public InflatedTypeSpec MakeGenericType (IModuleContext context, TypeSpec[] targs)
{
if (targs.Length == 0 && !IsNested)
throw new ArgumentException ("Empty type arguments for type " + GetSignatureForError ());
throw new InternalErrorException ("`{0}' must be type definition or nested non-inflated type to MakeGenericType",
GetSignatureForError ());
- instance = new InflatedTypeSpec (this, declaringType, targs);
+ instance = new InflatedTypeSpec (context, this, declaringType, targs);
inflated_instances.Add (targs, instance);
}
public class ArrayContainer : ElementTypeSpec
{
- struct TypeRankPair : IEquatable<TypeRankPair>
+ public struct TypeRankPair : IEquatable<TypeRankPair>
{
TypeSpec ts;
int rank;
}
readonly int rank;
- static Dictionary<TypeRankPair, ArrayContainer> instances = new Dictionary<TypeRankPair, ArrayContainer> ();
+ readonly ModuleContainer module;
- private ArrayContainer (TypeSpec element, int rank)
+ private ArrayContainer (ModuleContainer module, TypeSpec element, int rank)
: base (MemberKind.ArrayType, element, null)
{
+ this.module = module;
this.rank = rank;
}
public MethodInfo GetConstructor ()
{
- var mb = RootContext.ToplevelTypes.Builder;
+ var mb = module.Builder;
var arg_types = new MetaType[rank];
for (int i = 0; i < rank; i++)
public MethodInfo GetAddressMethod ()
{
- var mb = RootContext.ToplevelTypes.Builder;
+ var mb = module.Builder;
var arg_types = new MetaType[rank];
for (int i = 0; i < rank; i++)
public MethodInfo GetGetMethod ()
{
- var mb = RootContext.ToplevelTypes.Builder;
+ var mb = module.Builder;
var arg_types = new MetaType[rank];
for (int i = 0; i < rank; i++)
public MethodInfo GetSetMethod ()
{
- var mb = RootContext.ToplevelTypes.Builder;
+ var mb = module.Builder;
var arg_types = new MetaType[rank + 1];
for (int i = 0; i < rank; i++)
return sb.ToString ();
}
- public static ArrayContainer MakeType (TypeSpec element)
+ public static ArrayContainer MakeType (ModuleContainer module, TypeSpec element)
{
- return MakeType (element, 1);
+ return MakeType (module, element, 1);
}
- public static ArrayContainer MakeType (TypeSpec element, int rank)
+ public static ArrayContainer MakeType (ModuleContainer module, TypeSpec element, int rank)
{
ArrayContainer ac;
var key = new TypeRankPair (element, rank);
- if (!instances.TryGetValue (key, out ac)) {
- ac = new ArrayContainer (element, rank) {
+ if (!module.ArraysCache.TryGetValue (key, out ac)) {
+ ac = new ArrayContainer (module, element, rank) {
BaseType = TypeManager.array_type
};
- instances.Add (key, ac);
+ module.ArraysCache.Add (key, ac);
}
return ac;
}
-
- public static void Reset ()
- {
- instances = new Dictionary<TypeRankPair, ArrayContainer> ();
- }
}
class ReferenceContainer : ElementTypeSpec