/// <summary> /// Try to get a type definition (me or one of my nested typed) by the given full name. /// </summary> public override bool TryGet(string fullName, bool noImports, out XTypeDefinition xTypeDefinition) { if (base.TryGet(fullName, noImports, out xTypeDefinition)) { return(true); } if (!noImports) { EnsureDexImportType(); if (dexImportType != Module.TypeSystem.NoType) { if (dexImportType.FullName == fullName) { xTypeDefinition = this; return(true); } } EnsureJavaImportType(); if (javaImportType.FullName == fullName) { xTypeDefinition = this; return(true); } } return(false); }
/// <summary> /// Create a synthetic field and add it to the given declaring type. /// </summary> public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType) { var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType); declaringType.Add(type); return(type); }
/// <summary> /// Resolve this reference to it's definition. /// </summary> public override bool TryResolve(out XTypeDefinition type) { if (base.TryResolve(out type)) return true; switch (FullName) { case "B": return Module.TypeSystem.SByte.TryResolve(out type); case "C": return Module.TypeSystem.Char.TryResolve(out type); case "D": return Module.TypeSystem.Double.TryResolve(out type); case "F": return Module.TypeSystem.Float.TryResolve(out type); case "I": return Module.TypeSystem.Int.TryResolve(out type); case "J": return Module.TypeSystem.Long.TryResolve(out type); case "S": return Module.TypeSystem.Short.TryResolve(out type); case "Z": return Module.TypeSystem.Bool.TryResolve(out type); } // Try clumsy nested like classes if (Module.TryGetType(javaClassName, out type)) return true; return false; }
private void CreateMembersTree(LibraryNode current, XTypeDefinition scope, XSharpModuleId moduleId) { if (null == scope || XSolution.IsClosing) { return; } foreach (XMemberDefinition member in scope.Members) { XSharpLibraryNode newNode = new XSharpLibraryNode(member, "", moduleId.Hierarchy, moduleId.ItemID); // The classes are always added to the root node, the functions to the // current node. if ((newNode.NodeType & LibraryNode.LibraryNodeType.Members) != LibraryNode.LibraryNodeType.None) { current.AddNode(newNode); newNode.parent = current; lock (files) { files.Add(moduleId, newNode); } } } }
/// <summary> /// Create the XType for this builder. /// </summary> protected override XTypeDefinition CreateXType(XTypeDefinition parentXType) { var baseType = Compiler.GetDot42InternalType("EnumInfo"); return(XSyntheticTypeDefinition.Create(Compiler.Module, parentXType, XSyntheticTypeFlags.Private, null, ClassName, baseType, parentXType.ScopeId + ":Info")); }
/// <summary> /// Create a synthetic method and add it to the given declaring type. /// </summary> public static XSyntheticMethodDefinition Create(XTypeDefinition declaringType, XSyntheticMethodFlags flags, string name, string scopeId, XTypeReference returnType, params XParameter[] parameters) { var method = new XSyntheticMethodDefinition(declaringType, flags, name, scopeId, returnType, parameters); declaringType.Add(method); return(method); }
/// <summary> /// Create a synthetic field and add it to the given declaring type. /// </summary> public static XSyntheticFieldDefinition Create(XTypeDefinition declaringType, XSyntheticFieldFlags flags, string name, XTypeReference fieldType, object initialValue = null) { var field = new XSyntheticFieldDefinition(declaringType, flags, name, fieldType, initialValue); declaringType.Add(field); return(field); }
private List <XMemberDefinition> BuildMissingMembers(XTypeDefinition currentClass, System.Reflection.MemberInfo[] members) { List <XMemberDefinition> elementsToAdd = new List <XMemberDefinition>(); // foreach (System.Reflection.MemberInfo member in members) { System.Reflection.MemberTypes realType = member.MemberType; if (realType == System.Reflection.MemberTypes.Method) { System.Reflection.MethodInfo method = (System.Reflection.MethodInfo)member; // Check for Getter/Setter if ((method.Attributes & System.Reflection.MethodAttributes.SpecialName) == System.Reflection.MethodAttributes.SpecialName) { string getsetName = member.Name; if (getsetName.StartsWith("get_") || getsetName.StartsWith("set_")) { // Oooppsss continue; } } } // Now, We will have to check Parameters / Return Type if (!CheckForMember(currentClass, member)) { // and re-create our own prototype elementsToAdd.Add(CreateMember(member, members)); } } return(elementsToAdd); }
/// <summary> /// Convert the given node that holds a numeric value and convert it to it's enum instance. /// </summary> private static void ConvertNumericToEnum(AstExpression node, XTypeDefinition enumType, XTypeReference enumNumericType) { // Call Enum.GetValue(enumType, value) var enumValue = new AstExpression(node); node.SetCode(enumNumericType.IsWide() ? AstCode.Long_to_enum : AstCode.Int_to_enum).SetArguments(enumValue).SetType(enumType); node.Operand = null; }
/// <summary> /// Default ctor /// </summary> private XSyntheticFieldDefinition(XTypeDefinition declaringType, XSyntheticFieldFlags flags, string name, XTypeReference fieldType, object initialValue) : base(declaringType) { this.flags = flags; this.name = name; this.fieldType = fieldType; this.initialValue = initialValue; }
/// <summary> /// Default ctor /// </summary> private XSyntheticMethodDefinition(XTypeDefinition declaringType, XSyntheticMethodFlags flags, string name, XTypeReference returnType, params XParameter[] parameters) : base(declaringType) { this.flags = flags; this.name = name; this.returnType = returnType; this.parameters = parameters.ToList(); astParameters = parameters.Select(x => new AstParameterVariable(x)).Cast <AstVariable>().ToList(); }
/// <summary> /// Default ctor /// </summary> public ILTypeDefinition(XModule module, XTypeDefinition declaringType, TypeDefinition type) : base(module, declaringType, type.IsValueType, type.GenericParameters.Select(x => x.Name)) { this.type = type; fields = new List<XFieldDefinition>(type.Fields.Count); methods = new List<XMethodDefinition>(type.Methods.Count); nested = new List<XTypeDefinition>(); interfaces = new List<XTypeReference>(); }
/// <summary> /// Default ctor /// </summary> public DelegateType(AssemblyCompiler compiler, XTypeDefinition delegateType, ClassDefinition interfaceClass, Dex target, NameConverter nsConverter) { this.compiler = compiler; this.delegateType = delegateType; this.interfaceClass = interfaceClass; // Build invoke prototype invokeMethod = delegateType.Methods.First(x => x.EqualsName("Invoke")); }
/// <summary> /// Default ctor /// </summary> public ILTypeDefinition(XModule module, XTypeDefinition declaringType, TypeDefinition type) : base(module, declaringType, type.IsValueType, type.GenericParameters.Select(x => x.Name)) { this.type = type; fields = new List <XFieldDefinition>(type.Fields.Count); methods = new List <XMethodDefinition>(type.Methods.Count); nested = new List <XTypeDefinition>(); interfaces = new List <XTypeReference>(); }
/// <summary> /// Default ctor /// </summary> public JavaTypeDefinition(XModule module, XTypeDefinition declaringType, ClassFile type) : base(module, declaringType, false, null) { this.type = type; fields = type.Fields.Select(x => new JavaFieldDefinition(this, x)).Cast <XFieldDefinition>().ToList().AsReadOnly(); methods = type.Methods.Select(x => new JavaMethodDefinition(this, x)).Cast <XMethodDefinition>().ToList().AsReadOnly(); nested = type.InnerClasses.Where(x => x.InnerClassFile.DeclaringClass == type).Select(x => new JavaTypeDefinition(module, this, x.InnerClassFile)).Cast <XTypeDefinition>().ToList().AsReadOnly(); interfaces = new List <XTypeReference>(); }
/// <summary> /// Create a synthetic field and add it to the given declaring type. /// </summary> public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType, string fullScopeId) { var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType, fullScopeId); if(declaringType != null) declaringType.Add(type); module.Register(type); return type; }
/// <summary> /// Default ctor /// </summary> public JavaTypeDefinition(XModule module, XTypeDefinition declaringType, ClassFile type) : base(module, declaringType, false, null) { this.type = type; fields = type.Fields.Select(x => new JavaFieldDefinition(this, x)).Cast<XFieldDefinition>().ToList().AsReadOnly(); methods = type.Methods.Select(x => new JavaMethodDefinition(this, x)).Cast<XMethodDefinition>().ToList().AsReadOnly(); nested = type.InnerClasses.Where(x => x.InnerClassFile.DeclaringClass == type).Select(x => new JavaTypeDefinition(module, this, x.InnerClassFile)).Cast<XTypeDefinition>().ToList().AsReadOnly(); interfaces = new List<XTypeReference>(); }
/// <summary> /// Get's the namespace of the given type after conversion. /// </summary> public string GetConvertedNamespace(XTypeDefinition type) { if (type.IsNested) { return(GetConvertedNamespace(type.DeclaringType)); } var ns = type.Namespace; return(ConvertNamespace(ns)); }
/// <summary> /// Gets the struct $CopyFrom method of the given value type. /// Throws an exception if not found. /// </summary> private static XMethodDefinition GetCopyFromMethod(XTypeDefinition valueType) { var method = valueType.Methods.FirstOrDefault(x => !x.IsStatic && (x.Parameters.Count == 1) && (x.Name == NameConstants.Struct.CopyFromMethodName)); if (method == null) { throw new NotImplementedException(string.Format("Value type {0} has no struct copyFrom method", valueType.FullName)); } return(method); }
/// <summary> /// Resolve this reference to it's definition. /// </summary> public override bool TryResolve(out XTypeDefinition type) { if (resolved == null) { if (!base.TryResolve(out resolved)) throw new XResolutionException(this); } type = resolved; return true; }
/// <summary> /// Gets the default constructor of the given value type. /// Throws an exception if not found. /// </summary> internal static XMethodDefinition GetDefaultValueCtor(XTypeDefinition valueType) { var defaultCtor = valueType.Methods.FirstOrDefault(x => x.IsConstructor && !x.IsStatic && (x.Parameters.Count == 0)); if (defaultCtor == null) { throw new NotImplementedException(string.Format("Value type {0} has no default ctor", valueType.FullName)); } return(defaultCtor); }
/// <summary> /// Default ctor /// </summary> public AstBuilder(XModule module, MethodDefinition methodDef, XTypeDefinition declaringType, bool optimize) { this.module = module; typeSystem = module.TypeSystem; this.methodDef = methodDef; this.declaringType = declaringType; this.optimize = optimize; codeAttr = methodDef.Attributes.OfType <CodeAttribute>().FirstOrDefault(); validExceptionHandlers = (codeAttr != null) ? codeAttr.ExceptionHandlers.Where(IsValid).ToList() : null; }
/// <summary> /// Convert a integer compare operation (bge, bgt, ble, blt) with enum argument. /// </summary> private static void ConvertICmpArgument(AstExpression node, int argIndex, XTypeDefinition enumType, AssemblyCompiler compiler) { Debug.Assert(node.Arguments.Count == 2); var isWide = enumType.GetEnumUnderlyingType().IsWide(); var module = compiler.Module; var retType = isWide ? module.TypeSystem.Long : module.TypeSystem.Int; // Convert arguments ConvertNumericOpArgument(node, argIndex, enumType, isWide, retType); }
/// <summary> /// Gets the recorded delegate type for the given .NET delegate type. /// </summary> internal DelegateType GetDelegateType(XTypeDefinition type) { DelegateType result; if (delegateTypes.TryGetValue(type, out result)) { return(result); } throw new ArgumentException(string.Format("No delegate type found for {0}", type.FullName)); }
/// <summary> /// Create the current type as class definition. /// </summary> public virtual void Create(ClassDefinition declaringClass, XTypeDefinition declaringType, DexTargetPackage targetPackage) { // Find xfield xField = XBuilder.AsFieldDefinition(compiler.Module, field); // Create field definition dfield = new Dot42.DexLib.FieldDefinition(); dfield.Name = NameConverter.GetConvertedName(field); AddFieldToDeclaringClass(declaringClass, dfield, targetPackage); targetPackage.NameConverter.Record(xField, dfield); // Set access flags SetAccessFlags(dfield, field); // Give warning if static in generic class. // This could of cause also be handled automagically be the compiler, // with mixture of whats done in the Interlocked converter and whats // done in the GenericInstanceConverter. if (field.IsStatic && declaringType.IsGenericClass) { if (!field.HasSuppressMessageAttribute("StaticFieldInGenericType") && !field.DeclaringType.HasSuppressMessageAttribute("StaticFieldInGenericType")) { string msg; if (field.Name.Contains("CachedAnonymousMethodDelegate")) { msg = "The compiler generated a static field '{0}' in generic type '{1}'. This is not supported " + "in Dot42 if the anonymous delegate accesses a generic class parameter. A workaround " + "is to convert the anonymous static delegate to a normal method.\n"; } else { msg = "Static field '{0}' in generic type {1}: All generic instances will share " + "the same static field, contrary on how CLR operates. A workaround is to " + "use ConcurrentDictionaries to access the values dependent on the type.\n"; } msg += "You can suppress this warning with a [SuppressMessage(\"dot42\"," + " \"StaticFieldInGenericType\")] attribute, either on the field or on the class."; var body = field.DeclaringType.Methods.Select(m => m.Body) .FirstOrDefault(m => m != null && m.Instructions.Any(i => i.SequencePoint(m) != null)); if (body != null) { var seqPoint = body.Instructions.Select(i => i.SequencePoint(body)).First(i => i != null); DLog.Warning(DContext.CompilerILConverter, seqPoint.Document.Url, seqPoint.StartColumn, seqPoint.StartLine, msg, field.Name, declaringType.FullName); } else { DLog.Warning(DContext.CompilerILConverter, msg, field.Name, declaringType.FullName); } } } }
/// <summary> /// Default ctor /// </summary> private XSyntheticTypeDefinition(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType) : base(module, declaringType, flags.HasFlag(XSyntheticTypeFlags.ValueType), null) { this.flags = flags; this.@namespace = @namespace; this.name = name; this.baseType = baseType; fields = new List<XFieldDefinition>(); methods = new List<XMethodDefinition>(); nestedTypes = new List<XTypeDefinition>(); interfaces = new List<XTypeReference>(); }
/// <summary> /// Default ctor /// </summary> private XSyntheticTypeDefinition(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType) : base(module, declaringType, flags.HasFlag(XSyntheticTypeFlags.ValueType), null) { this.flags = flags; this.@namespace = @namespace; this.name = name; this.baseType = baseType; fields = new List <XFieldDefinition>(); methods = new List <XMethodDefinition>(); nestedTypes = new List <XTypeDefinition>(); interfaces = new List <XTypeReference>(); }
/// <summary> /// Resolve this reference to it's definition. /// </summary> public override bool TryResolve(out XTypeDefinition type) { if (resolved == null) { if (!base.TryResolve(out resolved)) { throw new XResolutionException(this); } } type = resolved; return(true); }
/// <summary> /// .NET ctor /// </summary> public DecompilerContext(XMethodDefinition currentMethod) { if (currentMethod == null) { throw new ArgumentNullException("currentMethod"); } name = currentMethod.Name; declaringTypeName = currentMethod.DeclaringType.Name; declaringType = currentMethod.DeclaringType; returnType = currentMethod.ReturnType; currentModule = currentMethod.Module; }
/// <summary> /// Get's the full name of the given type after conversion. /// </summary> public string GetConvertedFullName(XTypeDefinition type) { if (type.IsNested) { var declaringTypeName = GetConvertedFullName(type.DeclaringType); return(declaringTypeName + Dex.NestedClassSeparator + GetConvertedName(type)); } var ns = GetConvertedNamespace(type); return(ns + '.' + GetConvertedName(type)); }
/// <summary> /// Create a synthetic field and add it to the given declaring type. /// </summary> public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType, string fullScopeId) { var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType, fullScopeId); if (declaringType != null) { declaringType.Add(type); } module.Register(type); return(type); }
/// <summary> /// Try to get a type definition (me or one of my nested typed) by the given full name. /// </summary> public override bool TryGet(string fullName, bool noImports, out XTypeDefinition type) { if (base.TryGet(fullName, noImports, out type)) { return(true); } if (fullName == this.type.ClassName) { type = this; return(true); } return(false); }
protected override void CreateClassDefinition(DexTargetPackage targetPackage, ClassDefinition parent, TypeDefinition parentType, XTypeDefinition parentXType) { base.CreateClassDefinition(targetPackage, parent, parentType, parentXType); if (IsDot42InternalApplication()) { // FixUp Visiblility. Class.IsPublic = true; Class.IsProtected = false; Class.IsPrivate = false; } }
public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems) { try { XSharpModel.ModelWalker.Suspend(); if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase)) { return; } // var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot); if (!tp.HasValue) { return; } // var triggerPoint = tp.Value; IToken stopToken; // // Check if we can get the member where we are XMemberDefinition member = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file); XTypeDefinition currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(triggerPoint.Position, _file); var lineNumber = triggerPoint.GetContainingLine().LineNumber; var snapshot = _textBuffer.CurrentSnapshot; List <String> tokenList = XSharpTokenTools.GetTokenList(triggerPoint.Position, lineNumber, snapshot, out stopToken, true, _file, false, member); // LookUp for the BaseType, reading the TokenList (From left to right) CompletionElement gotoElement; String currentNS = ""; if (currentNamespace != null) { currentNS = currentNamespace.Name; } CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect); // if ((gotoElement != null) && (gotoElement.IsSourceElement)) { peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.SourceElement, _peekResultFactory)); } } catch (Exception ex) { XSettings.DisplayOutputMessage("XSharpPeekItemSource.AugmentPeekSession failed : "); XSettings.DisplayException(ex); } finally { ModelWalker.Resume(); } }
/// <summary> /// Gets a formatted full classname for the given type. /// </summary> private string FormatClassName(XTypeDefinition typeDef) { string className; if (typeDef.TryGetDexImportNames(out className)) { return(FormatImportedClassName(className)); } if (typeDef.TryGetJavaImportNames(out className)) { return(FormatImportedClassName(className)); } return(nsConverter.GetConvertedFullName(typeDef)); }
protected override XTypeDefinition CreateXType(XTypeDefinition parentXType) { var typeDef = (XBuilder.ILTypeDefinition)XBuilder.AsTypeReference(Compiler.Module, Type) .Resolve(); string name = NameConverter.GetNullableClassName(typeDef.Name); XSyntheticTypeFlags xflags = default(XSyntheticTypeFlags); return(XSyntheticTypeDefinition.Create(Compiler.Module, parentXType, xflags, typeDef.Namespace, name, Compiler.Module.TypeSystem.Object, string.Join(":", Type.Scope.Name, Type.MetadataToken.ToScopeId(), "Nullable"))); }
/// <summary> /// Default ctor /// </summary> public ILTypeDefinition(XModule module, XTypeDefinition declaringType, TypeDefinition type) : base(module, declaringType, type.IsValueType, type.GenericParameters.Select(x => x.Name)) { this.type = type; fields = new List<XFieldDefinition>(type.Fields.Count); methods = new List<XMethodDefinition>(type.Methods.Count); nested = new List<XTypeDefinition>(); interfaces = new List<XTypeReference>(); // Add nested types foreach (var source in type.NestedTypes/*.Where(t=>t.IsReachable) should we only consider reachables?*/) { var nestedType = new ILTypeDefinition(Module, this, source); nested.Add(nestedType); module.Register(nestedType); } methodToIdx = type.Methods.Select((m, idx) => new { m, idx }).ToDictionary(k => k.m, k => k.idx); }
/// <summary> /// Default ctor /// </summary> public ILFieldDefinition(XTypeDefinition declaringType, FieldDefinition field) : base(declaringType) { this.field = field; }
/// <summary> /// Try to get a type definition (me or one of my nested typed) by the given full name. /// </summary> public override bool TryGet(string fullName, bool noImports, out XTypeDefinition xTypeDefinition) { if (base.TryGet(fullName, noImports, out xTypeDefinition)) return true; if (!noImports) { EnsureDexImportType(); if (dexImportType != Module.TypeSystem.NoType) { if (dexImportType.FullName == fullName) { xTypeDefinition = this; return true; } } EnsureJavaImportType(); if (javaImportType.FullName == fullName) { xTypeDefinition = this; return true; } } return false; }
/// <summary> /// Default ctor /// </summary> protected XFieldDefinition(XTypeDefinition declaringType) : base(declaringType) { }
/// <summary> /// Try to get a type definition (me or one of my nested typed) by the given full name. /// </summary> public override bool TryGet(string fullName, bool noImports, out XTypeDefinition type) { if (base.TryGet(fullName, noImports, out type)) return true; if (fullName == this.type.ClassName) { type = this; return true; } return false; }
/// <summary> /// Create a synthetic field and add it to the given declaring type. /// </summary> public static XSyntheticTypeDefinition Create(XModule module, XTypeDefinition declaringType, XSyntheticTypeFlags flags, string @namespace, string name, XTypeReference baseType) { var type = new XSyntheticTypeDefinition(module, declaringType, flags, @namespace, name, baseType); declaringType.Add(type); return type; }
/// <summary> /// Resolve this reference to it's definition. /// </summary> public override bool TryResolve(out XTypeDefinition type) { type = null; return false; }
/// <summary> /// Default ctor /// </summary> public JavaMethodDefinition(XTypeDefinition declaringType, MethodDefinition method) : base(declaringType) { this.method = method; }
/// <summary> /// Create a synthetic field and add it to the given declaring type. /// </summary> public static XSyntheticFieldDefinition Create(XTypeDefinition declaringType, XSyntheticFieldFlags flags, string name, XTypeReference fieldType, object initialValue = null) { var field = new XSyntheticFieldDefinition(declaringType, flags, name, fieldType, initialValue); declaringType.Add(field); return field; }