// Collect types we need to compile private void CollectTypes() { foreach (var typeDef in assmEnv.Assembly.Types.Where(t => t.Invalid == null)) { var tyconEnv = assmEnv.AddType(typeDef); if (typeDef.IsModule) { // Look for any <Module>::.cctor() // We know both <Module> and the .cctor have no type parameters var methodDef = typeDef.Members.OfType <CST.MethodDef>().Where (m => m.Invalid == null && m.IsStatic && m.IsConstructor).FirstOrDefault(); if (methodDef != null) { moduleInitializer = methodDef.SelfMethodReference(tyconEnv); } } if (typeDef.IsUsed) { typeDefs.Add(typeDef); } else { if (assemblyTrace == null || assemblyTrace.IncludeAssembly) { Env.Log(new UnusedDefinitionMessage(CST.MessageContextBuilders.Env(tyconEnv))); } } } }
public AssemblyDef(Global global, IImSeq <Annotation> annotations, ISeq <CustomAttribute> customAttributes, AssemblyName name, IImSeq <AssemblyName> references, IImSeq <TypeDef> types, MethodRef entryPoint) { Annotations = annotations ?? Constants.EmptyAnnotations; CustomAttributes = customAttributes ?? new Seq <CustomAttribute>(); Name = name; References = references ?? Constants.EmptyStrongAssemblyNames; Types = types ?? Constants.EmptyTypeDefs; EntryPoint = entryPoint; nameToTypeDefCache = new Map <TypeName, TypeDef>(); if (types != null) { foreach (var t in types) { nameToTypeDefCache.Add(t.EffectiveName(global), t); } } }
public DuplicateEntryPointMessage(MethodRef existingEntryPoint, MethodRef newEntryPoint) : base(null, Severity.Warning, "1029") { ExistingEntryPoint = existingEntryPoint; NewEntryPoint = newEntryPoint; }
public IgnoringEntryPointMessage(MethodRef method, string fileName) : base(null, Severity.Warning, "1018") { Method = method; FileName = fileName; }
public void SeenMethod(MethodRef methodRef, bool isAlwaysUsed) { Add(Methods, methodRef, 1, isAlwaysUsed); }
private CST.MethodRef MatchingImportingConstructor(CST.PolymorphicMethodEnvironment polyMethEnv) { var state = GetTypeRepresentation(polyMethEnv.Assembly, polyMethEnv.Type).State; var bestRank = 0; var bestCtor = default(CST.MethodRef); foreach (var currCtor in polyMethEnv.Type.Members.OfType<CST.MethodDef>().Where (m => m.Invalid == null && !m.IsStatic && m.IsConstructor && !IsImported(polyMethEnv.Assembly, polyMethEnv.Type, m))) { var currRank = 0; var currArity = currCtor.ValueParameters.Count; switch (state) { case InstanceState.ManagedOnly: if (currArity == 1) // .ctor(C this) currRank = 1; break; case InstanceState.ManagedAndJavaScript: case InstanceState.JavaScriptOnly: if (currArity == 2 && currCtor.ValueParameters[1].Type.Equals(env.JSContextRef)) // .ctor(C this, JSContext ctxt) currRank = 1; else if (currArity == polyMethEnv.Method.Arity + 1 && currCtor.ValueParameters[1].Type.Equals(env.JSContextRef)) { // .ctor(C this, JSContext ctxt, T t, U u) currRank = 2; for (var i = 2; i < currArity; i++) { if ( !currCtor.ValueParameters[i].Type.IsEquivalentTo (polyMethEnv, polyMethEnv.Method.ValueParameters[i - 1].Type)) { currRank = 0; break; } } } break; case InstanceState.Merged: throw new InvalidOperationException ("'ManagedAndJavaScript' or 'JavaScriptOnly' type derived from a 'Merged' type"); default: throw new ArgumentOutOfRangeException(); } if (currRank > 0 && currCtor.Annotations.OfType<CST.AccessibilityAnnotation>().Where (a => a.Accessibility != CST.Accessibility.Public).Any()) { env.Log (new InvalidInteropMessage (CST.MessageContextBuilders.Member(env.Global, polyMethEnv.Assembly, polyMethEnv.Type, currCtor), "importing constructors must be public")); throw new DefinitionException(); } if (currRank > bestRank) { bestRank = currRank; bestCtor = new CST.MethodRef(polyMethEnv.TypeRef, currCtor.MethodSignature, null); } } if (bestRank > 0) return bestCtor; if (state == InstanceState.ManagedOnly) // No more implict constructors are available return null; if (polyMethEnv.Type.Extends == null) return null; // Try base type return DefaultImportingConstructor(polyMethEnv.Type.Extends.Enter(polyMethEnv)); }
public bool IsInlinable(CST.MethodRef methodRef) { var s = MethodBodySize(methodRef.QualifiedMemberName); return(s >= 0 && s <= env.InlineThreshold); }
private AssemblyCompiler(CompilerEnvironment env) { Env = env; moduleInitializer = null; typeDefs = new Seq <CST.TypeDef>(); }
public JST.Expression MethodCallExpression(CST.MethodRef methodRef, JST.NameSupply localNameSupply, bool isFactory, IImSeq <JST.Expression> arguments) { return(Env.JSTHelpers.DefaultMethodCallExpression(this, localNameSupply, methodRef, isFactory, arguments)); }
// Collect types we need to compile private void CollectTypes() { foreach (var typeDef in assmEnv.Assembly.Types.Where(t => t.Invalid == null)) { var tyconEnv = assmEnv.AddType(typeDef); if (typeDef.IsModule) { // Look for any <Module>::.cctor() // We know both <Module> and the .cctor have no type parameters var methodDef = typeDef.Members.OfType<CST.MethodDef>().Where (m => m.Invalid == null && m.IsStatic && m.IsConstructor).FirstOrDefault(); if (methodDef != null) moduleInitializer = methodDef.SelfMethodReference(tyconEnv); } if (typeDef.IsUsed) typeDefs.Add(typeDef); else { if (assemblyTrace == null || assemblyTrace.IncludeAssembly) Env.Log(new UnusedDefinitionMessage(CST.MessageContextBuilders.Env(tyconEnv))); } } }
private AssemblyCompiler(CompilerEnvironment env) { Env = env; moduleInitializer = null; typeDefs = new Seq<CST.TypeDef>(); }