Example #1
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());
 }
Example #2
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(" ", "")));
    }
Example #3
0
    public Filter GetFilterOrDefault(CppType cpptype)
    {
        var fqn = cpptype.ElementTypeName;

        // Convert any template types to their managed names
        var mod = cpptype.Modifiers.FirstOrDefault(m => m == CppModifiers.Template);

        if (mod != null)
        {
            fqn = CreateTemplateClassName(fqn, mod.ToString());
        }

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

        var newtype = new CppType(fqn, null);

        return(GetFilterOrDefault(newtype.ToString().Replace(" ", "")));
    }
Example #4
0
        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());
        }
Example #5
0
        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 ();
        }