コード例 #1
0
        private bool WalkPointerType(CppType cppType, out CppSharp.AST.Type pointerType)
        {
            if (string.IsNullOrEmpty(cppType.Pointer))
            {
                pointerType = null;
                return(false);
            }

            // It is a pointer type
            pointerType = new PointerType();
            switch (cppType.Pointer)
            {
            case "*":
                (pointerType as PointerType).Modifier = PointerType.TypeModifier.Pointer;
                break;

            case "&":
                (pointerType as PointerType).Modifier = PointerType.TypeModifier.LVReference;
                break;

            case "&&":
                (pointerType as PointerType).Modifier = PointerType.TypeModifier.RVReference;
                break;
            }

            // Try to find pointee
            (pointerType as PointerType).QualifiedPointee = new QualifiedType()
            {
                Qualifiers = new TypeQualifiers(),
                Type       = WalkType(cppType.TypeName)
            };

            return(true);
        }
コード例 #2
0
ファイル: CppField.cs プロジェクト: ysuiboli/Il2CppInspector
 // Initialize field
 public CppField(string name, CppType type, int bitfieldSize = 0, bool isConst = false)
 {
     Name         = name;
     Type         = type;
     BitfieldSize = bitfieldSize;
     IsConst      = isConst;
 }
コード例 #3
0
        internal string NativeToPinvokeType(CppType nativeType)
        {
            string type  = nativeType.GetDisplayName();
            bool   isPtr = type.Trim().EndsWith("*");

            type = CleanType(type);

            if (_mappings.TryGetValue(type, out string managedType))
            {
                return(managedType + (isPtr ? "*" : ""));
            }

            if (isPtr && _mappings.TryGetValue(type + "*", out string managedTypePtr))
            {
                return(managedTypePtr);
            }

            if (_registeredTypes.Contains(type))
            {
                return("IntPtr");
            }

            Logger.LogWarning($"No C# equivalent for {type}");
            return(type + (isPtr ? "*" : ""));
        }
コード例 #4
0
ファイル: TypeInfo.cs プロジェクト: fedarovich/xplane-dotnet
 public TypeInfo(string name, CppType cppType, TypeSyntax typeSyntax, bool isStandard = false)
 {
     Name       = name;
     CppType    = cppType;
     TypeSyntax = typeSyntax;
     IsStandard = isStandard;
 }
コード例 #5
0
        public virtual CppType GetMangleType(ICustomAttributeProvider icap, Type managedType)
        {
            CppType           mangleType = new CppType();
            MangleAsAttribute maa        = (MangleAsAttribute)icap.GetCustomAttributes(typeof(MangleAsAttribute), false).FirstOrDefault();

            if (maa != null)
            {
                mangleType = maa.MangleType;
            }

            // this means that either no MangleAsAttribute was defined, or
            //  only CppModifiers were applied .. apply CppType from managed parameter type
            if (mangleType.ElementType == CppTypes.Unknown && mangleType.ElementTypeName == null)
            {
                mangleType.CopyTypeFrom(CppType.ForManagedType(managedType));
            }
            else if (typeof(Delegate).IsAssignableFrom(managedType))
            {
                mangleType.ElementType = CppTypes.Delegate;
                mangleType.Modifiers.Add(CppModifiers.Delegate);
            }
            else if (mangleType.ElementType == CppTypes.Unknown)
            {
                // FIXME: otherwise, we just assume it's CppTypes.Class for now.
                mangleType.ElementType = CppTypes.Class;
            }

            return(mangleType);
        }
コード例 #6
0
        /// <inheritdoc/>
        public override void EndVisitType(Type sourceType)
        {
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            uint  typeIndex     = TypeMetadataMapper.GetTypeIndex(sourceType);
            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteLine();

            WriteLine("return hashValue;");
            IndentationLevel--;
            WriteLine("}");
            WriteLine();

            string dispatchTableBaseIndexVariable =
                "global::" +
                (string.IsNullOrEmpty(DispatchTableCSharpNamespace) ? string.Empty : $"{DispatchTableCSharpNamespace}.")
                + "ObjectDeserializeHandler.DispatchTableBaseIndex";

            WriteBlock($@"
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                uint global::Mlos.Core.ICodegenKey.CodegenTypeIndex() => {typeIndex} + {dispatchTableBaseIndexVariable};");

            WriteBlock($@"
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenKey.CodegenTypeHash() => 0x{typeHashValue:x};");

            WriteBlock($@"
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenType.CodegenTypeSize() => {cppType.TypeSize};");

            WriteCloseTypeDeclaration(sourceType);
        }
コード例 #7
0
 static public bool IsByVal(CppType t)
 {
     return((t.ElementType == CppTypes.Class || t.ElementType == CppTypes.Struct) &&
            !t.Modifiers.Contains(CppModifiers.Pointer) &&
            !t.Modifiers.Contains(CppModifiers.Reference) &&
            !t.Modifiers.Contains(CppModifiers.Array));
 }
コード例 #8
0
ファイル: TypeMap.cs プロジェクト: fedarovich/xplane-dotnet
        public bool TryResolveType(CppType cppType, out TypeInfo typeInfo, bool lookForward = true)
        {
            if (TryGetType(cppType.GetDisplayName(), out typeInfo))
            {
                return(true);
            }

            if (cppType is CppQualifiedType qualified)
            {
                return(TryResolveType(qualified.ElementType, out typeInfo, lookForward));
            }

            if (cppType is CppPointerType pointer)
            {
                if (TryResolveType(pointer.ElementType, out var innerTypeInfo, lookForward))
                {
                    typeInfo = new TypeInfo(cppType.GetDisplayName(), cppType, PointerType(innerTypeInfo.TypeSyntax));
                    _nativeMap.Add(typeInfo.Name, typeInfo);
                    return(true);
                }
            }

            if (lookForward)
            {
                _buildType(cppType).GetAwaiter().GetResult();
                return(TryResolveType(cppType, out typeInfo, false));
            }

            return(false);
        }
コード例 #9
0
    // Return the System.Type name corresponding to T, or null
    //  Returned as a string, because other wrappers do not have System.Types yet
    public string CppTypeToManaged(CppType t)
    {
        Type mtype = t.ToManagedType();

        if (mtype != null && mtype != typeof(ICppObject))
        {
            return(mtype.FullName);
        }

        switch (t.ElementType)
        {
        case CppTypes.Class:
        case CppTypes.Struct:
        case CppTypes.Enum:
        case CppTypes.Delegate:
            var filter = GetFilterOrDefault(t);
            var qname  = filter.TypeName.Replace("::", ".");

            if (filter.ImplType == ImplementationType.@struct && !IsByVal(t))
            {
                return(qname + "&");
            }
            else
            {
                return(qname);
            }
        }

        return(null);
    }
コード例 #10
0
        internal string MapToManagedApiType(CppType nativeType)
        {
            string type = nativeType.GetDisplayName();

            if (IsKnownNativeType(nativeType))
            {
                return(RenameForApi(CleanType(type), false));
            }

            type = NativeToPinvokeType(nativeType);
            if (type.Contains("/*usize_t*/"))
            {
                return(nameof(UInt64));
            }
            if (type.Contains("/*size_t*/"))
            {
                return(nameof(Int64));
            }
            if (type.Contains("/*bool*/"))
            {
                return(nameof(Boolean));
            }

            return(type);
        }
コード例 #11
0
        private TypeQualifiers GetTypeQualifiers(CppType cppType)
        {
            TypeQualifiers result = new TypeQualifiers();

            result.IsConst = cppType.Const;

            return(result);
        }
コード例 #12
0
 /// <summary>
 /// Gets the display name of the specified type. If the type is <see cref="ICppMember"/> it will
 /// only use the name provided by <see cref="ICppMember.Name"/>
 /// </summary>
 /// <param name="type">The type</param>
 /// <returns>The display name</returns>
 public static string GetDisplayName(this CppType type)
 {
     if (type is ICppMember member)
     {
         return(member.Name);
     }
     return(type.ToString());
 }
コード例 #13
0
ファイル: Helpers.cs プロジェクト: vicfergar/RenderDoc.NET
        public static string ConvertToCSharpType(CppType type, bool isPointer = false)
        {
            if (type is CppPrimitiveType primitiveType)
            {
                return(GetCsTypeName(primitiveType, isPointer));
            }

            if (type is CppQualifiedType qualifiedType)
            {
                return(GetCsTypeName(qualifiedType.ElementType, isPointer));
            }

            if (type is CppEnum enumType)
            {
                var enumCsName = GetCsCleanName(enumType.Name);
                if (isPointer)
                {
                    return(enumCsName + "*");
                }

                return(enumCsName);
            }

            if (type is CppTypedef typedef)
            {
                var typeDefCsName = GetCsCleanName(typedef.Name);
                if (isPointer)
                {
                    return(typeDefCsName + "*");
                }

                return(typeDefCsName);
            }

            if (type is CppClass @class)
            {
                var className = GetCsCleanName(@class.Name);
                if (isPointer)
                {
                    return(className + "*");
                }

                return(className);
            }

            if (type is CppPointerType pointerType)
            {
                return(GetCsTypeName(pointerType));
            }

            if (type is CppArrayType arrayType)
            {
                return(GetCsTypeName(arrayType.ElementType, isPointer));
            }

            return(string.Empty);
        }
コード例 #14
0
        /// <inheritdoc />
        public override bool Accept(Type sourceType)
        {
            // Fixed size structures do not have variable data fields.
            // No custom serialization code is required.
            //
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            return(cppType.HasVariableData);
        }
コード例 #15
0
        /// <inheritdoc />
        public override bool Accept(Type sourceType)
        {
            // Fixed length structure with no variable length fields.
            // No custom serialization is required.
            //
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            return(cppType.HasVariableData);
        }
コード例 #16
0
        internal bool IsKnownNativeType(CppType nativeTtype)
        {
            var type = nativeTtype.GetDisplayName();

            if (_registeredTypes.Any(rt => rt == CleanType(type)))
            {
                return(true);
            }
            return(false);
        }
コード例 #17
0
ファイル: TypeMap.cs プロジェクト: fedarovich/xplane-dotnet
        public TypeInfo RegisterType(CppType cppType, string nativeName, string managedName, string @namespace)
        {
            var typeSyntax = IdentifierName(managedName)
                             .WithAdditionalAnnotations(new SyntaxAnnotation(Annotations.Namespace, @namespace));
            var typeInfo = new TypeInfo(nativeName, cppType, typeSyntax);

            _nativeMap.Add(nativeName, typeInfo);
            _managedMap.Add(managedName, typeInfo);
            return(typeInfo);
        }
コード例 #18
0
        private QualifiedType GetQualifiedType(CppType cppType)
        {
            QualifiedType qualType = new QualifiedType()
            {
                Type       = WalkType(cppType),
                Qualifiers = GetTypeQualifiers(cppType)
            };

            return(qualType);
        }
コード例 #19
0
ファイル: CefApiBuilderBase.cs プロジェクト: wuzlai521/CefNet
        protected TypeDesc GetTypeDesc(CppType type)
        {
            var t = new TypeDesc(type.GetDisplayName(), type);

            if (type is CppPointerType pointerType)
            {
                t.FunctionTypeRef = pointerType.ElementType as CppFunctionType;
            }
            return(t);
        }
コード例 #20
0
        /// <summary>
        /// If a type defined under another type, then print the full name, e.g. Class1::Class2
        /// </summary>
        public static string GetFullTypeName(this CppType cppType)
        {
            string name = cppType.GetDisplayName();

            while (cppType.Parent is CppType parentType)
            {
                name    = parentType.GetDisplayName() + "::" + name;
                cppType = parentType;
            }
            return(name);
        }
コード例 #21
0
        private static bool IsConst(CppType type, out CppType elementType)
        {
            elementType = null;
            if (type is CppQualifiedType qualifiedType && qualifiedType.Qualifier == CppTypeQualifier.Const)
            {
                elementType = qualifiedType.ElementType;
                return(true);
            }

            return(false);
        }
コード例 #22
0
ファイル: TypeToString.cs プロジェクト: d4nnyk/WinDbgCs
        /// <summary>
        /// Gets the code of the specified type in original language.
        /// </summary>
        /// <param name="type">The type.</param>
        public static string GetTypeString(IDiaSymbol type)
        {
            switch ((CV_CFL_LANG)type.language)
            {
            case CV_CFL_LANG.CV_CFL_C:
            case CV_CFL_LANG.CV_CFL_CXX:
                return(CppType.GetTypeString(type));

            default:
                throw new Exception("Unsupported language");
            }
        }
コード例 #23
0
        public static CSharpType GetCSharpType(CSharpConverter converter, CppType cppType, CSharpElement context, bool nested)
        {
            // Check if a particular CppType has been already converted
            var csType = converter.FindCSharpType(cppType);

            if (csType != null)
            {
                return(csType);
            }

            switch (cppType.TypeKind)
            {
            case CppTypeKind.Pointer:
                if (context is CSharpField)
                {
                    return(null);
                }
                var pointerType        = (CppPointerType)cppType;
                var pointerElementType = pointerType.ElementType;
                if (IsConst(pointerElementType, out var eltType))
                {
                    pointerElementType = eltType;
                }
                pointerElementType = pointerElementType.GetCanonicalType();
                return(pointerElementType.TypeKind == CppTypeKind.Primitive ? new CSharpPrimitiveType(CSharpPrimitiveKind.IntPtr) : null);

            case CppTypeKind.Array:

                if (context is CSharpField)
                {
                    return(null);
                }
                var arrayType        = (CppArrayType)cppType;
                var arrayElementType = arrayType.ElementType;
                if (arrayType.Size <= 0)
                {
                    return(null);
                }

                bool isConst = IsConst(arrayElementType, out _);

                var csArrayElementType = converter.GetCSharpType(arrayElementType, context, true);
                var elementTypeName    = csArrayElementType.ToString();
                elementTypeName = char.ToUpper(elementTypeName[0]) + elementTypeName.Substring(1);
                var freeType = new CSharpArrayLikeType($"{elementTypeName}{arrayType.Size}", arrayType.Size);
                csType = new CSharpRefType(isConst ? CSharpRefKind.In : CSharpRefKind.Ref, freeType);

                return(csType);
            }

            return(null);
        }
コード例 #24
0
        internal bool NeedsCastForApi(CppType nativeType, out string cast)
        {
            string managedType = NativeToPinvokeType(nativeType);

            if (!managedType.Contains("/*") || nativeType.IsBool())
            {
                cast = null;
                return(false);
            }

            cast = $"({MapToManagedApiType(nativeType)})";
            return(true);
        }
コード例 #25
0
    public Filter GetFilterOrDefault(CppType cpptype)
    {
        var fqn = cpptype.ElementTypeName;

        if (cpptype.Namespaces != null)
        {
            fqn = string.Join("::", cpptype.Namespaces) + "::" + fqn;
        }

        var newtype = new CppType(fqn, cpptype.Modifiers.Where(m => m == CppModifiers.Template));

        return(GetFilterOrDefault(newtype.ToString().Replace(" ", "")));
    }
コード例 #26
0
        public override void EndVisitType(Type sourceType)
        {
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            if (cppType.PaddingSize != 0)
            {
                // Include padding to match defined structure size.
                //
                WriteLine($"byte __finalPadding[{cppType.PaddingSize}];");
            }

            base.EndVisitType(sourceType);
        }
コード例 #27
0
        private CppSharp.AST.Type WalkType(CppType cppType)
        {
            CppSharp.AST.Type resultType;
            if (WalkPointerType(cppType, out resultType))
            {
                return(resultType);
            }
            else if (WalkArrayType(cppType, out resultType))
            {
                return(resultType);
            }

            return(WalkType(cppType.TypeName));
        }
コード例 #28
0
 public static bool IsFunctionType(CppType type, out CppFunctionType cppFunctionType)
 {
     type            = type.GetCanonicalType();
     cppFunctionType = type as CppFunctionType;
     if (cppFunctionType == null)
     {
         if (type is CppPointerType ptrType && (ptrType.ElementType is CppFunctionType cppFunctionType2))
         {
             cppFunctionType = cppFunctionType2;
         }
         else
         {
             return(false);
         }
     }
コード例 #29
0
        /// <inheritdoc/>
        public override void EndVisitType(Type sourceType)
        {
            // Get the cppType.
            //
            CppType cppType = CppTypeMapper.GetCppType(sourceType);

            uint  typeIndex     = TypeMetadataMapper.GetTypeIndex(sourceType);
            ulong typeHashValue = TypeMetadataMapper.GetTypeHashValue(sourceType);

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                uint global::Mlos.Core.ICodegenKey.CodegenTypeIndex()
                {{
                    return {typeIndex} + {DispatchTableBaseIndexVariableName};
                }}");

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                ulong global::Mlos.Core.ICodegenKey.CodegenTypeHash() => 0x{typeHashValue:x};");

            WriteBlock($@"
                /// <inheritdoc/>
                [MethodImpl(MethodImplOptions.AggressiveInlining)]
                public ulong CodegenTypeSize() => {cppType.TypeSize};");

            WriteBlock($@"
                /// <inheritdoc/>
                [System.Text.Json.Serialization.JsonIgnore]
                public IntPtr Buffer
                {{
                    get
                    {{
                        return buffer;
                    }}
                    set
                    {{
                        buffer = value;
                    }}
                }}");

            WriteBlock($@"
                private IntPtr buffer;");

            WriteCloseTypeDeclaration(sourceType);
        }
コード例 #30
0
        public void TestSimple()
        {
            ParseAssert(@"
typedef int& t0; // reference type
typedef const float t1;
char* f0; // pointer type
const int f1 = 5; // qualified type
int f2[5]; // array type
void (*f3)(int arg1, float arg2); // function type
t1* f4;
",
                        compilation =>
            {
                Assert.False(compilation.HasErrors);

                Assert.AreEqual(5, compilation.Fields.Count);
                Assert.AreEqual(2, compilation.Typedefs.Count);

                var types = new CppType[]
                {
                    new CppReferenceType(CppPrimitiveType.Int),
                    new CppQualifiedType(CppTypeQualifier.Const, CppPrimitiveType.Float),

                    new CppPointerType(CppPrimitiveType.Char),
                    new CppQualifiedType(CppTypeQualifier.Const, CppPrimitiveType.Int),
                    new CppArrayType(CppPrimitiveType.Int, 5),
                    new CppPointerType(new CppFunctionType(CppPrimitiveType.Void)
                    {
                        Parameters =
                        {
                            new CppParameter(CppPrimitiveType.Int,   "a"),
                            new CppParameter(CppPrimitiveType.Float, "b"),
                        }
                    })
                    {
                        SizeOf = IntPtr.Size
                    },
                    new CppPointerType(new CppQualifiedType(CppTypeQualifier.Const, CppPrimitiveType.Float))
                };

                var canonicalTypes = compilation.Typedefs.Select(x => x.GetCanonicalType()).Concat(compilation.Fields.Select(x => x.Type.GetCanonicalType())).ToList();
                Assert.AreEqual(types, canonicalTypes);
                Assert.AreEqual(types.Select(x => x.SizeOf), canonicalTypes.Select(x => x.SizeOf));
            }
                        );
        }
コード例 #31
0
        public ParsedTypedef(string rawTypedef)
        {
            string[] lineSplit = rawTypedef.Split(' ');

            string toStr = "";

            for (int i = 1; i < lineSplit.Length - 1; ++i)
            {
                toStr += lineSplit[i] + " ";
            }

            toStr = toStr.TrimEnd();

            string fromStr = lineSplit[lineSplit.Length - 1].TrimEnd(';');

            from = new CppType(fromStr);
            to = new CppType(toStr);
        }
コード例 #32
0
ファイル: ItaniumAbi.cs プロジェクト: kthompson/cxxi
 public virtual string GetTypeCode(CppType mangleType)
 {
     return GetTypeCode (mangleType, new Dictionary<string, int> ());
 }
コード例 #33
0
ファイル: ItaniumAbi.cs プロジェクト: kthompson/cxxi
        string GetTypeCode(CppType mangleType, Dictionary<string, int> compressMap)
        {
            CppTypes element = mangleType.ElementType;
            IEnumerable<CppModifiers> modifiers = mangleType.Modifiers;

            StringBuilder code = new StringBuilder ();

            var ptrOrRef = For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Reference);
            var modifierCode = modifiers.Reverse ().Transform (
                For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Array).Emit ("P"),
                For.AnyInputIn (CppModifiers.Reference).Emit ("R"),

                // Itanium mangled names do not include const or volatile unless
                //  they modify the type pointed to by pointer or reference.
                Choose.TopOne (
                    For.AllInputsIn (CppModifiers.Volatile, CppModifiers.Const).InAnyOrder ().After (ptrOrRef).Emit ("VK"),
                    For.AnyInputIn  (CppModifiers.Volatile).After (ptrOrRef).Emit ("V"),
                    For.AnyInputIn  (CppModifiers.Const).After (ptrOrRef).Emit ("K")
                    )
            );
            code.Append (string.Join(string.Empty, modifierCode.ToArray ()));
            int modifierLength = code.Length;

            switch (element) {
            case CppTypes.Int:
                code.Append (modifiers.Transform (
                    For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Short).InAnyOrder ().Emit ('t'),
                    For.AnyInputIn (CppModifiers.Short).Emit ('s'),
                    For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Long, CppModifiers.Long).InAnyOrder ().Emit ('y'),
                    For.AllInputsIn (CppModifiers.Long, CppModifiers.Long).InAnyOrder ().Emit ('x'),
                    For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Long).InAnyOrder ().Emit ('m'),
                    For.AnyInputIn (CppModifiers.Long).Emit ('l'),
                    For.AnyInputIn (CppModifiers.Unsigned).Emit ('j')
                ).DefaultIfEmpty ('i').ToArray ());
                break;
            case CppTypes.Bool:
                code.Append ('b');
                break;
            case CppTypes.Char:
                if (modifiers.Contains (CppModifiers.Signed))
                    code.Append ('a');
                else if (modifiers.Contains (CppModifiers.Unsigned))
                    code.Append ('h');
                else
                    code.Append ('c');
                break;
            case CppTypes.Float:
                code.Append ('f');
                break;
            case CppTypes.Double:
                if (modifiers.Contains (CppModifiers.Long))
                    code.Append ('e');
                else
                    code.Append ('d');
                break;
            case CppTypes.Class:
            case CppTypes.Struct:
            case CppTypes.Union:
            case CppTypes.Enum:
                // TODO: This is getting a little ridiculous and should probably be refactored...

                // Determine if we have any namespaces to print out
                bool hasNamespace = (mangleType.Namespaces != null);
                if (hasNamespace) {
                    code.Append ('N');
                    foreach (var ns in mangleType.Namespaces)
                        code.Append (GetIdentifier (compressMap, ns));
                }

                // Look up the type by itself first
                // NOTE: Order here is important so that they get sequenced properly
                bool foundType;
                string value = GetIdentifier (compressMap, mangleType.ElementTypeName, 0, out foundType);
                if (modifierLength > 0)
                {
                    // Next lookup the type with modifiers for a match
                    bool foundExact;
                    string exact = GetIdentifier(compressMap, mangleType.ToString(), modifierLength, out foundExact);
                    if (foundExact)
                    {
                        // Use the exact values sequence ID and remove all modifiers and namespaces
                        code.Length = 0;
                        hasNamespace = false;
                        value = exact;
                    }
                    else if (foundType)
                    {
                        // We didn't get an exact match but we know the type
                        // so remove the namespaces, but not the modifiers
                        code.Length = modifierLength;
                        hasNamespace = false;
                    }
                }

                // Print out our class identifier
                code.Append(value);

                // If we're printing out namespaces then signal the end of the namespace
                if (hasNamespace)
                    code.Append ('E');

                // Since we handle the modifier compression in here make sure we skip the logic below
                modifierLength = 0;
                break;

            }

            // If there were modifiers then always add it to the compression map
            // NOTE: If there were multiple modifiers this causes us to skip sequence numbers
            if (modifierLength > 0)
            {
                bool found;
                string value = GetIdentifier(compressMap, mangleType.ToString(), modifierLength, out found);
                if (found)
                    return value;
            }

            return code.ToString ();
        }
コード例 #34
0
ファイル: ItaniumAbi.cs プロジェクト: shana/cppinterop
        string GetTypeCode(CppType mangleType, Dictionary<string, int> compressMap)
        {
            CppTypes element = mangleType.ElementType;
            IEnumerable<CppModifiers> modifiers = mangleType.Modifiers;

            StringBuilder code = new StringBuilder ();

            var ptrOrRef = For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Reference);
            var modifierCode = modifiers.Reverse ().Transform (
                For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Array).Emit ("P"),
                For.AnyInputIn (CppModifiers.Reference).Emit ("R"),

                // Itanium mangled names do not include const or volatile unless
                //  they modify the type pointed to by pointer or reference.
                Choose.TopOne (
                    For.AllInputsIn (CppModifiers.Volatile, CppModifiers.Const).InAnyOrder ().After (ptrOrRef).Emit ("VK"),
                    For.AnyInputIn(CppModifiers.Volatile).After (ptrOrRef).Emit ("V"),
                    For.AnyInputIn(CppModifiers.Const).After (ptrOrRef).Emit ("K")
                    )
            );
            code.Append (string.Join(string.Empty, modifierCode.ToArray ()));

            switch (element) {
            case CppTypes.Int:
                code.Append (modifiers.Transform (
                    For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Short).InAnyOrder ().Emit ('t')
                ).DefaultIfEmpty ('i').ToArray ());
                break;
            case CppTypes.Char:
                code.Append ('c');
                break;
            case CppTypes.Class:
            case CppTypes.Struct:
            case CppTypes.Union:
            case CppTypes.Enum: {
                int cid;
                if (compressMap.TryGetValue (mangleType.ElementTypeName, out cid)) {
                    if (cid == 0)
                        code.Append ("S_");
                    else
                        throw new NotImplementedException ();
                } else {
                    code.Append(mangleType.ElementTypeName.Length);
                    code.Append(mangleType.ElementTypeName);
                }
                break;
            }
            }

            return code.ToString ();
        }
コード例 #35
0
ファイル: ItaniumAbi.cs プロジェクト: ctguxp/cxxi
		string GetTypeCode (CppType mangleType, Dictionary<string, int> compressMap)
		{
			CppTypes element = mangleType.ElementType;
			IEnumerable<CppModifiers> modifiers = mangleType.Modifiers;

			StringBuilder code = new StringBuilder ();

			var ptrOrRef = For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Reference);
			var modifierCode = modifiers.Reverse ().Transform (
				For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Array).Emit ("P"),
				For.AnyInputIn (CppModifiers.Reference).Emit ("R"),

				// Itanium mangled names do not include const or volatile unless
				//  they modify the type pointed to by pointer or reference.
				Choose.TopOne (
					For.AllInputsIn (CppModifiers.Volatile, CppModifiers.Const).InAnyOrder ().After (ptrOrRef).Emit ("VK"),
					For.AnyInputIn  (CppModifiers.Volatile).After (ptrOrRef).Emit ("V"),
					For.AnyInputIn  (CppModifiers.Const).After (ptrOrRef).Emit ("K")
			        )
			);
			code.Append (string.Join(string.Empty, modifierCode.ToArray ()));

			switch (element) {
			case CppTypes.Int:
				code.Append (modifiers.Transform (
					For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Short).InAnyOrder ().Emit ('t'),
					For.AnyInputIn (CppModifiers.Short).Emit ('s'),
					For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Long, CppModifiers.Long).InAnyOrder ().Emit ('y'),
					For.AllInputsIn (CppModifiers.Long, CppModifiers.Long).InAnyOrder ().Emit ('x'),
					For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Long).InAnyOrder ().Emit ('m'),
					For.AnyInputIn (CppModifiers.Long).Emit ('l'),
					For.AnyInputIn (CppModifiers.Unsigned).Emit ('j')
				).DefaultIfEmpty ('i').ToArray ());
				break;
			case CppTypes.Bool:
				code.Append ('b');
				break;
			case CppTypes.Char:
				if (modifiers.Contains (CppModifiers.Signed))
					code.Append ('a');
				else if (modifiers.Contains (CppModifiers.Unsigned))
					code.Append ('h');
				else
					code.Append ('c');
				break;
			case CppTypes.Float:
				code.Append ('f');
				break;
			case CppTypes.Double:
				if (modifiers.Contains (CppModifiers.Long))
					code.Append ('e');
				else
					code.Append ('d');
				break;
			case CppTypes.Class:
			case CppTypes.Struct:
			case CppTypes.Union:
			case CppTypes.Enum:
				if (mangleType.Namespaces != null) {
					code.Append ('N');
					foreach (var ns in mangleType.Namespaces)
						code.Append (GetIdentifier (compressMap, ns));
				}

				code.Append (GetIdentifier (compressMap, mangleType.ElementTypeName));

				if (mangleType.Namespaces != null)
					code.Append ('E');
				break;

			}

			return code.ToString ();
		}