// // Copyright (c) 2008-2020 the Urho3D project. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #pragma once #include #include #include #include #include #include "XmlSourceData.h" #include "Utils.h" using namespace pugi; using namespace std; // ... class TypeAnalyzer { private: string fullType_; string name_; bool isConst_; bool isPointer_; // * bool isReference_; // & bool isRvalueReference_; // && bool isDoublePointer_; // ** bool isRefToPoiner_; // *& string templateParams_; public: TypeAnalyzer(xml_node type, const map& templateSpecialization = map()); string ToString() const { return fullType_; } string GetName() const { return name_; } bool IsConst() const { return isConst_; } bool IsPointer() const { return isPointer_; } bool IsReference() const { return isReference_; } bool IsRvalueReference() const { return isRvalueReference_; } bool IsDoublePointer() const { return isDoublePointer_; } bool IsRefToPointer() const { return isRefToPoiner_; } bool IsTemplate() const { return templateParams_.length() > 0; } string GetTemplateParams() { return templateParams_; } string GetNameWithTemplateParams() const { return IsTemplate() ? name_ + "<" + templateParams_ + ">" : name_; } }; // // ... class ParamAnalyzer { private: xml_node node_; map templateSpecialization_; public: ParamAnalyzer(xml_node param, const map& templateSpecialization = map()); xml_node GetNode() const { return node_; } string ToString() const; // "type name" // // .... TypeAnalyzer GetType() const; // // .... string GetDeclname() const; // // .... string GetDefval() const; // Default value }; // inline bool IsMemberdef(xml_node node) { return node.name() == string("memberdef"); } // inline bool IsCompounddef(xml_node node) { return node.name() == string("compounddef"); } // inline bool IsMember(xml_node node) { return node.name() == string("member"); } // inline bool IsSectiondef(xml_node node) { return node.name() == string("sectiondef"); } // inline bool IsEnumvalue(xml_node node) { return node.name() == string("enumvalue"); } // // ... string ExtractCompoundname(xml_node compounddef); // // ... xml_node FindSectiondef(xml_node compounddef, const string& kind); // bool IsStatic(xml_node memberdef); // bool IsExplicit(xml_node memberdef); // // ... string ExtractDefinition(xml_node memberdef); // // ... string ExtractArgsstring(xml_node memberdef); // // // ... // ... vector ExtractTemplateParams(xml_node memberdef); // string ExtractProt(xml_node memberdef); // // ... TypeAnalyzer ExtractType(xml_node memberdef, const map& templateSpecialization = map()); // // ... // ... vector ExtractParams(xml_node memberdef, const map& templateSpecialization = map()); // // ... // ... string JoinParamsTypes(xml_node memberdef, const map& templateSpecialization = map()); string JoinParamsNames(xml_node memberdef, bool skipContext = false); // string ExtractID(xml_node node); // string ExtractKind(xml_node node); // // ... string ExtractName(xml_node node); // // string ExtractLine(xml_node node); // // string ExtractColumn(xml_node node); // // ... // ... string ExtractComment(xml_node node); // // // Extract header file path and convert to relative. // Return empty string when declared in *.cpp string ExtractHeaderFile(xml_node node); // // bool IsTemplate(xml_node node); // ============================================================================ // // // ... class EnumAnalyzer { xml_node memberdef_; public: EnumAnalyzer(xml_node memberdef); string GetTypeName() const { return ExtractName(memberdef_); } string GetHeaderFile() const { return ExtractHeaderFile(memberdef_); } string GetComment() const { return ExtractComment(memberdef_); } bool IsInternal() const { return GetHeaderFile().empty(); } // true if declared in .cpp file string GetBaseType() const; string GetLocation() const; // // ... // ... vector GetEnumerators() const; }; // ============================================================================ // // // ... class GlobalVariableAnalyzer { xml_node memberdef_; public: GlobalVariableAnalyzer(xml_node memberdef); string GetName() const { return ExtractName(memberdef_); } string GetHeaderFile() const { return ExtractHeaderFile(memberdef_); } bool IsStatic() const { return ::IsStatic(memberdef_); } TypeAnalyzer GetType() const { return ExtractType(memberdef_); } bool IsArray() const { return StartsWith(ExtractArgsstring(memberdef_), "["); } string GetLocation() const; }; // ============================================================================ class ClassFunctionAnalyzer; class ClassVariableAnalyzer; // ... class ClassAnalyzer { private: xml_node compounddef_; vector GetMemberdefs() const; public: ClassAnalyzer(xml_node compounddef); string GetClassName() const; string GetComment() const { return ExtractComment(compounddef_); } string GetHeaderFile() const { return ExtractHeaderFile(compounddef_); } string GetKind() const { return ExtractKind(compounddef_); } bool IsInternal() const; bool IsTemplate() const { return ::IsTemplate(compounddef_); } vector GetFunctions() const; vector GetVariables() const; bool ContainsFunction(const string& name) const; ClassFunctionAnalyzer GetFunction(const string& name) const; int NumFunctions(const string& name) const; bool IsRefCounted() const { return ContainsFunction("AddRef") && ContainsFunction("ReleaseRef"); } bool HasDestructor() const { return ContainsFunction("~" + GetClassName()); } bool HasThisConstructor() const; bool IsAbstract() const; string GetLocation() const { return GetKind() + " " + GetClassName() + " | File: " + GetHeaderFile(); } bool AllFloats() const; bool AllInts() const; bool IsPod() const; shared_ptr GetBaseClass() const; vector GetBaseClasses() const; vector GetAllBaseClasses() const; }; // ============================================================================ // // // ... class ClassFunctionAnalyzer { ClassAnalyzer classAnalyzer_; xml_node memberdef_; public: ClassFunctionAnalyzer(ClassAnalyzer classAnalyzer, xml_node memberdef); ClassAnalyzer GetClass() const { return classAnalyzer_; } xml_node GetMemberdef() const { return memberdef_; } // string GetVirt() const; bool IsPureVirtual() const { return GetVirt() == "pure-virtual"; } // bool IsConst() const; // // shared_ptr Reimplements() const; string GetName() const { return ExtractName(memberdef_); } string GetClassName() const { return classAnalyzer_.GetClassName(); } string GetContainsClassName() const; // May this function defined in parent class, so return name o class, real define this function string GetLine() const { return ExtractLine(memberdef_); } string GetColumn() const { return ExtractColumn(memberdef_); } string GetComment() const { return ExtractComment(memberdef_); } bool IsStatic() const { return ::IsStatic(memberdef_); } bool IsPublic() const { return ExtractProt(memberdef_) == "public"; } bool IsThisConstructor() const { return GetName() == GetClassName(); } bool IsParentConstructor() const; bool IsThisDestructor() const { return GetName() == "~" + GetClassName(); } bool IsParentDestructor() const; string GetLocation() const; string GetHeaderFile() const { return ExtractHeaderFile(memberdef_); } TypeAnalyzer GetReturnType(const map& templateSpecialization = map()) const { return ExtractType(memberdef_, templateSpecialization); } bool CanBeGetProperty() const; bool CanBeSetProperty() const; bool IsTemplate() const { return ::IsTemplate(memberdef_); } bool IsExplicit() const { return ::IsExplicit(memberdef_); } bool IsDefine() const { return CONTAINS(SourceData::defines_, GetName()); } bool IsDeleted() const { return EndsWith(ExtractArgsstring(memberdef_), "=delete"); } bool IsConsversionOperator() const { return StartsWith(GetName(), "operator "); } vector GetParams() const { return ExtractParams(memberdef_); } string JoinParamsNames(bool skipContext = false) const { return ::JoinParamsNames(memberdef_, skipContext); } string JoinParamsTypes() const { return ::JoinParamsTypes(memberdef_); } }; // ============================================================================ // // // ... class ClassVariableAnalyzer { ClassAnalyzer classAnalyzer_; xml_node memberdef_; public: ClassVariableAnalyzer(ClassAnalyzer classAnalyzer, xml_node memberdef); bool IsStatic() const { return ::IsStatic(memberdef_); } TypeAnalyzer GetType() const { return ExtractType(memberdef_); } string GetName() const { return ExtractName(memberdef_); } string GetComment() const { return ExtractComment(memberdef_); } bool IsPublic() const { return ExtractProt(memberdef_) == "public"; } string GetHeaderFile() const { return ExtractHeaderFile(memberdef_); } string GetLocation() const; string GetClassName() const { return classAnalyzer_.GetClassName(); } bool IsArray() const { return StartsWith(ExtractArgsstring(memberdef_), "["); }; }; // ============================================================================ // // // ... class GlobalFunctionAnalyzer { xml_node memberdef_; public: GlobalFunctionAnalyzer(xml_node memberdef); string GetName() const { return ExtractName(memberdef_); } string GetHeaderFile() const { return ExtractHeaderFile(memberdef_); } bool IsTemplate() const { return ::IsTemplate(memberdef_); } string GetComment() const { return ExtractComment(memberdef_); } vector GetParams(const map& templateSpecialization = map()) const { return ExtractParams(memberdef_, templateSpecialization); } TypeAnalyzer GetReturnType(const map& templateSpecialization = map()) const { return ExtractType(memberdef_, templateSpecialization); } xml_node GetMemberdef() const { return memberdef_; } vector GetTemplateParams() const { return ExtractTemplateParams(memberdef_); } string JoinParamsNames() const { return ::JoinParamsNames(memberdef_); } string JoinParamsTypes() const { return ::JoinParamsTypes(memberdef_); } bool IsDefine() const { return CONTAINS(SourceData::defines_, GetName()); } string GetLocation() const; }; // ============================================================================ // // // ... class ClassStaticFunctionAnalyzer { ClassAnalyzer classAnalyzer_; xml_node memberdef_; public: ClassStaticFunctionAnalyzer(ClassAnalyzer classAnalyzer, xml_node memberdef); string GetName() const { return ExtractName(memberdef_); } string GetHeaderFile() const { return ExtractHeaderFile(memberdef_); } bool IsTemplate() const { return ::IsTemplate(memberdef_); } string GetComment() const { return ExtractComment(memberdef_); } vector GetParams(const map& templateSpecialization = map()) const { return ExtractParams(memberdef_, templateSpecialization); } TypeAnalyzer GetReturnType(const map& templateSpecialization = map()) const { return ExtractType(memberdef_, templateSpecialization); } xml_node GetMemberdef() const { return memberdef_; } vector GetTemplateParams() const { return ExtractTemplateParams(memberdef_); } string GetClassName() const { return classAnalyzer_.GetClassName(); } bool IsDefine() const { return CONTAINS(SourceData::defines_, GetName()); }; string JoinParamsNames() const { return ::JoinParamsNames(memberdef_); } string JoinParamsTypes() const { return ::JoinParamsTypes(memberdef_); }; string GetLocation() const; }; // ============================================================================ // // using ... class UsingAnalyzer { private: xml_node memberdef_; public: UsingAnalyzer(xml_node memberdef); string GetIdentifier() const; }; // ============================================================================ // ... class NamespaceAnalyzer { private: xml_node compounddef_; public: NamespaceAnalyzer(xml_node compounddef); // // // ... // ... vector GetEnums(); // // // ... // ... vector GetVariables(); // // // ... // ... vector GetFunctions(); };