Browse Source

Clean up the parser. (#970)

pull/971/head
João Matos 9 years ago committed by Dimitar Dobrev
parent
commit
4438465cbd
  1. 35
      src/CppParser/Parser.cpp
  2. 2
      src/CppParser/Parser.h

35
src/CppParser/Parser.cpp

@ -91,7 +91,7 @@ void Parser::ReadClassLayout(Class* Class, const clang::RecordDecl* RD,
auto CXXRD = dyn_cast<CXXRecordDecl>(RD); auto CXXRD = dyn_cast<CXXRecordDecl>(RD);
auto Parent = static_cast<AST::Class*>( auto Parent = static_cast<AST::Class*>(
WalkDeclaration(RD, /*CanBeDefinition =*/false)); WalkDeclaration(RD));
if (Class != Parent) if (Class != Parent)
{ {
@ -790,7 +790,7 @@ Class* Parser::GetRecord(const clang::RecordDecl* Record, bool& Process)
if (Redecl->isImplicit() || Redecl == Record) if (Redecl->isImplicit() || Redecl == Record)
continue; continue;
RC->Redeclarations.push_back(WalkDeclaration(Redecl, false)); RC->Redeclarations.push_back(WalkDeclaration(Redecl));
} }
if (HasEmptyName) if (HasEmptyName)
@ -1063,7 +1063,7 @@ Parser::WalkClassTemplateSpecialization(const clang::ClassTemplateSpecialization
TS->isIncomplete = true; TS->isIncomplete = true;
if (CTS->getDefinition()) if (CTS->getDefinition())
{ {
auto Complete = WalkDeclaration(CTS->getDefinition(), /*CanBeDefinition=*/true); auto Complete = WalkDeclaration(CTS->getDefinition());
if (!Complete->isIncomplete) if (!Complete->isIncomplete)
TS->completeDeclaration = Complete; TS->completeDeclaration = Complete;
} }
@ -1113,7 +1113,7 @@ Parser::WalkClassTemplatePartialSpecialization(const clang::ClassTemplatePartial
TS->isIncomplete = true; TS->isIncomplete = true;
if (CTS->getDefinition()) if (CTS->getDefinition())
{ {
auto Complete = WalkDeclaration(CTS->getDefinition(), /*CanBeDefinition=*/true); auto Complete = WalkDeclaration(CTS->getDefinition());
if (!Complete->isIncomplete) if (!Complete->isIncomplete)
TS->completeDeclaration = Complete; TS->completeDeclaration = Complete;
} }
@ -1131,7 +1131,7 @@ std::vector<Declaration*> Parser::WalkTemplateParameterList(const clang::Templat
for (auto it = TPL->begin(); it != TPL->end(); ++it) for (auto it = TPL->begin(); it != TPL->end(); ++it)
{ {
auto ND = *it; auto ND = *it;
auto TP = WalkDeclaration(ND, /*IgnoreSystemDecls=*/false); auto TP = WalkDeclaration(ND);
params.push_back(TP); params.push_back(TP);
} }
@ -1185,7 +1185,7 @@ TemplateTemplateParameter* Parser::WalkTemplateTemplateParameter(const clang::Te
TP->isExpandedParameterPack = TTP->isExpandedParameterPack(); TP->isExpandedParameterPack = TTP->isExpandedParameterPack();
if (TTP->getTemplatedDecl()) if (TTP->getTemplatedDecl())
{ {
auto TD = WalkDeclaration(TTP->getTemplatedDecl(), /*IgnoreSystemDecls=*/false); auto TD = WalkDeclaration(TTP->getTemplatedDecl());
TP->TemplatedDecl = TD; TP->TemplatedDecl = TD;
} }
walkedTemplateTemplateParameters[TTP] = TP; walkedTemplateTemplateParameters[TTP] = TP;
@ -1317,7 +1317,7 @@ Parser::WalkTemplateArgument(const clang::TemplateArgument& TA, clang::TemplateA
} }
case clang::TemplateArgument::Declaration: case clang::TemplateArgument::Declaration:
Arg.kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Declaration; Arg.kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::Declaration;
Arg.declaration = WalkDeclaration(TA.getAsDecl(), 0); Arg.declaration = WalkDeclaration(TA.getAsDecl());
break; break;
case clang::TemplateArgument::NullPtr: case clang::TemplateArgument::NullPtr:
Arg.kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::NullPtr; Arg.kind = CppSharp::CppParser::TemplateArgument::ArgumentKind::NullPtr;
@ -1600,7 +1600,7 @@ Method* Parser::WalkMethodCXX(const clang::CXXMethodDecl* MD)
return WalkMethodCXX(cast<CXXMethodDecl>(MD->getPrimaryContext())); return WalkMethodCXX(cast<CXXMethodDecl>(MD->getPrimaryContext()));
auto RD = MD->getParent(); auto RD = MD->getParent();
auto Decl = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false); auto Decl = WalkDeclaration(RD);
auto Class = static_cast<CppSharp::CppParser::AST::Class*>(Decl); auto Class = static_cast<CppSharp::CppParser::AST::Class*>(Decl);
@ -2137,7 +2137,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
EnumDecl* ED = ET->getDecl(); EnumDecl* ED = ET->getDecl();
auto TT = new TagType(); auto TT = new TagType();
TT->declaration = TT->declaration = WalkDeclaration(ED, /*IgnoreSystemDecls=*/false); TT->declaration = TT->declaration = WalkDeclaration(ED);
Ty = TT; Ty = TT;
break; break;
@ -2164,8 +2164,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
auto TD = TT->getDecl(); auto TD = TT->getDecl();
auto TTL = TD->getTypeSourceInfo()->getTypeLoc(); auto TTL = TD->getTypeSourceInfo()->getTypeLoc();
auto TDD = static_cast<TypedefNameDecl*>(WalkDeclaration(TD, auto TDD = static_cast<TypedefNameDecl*>(WalkDeclaration(TD));
/*IgnoreSystemDecls=*/false));
auto Type = new TypedefType(); auto Type = new TypedefType();
Type->declaration = TDD; Type->declaration = TDD;
@ -2204,7 +2203,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
RecordDecl* RD = RT->getDecl(); RecordDecl* RD = RT->getDecl();
auto TT = new TagType(); auto TT = new TagType();
TT->declaration = WalkDeclaration(RD, /*IgnoreSystemDecls=*/false); TT->declaration = WalkDeclaration(RD);
Ty = TT; Ty = TT;
break; break;
@ -2384,7 +2383,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
TemplateName Name = TS->getTemplateName(); TemplateName Name = TS->getTemplateName();
TST->_template = static_cast<Template*>(WalkDeclaration( TST->_template = static_cast<Template*>(WalkDeclaration(
Name.getAsTemplateDecl(), 0)); Name.getAsTemplateDecl()));
if (TS->isSugared()) if (TS->isSugared())
TST->desugared = GetQualifiedType(TS->desugar(), TL); TST->desugared = GetQualifiedType(TS->desugar(), TL);
@ -2535,7 +2534,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL,
auto ICN = Type->getAs<clang::InjectedClassNameType>(); auto ICN = Type->getAs<clang::InjectedClassNameType>();
auto ICNT = new InjectedClassNameType(); auto ICNT = new InjectedClassNameType();
ICNT->_class = static_cast<Class*>(WalkDeclaration( ICNT->_class = static_cast<Class*>(WalkDeclaration(
ICN->getDecl(), 0)); ICN->getDecl()));
ICNT->injectedSpecializationType = GetQualifiedType( ICNT->injectedSpecializationType = GetQualifiedType(
ICN->getInjectedSpecializationType()); ICN->getInjectedSpecializationType());
@ -3479,10 +3478,10 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
Declaration* Parser::WalkDeclarationDef(clang::Decl* D) Declaration* Parser::WalkDeclarationDef(clang::Decl* D)
{ {
return WalkDeclaration(D, /*CanBeDefinition=*/true); return WalkDeclaration(D);
} }
Declaration* Parser::WalkDeclaration(const clang::Decl* D, bool CanBeDefinition) Declaration* Parser::WalkDeclaration(const clang::Decl* D)
{ {
using namespace clang; using namespace clang;
@ -3501,7 +3500,7 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D, bool CanBeDefinition)
// soon as they are referenced and we need to know the original order // soon as they are referenced and we need to know the original order
// of the declarations. // of the declarations.
if (CanBeDefinition && Record->definitionOrder == 0 && if (Record->definitionOrder == 0 &&
RD->isCompleteDefinition()) RD->isCompleteDefinition())
{ {
Record->definitionOrder = index++; Record->definitionOrder = index++;
@ -3521,7 +3520,7 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D, bool CanBeDefinition)
// soon as they are referenced and we need to know the original order // soon as they are referenced and we need to know the original order
// of the declarations. // of the declarations.
if (CanBeDefinition && Class->definitionOrder == 0 && if (Class->definitionOrder == 0 &&
RD->isCompleteDefinition()) RD->isCompleteDefinition())
{ {
Class->definitionOrder = index++; Class->definitionOrder = index++;

2
src/CppParser/Parser.h

@ -61,7 +61,7 @@ public:
private: private:
// AST traversers // AST traversers
void WalkAST(); void WalkAST();
Declaration* WalkDeclaration(const clang::Decl* D, bool CanBeDefinition = false); Declaration* WalkDeclaration(const clang::Decl* D);
Declaration* WalkDeclarationDef(clang::Decl* D); Declaration* WalkDeclarationDef(clang::Decl* D);
Enumeration* WalkEnum(const clang::EnumDecl* ED); Enumeration* WalkEnum(const clang::EnumDecl* ED);
Enumeration::Item* WalkEnumItem(clang::EnumConstantDecl* ECD); Enumeration::Item* WalkEnumItem(clang::EnumConstantDecl* ECD);

Loading…
Cancel
Save