private TypeTrace ResolveTypeTrace(CST.TypeDef typeDef) { var name = typeDef.EffectiveName(Parent.Parent.Env.Global); var typeTrace = default(TypeTrace); if (!TypeMap.TryGetValue(name, out typeTrace)) { typeTrace = new TypeTrace(this, typeDef); TypeMap.Add(name, typeTrace); } return typeTrace; }
// Imports: // - instance methods: no qualification // - static methods & constructors: add qualification // Exports: // - instance methods, not prototype bound: no qualification // - instance methods, prototype bound: add qualification and 'prototype' // - static methods & constructors: add qualification private JST.Expression PrefixName(CST.AssemblyDef assemblyDef, CST.TypeDef typeDef, CST.MethodDef methodDef, JST.Expression script, bool isExport) { if (script != null && script is JST.FunctionExpression) return script; var isNonInstance = methodDef.IsStatic || methodDef.IsConstructor; var qual = default(Qualification); attributeHelper.GetValueFromMethod (assemblyDef, typeDef, methodDef, attributeHelper.NamingAttributeRef, attributeHelper.TheQualificationProperty, true, false, ref qual); var bindToProto = default(bool); attributeHelper.GetValueFromMethod (assemblyDef, typeDef, methodDef, attributeHelper.ExportAttributeRef, attributeHelper.TheBindToPrototypeProperty, true, false, ref bindToProto); var isProto = isExport && bindToProto; var path = new Seq<JST.PropertyName>(); if (script == null && !methodDef.IsStatic && methodDef.IsConstructor && qual == Qualification.None) qual = Qualification.Type; if (!isExport && !isNonInstance && qual != Qualification.None) qual = Qualification.None; if (isExport && !isNonInstance && !isProto && qual != Qualification.None) qual = Qualification.None; if (isExport && !isNonInstance && isProto && qual == Qualification.None) qual = Qualification.Type; if (isNonInstance) { var global = default(JST.Expression); attributeHelper.GetValueFromMethod (assemblyDef, typeDef, methodDef, attributeHelper.NamingAttributeRef, attributeHelper.TheGlobalObjectProperty, true, false, ref global); if (global != null) { if (global is JST.FunctionExpression) { var ctxt = CST.MessageContextBuilders.Member(env.Global, assemblyDef, typeDef, methodDef); env.Log(new InvalidInteropMessage(ctxt, "global object expression cannot be a function")); throw new DefinitionException(); } foreach (var p in JST.Expression.ExplodePath(global)) path.Add(p); } } if (qual == Qualification.Full) { var nm = typeDef.EffectiveName(env.Global); if (nm.Namespace.Length > 0) { var nsCasing = default(Casing); attributeHelper.GetValueFromMethod (assemblyDef, typeDef, methodDef, attributeHelper.NamingAttributeRef, attributeHelper.TheNamespaceCasingProperty, true, false, ref nsCasing); foreach (var n in nm.Namespace.Split('.')) path.Add(new JST.PropertyName(Recase(n, nsCasing))); } } if (qual == Qualification.Full || qual == Qualification.Type) { var tnCasing = default(Casing); attributeHelper.GetValueFromType (assemblyDef, typeDef, attributeHelper.NamingAttributeRef, attributeHelper.TheTypeNameCasingProperty, true, false, ref tnCasing); foreach (var n in typeDef.EffectiveName(env.Global).Types.Select (name => new JST.PropertyName(Recase(name, tnCasing)))) path.Add(n); } if (isProto) path.Add(new JST.PropertyName(Constants.prototype)); if (script != null) { foreach (var p in JST.Expression.ExplodePath(script)) path.Add(p); } return JST.Expression.Path(path); }
public string ResolveTypeDefToSlot(CST.AssemblyDef assemblyDef, CST.TypeDef typeDef) { return AssemblyMappingFor(assemblyDef).ResolveTypeDefinitionToSlot(typeDef.EffectiveName(env.Global)); }