diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index cd2369ca..82a5bd83 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -158,5 +158,5 @@ int ApplicationSettings::getControlsMouseBackButton() const int ApplicationSettings::getControlsMouseForwardButton() const { - return getValue("controls/mouse_forward_button", 0x16); + return getValue("controls/mouse_forward_button", 0x10); } diff --git a/src/lib_parser/data/parser/cxx/ASTVisitor.cpp b/src/lib_parser/data/parser/cxx/ASTVisitor.cpp index 6b7dc3ec..b709662a 100644 --- a/src/lib_parser/data/parser/cxx/ASTVisitor.cpp +++ b/src/lib_parser/data/parser/cxx/ASTVisitor.cpp @@ -179,11 +179,7 @@ bool ASTVisitor::VisitParmVarDecl(clang::ParmVarDecl* declaration) { // todo: handle parameters here! // maybe handle template args in visitvardecl to account for local variables and stuff... - clang::TypeLoc loc = declaration->getTypeSourceInfo()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(declaration->getTypeSourceInfo()->getTypeLoc()); return true; } @@ -552,38 +548,22 @@ void ASTVisitor::VisitCXXConstructExprInDeclBody(clang::DeclaratorDecl* decl, cl void ASTVisitor::VisitExplicitCastExprInDeclBody(clang::FunctionDecl* decl, clang::ExplicitCastExpr* expr) { - clang::TypeLoc loc = expr->getTypeInfoAsWritten()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(expr->getTypeInfoAsWritten()->getTypeLoc()); } void ASTVisitor::VisitExplicitCastExprInDeclBody(clang::DeclaratorDecl* decl, clang::ExplicitCastExpr* expr) { - clang::TypeLoc loc = expr->getTypeInfoAsWritten()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(expr->getTypeInfoAsWritten()->getTypeLoc()); } void ASTVisitor::VisitCXXTemporaryObjectExprInDeclBody(clang::FunctionDecl* decl, clang::CXXTemporaryObjectExpr* expr) { - clang::TypeLoc loc = expr->getTypeSourceInfo()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(expr->getTypeSourceInfo()->getTypeLoc()); } void ASTVisitor::VisitCXXTemporaryObjectExprInDeclBody(clang::DeclaratorDecl* decl, clang::CXXTemporaryObjectExpr* expr) { - clang::TypeLoc loc = expr->getTypeSourceInfo()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(expr->getTypeSourceInfo()->getTypeLoc()); } void ASTVisitor::VisitCXXNewExprInDeclBody(clang::FunctionDecl* decl, clang::CXXNewExpr* expr) @@ -593,11 +573,7 @@ void ASTVisitor::VisitCXXNewExprInDeclBody(clang::FunctionDecl* decl, clang::CXX getParseFunction(decl) ); - clang::TypeLoc loc = expr->getAllocatedTypeSourceInfo()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(expr->getAllocatedTypeSourceInfo()->getTypeLoc()); } void ASTVisitor::VisitCXXNewExprInDeclBody(clang::DeclaratorDecl* decl, clang::CXXNewExpr* expr) @@ -607,11 +583,7 @@ void ASTVisitor::VisitCXXNewExprInDeclBody(clang::DeclaratorDecl* decl, clang::C getParseVariable(decl) ); - clang::TypeLoc loc = expr->getAllocatedTypeSourceInfo()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(expr->getAllocatedTypeSourceInfo()->getTypeLoc()); } void ASTVisitor::VisitMemberExprInDeclBody(clang::FunctionDecl* decl, clang::MemberExpr* expr) @@ -705,11 +677,7 @@ void ASTVisitor::VisitVarDeclInDeclBody(clang::FunctionDecl* decl, clang::VarDec getParseFunction(decl) ); - clang::TypeLoc loc = varDecl->getTypeSourceInfo()->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(varDecl->getTypeSourceInfo()->getTypeLoc()); } void ASTVisitor::processFunctionDecl(clang::FunctionDecl* declaration) @@ -724,11 +692,7 @@ void ASTVisitor::processFunctionDecl(clang::FunctionDecl* declaration) clang::TypeLoc functionLoc = declaration->getTypeSourceInfo()->getTypeLoc(); if (functionLoc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::FunctionProto) { - clang::TypeLoc returnLoc = functionLoc.getAs().getReturnLoc(); - if (returnLoc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(returnLoc.getAs()); - } + processTemplateArguments(functionLoc.getAs().getReturnLoc()); } @@ -794,11 +758,7 @@ void ASTVisitor::processTemplateArgumentsOfExplicitSpecialization(clang::ClassTe { if (clang::TypeSourceInfo* typeSourceInfo = specializationDecl->getTypeAsWritten()) { - clang::TypeLoc loc = typeSourceInfo->getTypeLoc(); - if (loc.getTypeLocClass() == clang::TypeLoc::TypeLocClass::TemplateSpecialization) - { - processTemplateArguments(loc.getAs()); - } + processTemplateArguments(typeSourceInfo->getTypeLoc()); } else { @@ -866,26 +826,30 @@ void ASTVisitor::processTemplateArguments(clang::DeclRefExpr* expr) } } -void ASTVisitor::processTemplateArguments(clang::TemplateSpecializationTypeLoc loc) +void ASTVisitor::processTemplateArguments(clang::TypeLoc typeLoc) { - NameHierarchy specializationNameHierarchy = utility::qualTypeToDataType(loc.getType())->getTypeNameHierarchy(); - - if (!isLocatedInProjectFile(getParseLocation(loc.getSourceRange()))) + clang::TemplateSpecializationTypeLoc specializationLoc = utility::getNextTypeLoc(typeLoc); + if (!specializationLoc.isNull()) { - return; - } + NameHierarchy specializationNameHierarchy = utility::qualTypeToDataType(specializationLoc.getType())->getTypeNameHierarchy(); - for (unsigned int i = 0; i < loc.getNumArgs(); i++) - { - const clang::TemplateArgument& argument = loc.getArgLoc(i).getArgument(); - NameHierarchy argumentNameHierarchy = utility::templateArgumentToDataType(argument)->getTypeNameHierarchy(); - if (argumentNameHierarchy.size()) // FIXME: Some TemplateArgument kinds are not handled yet. + if (!isLocatedInProjectFile(getParseLocation(specializationLoc.getSourceRange()))) { - m_client->onTemplateArgumentTypeOfTemplateRecordParsed( - getParseLocationForTokensInRange(loc.getArgLoc(i).getSourceRange()), - argumentNameHierarchy, - specializationNameHierarchy + return; + } + + for (unsigned int i = 0; i < specializationLoc.getNumArgs(); i++) + { + const clang::TemplateArgument& argument = specializationLoc.getArgLoc(i).getArgument(); + NameHierarchy argumentNameHierarchy = utility::templateArgumentToDataType(argument)->getTypeNameHierarchy(); + if (argumentNameHierarchy.size()) // FIXME: Some TemplateArgument kinds are not handled yet. + { + m_client->onTemplateArgumentTypeOfTemplateRecordParsed( + getParseLocationForTokensInRange(specializationLoc.getArgLoc(i).getSourceRange()), + argumentNameHierarchy, + specializationNameHierarchy ); + } } } } diff --git a/src/lib_parser/data/parser/cxx/ASTVisitor.h b/src/lib_parser/data/parser/cxx/ASTVisitor.h index 3add016f..a4f9a322 100644 --- a/src/lib_parser/data/parser/cxx/ASTVisitor.h +++ b/src/lib_parser/data/parser/cxx/ASTVisitor.h @@ -72,7 +72,7 @@ private: void processTemplateArgumentsOfExplicitSpecialization(clang::FunctionDecl* declaration); void processTemplateArgumentsOfExplicitSpecialization(clang::ClassTemplateSpecializationDecl* specializationDecl); void processTemplateArguments(clang::DeclRefExpr* expr); - void processTemplateArguments(clang::TemplateSpecializationTypeLoc loc); + void processTemplateArguments(clang::TypeLoc loc); bool isLocatedInUnparsedProjectFile(const clang::Decl* declaration) const; bool isLocatedInProjectFile(const ParseLocation& location) const; diff --git a/src/lib_parser/data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp b/src/lib_parser/data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp index 93873380..9234643a 100644 --- a/src/lib_parser/data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp +++ b/src/lib_parser/data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp @@ -65,9 +65,9 @@ std::shared_ptr CxxTypeNameResolver::typeToDataType(const clang::Type* break; } case clang::Type::ConstantArray: - case clang::Type::VariableArray: case clang::Type::DependentSizedArray: case clang::Type::IncompleteArray: + case clang::Type::VariableArray: { std::shared_ptr innerType = qualTypeToDataType(clang::dyn_cast(type)->getElementType()); dataType = std::make_shared(innerType); diff --git a/src/lib_parser/data/parser/cxx/utilityCxx.h b/src/lib_parser/data/parser/cxx/utilityCxx.h index a1bdb1d7..29b577c5 100644 --- a/src/lib_parser/data/parser/cxx/utilityCxx.h +++ b/src/lib_parser/data/parser/cxx/utilityCxx.h @@ -6,6 +6,7 @@ #include #include "clang/AST/Type.h" +#include "clang/AST/TypeLoc.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclTemplate.h" @@ -14,6 +15,9 @@ class NameHierarchy; namespace utility { + template + TypeLocType getNextTypeLoc(clang::TypeLoc loc); + std::shared_ptr qualTypeToDataType(clang::QualType qualType); NameHierarchy getDeclNameHierarchy(const clang::Decl* declaration); @@ -21,4 +25,19 @@ namespace utility NameHierarchy getTemplateSpecializationParentNameHierarchy(clang::ClassTemplateSpecializationDecl* declaration); } +template +TypeLocType utility::getNextTypeLoc(clang::TypeLoc loc) +{ + while (!loc.isNull()) + { + TypeLocType ret = loc.getAs(); + if (!ret.isNull()) + { + return ret; + } + loc = loc.getNextTypeLoc(); + } + return TypeLocType(); // isNull() of this object returns true. +} + #endif // UTILITY_CLANG_H