示例#1
0
        public override bool VisitCppInterface(CppInterface cppInterface)
        {
            Declaration unitDecl;

            cppElementToDeclarationMapping.TryGetValue(cppInterface.ParentInclude, out unitDecl);
            TranslationUnit unit = unitDecl != null ? unitDecl as TranslationUnit : FindDeclParent <TranslationUnit>(cppInterface.ParentInclude);

            Namespace @namespace = null;
            Class     @interface = null;

            // Check if we have an namespace
            if (!string.IsNullOrEmpty(cppInterface.Namespace))
            {
                @namespace = unit.FindCreateNamespace(cppInterface.Namespace.TrimStart(':'));
                @interface = @namespace.FindClass(cppInterface.Name, true, true);
            }
            else
            {
                @interface = unit.FindClass(cppInterface.Name, true, true);
            }

            @interface.Type = ClassType.Interface;

            // Check if we have an base class
            if (!string.IsNullOrEmpty(cppInterface.ParentName))
            {
                Class baseClass = null;
                if (@namespace != null)
                {
                    baseClass = @namespace.FindClass(cppInterface.ParentName, true, true);
                }
                else
                {
                    baseClass = unit.FindClass(cppInterface.ParentName, true, true);
                }

                // Set type of base class
                baseClass.Type = baseClass.Name.StartsWith("I") ? ClassType.Interface : ClassType.ValueType;

                // Add type tag
                @interface.Bases.Add(new BaseClassSpecifier
                {
                    Access = AccessSpecifier.Public,
                    Type   = new TagType(baseClass)
                });
            }

            cppElementToDeclarationMapping.Add(cppInterface, @interface);
            return(base.VisitCppInterface(cppInterface));
        }
示例#2
0
        public override bool VisitCppStruct(CppStruct cppStruct)
        {
            Declaration unitDecl;

            cppElementToDeclarationMapping.TryGetValue(cppStruct.ParentInclude, out unitDecl);
            TranslationUnit unit = unitDecl != null ? unitDecl as TranslationUnit : FindDeclParent <TranslationUnit>(cppStruct.ParentInclude);

            Namespace @namespace     = null;
            Class     @structAsClass = null;

            // Check if we have an namespace
            if (!string.IsNullOrEmpty(cppStruct.Namespace))
            {
                @namespace     = unit.FindCreateNamespace(cppStruct.Namespace.TrimStart(':'));
                @structAsClass = @namespace.FindClass(cppStruct.Name, true, true);
            }
            else
            {
                @structAsClass = unit.FindClass(cppStruct.Name, true, true);
            }

            @structAsClass.Type = ClassType.ValueType;

            cppElementToDeclarationMapping.Add(cppStruct, @structAsClass);
            return(base.VisitCppStruct(cppStruct));
        }
 public static bool GetCreateWrappingClass(string className, TranslationUnit tu, out Class wrappingClass)
 {
     wrappingClass = tu.FindClass(className);
     if (wrappingClass == null)
     {
         wrappingClass = new Class {
             Name = className, Namespace = tu, IsStatic = true
         };
         return(true);
     }
     return(false);
 }