Beispiel #1
0
        public static string ComputeMd5(ClangSharp.Type type)
        {
            using (var md5 = MD5.Create())
            {
                string Type             = "";
                string typekindSpelling = "";
                string isConst          = "";
                string isVolatile       = "";

                if (type != null)
                {
                    Type = type.Spelling;

                    isConst          = type.IsConstQualifiedType.ToString();
                    isVolatile       = type.IsVolatileQualifiedType.ToString();
                    typekindSpelling = (type.TypeKindSpelling);



                    byte[] CursorData = Encoding.ASCII.GetBytes(Type + typekindSpelling + isConst + isVolatile);
                    var    hash       = md5.ComputeHash(CursorData);
                    return(BitConverter.ToString(hash).Replace("-", "").ToUpperInvariant());
                }
                else
                {
                    return("");
                }
            }
        }
Beispiel #2
0
        public static string GetFullyQualifiedName(ClangSharp.Type type)
        {
            string name;
            var    decl = type.Declaration;

            if (decl.IsInvalid)
            {
                name = "[unexposed type]";
            }
            else
            {
                name = decl.Spelling;
                while (decl.SemanticParent.Kind == ClangSharp.CursorKind.ClassDecl ||
                       decl.SemanticParent.Kind == ClangSharp.CursorKind.StructDecl ||
                       decl.SemanticParent.Kind == ClangSharp.CursorKind.ClassTemplate ||
                       decl.SemanticParent.Kind == ClangSharp.CursorKind.Namespace)
                {
                    name = decl.SemanticParent.Spelling + "::" + name;
                    decl = decl.SemanticParent;
                }
            }
            return(name);
        }
Beispiel #3
0
        public TypeRefDefinition(ClangSharp.Type type)
        {
            IsConst = type.IsConstQualifiedType;

            switch (type.TypeKind)
            {
            case ClangSharp.Type.Kind.Void:
            case ClangSharp.Type.Kind.Bool:
            case ClangSharp.Type.Kind.CharS:
            case ClangSharp.Type.Kind.Double:
            case ClangSharp.Type.Kind.Float:
            case ClangSharp.Type.Kind.Int:
            case ClangSharp.Type.Kind.UChar:
            case ClangSharp.Type.Kind.UInt:
                Name    = type.Spelling;
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.Long:
                Name    = "long";
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.LongLong:
                Name    = "long long";
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.Short:
                Name    = "short";
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.ULong:
                Name    = "unsigned long";
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.UShort:
                Name    = "unsigned short";
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.Typedef:
                Name       = GetFullyQualifiedName(type);
                Referenced = new TypeRefDefinition(type.Canonical);
                IsBasic    = Referenced.IsBasic;
                break;

            case ClangSharp.Type.Kind.Pointer:
                Referenced = new TypeRefDefinition(type.Pointee);
                IsPointer  = true;
                break;

            case ClangSharp.Type.Kind.LValueReference:
                Referenced  = new TypeRefDefinition(type.Pointee);
                IsReference = true;
                break;

            case ClangSharp.Type.Kind.ConstantArray:
                Referenced      = new TypeRefDefinition(type.ArrayElementType);
                IsConstantArray = true;
                break;

            case ClangSharp.Type.Kind.FunctionProto:
                // ??
                break;

            case ClangSharp.Type.Kind.Enum:
                Name    = type.Canonical.Declaration.Spelling;
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.Record:
            case ClangSharp.Type.Kind.Unexposed:
                Name = GetFullyQualifiedName(type);
                break;

            case ClangSharp.Type.Kind.DependentSizedArray:
                break;

            default:
                throw new NotImplementedException();
            }
        }
        public TypeRefDefinition(ClangSharp.Type type)
            : base(GetName(type))
        {
            switch (type.TypeKind)
            {
            case ClangSharp.Type.Kind.Void:
            case ClangSharp.Type.Kind.Bool:
            case ClangSharp.Type.Kind.CharS:
            case ClangSharp.Type.Kind.Double:
            case ClangSharp.Type.Kind.Float:
            case ClangSharp.Type.Kind.Int:
            case ClangSharp.Type.Kind.UChar:
            case ClangSharp.Type.Kind.UInt:
            case ClangSharp.Type.Kind.WChar:
            case ClangSharp.Type.Kind.SChar:
            case ClangSharp.Type.Kind.Long:
            case ClangSharp.Type.Kind.LongLong:
            case ClangSharp.Type.Kind.Short:
            case ClangSharp.Type.Kind.ULong:
            case ClangSharp.Type.Kind.ULongLong:
            case ClangSharp.Type.Kind.UShort:
            case ClangSharp.Type.Kind.Enum:
            case ClangSharp.Type.Kind.LongDouble:
                IsBasic = true;
                break;

            case ClangSharp.Type.Kind.Typedef:
                if (type.Canonical.TypeKind == ClangSharp.Type.Kind.MemberPointer)
                {
                    IsBasic = false;
                }
                else
                {
                    Referenced = new TypeRefDefinition(type.Canonical);
                    IsBasic    = Referenced.IsBasic;
                }
                break;

            case ClangSharp.Type.Kind.Pointer:
                Referenced = new TypeRefDefinition(type.Pointee);
                IsPointer  = true;
                break;

            case ClangSharp.Type.Kind.LValueReference:
                Referenced  = new TypeRefDefinition(type.Pointee);
                IsReference = true;
                break;

            case ClangSharp.Type.Kind.ConstantArray:
                Referenced      = new TypeRefDefinition(type.ArrayElementType);
                IsConstantArray = true;
                break;

            case ClangSharp.Type.Kind.FunctionProto:
            case ClangSharp.Type.Kind.Record:
            case ClangSharp.Type.Kind.Unexposed:
            case ClangSharp.Type.Kind.DependentSizedArray:
            case ClangSharp.Type.Kind.IncompleteArray:
                break;

            default:
                throw new NotImplementedException();
            }
        }
        private static string GetName(ClangSharp.Type type)
        {
            switch (type.TypeKind)
            {
            case ClangSharp.Type.Kind.Void:
            case ClangSharp.Type.Kind.Bool:
            case ClangSharp.Type.Kind.CharS:
            case ClangSharp.Type.Kind.Double:
            case ClangSharp.Type.Kind.Float:
            case ClangSharp.Type.Kind.Int:
            case ClangSharp.Type.Kind.UChar:
            case ClangSharp.Type.Kind.UInt:
            case ClangSharp.Type.Kind.WChar:
                return(type.Spelling);

            case ClangSharp.Type.Kind.SChar:
                return("char");

            case ClangSharp.Type.Kind.Long:
                return("long");

            case ClangSharp.Type.Kind.LongLong:
                return("long long");

            case ClangSharp.Type.Kind.Short:
                return("short");

            case ClangSharp.Type.Kind.ULong:
                return("unsigned long");

            case ClangSharp.Type.Kind.ULongLong:
                return("unsigned long long");

            case ClangSharp.Type.Kind.UShort:
                return("unsigned short");

            case ClangSharp.Type.Kind.LongDouble:
                return("double");

            case ClangSharp.Type.Kind.Typedef:
                return(type.Declaration.Spelling);

            case ClangSharp.Type.Kind.Enum:
                return(type.Canonical.Declaration.Spelling);

            case ClangSharp.Type.Kind.Record:
                return(type.Canonical.Declaration.Spelling);

            case ClangSharp.Type.Kind.Unexposed:
                if (type.Canonical.Declaration.IsInvalid)
                {
                    return("[unexposed type]");
                }
                else
                {
                    return(type.Canonical.Declaration.Spelling);
                }

            case ClangSharp.Type.Kind.Pointer:
            case ClangSharp.Type.Kind.LValueReference:
            case ClangSharp.Type.Kind.FunctionProto:
            case ClangSharp.Type.Kind.DependentSizedArray:
            case ClangSharp.Type.Kind.ConstantArray:
            case ClangSharp.Type.Kind.IncompleteArray:
                return(null);

            default:
                throw new NotImplementedException();
            }
        }