eduucaldas updated this revision to Diff 283659. eduucaldas added a comment.
removed namespace specifiers `llvm::` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85427/new/ https://reviews.llvm.org/D85427 Files: clang/include/clang/Tooling/Syntax/Nodes.h clang/include/clang/Tooling/Syntax/Tree.h clang/lib/Tooling/Syntax/BuildTree.cpp clang/lib/Tooling/Syntax/Nodes.cpp clang/lib/Tooling/Syntax/Tree.cpp clang/unittests/Tooling/Syntax/TreeTest.cpp
Index: clang/unittests/Tooling/Syntax/TreeTest.cpp =================================================================== --- clang/unittests/Tooling/Syntax/TreeTest.cpp +++ clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -40,7 +40,7 @@ using namespace clang; namespace { -static llvm::ArrayRef<syntax::Token> tokens(syntax::Node *N) { +static ArrayRef<syntax::Token> tokens(syntax::Node *N) { assert(N->isOriginal() && "tokens of modified nodes are not well-defined"); if (auto *L = dyn_cast<syntax::Leaf>(N)) return llvm::makeArrayRef(L->token(), 1); @@ -53,7 +53,7 @@ public ::testing::WithParamInterface<TestClangConfig> { protected: // Build a syntax tree for the code. - syntax::TranslationUnit *buildTree(llvm::StringRef Code, + syntax::TranslationUnit *buildTree(StringRef Code, const TestClangConfig &ClangConfig) { // FIXME: this code is almost the identical to the one in TokensTest. Share // it. @@ -169,7 +169,7 @@ } // Adds a file to the test VFS. - void addFile(llvm::StringRef Path, llvm::StringRef Contents) { + void addFile(StringRef Path, StringRef Contents) { if (!FS->addFile(Path, time_t(), llvm::MemoryBuffer::getMemBufferCopy(Contents))) { ADD_FAILURE() << "could not add a file to VFS: " << Path; @@ -179,7 +179,7 @@ /// Finds the deepest node in the tree that covers exactly \p R. /// FIXME: implement this efficiently and move to public syntax tree API. syntax::Node *nodeByRange(llvm::Annotations::Range R, syntax::Node *Root) { - llvm::ArrayRef<syntax::Token> Toks = tokens(Root); + ArrayRef<syntax::Token> Toks = tokens(Root); if (Toks.front().location().isFileID() && Toks.back().location().isFileID() && @@ -198,15 +198,14 @@ } // Data fields. - llvm::IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = - new DiagnosticOptions(); - llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags = + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + IntrusiveRefCntPtr<DiagnosticsEngine> Diags = new DiagnosticsEngine(new DiagnosticIDs, DiagOpts.get()); IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS = new llvm::vfs::InMemoryFileSystem; - llvm::IntrusiveRefCntPtr<FileManager> FileMgr = + IntrusiveRefCntPtr<FileManager> FileMgr = new FileManager(FileSystemOptions(), FS); - llvm::IntrusiveRefCntPtr<SourceManager> SourceMgr = + IntrusiveRefCntPtr<SourceManager> SourceMgr = new SourceManager(*Diags, *FileMgr); std::shared_ptr<CompilerInvocation> Invocation; // Set after calling buildTree(). Index: clang/lib/Tooling/Syntax/Tree.cpp =================================================================== --- clang/lib/Tooling/Syntax/Tree.cpp +++ clang/lib/Tooling/Syntax/Tree.cpp @@ -36,11 +36,9 @@ const TokenBuffer &Tokens) : SourceMgr(SourceMgr), LangOpts(LangOpts), Tokens(Tokens) {} -const clang::syntax::TokenBuffer &syntax::Arena::tokenBuffer() const { - return Tokens; -} +const syntax::TokenBuffer &syntax::Arena::tokenBuffer() const { return Tokens; } -std::pair<FileID, llvm::ArrayRef<syntax::Token>> +std::pair<FileID, ArrayRef<syntax::Token>> syntax::Arena::lexBuffer(std::unique_ptr<llvm::MemoryBuffer> Input) { auto FID = SourceMgr.createFileID(std::move(Input)); auto It = ExtraTokens.try_emplace(FID, tokenize(FID, SourceMgr, LangOpts)); @@ -135,7 +133,7 @@ } namespace { -static void dumpTokens(llvm::raw_ostream &OS, ArrayRef<syntax::Token> Tokens, +static void dumpTokens(raw_ostream &OS, ArrayRef<syntax::Token> Tokens, const SourceManager &SM) { assert(!Tokens.empty()); bool First = true; @@ -153,7 +151,7 @@ } } -static void dumpTree(llvm::raw_ostream &OS, const syntax::Node *N, +static void dumpTree(raw_ostream &OS, const syntax::Node *N, const syntax::Arena &A, std::vector<bool> IndentMask) { std::string Marks; if (!N->isOriginal()) @@ -165,13 +163,13 @@ if (!Marks.empty()) OS << Marks << ": "; - if (auto *L = llvm::dyn_cast<syntax::Leaf>(N)) { + if (auto *L = dyn_cast<syntax::Leaf>(N)) { dumpTokens(OS, *L->token(), A.sourceManager()); OS << "\n"; return; } - auto *T = llvm::cast<syntax::Tree>(N); + auto *T = cast<syntax::Tree>(N); OS << T->kind() << "\n"; for (auto It = T->firstChild(); It != nullptr; It = It->nextSibling()) { @@ -205,7 +203,7 @@ std::string Storage; llvm::raw_string_ostream OS(Storage); traverse(this, [&](const syntax::Node *N) { - auto *L = llvm::dyn_cast<syntax::Leaf>(N); + auto *L = dyn_cast<syntax::Leaf>(N); if (!L) return; ::dumpTokens(OS, *L->token(), A.sourceManager()); Index: clang/lib/Tooling/Syntax/Nodes.cpp =================================================================== --- clang/lib/Tooling/Syntax/Nodes.cpp +++ clang/lib/Tooling/Syntax/Nodes.cpp @@ -10,7 +10,7 @@ using namespace clang; -llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, NodeKind K) { +raw_ostream &syntax::operator<<(raw_ostream &OS, NodeKind K) { switch (K) { case NodeKind::Leaf: return OS << "Leaf"; @@ -124,7 +124,7 @@ llvm_unreachable("unknown node kind"); } -llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, NodeRole R) { +raw_ostream &syntax::operator<<(raw_ostream &OS, NodeRole R) { switch (R) { case syntax::NodeRole::Detached: return OS << "Detached"; @@ -200,202 +200,197 @@ std::vector<syntax::NameSpecifier *> Children; for (auto *C = firstChild(); C; C = C->nextSibling()) { assert(C->role() == syntax::NodeRole::NestedNameSpecifier_specifier); - Children.push_back(llvm::cast<syntax::NameSpecifier>(C)); + Children.push_back(cast<syntax::NameSpecifier>(C)); } return Children; } syntax::NestedNameSpecifier *syntax::IdExpression::qualifier() { - return llvm::cast_or_null<syntax::NestedNameSpecifier>( + return cast_or_null<syntax::NestedNameSpecifier>( findChild(syntax::NodeRole::IdExpression_qualifier)); } syntax::UnqualifiedId *syntax::IdExpression::unqualifiedId() { - return llvm::cast_or_null<syntax::UnqualifiedId>( + return cast_or_null<syntax::UnqualifiedId>( findChild(syntax::NodeRole::IdExpression_id)); } syntax::Leaf *syntax::ParenExpression::openParen() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::OpenParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen)); } syntax::Expression *syntax::ParenExpression::subExpression() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::ParenExpression_subExpression)); } syntax::Leaf *syntax::ParenExpression::closeParen() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::CloseParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen)); } syntax::Leaf *syntax::LiteralExpression::literalToken() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::LiteralToken)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::LiteralToken)); } syntax::Expression *syntax::BinaryOperatorExpression::lhs() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::BinaryOperatorExpression_leftHandSide)); } syntax::Leaf *syntax::UnaryOperatorExpression::operatorToken() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::OperatorExpression_operatorToken)); } syntax::Expression *syntax::UnaryOperatorExpression::operand() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::UnaryOperatorExpression_operand)); } syntax::Leaf *syntax::BinaryOperatorExpression::operatorToken() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::OperatorExpression_operatorToken)); } syntax::Expression *syntax::BinaryOperatorExpression::rhs() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::BinaryOperatorExpression_rightHandSide)); } syntax::Leaf *syntax::SwitchStatement::switchKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Statement *syntax::SwitchStatement::body() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::BodyStatement)); } syntax::Leaf *syntax::CaseStatement::caseKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Expression *syntax::CaseStatement::value() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::CaseStatement_value)); } syntax::Statement *syntax::CaseStatement::body() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::BodyStatement)); } syntax::Leaf *syntax::DefaultStatement::defaultKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Statement *syntax::DefaultStatement::body() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::BodyStatement)); } syntax::Leaf *syntax::IfStatement::ifKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Statement *syntax::IfStatement::thenStatement() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::IfStatement_thenStatement)); } syntax::Leaf *syntax::IfStatement::elseKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IfStatement_elseKeyword)); } syntax::Statement *syntax::IfStatement::elseStatement() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::IfStatement_elseStatement)); } syntax::Leaf *syntax::ForStatement::forKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Statement *syntax::ForStatement::body() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::BodyStatement)); } syntax::Leaf *syntax::WhileStatement::whileKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Statement *syntax::WhileStatement::body() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::BodyStatement)); } syntax::Leaf *syntax::ContinueStatement::continueKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Leaf *syntax::BreakStatement::breakKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Leaf *syntax::ReturnStatement::returnKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Expression *syntax::ReturnStatement::value() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::ReturnStatement_value)); } syntax::Leaf *syntax::RangeBasedForStatement::forKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Statement *syntax::RangeBasedForStatement::body() { - return llvm::cast_or_null<syntax::Statement>( + return cast_or_null<syntax::Statement>( findChild(syntax::NodeRole::BodyStatement)); } syntax::Expression *syntax::ExpressionStatement::expression() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::ExpressionStatement_expression)); } syntax::Leaf *syntax::CompoundStatement::lbrace() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::OpenParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen)); } std::vector<syntax::Statement *> syntax::CompoundStatement::statements() { std::vector<syntax::Statement *> Children; for (auto *C = firstChild(); C; C = C->nextSibling()) { assert(C->role() == syntax::NodeRole::CompoundStatement_statement); - Children.push_back(llvm::cast<syntax::Statement>(C)); + Children.push_back(cast<syntax::Statement>(C)); } return Children; } syntax::Leaf *syntax::CompoundStatement::rbrace() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::CloseParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen)); } syntax::Expression *syntax::StaticAssertDeclaration::condition() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::StaticAssertDeclaration_condition)); } syntax::Expression *syntax::StaticAssertDeclaration::message() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::StaticAssertDeclaration_message)); } @@ -404,74 +399,67 @@ std::vector<syntax::SimpleDeclarator *> Children; for (auto *C = firstChild(); C; C = C->nextSibling()) { if (C->role() == syntax::NodeRole::SimpleDeclaration_declarator) - Children.push_back(llvm::cast<syntax::SimpleDeclarator>(C)); + Children.push_back(cast<syntax::SimpleDeclarator>(C)); } return Children; } syntax::Leaf *syntax::TemplateDeclaration::templateKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Declaration *syntax::TemplateDeclaration::declaration() { - return llvm::cast_or_null<syntax::Declaration>( + return cast_or_null<syntax::Declaration>( findChild(syntax::NodeRole::TemplateDeclaration_declaration)); } syntax::Leaf *syntax::ExplicitTemplateInstantiation::templateKeyword() { - return llvm::cast_or_null<syntax::Leaf>( + return cast_or_null<syntax::Leaf>( findChild(syntax::NodeRole::IntroducerKeyword)); } syntax::Leaf *syntax::ExplicitTemplateInstantiation::externKeyword() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::ExternKeyword)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::ExternKeyword)); } syntax::Declaration *syntax::ExplicitTemplateInstantiation::declaration() { - return llvm::cast_or_null<syntax::Declaration>( + return cast_or_null<syntax::Declaration>( findChild(syntax::NodeRole::ExplicitTemplateInstantiation_declaration)); } syntax::Leaf *syntax::ParenDeclarator::lparen() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::OpenParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen)); } syntax::Leaf *syntax::ParenDeclarator::rparen() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::CloseParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen)); } syntax::Leaf *syntax::ArraySubscript::lbracket() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::OpenParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen)); } syntax::Expression *syntax::ArraySubscript::sizeExpression() { - return llvm::cast_or_null<syntax::Expression>( + return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::ArraySubscript_sizeExpression)); } syntax::Leaf *syntax::ArraySubscript::rbracket() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::CloseParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen)); } syntax::Leaf *syntax::TrailingReturnType::arrowToken() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::ArrowToken)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::ArrowToken)); } syntax::SimpleDeclarator *syntax::TrailingReturnType::declarator() { - return llvm::cast_or_null<syntax::SimpleDeclarator>( + return cast_or_null<syntax::SimpleDeclarator>( findChild(syntax::NodeRole::TrailingReturnType_declarator)); } syntax::Leaf *syntax::ParametersAndQualifiers::lparen() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::OpenParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::OpenParen)); } std::vector<syntax::SimpleDeclaration *> @@ -479,17 +467,16 @@ std::vector<syntax::SimpleDeclaration *> Children; for (auto *C = firstChild(); C; C = C->nextSibling()) { if (C->role() == syntax::NodeRole::ParametersAndQualifiers_parameter) - Children.push_back(llvm::cast<syntax::SimpleDeclaration>(C)); + Children.push_back(cast<syntax::SimpleDeclaration>(C)); } return Children; } syntax::Leaf *syntax::ParametersAndQualifiers::rparen() { - return llvm::cast_or_null<syntax::Leaf>( - findChild(syntax::NodeRole::CloseParen)); + return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::CloseParen)); } syntax::TrailingReturnType *syntax::ParametersAndQualifiers::trailingReturn() { - return llvm::cast_or_null<syntax::TrailingReturnType>( + return cast_or_null<syntax::TrailingReturnType>( findChild(syntax::NodeRole::ParametersAndQualifiers_trailingReturn)); } Index: clang/lib/Tooling/Syntax/BuildTree.cpp =================================================================== --- clang/lib/Tooling/Syntax/BuildTree.cpp +++ clang/lib/Tooling/Syntax/BuildTree.cpp @@ -45,7 +45,7 @@ using namespace clang; LLVM_ATTRIBUTE_UNUSED -static bool isImplicitExpr(clang::Expr *E) { return E->IgnoreImplicit() != E; } +static bool isImplicitExpr(Expr *E) { return E->IgnoreImplicit() != E; } namespace { /// Get start location of the Declarator from the TypeLoc. @@ -275,15 +275,13 @@ /// Populate children for \p New node, assuming it covers tokens from \p /// Range. - void foldNode(llvm::ArrayRef<syntax::Token> Range, syntax::Tree *New, - ASTPtr From) { + void foldNode(ArrayRef<syntax::Token> Range, syntax::Tree *New, ASTPtr From) { assert(New); Pending.foldChildren(Arena, Range, New); if (From) Mapping.add(From, New); } - void foldNode(llvm::ArrayRef<syntax::Token> Range, syntax::Tree *New, - TypeLoc L) { + void foldNode(ArrayRef<syntax::Token> Range, syntax::Tree *New, TypeLoc L) { // FIXME: add mapping for TypeLocs foldNode(Range, New, nullptr); } @@ -329,7 +327,7 @@ const syntax::Token *findToken(SourceLocation L) const; /// Finds the syntax tokens corresponding to the \p SourceRange. - llvm::ArrayRef<syntax::Token> getRange(SourceRange Range) const { + ArrayRef<syntax::Token> getRange(SourceRange Range) const { assert(Range.isValid()); return getRange(Range.getBegin(), Range.getEnd()); } @@ -337,8 +335,8 @@ /// Finds the syntax tokens corresponding to the passed source locations. /// \p First is the start position of the first token and \p Last is the start /// position of the last token. - llvm::ArrayRef<syntax::Token> getRange(SourceLocation First, - SourceLocation Last) const { + ArrayRef<syntax::Token> getRange(SourceLocation First, + SourceLocation Last) const { assert(First.isValid()); assert(Last.isValid()); assert(First == Last || @@ -346,7 +344,7 @@ return llvm::makeArrayRef(findToken(First), std::next(findToken(Last))); } - llvm::ArrayRef<syntax::Token> + ArrayRef<syntax::Token> getTemplateRange(const ClassTemplateSpecializationDecl *D) const { auto Tokens = getRange(D->getSourceRange()); return maybeAppendSemicolon(Tokens, D); @@ -366,7 +364,7 @@ if (Next == nullptr) { return true; } - const auto *NextT = llvm::dyn_cast<T>(Next); + const auto *NextT = dyn_cast<T>(Next); // Next sibling is not the same type, this one is responsible. if (NextT == nullptr) { @@ -383,23 +381,23 @@ return false; } - llvm::ArrayRef<syntax::Token> getDeclarationRange(Decl *D) { - llvm::ArrayRef<clang::syntax::Token> Tokens; + ArrayRef<syntax::Token> getDeclarationRange(Decl *D) { + ArrayRef<syntax::Token> Tokens; // We want to drop the template parameters for specializations. - if (const auto *S = llvm::dyn_cast<TagDecl>(D)) + if (const auto *S = dyn_cast<TagDecl>(D)) Tokens = getRange(S->TypeDecl::getBeginLoc(), S->getEndLoc()); else Tokens = getRange(D->getSourceRange()); return maybeAppendSemicolon(Tokens, D); } - llvm::ArrayRef<syntax::Token> getExprRange(const Expr *E) const { + ArrayRef<syntax::Token> getExprRange(const Expr *E) const { return getRange(E->getSourceRange()); } /// Find the adjusted range for the statement, consuming the trailing /// semicolon when needed. - llvm::ArrayRef<syntax::Token> getStmtRange(const Stmt *S) const { + ArrayRef<syntax::Token> getStmtRange(const Stmt *S) const { auto Tokens = getRange(S->getSourceRange()); if (isa<CompoundStmt>(S)) return Tokens; @@ -412,10 +410,9 @@ } private: - llvm::ArrayRef<syntax::Token> - maybeAppendSemicolon(llvm::ArrayRef<syntax::Token> Tokens, - const Decl *D) const { - if (llvm::isa<NamespaceDecl>(D)) + ArrayRef<syntax::Token> maybeAppendSemicolon(ArrayRef<syntax::Token> Tokens, + const Decl *D) const { + if (isa<NamespaceDecl>(D)) return Tokens; if (DeclsWithoutSemicolons.count(D)) return Tokens; @@ -424,8 +421,8 @@ return withTrailingSemicolon(Tokens); } - llvm::ArrayRef<syntax::Token> - withTrailingSemicolon(llvm::ArrayRef<syntax::Token> Tokens) const { + ArrayRef<syntax::Token> + withTrailingSemicolon(ArrayRef<syntax::Token> Tokens) const { assert(!Tokens.empty()); assert(Tokens.back().kind() != tok::eof); // We never consume 'eof', so looking at the next token is ok. @@ -459,8 +456,7 @@ } } - void assignRole(llvm::ArrayRef<syntax::Token> Range, - syntax::NodeRole Role) { + void assignRole(ArrayRef<syntax::Token> Range, syntax::NodeRole Role) { assert(!Range.empty()); auto It = Trees.lower_bound(Range.begin()); assert(It != Trees.end() && "no node found"); @@ -474,8 +470,7 @@ } /// Add \p Node to the forest and attach child nodes based on \p Tokens. - void foldChildren(const syntax::Arena &A, - llvm::ArrayRef<syntax::Token> Tokens, + void foldChildren(const syntax::Arena &A, ArrayRef<syntax::Token> Tokens, syntax::Tree *Node) { // Attach children to `Node`. assert(Node->firstChild() == nullptr && "node already has children"); @@ -523,9 +518,9 @@ ? (std::next(It)->first - It->first) : A.tokenBuffer().expandedTokens().end() - It->first; - R += std::string(llvm::formatv( - "- '{0}' covers '{1}'+{2} tokens\n", It->second->kind(), - It->first->text(A.sourceManager()), CoveredTokens)); + R += std::string( + formatv("- '{0}' covers '{1}'+{2} tokens\n", It->second->kind(), + It->first->text(A.sourceManager()), CoveredTokens)); R += It->second->dump(A); } return R; @@ -623,7 +618,7 @@ foldTemplateDeclaration(R, TemplateKW, DeclarationRange, nullptr); DeclarationRange = R; }; - if (auto *S = llvm::dyn_cast<ClassTemplatePartialSpecializationDecl>(C)) + if (auto *S = dyn_cast<ClassTemplatePartialSpecializationDecl>(C)) ConsumeTemplateParameters(*S->getTemplateParameters()); for (unsigned I = C->getNumTemplateParameterLists(); 0 < I; --I) ConsumeTemplateParameters(*C->getTemplateParameterList(I - 1)); @@ -677,11 +672,11 @@ } bool TraverseStmt(Stmt *S) { - if (auto *DS = llvm::dyn_cast_or_null<DeclStmt>(S)) { + if (auto *DS = dyn_cast_or_null<DeclStmt>(S)) { // We want to consume the semicolon, make sure SimpleDeclaration does not. for (auto *D : DS->decls()) Builder.noticeDeclWithoutSemicolon(D); - } else if (auto *E = llvm::dyn_cast_or_null<Expr>(S)) { + } else if (auto *E = dyn_cast_or_null<Expr>(S)) { return RecursiveASTVisitor::TraverseStmt(E->IgnoreImplicit()); } return RecursiveASTVisitor::TraverseStmt(S); @@ -722,16 +717,16 @@ syntax::UserDefinedLiteralExpression * buildUserDefinedLiteral(UserDefinedLiteral *S) { switch (S->getLiteralOperatorKind()) { - case clang::UserDefinedLiteral::LOK_Integer: + case UserDefinedLiteral::LOK_Integer: return new (allocator()) syntax::IntegerUserDefinedLiteralExpression; - case clang::UserDefinedLiteral::LOK_Floating: + case UserDefinedLiteral::LOK_Floating: return new (allocator()) syntax::FloatUserDefinedLiteralExpression; - case clang::UserDefinedLiteral::LOK_Character: + case UserDefinedLiteral::LOK_Character: return new (allocator()) syntax::CharUserDefinedLiteralExpression; - case clang::UserDefinedLiteral::LOK_String: + case UserDefinedLiteral::LOK_String: return new (allocator()) syntax::StringUserDefinedLiteralExpression; - case clang::UserDefinedLiteral::LOK_Raw: - case clang::UserDefinedLiteral::LOK_Template: + case UserDefinedLiteral::LOK_Raw: + case UserDefinedLiteral::LOK_Template: // For raw literal operator and numeric literal operator template we // cannot get the type of the operand in the semantic AST. We get this // information from the token. As integer and floating point have the same @@ -1183,7 +1178,7 @@ if (IsAnonymous) return SourceLocation(); - if (const auto *DD = llvm::dyn_cast<DeclaratorDecl>(D)) { + if (const auto *DD = dyn_cast<DeclaratorDecl>(D)) { if (DD->getQualifierLoc()) { return DD->getQualifierLoc().getBeginLoc(); } @@ -1193,7 +1188,7 @@ } SourceRange getInitializerRange(Decl *D) { - if (auto *V = llvm::dyn_cast<VarDecl>(D)) { + if (auto *V = dyn_cast<VarDecl>(D)) { auto *I = V->getInit(); // Initializers in range-based-for are not part of the declarator if (I && !V->isCXXForRangeDecl()) Index: clang/include/clang/Tooling/Syntax/Tree.h =================================================================== --- clang/include/clang/Tooling/Syntax/Tree.h +++ clang/include/clang/Tooling/Syntax/Tree.h @@ -50,7 +50,7 @@ /// Add \p Buffer to the underlying source manager, tokenize it and store the /// resulting tokens. Useful when there is a need to materialize tokens that /// were not written in user code. - std::pair<FileID, llvm::ArrayRef<syntax::Token>> + std::pair<FileID, ArrayRef<Token>> lexBuffer(std::unique_ptr<llvm::MemoryBuffer> Buffer); private: @@ -58,7 +58,7 @@ const LangOptions &LangOpts; const TokenBuffer &Tokens; /// IDs and storage for additional tokenized files. - llvm::DenseMap<FileID, std::vector<syntax::Token>> ExtraTokens; + llvm::DenseMap<FileID, std::vector<Token>> ExtraTokens; /// Keeps all the allocated nodes and their intermediate data structures. llvm::BumpPtrAllocator Allocator; }; @@ -139,13 +139,13 @@ /// A leaf node points to a single token inside the expanded token stream. class Leaf final : public Node { public: - Leaf(const syntax::Token *T); + Leaf(const Token *T); static bool classof(const Node *N); - const syntax::Token *token() const { return Tok; } + const Token *token() const { return Tok; } private: - const syntax::Token *Tok; + const Token *Tok; }; /// A node that has children and represents a syntactic language construct. @@ -167,7 +167,7 @@ protected: /// Find the first node with a corresponding role. - syntax::Node *findChild(NodeRole R); + Node *findChild(NodeRole R); private: /// Prepend \p Child to the list of children and and sets the parent pointer. Index: clang/include/clang/Tooling/Syntax/Nodes.h =================================================================== --- clang/include/clang/Tooling/Syntax/Nodes.h +++ clang/include/clang/Tooling/Syntax/Nodes.h @@ -100,7 +100,7 @@ UnqualifiedId }; /// For debugging purposes. -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeKind K); +raw_ostream &operator<<(raw_ostream &OS, NodeKind K); /// A relation between a parent and child node, e.g. 'left-hand-side of /// a binary expression'. Used for implementing accessors. @@ -170,7 +170,7 @@ ParenExpression_subExpression }; /// For debugging purposes. -llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NodeRole R); +raw_ostream &operator<<(raw_ostream &OS, NodeRole R); class SimpleDeclarator; @@ -212,7 +212,7 @@ static bool classof(const Node *N) { return N->kind() <= NodeKind::NestedNameSpecifier; } - std::vector<syntax::NameSpecifier *> specifiers(); + std::vector<NameSpecifier *> specifiers(); }; /// Models an `unqualified-id`. C++ [expr.prim.id.unqual] @@ -238,10 +238,10 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::IdExpression; } - syntax::NestedNameSpecifier *qualifier(); + NestedNameSpecifier *qualifier(); // TODO after expose `id-expression` from `DependentScopeDeclRefExpr`: // Add accessor for `template_opt`. - syntax::UnqualifiedId *unqualifiedId(); + UnqualifiedId *unqualifiedId(); }; /// An expression of an unknown kind, i.e. one not currently handled by the @@ -262,9 +262,9 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ParenExpression; } - syntax::Leaf *openParen(); - syntax::Expression *subExpression(); - syntax::Leaf *closeParen(); + Leaf *openParen(); + Expression *subExpression(); + Leaf *closeParen(); }; /// Expression for literals. C++ [lex.literal] @@ -283,7 +283,7 @@ N->kind() == NodeKind::CharUserDefinedLiteralExpression || N->kind() == NodeKind::StringUserDefinedLiteralExpression; } - syntax::Leaf *literalToken(); + Leaf *literalToken(); }; /// Expression for integer literals. C++ [lex.icon] @@ -418,8 +418,8 @@ return N->kind() == NodeKind::PrefixUnaryOperatorExpression || N->kind() == NodeKind::PostfixUnaryOperatorExpression; } - syntax::Leaf *operatorToken(); - syntax::Expression *operand(); + Leaf *operatorToken(); + Expression *operand(); }; /// <operator> <operand> @@ -467,9 +467,9 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::BinaryOperatorExpression; } - syntax::Expression *lhs(); - syntax::Leaf *operatorToken(); - syntax::Expression *rhs(); + Expression *lhs(); + Leaf *operatorToken(); + Expression *rhs(); }; /// An abstract node for C++ statements, e.g. 'while', 'if', etc. @@ -518,8 +518,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::SwitchStatement; } - syntax::Leaf *switchKeyword(); - syntax::Statement *body(); + Leaf *switchKeyword(); + Statement *body(); }; /// case <value>: <body> @@ -529,9 +529,9 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::CaseStatement; } - syntax::Leaf *caseKeyword(); - syntax::Expression *value(); - syntax::Statement *body(); + Leaf *caseKeyword(); + Expression *value(); + Statement *body(); }; /// default: <body> @@ -541,8 +541,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::DefaultStatement; } - syntax::Leaf *defaultKeyword(); - syntax::Statement *body(); + Leaf *defaultKeyword(); + Statement *body(); }; /// if (cond) <then-statement> else <else-statement> @@ -553,10 +553,10 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::IfStatement; } - syntax::Leaf *ifKeyword(); - syntax::Statement *thenStatement(); - syntax::Leaf *elseKeyword(); - syntax::Statement *elseStatement(); + Leaf *ifKeyword(); + Statement *thenStatement(); + Leaf *elseKeyword(); + Statement *elseStatement(); }; /// for (<init>; <cond>; <increment>) <body> @@ -566,8 +566,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ForStatement; } - syntax::Leaf *forKeyword(); - syntax::Statement *body(); + Leaf *forKeyword(); + Statement *body(); }; /// while (<cond>) <body> @@ -577,8 +577,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::WhileStatement; } - syntax::Leaf *whileKeyword(); - syntax::Statement *body(); + Leaf *whileKeyword(); + Statement *body(); }; /// continue; @@ -588,7 +588,7 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ContinueStatement; } - syntax::Leaf *continueKeyword(); + Leaf *continueKeyword(); }; /// break; @@ -598,7 +598,7 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::BreakStatement; } - syntax::Leaf *breakKeyword(); + Leaf *breakKeyword(); }; /// return <expr>; @@ -609,8 +609,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ReturnStatement; } - syntax::Leaf *returnKeyword(); - syntax::Expression *value(); + Leaf *returnKeyword(); + Expression *value(); }; /// for (<decl> : <init>) <body> @@ -620,8 +620,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::RangeBasedForStatement; } - syntax::Leaf *forKeyword(); - syntax::Statement *body(); + Leaf *forKeyword(); + Statement *body(); }; /// Expression in a statement position, e.g. functions calls inside compound @@ -632,7 +632,7 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ExpressionStatement; } - syntax::Expression *expression(); + Expression *expression(); }; /// { statement1; statement2; ⦠} @@ -642,10 +642,10 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::CompoundStatement; } - syntax::Leaf *lbrace(); + Leaf *lbrace(); /// FIXME: use custom iterator instead of 'vector'. - std::vector<syntax::Statement *> statements(); - syntax::Leaf *rbrace(); + std::vector<Statement *> statements(); + Leaf *rbrace(); }; /// A declaration that can appear at the top-level. Note that this does *not* @@ -687,8 +687,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::StaticAssertDeclaration; } - syntax::Expression *condition(); - syntax::Expression *message(); + Expression *condition(); + Expression *message(); }; /// extern <string-literal> declaration @@ -712,7 +712,7 @@ return N->kind() == NodeKind::SimpleDeclaration; } /// FIXME: use custom iterator instead of 'vector'. - std::vector<syntax::SimpleDeclarator *> declarators(); + std::vector<SimpleDeclarator *> declarators(); }; /// template <template-parameters> <declaration> @@ -722,8 +722,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::TemplateDeclaration; } - syntax::Leaf *templateKeyword(); - syntax::Declaration *declaration(); + Leaf *templateKeyword(); + Declaration *declaration(); }; /// template <declaration> @@ -738,9 +738,9 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ExplicitTemplateInstantiation; } - syntax::Leaf *templateKeyword(); - syntax::Leaf *externKeyword(); - syntax::Declaration *declaration(); + Leaf *templateKeyword(); + Leaf *externKeyword(); + Declaration *declaration(); }; /// namespace <name> { <decls> } @@ -830,8 +830,8 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ParenDeclarator; } - syntax::Leaf *lparen(); - syntax::Leaf *rparen(); + Leaf *lparen(); + Leaf *rparen(); }; /// Array size specified inside a declarator. @@ -845,9 +845,9 @@ return N->kind() == NodeKind::ArraySubscript; } // TODO: add an accessor for the "static" keyword. - syntax::Leaf *lbracket(); - syntax::Expression *sizeExpression(); - syntax::Leaf *rbracket(); + Leaf *lbracket(); + Expression *sizeExpression(); + Leaf *rbracket(); }; /// Trailing return type after the parameter list, including the arrow token. @@ -859,8 +859,8 @@ return N->kind() == NodeKind::TrailingReturnType; } // TODO: add accessors for specifiers. - syntax::Leaf *arrowToken(); - syntax::SimpleDeclarator *declarator(); + Leaf *arrowToken(); + SimpleDeclarator *declarator(); }; /// Parameter list for a function type and a trailing return type, if the @@ -880,11 +880,11 @@ static bool classof(const Node *N) { return N->kind() == NodeKind::ParametersAndQualifiers; } - syntax::Leaf *lparen(); + Leaf *lparen(); /// FIXME: use custom iterator instead of 'vector'. - std::vector<syntax::SimpleDeclaration *> parameters(); - syntax::Leaf *rparen(); - syntax::TrailingReturnType *trailingReturn(); + std::vector<SimpleDeclaration *> parameters(); + Leaf *rparen(); + TrailingReturnType *trailingReturn(); }; /// Member pointer inside a declarator
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits