diff options
author | Sam McCall <sam.mccall@gmail.com> | 2022-03-16 01:08:02 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2022-03-16 01:10:55 +0100 |
commit | 89cd86bbc58afe7d036bdb2f656dca38b62d8ef0 (patch) | |
tree | 90fc6d26ae8b2b605ef1563d6ab4ec85559c9779 | |
parent | 049f4e4eab19c6e468e029232e94ca71245b0f56 (diff) | |
download | llvm-89cd86bbc58afe7d036bdb2f656dca38b62d8ef0.zip llvm-89cd86bbc58afe7d036bdb2f656dca38b62d8ef0.tar.gz llvm-89cd86bbc58afe7d036bdb2f656dca38b62d8ef0.tar.bz2 |
Reapply [pseudo] Move pseudoparser from clang to clang-tools-extra"
This reverts commit 049f4e4eab19c6e468e029232e94ca71245b0f56.
The problem was a stray dependency in CLANG_TEST_DEPS which caused cmake
to fail if clang-pseudo wasn't built. This is now removed.
-rw-r--r-- | clang-tools-extra/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/CMakeLists.txt | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/README.md (renamed from clang/lib/Tooling/Syntax/Pseudo/README.md) | 0 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h (renamed from clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h) | 8 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h (renamed from clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h) | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h (renamed from clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h) | 26 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h (renamed from clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h) | 8 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/include/clang-pseudo/Token.h (renamed from clang/include/clang/Tooling/Syntax/Pseudo/Token.h) | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/CMakeLists.txt (renamed from clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt) | 2 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/DirectiveMap.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp) | 8 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/Grammar.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp) | 4 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/GrammarBNF.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp) | 4 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/LRGraph.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp) | 14 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/LRTable.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp) | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/LRTableBuild.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp) | 20 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/Lex.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/Lex.cpp) | 4 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/Token.cpp (renamed from clang/lib/Tooling/Syntax/Pseudo/Token.cpp) | 4 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/lib/cxx.bnf (renamed from clang/lib/Tooling/Syntax/Pseudo/cxx.bnf) | 0 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/CMakeLists.txt | 38 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/Unit/lit.cfg.py | 19 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/Unit/lit.site.cfg.py.in | 11 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/check-cxx-bnf.test (renamed from clang/test/Syntax/check-cxx-bnf.test) | 0 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/lex.c (renamed from clang/test/Syntax/lex.c) | 0 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/lit.cfg.py | 16 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/lit.local.cfg | 2 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/lit.site.cfg.py.in | 14 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/lr-build-basic.test (renamed from clang/test/Syntax/lr-build-basic.test) | 0 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/test/lr-build-conflicts.test (renamed from clang/test/Syntax/lr-build-conflicts.test) | 0 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/tool/CMakeLists.txt (renamed from clang/tools/clang-pseudo/CMakeLists.txt) | 9 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/tool/ClangPseudo.cpp (renamed from clang/tools/clang-pseudo/ClangPseudo.cpp) | 22 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/unittests/CMakeLists.txt (renamed from clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt) | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp (renamed from clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp) | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/unittests/GrammarTest.cpp (renamed from clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp) | 4 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/unittests/LRTableTest.cpp (renamed from clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp) | 6 | ||||
-rw-r--r-- | clang-tools-extra/pseudo/unittests/TokenTest.cpp (renamed from clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp) | 4 | ||||
-rw-r--r-- | clang/lib/Tooling/Syntax/CMakeLists.txt | 2 | ||||
-rw-r--r-- | clang/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang/test/Syntax/lit.local.cfg | 4 | ||||
-rw-r--r-- | clang/tools/CMakeLists.txt | 1 | ||||
-rw-r--r-- | clang/unittests/Tooling/Syntax/CMakeLists.txt | 2 |
40 files changed, 178 insertions, 116 deletions
diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt index 7b8274a..285e552 100644 --- a/clang-tools-extra/CMakeLists.txt +++ b/clang-tools-extra/CMakeLists.txt @@ -15,6 +15,7 @@ add_subdirectory(clang-include-fixer) add_subdirectory(clang-move) add_subdirectory(clang-query) add_subdirectory(pp-trace) +add_subdirectory(pseudo) add_subdirectory(tool-template) # Add the common testsuite after all the tools. diff --git a/clang-tools-extra/pseudo/CMakeLists.txt b/clang-tools-extra/pseudo/CMakeLists.txt new file mode 100644 index 0000000..a10884a --- /dev/null +++ b/clang-tools-extra/pseudo/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(include) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) +add_subdirectory(lib) +add_subdirectory(tool) +add_subdirectory(unittests) +add_subdirectory(test) diff --git a/clang/lib/Tooling/Syntax/Pseudo/README.md b/clang-tools-extra/pseudo/README.md index 0958f5d..0958f5d 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/README.md +++ b/clang-tools-extra/pseudo/README.md diff --git a/clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h index 177302d..e95f5fb 100644 --- a/clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h @@ -25,16 +25,15 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLING_SYNTAX_PREPROCESS_H -#define LLVM_CLANG_TOOLING_SYNTAX_PREPROCESS_H +#ifndef CLANG_PSEUDO_DIRECTIVEMAP_H +#define CLANG_PSEUDO_DIRECTIVEMAP_H +#include "clang-pseudo/Token.h" #include "clang/Basic/TokenKinds.h" -#include "clang/Tooling/Syntax/Pseudo/Token.h" #include <vector> namespace clang { class LangOptions; -namespace syntax { namespace pseudo { /// Describes the structure of a source file, as seen by the preprocessor. @@ -142,7 +141,6 @@ private: }; } // namespace pseudo -} // namespace syntax } // namespace clang #endif diff --git a/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h index 086809e..d7bbee3 100644 --- a/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h @@ -33,8 +33,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H -#define LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H +#ifndef CLANG_PSEUDO_GRAMMAR_H +#define CLANG_PSEUDO_GRAMMAR_H #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" @@ -44,7 +44,6 @@ #include <vector> namespace clang { -namespace syntax { namespace pseudo { // A SymbolID uniquely identifies a terminal/non-terminal symbol in a grammar. // Non-terminal IDs are indexes into a table of non-terminal symbols. @@ -178,7 +177,6 @@ struct GrammarTable { }; } // namespace pseudo -} // namespace syntax } // namespace clang #endif // LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H diff --git a/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h b/clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h index 1de15b7..ba244d8 100644 --- a/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h @@ -28,15 +28,14 @@ // in making decisions. //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRGRAPH_H -#define LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRGRAPH_H +#ifndef CLANG_PSEUDO_LRGRAPH_H +#define CLANG_PSEUDO_LRGRAPH_H -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" +#include "clang-pseudo/Grammar.h" #include "llvm/ADT/Hashing.h" #include <vector> namespace clang { -namespace syntax { namespace pseudo { // An LR item -- a grammar rule with a dot at some position of the body. @@ -152,23 +151,22 @@ private: }; } // namespace pseudo -} // namespace syntax } // namespace clang namespace llvm { -// Support clang::syntax::pseudo::Item as DenseMap keys. -template <> struct DenseMapInfo<clang::syntax::pseudo::Item> { - static inline clang::syntax::pseudo::Item getEmptyKey() { - return clang::syntax::pseudo::Item::sentinel(-1); +// Support clang::pseudo::Item as DenseMap keys. +template <> struct DenseMapInfo<clang::pseudo::Item> { + static inline clang::pseudo::Item getEmptyKey() { + return clang::pseudo::Item::sentinel(-1); } - static inline clang::syntax::pseudo::Item getTombstoneKey() { - return clang::syntax::pseudo::Item::sentinel(-2); + static inline clang::pseudo::Item getTombstoneKey() { + return clang::pseudo::Item::sentinel(-2); } - static unsigned getHashValue(const clang::syntax::pseudo::Item &I) { + static unsigned getHashValue(const clang::pseudo::Item &I) { return hash_value(I); } - static bool isEqual(const clang::syntax::pseudo::Item &LHS, - const clang::syntax::pseudo::Item &RHS) { + static bool isEqual(const clang::pseudo::Item &LHS, + const clang::pseudo::Item &RHS) { return LHS == RHS; } }; diff --git a/clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h b/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h index 025f7f1..b7e166ae 100644 --- a/clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h @@ -34,16 +34,15 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRTABLE_H -#define LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRTABLE_H +#ifndef CLANG_PSEUDO_LRTABLE_H +#define CLANG_PSEUDO_LRTABLE_H -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" +#include "clang-pseudo/Grammar.h" #include "llvm/ADT/ArrayRef.h" #include <cstdint> #include <vector> namespace clang { -namespace syntax { namespace pseudo { // Represents the LR parsing table, which can efficiently the question "what is @@ -176,7 +175,6 @@ private: llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LRTable::Action &); } // namespace pseudo -} // namespace syntax } // namespace clang #endif // LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRTABLE_H diff --git a/clang/include/clang/Tooling/Syntax/Pseudo/Token.h b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h index a54146c..69c75329c 100644 --- a/clang/include/clang/Tooling/Syntax/Pseudo/Token.h +++ b/clang-tools-extra/pseudo/include/clang-pseudo/Token.h @@ -25,8 +25,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLING_SYNTAX_TOKEN_H -#define LLVM_CLANG_TOOLING_SYNTAX_TOKEN_H +#ifndef CLANG_PSEUDO_TOKEN_H +#define CLANG_PSEUDO_TOKEN_H #include "clang/Basic/LLVM.h" #include "clang/Basic/TokenKinds.h" @@ -39,7 +39,6 @@ namespace clang { class LangOptions; -namespace syntax { namespace pseudo { /// A single C++ or preprocessor token. @@ -199,7 +198,6 @@ TokenStream cook(const TokenStream &, const clang::LangOptions &); TokenStream stripComments(const TokenStream &); } // namespace pseudo -} // namespace syntax } // namespace clang #endif diff --git a/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt b/clang-tools-extra/pseudo/lib/CMakeLists.txt index 1e00905..7239a58 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt +++ b/clang-tools-extra/pseudo/lib/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_LINK_COMPONENTS Support) -add_clang_library(clangToolingSyntaxPseudo +add_clang_library(clangPseudo DirectiveMap.cpp Grammar.cpp GrammarBNF.cpp diff --git a/clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp b/clang-tools-extra/pseudo/lib/DirectiveMap.cpp index 06a3b44..6e66708 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp +++ b/clang-tools-extra/pseudo/lib/DirectiveMap.cpp @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/DirectiveMap.h" +#include "clang-pseudo/DirectiveMap.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/TokenKinds.h" #include "llvm/Support/FormatVariadic.h" namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -151,8 +150,8 @@ DirectiveMap DirectiveMap::parse(const TokenStream &Code) { } static void dump(llvm::raw_ostream &OS, const DirectiveMap &, unsigned Indent); -static void dump(llvm::raw_ostream &OS, const DirectiveMap::Directive &Directive, - unsigned Indent) { +static void dump(llvm::raw_ostream &OS, + const DirectiveMap::Directive &Directive, unsigned Indent) { OS.indent(Indent) << llvm::formatv("#{0} ({1} tokens)\n", tok::getPPKeywordSpelling(Directive.Kind), Directive.Tokens.size()); @@ -205,5 +204,4 @@ OSTREAM_DUMP(DirectiveMap::Code) #undef OSTREAM_DUMP } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp b/clang-tools-extra/pseudo/lib/Grammar.cpp index 4f1a511..542d30c 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp +++ b/clang-tools-extra/pseudo/lib/Grammar.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" +#include "clang-pseudo/Grammar.h" #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" @@ -15,7 +15,6 @@ #include "llvm/Support/raw_ostream.h" namespace clang { -namespace syntax { namespace pseudo { Rule::Rule(SymbolID Target, llvm::ArrayRef<SymbolID> Sequence) @@ -181,5 +180,4 @@ static llvm::ArrayRef<std::string> getTerminalNames() { GrammarTable::GrammarTable() : Terminals(getTerminalNames()) {} } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp b/clang-tools-extra/pseudo/lib/GrammarBNF.cpp index bc90a96..5e473971 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp +++ b/clang-tools-extra/pseudo/lib/GrammarBNF.cpp @@ -6,15 +6,14 @@ // //===----------------------------------------------------------------------===// +#include "clang-pseudo/Grammar.h" #include "clang/Basic/TokenKinds.h" -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/FormatVariadic.h" #include <memory> namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -244,5 +243,4 @@ Grammar::parseBNF(llvm::StringRef BNF, std::vector<std::string> &Diagnostics) { } } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp b/clang-tools-extra/pseudo/lib/LRGraph.cpp index 17e4771..edb544f 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp +++ b/clang-tools-extra/pseudo/lib/LRGraph.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/LRGraph.h" -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" +#include "clang-pseudo/LRGraph.h" +#include "clang-pseudo/Grammar.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/STLExtras.h" @@ -15,16 +15,16 @@ #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" -using ItemSet = std::vector<clang::syntax::pseudo::Item>; +using ItemSet = std::vector<clang::pseudo::Item>; namespace llvm { -// Support clang::syntax::pseudo::Item as DenseMap keys. +// Support clang::pseudo::Item as DenseMap keys. template <> struct DenseMapInfo<ItemSet> { static inline ItemSet getEmptyKey() { - return {DenseMapInfo<clang::syntax::pseudo::Item>::getEmptyKey()}; + return {DenseMapInfo<clang::pseudo::Item>::getEmptyKey()}; } static inline ItemSet getTombstoneKey() { - return {DenseMapInfo<clang::syntax::pseudo::Item>::getTombstoneKey()}; + return {DenseMapInfo<clang::pseudo::Item>::getTombstoneKey()}; } static unsigned getHashValue(const ItemSet &I) { return llvm::hash_combine_range(I.begin(), I.end()); @@ -36,7 +36,6 @@ template <> struct DenseMapInfo<ItemSet> { } // namespace llvm namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -227,5 +226,4 @@ LRGraph LRGraph::buildLR0(const Grammar &G) { } } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp b/clang-tools-extra/pseudo/lib/LRTable.cpp index 957d17a..b9ff7e4 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp +++ b/clang-tools-extra/pseudo/lib/LRTable.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/LRTable.h" -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" +#include "clang-pseudo/LRTable.h" +#include "clang-pseudo/Grammar.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ErrorHandling.h" @@ -15,7 +15,6 @@ #include "llvm/Support/raw_ostream.h" namespace clang { -namespace syntax { namespace pseudo { llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LRTable::Action &A) { @@ -122,5 +121,4 @@ llvm::ArrayRef<LRTable::Action> LRTable::find(StateID Src, SymbolID ID) const { } } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp b/clang-tools-extra/pseudo/lib/LRTableBuild.cpp index aaf9cad..cb4ea69 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp +++ b/clang-tools-extra/pseudo/lib/LRTableBuild.cpp @@ -6,23 +6,23 @@ // //===----------------------------------------------------------------------===// +#include "clang-pseudo/Grammar.h" +#include "clang-pseudo/LRGraph.h" +#include "clang-pseudo/LRTable.h" #include "clang/Basic/TokenKinds.h" -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" -#include "clang/Tooling/Syntax/Pseudo/LRGraph.h" -#include "clang/Tooling/Syntax/Pseudo/LRTable.h" #include <cstdint> namespace llvm { -template <> struct DenseMapInfo<clang::syntax::pseudo::LRTable::Entry> { - using Entry = clang::syntax::pseudo::LRTable::Entry; +template <> struct DenseMapInfo<clang::pseudo::LRTable::Entry> { + using Entry = clang::pseudo::LRTable::Entry; static inline Entry getEmptyKey() { - static Entry E{static_cast<clang::syntax::pseudo::SymbolID>(-1), 0, - clang::syntax::pseudo::LRTable::Action::sentinel()}; + static Entry E{static_cast<clang::pseudo::SymbolID>(-1), 0, + clang::pseudo::LRTable::Action::sentinel()}; return E; } static inline Entry getTombstoneKey() { - static Entry E{static_cast<clang::syntax::pseudo::SymbolID>(-2), 0, - clang::syntax::pseudo::LRTable::Action::sentinel()}; + static Entry E{static_cast<clang::pseudo::SymbolID>(-2), 0, + clang::pseudo::LRTable::Action::sentinel()}; return E; } static unsigned getHashValue(const Entry &I) { @@ -36,7 +36,6 @@ template <> struct DenseMapInfo<clang::syntax::pseudo::LRTable::Entry> { } // namespace llvm namespace clang { -namespace syntax { namespace pseudo { class LRTable::Builder { @@ -139,5 +138,4 @@ LRTable LRTable::buildSLR(const Grammar &G) { } } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/Lex.cpp b/clang-tools-extra/pseudo/lib/Lex.cpp index ac0120c..f5a2395 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/Lex.cpp +++ b/clang-tools-extra/pseudo/lib/Lex.cpp @@ -6,14 +6,13 @@ // //===----------------------------------------------------------------------===// +#include "clang-pseudo/Token.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TokenKinds.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/LiteralSupport.h" -#include "clang/Tooling/Syntax/Pseudo/Token.h" namespace clang { -namespace syntax { namespace pseudo { TokenStream lex(const std::string &Code, const clang::LangOptions &LangOpts) { @@ -110,5 +109,4 @@ TokenStream cook(const TokenStream &Code, const LangOptions &LangOpts) { } } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/Token.cpp b/clang-tools-extra/pseudo/lib/Token.cpp index e7a572a..f07c1d1 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/Token.cpp +++ b/clang-tools-extra/pseudo/lib/Token.cpp @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/Token.h" +#include "clang-pseudo/Token.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormatVariadic.h" namespace clang { -namespace syntax { namespace pseudo { llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Token &T) { @@ -105,5 +104,4 @@ TokenStream stripComments(const TokenStream &Input) { } } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/Pseudo/cxx.bnf b/clang-tools-extra/pseudo/lib/cxx.bnf index 2619ce1..2619ce1 100644 --- a/clang/lib/Tooling/Syntax/Pseudo/cxx.bnf +++ b/clang-tools-extra/pseudo/lib/cxx.bnf diff --git a/clang-tools-extra/pseudo/test/CMakeLists.txt b/clang-tools-extra/pseudo/test/CMakeLists.txt new file mode 100644 index 0000000..334acb5 --- /dev/null +++ b/clang-tools-extra/pseudo/test/CMakeLists.txt @@ -0,0 +1,38 @@ +# Set CLANG_TOOLS_DIR to buildtree/bin, or buildtree/%(build_mode)s/bin if the +# location is dynamic. The latter must be interpolated by lit configs. +# FIXME: this is duplicated in many places. +if (CMAKE_CFG_INTDIR STREQUAL ".") + set(LLVM_BUILD_MODE ".") +else () + set(LLVM_BUILD_MODE "%(build_mode)s") +endif () +string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) + +set(CLANG_PSEUDO_TEST_DEPS + clang-pseudo + ClangPseudoTests + ) + +foreach(dep FileCheck not) + if(TARGET ${dep}) + list(APPEND CLANG_PSEUDO_TEST_DEPS ${dep}) + endif() +endforeach() + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py + ) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py + ) + +add_lit_testsuite(check-clang-pseudo "Running the clang-pseudo regression tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${CLANG_PSEUDO_TEST_DEPS}) diff --git a/clang-tools-extra/pseudo/test/Unit/lit.cfg.py b/clang-tools-extra/pseudo/test/Unit/lit.cfg.py new file mode 100644 index 0000000..1ba9626 --- /dev/null +++ b/clang-tools-extra/pseudo/test/Unit/lit.cfg.py @@ -0,0 +1,19 @@ +import lit.formats +config.name = "clangPseudo Unit Tests" +config.test_format = lit.formats.GoogleTest('.', 'Tests') +config.test_source_root = config.clang_pseudo_binary_dir + "/unittests" +config.test_exec_root = config.clang_pseudo_binary_dir + "/unittests" + +# Point the dynamic loader at dynamic libraries in 'lib'. +# FIXME: it seems every project has a copy of this logic. Move it somewhere. +import platform +if platform.system() == 'Darwin': + shlibpath_var = 'DYLD_LIBRARY_PATH' +elif platform.system() == 'Windows': + shlibpath_var = 'PATH' +else: + shlibpath_var = 'LD_LIBRARY_PATH' +config.environment[shlibpath_var] = os.path.pathsep.join(( + "@SHLIBDIR@", "@LLVM_LIBS_DIR@", + config.environment.get(shlibpath_var,''))) + diff --git a/clang-tools-extra/pseudo/test/Unit/lit.site.cfg.py.in b/clang-tools-extra/pseudo/test/Unit/lit.site.cfg.py.in new file mode 100644 index 0000000..4107b0d --- /dev/null +++ b/clang-tools-extra/pseudo/test/Unit/lit.site.cfg.py.in @@ -0,0 +1,11 @@ +@LIT_SITE_CFG_IN_HEADER@ +# This is a shim to run the gtest unittests in ../unittests using lit. + +config.llvm_libs_dir = "@LLVM_LIBS_DIR@" +config.shlibdir = "@SHLIBDIR@" + +config.clang_pseudo_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.." +config.clang_pseudo_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.." + +# Delegate logic to lit.cfg.py. +lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/Unit/lit.cfg.py") diff --git a/clang/test/Syntax/check-cxx-bnf.test b/clang-tools-extra/pseudo/test/check-cxx-bnf.test index e7e71942..e7e71942 100644 --- a/clang/test/Syntax/check-cxx-bnf.test +++ b/clang-tools-extra/pseudo/test/check-cxx-bnf.test diff --git a/clang/test/Syntax/lex.c b/clang-tools-extra/pseudo/test/lex.c index 39b114e..39b114e 100644 --- a/clang/test/Syntax/lex.c +++ b/clang-tools-extra/pseudo/test/lex.c diff --git a/clang-tools-extra/pseudo/test/lit.cfg.py b/clang-tools-extra/pseudo/test/lit.cfg.py new file mode 100644 index 0000000..d92c95c --- /dev/null +++ b/clang-tools-extra/pseudo/test/lit.cfg.py @@ -0,0 +1,16 @@ +import lit.llvm + +lit.llvm.initialize(lit_config, config) +lit.llvm.llvm_config.use_default_substitutions() + +config.name = 'ClangPseudo' +config.suffixes = ['.test', '.c', '.cpp'] +config.excludes = ['Inputs'] +config.test_format = lit.formats.ShTest(not lit.llvm.llvm_config.use_lit_shell) +config.test_source_root = config.clang_pseudo_source_dir + "/test" +config.test_exec_root = config.clang_pseudo_binary_dir + "/test" + +config.environment['PATH'] = os.path.pathsep.join(( + config.clang_tools_dir, + config.llvm_tools_dir, + config.environment['PATH'])) diff --git a/clang-tools-extra/pseudo/test/lit.local.cfg b/clang-tools-extra/pseudo/test/lit.local.cfg new file mode 100644 index 0000000..899b7e1 --- /dev/null +++ b/clang-tools-extra/pseudo/test/lit.local.cfg @@ -0,0 +1,2 @@ +cxx_bnf_file = os.path.join(config.clang_pseudo_source_dir, 'lib', 'cxx.bnf') +config.substitutions.append(('%cxx-bnf-file', cxx_bnf_file)) diff --git a/clang-tools-extra/pseudo/test/lit.site.cfg.py.in b/clang-tools-extra/pseudo/test/lit.site.cfg.py.in new file mode 100644 index 0000000..2f7a095 --- /dev/null +++ b/clang-tools-extra/pseudo/test/lit.site.cfg.py.in @@ -0,0 +1,14 @@ +@LIT_SITE_CFG_IN_HEADER@ + +# Variables needed for common llvm config. +config.clang_tools_dir = "@CLANG_TOOLS_DIR@" +config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" +config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") +config.llvm_libs_dir = lit_config.substitute("@LLVM_LIBS_DIR@") +config.target_triple = "@TARGET_TRIPLE@" +config.python_executable = "@Python3_EXECUTABLE@" + +config.clang_pseudo_source_dir = "@CMAKE_CURRENT_SOURCE_DIR@/.." +config.clang_pseudo_binary_dir = "@CMAKE_CURRENT_BINARY_DIR@/.." +# Delegate logic to lit.cfg.py. +lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py") diff --git a/clang/test/Syntax/lr-build-basic.test b/clang-tools-extra/pseudo/test/lr-build-basic.test index d02fdae..d02fdae 100644 --- a/clang/test/Syntax/lr-build-basic.test +++ b/clang-tools-extra/pseudo/test/lr-build-basic.test diff --git a/clang/test/Syntax/lr-build-conflicts.test b/clang-tools-extra/pseudo/test/lr-build-conflicts.test index 4292a71..4292a71 100644 --- a/clang/test/Syntax/lr-build-conflicts.test +++ b/clang-tools-extra/pseudo/test/lr-build-conflicts.test diff --git a/clang/tools/clang-pseudo/CMakeLists.txt b/clang-tools-extra/pseudo/tool/CMakeLists.txt index c03c8c6..bf73f89 100644 --- a/clang/tools/clang-pseudo/CMakeLists.txt +++ b/clang-tools-extra/pseudo/tool/CMakeLists.txt @@ -4,12 +4,13 @@ add_clang_tool(clang-pseudo ClangPseudo.cpp ) -set(CLANG_PSEUDO_LIB_DEPS +clang_target_link_libraries(clang-pseudo + PRIVATE clangBasic - clangToolingSyntaxPseudo ) -clang_target_link_libraries(clang-pseudo +target_link_libraries(clang-pseudo PRIVATE - ${CLANG_PSEUDO_LIB_DEPS} + clangPseudo ) + diff --git a/clang/tools/clang-pseudo/ClangPseudo.cpp b/clang-tools-extra/pseudo/tool/ClangPseudo.cpp index c03cc0a..076ec5b 100644 --- a/clang/tools/clang-pseudo/ClangPseudo.cpp +++ b/clang-tools-extra/pseudo/tool/ClangPseudo.cpp @@ -6,18 +6,18 @@ // //===----------------------------------------------------------------------===// +#include "clang-pseudo/DirectiveMap.h" +#include "clang-pseudo/Grammar.h" +#include "clang-pseudo/LRGraph.h" +#include "clang-pseudo/LRTable.h" +#include "clang-pseudo/Token.h" #include "clang/Basic/LangOptions.h" -#include "clang/Tooling/Syntax/Pseudo/DirectiveMap.h" -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" -#include "clang/Tooling/Syntax/Pseudo/LRGraph.h" -#include "clang/Tooling/Syntax/Pseudo/LRTable.h" -#include "clang/Tooling/Syntax/Pseudo/Token.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/MemoryBuffer.h" -using clang::syntax::pseudo::Grammar; +using clang::pseudo::Grammar; using llvm::cl::desc; using llvm::cl::init; using llvm::cl::opt; @@ -64,19 +64,17 @@ int main(int argc, char *argv[]) { if (PrintGrammar) llvm::outs() << G->dump(); if (PrintGraph) - llvm::outs() << clang::syntax::pseudo::LRGraph::buildLR0(*G).dumpForTests( - *G); + llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G); if (PrintTable) - llvm::outs() << clang::syntax::pseudo::LRTable::buildSLR(*G).dumpForTests( - *G); + llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G); return 0; } if (Source.getNumOccurrences()) { std::string Text = readOrDie(Source); clang::LangOptions LangOpts; // FIXME: use real options. - auto Stream = clang::syntax::pseudo::lex(Text, LangOpts); - auto Structure = clang::syntax::pseudo::DirectiveMap::parse(Stream); + auto Stream = clang::pseudo::lex(Text, LangOpts); + auto Structure = clang::pseudo::DirectiveMap::parse(Stream); if (PrintDirectiveMap) llvm::outs() << Structure; diff --git a/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt b/clang-tools-extra/pseudo/unittests/CMakeLists.txt index 0ece44a..e4919f8 100644 --- a/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt +++ b/clang-tools-extra/pseudo/unittests/CMakeLists.txt @@ -2,7 +2,8 @@ set(LLVM_LINK_COMPONENTS Support ) -add_clang_unittest(ClangPseudoTests +add_custom_target(ClangPseudoUnitTests) +add_unittest(ClangPseudoUnitTests ClangPseudoTests DirectiveMapTest.cpp GrammarTest.cpp LRTableTest.cpp @@ -13,11 +14,10 @@ clang_target_link_libraries(ClangPseudoTests PRIVATE clangBasic clangLex - clangToolingSyntaxPseudo clangTesting ) target_link_libraries(ClangPseudoTests PRIVATE - LLVMTestingSupport + clangPseudo ) diff --git a/clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp b/clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp index 1c3220b..1feae34 100644 --- a/clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp +++ b/clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp @@ -6,18 +6,17 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/DirectiveMap.h" +#include "clang-pseudo/DirectiveMap.h" +#include "clang-pseudo/Token.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/TokenKinds.h" -#include "clang/Tooling/Syntax/Pseudo/Token.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "gmock/gmock.h" #include "gtest/gtest.h" namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -148,5 +147,4 @@ TEST(DirectiveMap, ParseBroken) { } // namespace } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp b/clang-tools-extra/pseudo/unittests/GrammarTest.cpp index 1b928b3..2a10706 100644 --- a/clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp +++ b/clang-tools-extra/pseudo/unittests/GrammarTest.cpp @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" +#include "clang-pseudo/Grammar.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include <memory> namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -157,5 +156,4 @@ simple-type-specifier := INT } // namespace } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp b/clang-tools-extra/pseudo/unittests/LRTableTest.cpp index 88ac697..9823159 100644 --- a/clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp +++ b/clang-tools-extra/pseudo/unittests/LRTableTest.cpp @@ -6,15 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/LRTable.h" +#include "clang-pseudo/LRTable.h" +#include "clang-pseudo/Grammar.h" #include "clang/Basic/TokenKinds.h" -#include "clang/Tooling/Syntax/Pseudo/Grammar.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include <vector> namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -52,5 +51,4 @@ TEST(LRTable, Builder) { } // namespace } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp b/clang-tools-extra/pseudo/unittests/TokenTest.cpp index c431457..1357d23 100644 --- a/clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp +++ b/clang-tools-extra/pseudo/unittests/TokenTest.cpp @@ -6,14 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "clang/Tooling/Syntax/Pseudo/Token.h" +#include "clang-pseudo/Token.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/TokenKinds.h" #include "gmock/gmock.h" #include "gtest/gtest.h" namespace clang { -namespace syntax { namespace pseudo { namespace { @@ -191,5 +190,4 @@ TEST(TokenTest, DropComments) { } // namespace } // namespace pseudo -} // namespace syntax } // namespace clang diff --git a/clang/lib/Tooling/Syntax/CMakeLists.txt b/clang/lib/Tooling/Syntax/CMakeLists.txt index f8d9184..e933fae 100644 --- a/clang/lib/Tooling/Syntax/CMakeLists.txt +++ b/clang/lib/Tooling/Syntax/CMakeLists.txt @@ -19,5 +19,3 @@ add_clang_library(clangToolingSyntax DEPENDS omp_gen ) - -add_subdirectory(Pseudo) diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 15b3847..d7cc8d2 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -76,7 +76,6 @@ list(APPEND CLANG_TEST_DEPS clang-repl clang-diff clang-scan-deps - clang-pseudo diagtool hmaptool ) diff --git a/clang/test/Syntax/lit.local.cfg b/clang/test/Syntax/lit.local.cfg deleted file mode 100644 index 5a2e1cd..0000000 --- a/clang/test/Syntax/lit.local.cfg +++ /dev/null @@ -1,4 +0,0 @@ -cxx_bnf_file = os.path.join(config.clang_src_dir, 'lib', 'Tooling', 'Syntax', - 'Pseudo', 'cxx.bnf') -config.substitutions.append(('%cxx-bnf-file', - '%s' % (cxx_bnf_file))) diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt index 933b428..b071a77 100644 --- a/clang/tools/CMakeLists.txt +++ b/clang/tools/CMakeLists.txt @@ -14,7 +14,6 @@ add_clang_subdirectory(clang-offload-bundler) add_clang_subdirectory(clang-offload-wrapper) add_clang_subdirectory(clang-scan-deps) add_clang_subdirectory(clang-repl) -add_clang_subdirectory(clang-pseudo) add_clang_subdirectory(c-index-test) diff --git a/clang/unittests/Tooling/Syntax/CMakeLists.txt b/clang/unittests/Tooling/Syntax/CMakeLists.txt index a21d558..174f3e7 100644 --- a/clang/unittests/Tooling/Syntax/CMakeLists.txt +++ b/clang/unittests/Tooling/Syntax/CMakeLists.txt @@ -28,5 +28,3 @@ target_link_libraries(SyntaxTests PRIVATE LLVMTestingSupport ) - -add_subdirectory(Pseudo) |