Author: Sam McCall Date: 2022-03-16T01:06:24+01:00 New Revision: 049f4e4eab19c6e468e029232e94ca71245b0f56
URL: https://github.com/llvm/llvm-project/commit/049f4e4eab19c6e468e029232e94ca71245b0f56 DIFF: https://github.com/llvm/llvm-project/commit/049f4e4eab19c6e468e029232e94ca71245b0f56.diff LOG: Revert "[pseudo] Move pseudoparser from clang to clang-tools-extra" This reverts commit b97856c4cfe7efb13887d5691002a7aa38440924. Breaks a bunch of bots: https://lab.llvm.org/buildbot/#/builders/193/builds/8513 Added: clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h clang/include/clang/Tooling/Syntax/Pseudo/Token.h clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp clang/lib/Tooling/Syntax/Pseudo/Lex.cpp clang/lib/Tooling/Syntax/Pseudo/README.md clang/lib/Tooling/Syntax/Pseudo/Token.cpp clang/lib/Tooling/Syntax/Pseudo/cxx.bnf clang/test/Syntax/check-cxx-bnf.test clang/test/Syntax/lex.c clang/test/Syntax/lit.local.cfg clang/test/Syntax/lr-build-basic.test clang/test/Syntax/lr-build-conflicts.test clang/tools/clang-pseudo/CMakeLists.txt clang/tools/clang-pseudo/ClangPseudo.cpp clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp Modified: clang-tools-extra/CMakeLists.txt clang/lib/Tooling/Syntax/CMakeLists.txt clang/tools/CMakeLists.txt clang/unittests/Tooling/Syntax/CMakeLists.txt Removed: clang-tools-extra/pseudo/CMakeLists.txt clang-tools-extra/pseudo/README.md clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h clang-tools-extra/pseudo/include/clang-pseudo/Token.h clang-tools-extra/pseudo/lib/CMakeLists.txt clang-tools-extra/pseudo/lib/DirectiveMap.cpp clang-tools-extra/pseudo/lib/Grammar.cpp clang-tools-extra/pseudo/lib/GrammarBNF.cpp clang-tools-extra/pseudo/lib/LRGraph.cpp clang-tools-extra/pseudo/lib/LRTable.cpp clang-tools-extra/pseudo/lib/LRTableBuild.cpp clang-tools-extra/pseudo/lib/Lex.cpp clang-tools-extra/pseudo/lib/Token.cpp clang-tools-extra/pseudo/lib/cxx.bnf clang-tools-extra/pseudo/test/CMakeLists.txt clang-tools-extra/pseudo/test/Unit/lit.cfg.py clang-tools-extra/pseudo/test/Unit/lit.site.cfg.py.in clang-tools-extra/pseudo/test/check-cxx-bnf.test clang-tools-extra/pseudo/test/lex.c clang-tools-extra/pseudo/test/lit.cfg.py clang-tools-extra/pseudo/test/lit.local.cfg clang-tools-extra/pseudo/test/lit.site.cfg.py.in clang-tools-extra/pseudo/test/lr-build-basic.test clang-tools-extra/pseudo/test/lr-build-conflicts.test clang-tools-extra/pseudo/tool/CMakeLists.txt clang-tools-extra/pseudo/tool/ClangPseudo.cpp clang-tools-extra/pseudo/unittests/CMakeLists.txt clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp clang-tools-extra/pseudo/unittests/GrammarTest.cpp clang-tools-extra/pseudo/unittests/LRTableTest.cpp clang-tools-extra/pseudo/unittests/TokenTest.cpp ################################################################################ diff --git a/clang-tools-extra/CMakeLists.txt b/clang-tools-extra/CMakeLists.txt index 285e5529e6fc6..7b8274a97336b 100644 --- a/clang-tools-extra/CMakeLists.txt +++ b/clang-tools-extra/CMakeLists.txt @@ -15,7 +15,6 @@ 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 deleted file mode 100644 index a10884ad406b9..0000000000000 --- a/clang-tools-extra/pseudo/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -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-tools-extra/pseudo/test/CMakeLists.txt b/clang-tools-extra/pseudo/test/CMakeLists.txt deleted file mode 100644 index 334acb58d41c2..0000000000000 --- a/clang-tools-extra/pseudo/test/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# 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 deleted file mode 100644 index 1ba9626e489ad..0000000000000 --- a/clang-tools-extra/pseudo/test/Unit/lit.cfg.py +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 4107b0d2eb83f..0000000000000 --- a/clang-tools-extra/pseudo/test/Unit/lit.site.cfg.py.in +++ /dev/null @@ -1,11 +0,0 @@ -@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-tools-extra/pseudo/test/lit.cfg.py b/clang-tools-extra/pseudo/test/lit.cfg.py deleted file mode 100644 index d92c95c80b5f1..0000000000000 --- a/clang-tools-extra/pseudo/test/lit.cfg.py +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 899b7e159a7f4..0000000000000 --- a/clang-tools-extra/pseudo/test/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 2f7a095736ecb..0000000000000 --- a/clang-tools-extra/pseudo/test/lit.site.cfg.py.in +++ /dev/null @@ -1,14 +0,0 @@ -@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-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h b/clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h similarity index 96% rename from clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h rename to clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h index e95f5fbfb720c..177302d9bae7a 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/DirectiveMap.h +++ b/clang/include/clang/Tooling/Syntax/Pseudo/DirectiveMap.h @@ -25,15 +25,16 @@ // //===----------------------------------------------------------------------===// -#ifndef CLANG_PSEUDO_DIRECTIVEMAP_H -#define CLANG_PSEUDO_DIRECTIVEMAP_H +#ifndef LLVM_CLANG_TOOLING_SYNTAX_PREPROCESS_H +#define LLVM_CLANG_TOOLING_SYNTAX_PREPROCESS_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. @@ -141,6 +142,7 @@ class DirectiveMap::Chunk { }; } // namespace pseudo +} // namespace syntax } // namespace clang #endif diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h b/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h similarity index 98% rename from clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h rename to clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h index d7bbee35ce0b9..086809ef41423 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h +++ b/clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h @@ -33,8 +33,8 @@ // //===----------------------------------------------------------------------===// -#ifndef CLANG_PSEUDO_GRAMMAR_H -#define CLANG_PSEUDO_GRAMMAR_H +#ifndef LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H +#define LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" @@ -44,6 +44,7 @@ #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. @@ -177,6 +178,7 @@ struct GrammarTable { }; } // namespace pseudo +} // namespace syntax } // namespace clang #endif // LLVM_CLANG_TOOLING_SYNTAX_GRAMMAR_H diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h b/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h similarity index 88% rename from clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h rename to clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h index ba244d83a4293..1de15b79ee40f 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h +++ b/clang/include/clang/Tooling/Syntax/Pseudo/LRGraph.h @@ -28,14 +28,15 @@ // in making decisions. //===----------------------------------------------------------------------===// -#ifndef CLANG_PSEUDO_LRGRAPH_H -#define CLANG_PSEUDO_LRGRAPH_H +#ifndef LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRGRAPH_H +#define LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRGRAPH_H -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/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. @@ -151,22 +152,23 @@ class LRGraph { }; } // namespace pseudo +} // namespace syntax } // namespace clang namespace llvm { -// 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); +// 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); } - static inline clang::pseudo::Item getTombstoneKey() { - return clang::pseudo::Item::sentinel(-2); + static inline clang::syntax::pseudo::Item getTombstoneKey() { + return clang::syntax::pseudo::Item::sentinel(-2); } - static unsigned getHashValue(const clang::pseudo::Item &I) { + static unsigned getHashValue(const clang::syntax::pseudo::Item &I) { return hash_value(I); } - static bool isEqual(const clang::pseudo::Item &LHS, - const clang::pseudo::Item &RHS) { + static bool isEqual(const clang::syntax::pseudo::Item &LHS, + const clang::syntax::pseudo::Item &RHS) { return LHS == RHS; } }; diff --git a/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h b/clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h similarity index 97% rename from clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h rename to clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h index b7e166ae30d5e..025f7f141633a 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h +++ b/clang/include/clang/Tooling/Syntax/Pseudo/LRTable.h @@ -34,15 +34,16 @@ // //===----------------------------------------------------------------------===// -#ifndef CLANG_PSEUDO_LRTABLE_H -#define CLANG_PSEUDO_LRTABLE_H +#ifndef LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRTABLE_H +#define LLVM_CLANG_TOOLING_SYNTAX_PSEUDO_LRTABLE_H -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/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 @@ -175,6 +176,7 @@ class LRTable { 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-tools-extra/pseudo/include/clang-pseudo/Token.h b/clang/include/clang/Tooling/Syntax/Pseudo/Token.h similarity index 98% rename from clang-tools-extra/pseudo/include/clang-pseudo/Token.h rename to clang/include/clang/Tooling/Syntax/Pseudo/Token.h index 69c75329c91e4..a54146c2f6f32 100644 --- a/clang-tools-extra/pseudo/include/clang-pseudo/Token.h +++ b/clang/include/clang/Tooling/Syntax/Pseudo/Token.h @@ -25,8 +25,8 @@ // //===----------------------------------------------------------------------===// -#ifndef CLANG_PSEUDO_TOKEN_H -#define CLANG_PSEUDO_TOKEN_H +#ifndef LLVM_CLANG_TOOLING_SYNTAX_TOKEN_H +#define LLVM_CLANG_TOOLING_SYNTAX_TOKEN_H #include "clang/Basic/LLVM.h" #include "clang/Basic/TokenKinds.h" @@ -39,6 +39,7 @@ namespace clang { class LangOptions; +namespace syntax { namespace pseudo { /// A single C++ or preprocessor token. @@ -198,6 +199,7 @@ 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/CMakeLists.txt b/clang/lib/Tooling/Syntax/CMakeLists.txt index e933faeb0f506..f8d9184977e8a 100644 --- a/clang/lib/Tooling/Syntax/CMakeLists.txt +++ b/clang/lib/Tooling/Syntax/CMakeLists.txt @@ -19,3 +19,5 @@ add_clang_library(clangToolingSyntax DEPENDS omp_gen ) + +add_subdirectory(Pseudo) diff --git a/clang-tools-extra/pseudo/lib/CMakeLists.txt b/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt similarity index 81% rename from clang-tools-extra/pseudo/lib/CMakeLists.txt rename to clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt index 7239a58bc85f2..1e00905731c83 100644 --- a/clang-tools-extra/pseudo/lib/CMakeLists.txt +++ b/clang/lib/Tooling/Syntax/Pseudo/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_LINK_COMPONENTS Support) -add_clang_library(clangPseudo +add_clang_library(clangToolingSyntaxPseudo DirectiveMap.cpp Grammar.cpp GrammarBNF.cpp diff --git a/clang-tools-extra/pseudo/lib/DirectiveMap.cpp b/clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp similarity index 97% rename from clang-tools-extra/pseudo/lib/DirectiveMap.cpp rename to clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp index 6e66708818954..06a3b4400cf39 100644 --- a/clang-tools-extra/pseudo/lib/DirectiveMap.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/DirectiveMap.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/DirectiveMap.h" +#include "clang/Tooling/Syntax/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 { @@ -150,8 +151,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()); @@ -204,4 +205,5 @@ OSTREAM_DUMP(DirectiveMap::Code) #undef OSTREAM_DUMP } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/Grammar.cpp b/clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp similarity index 98% rename from clang-tools-extra/pseudo/lib/Grammar.cpp rename to clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp index 542d30c7c5051..4f1a5111ea73c 100644 --- a/clang-tools-extra/pseudo/lib/Grammar.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/Grammar.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/Pseudo/Grammar.h" #include "clang/Basic/TokenKinds.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" @@ -15,6 +15,7 @@ #include "llvm/Support/raw_ostream.h" namespace clang { +namespace syntax { namespace pseudo { Rule::Rule(SymbolID Target, llvm::ArrayRef<SymbolID> Sequence) @@ -180,4 +181,5 @@ static llvm::ArrayRef<std::string> getTerminalNames() { GrammarTable::GrammarTable() : Terminals(getTerminalNames()) {} } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/GrammarBNF.cpp b/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp similarity index 98% rename from clang-tools-extra/pseudo/lib/GrammarBNF.cpp rename to clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp index 5e4739719eacd..bc90a9674d9ef 100644 --- a/clang-tools-extra/pseudo/lib/GrammarBNF.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp @@ -6,14 +6,15 @@ // //===----------------------------------------------------------------------===// -#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 { @@ -243,4 +244,5 @@ Grammar::parseBNF(llvm::StringRef BNF, std::vector<std::string> &Diagnostics) { } } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/LRGraph.cpp b/clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp similarity index 94% rename from clang-tools-extra/pseudo/lib/LRGraph.cpp rename to clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp index edb544fef4940..17e47718812ad 100644 --- a/clang-tools-extra/pseudo/lib/LRGraph.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/LRGraph.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/LRGraph.h" -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/Pseudo/LRGraph.h" +#include "clang/Tooling/Syntax/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::pseudo::Item>; +using ItemSet = std::vector<clang::syntax::pseudo::Item>; namespace llvm { -// Support clang::pseudo::Item as DenseMap keys. +// Support clang::syntax::pseudo::Item as DenseMap keys. template <> struct DenseMapInfo<ItemSet> { static inline ItemSet getEmptyKey() { - return {DenseMapInfo<clang::pseudo::Item>::getEmptyKey()}; + return {DenseMapInfo<clang::syntax::pseudo::Item>::getEmptyKey()}; } static inline ItemSet getTombstoneKey() { - return {DenseMapInfo<clang::pseudo::Item>::getTombstoneKey()}; + return {DenseMapInfo<clang::syntax::pseudo::Item>::getTombstoneKey()}; } static unsigned getHashValue(const ItemSet &I) { return llvm::hash_combine_range(I.begin(), I.end()); @@ -36,6 +36,7 @@ template <> struct DenseMapInfo<ItemSet> { } // namespace llvm namespace clang { +namespace syntax { namespace pseudo { namespace { @@ -226,4 +227,5 @@ LRGraph LRGraph::buildLR0(const Grammar &G) { } } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/LRTable.cpp b/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp similarity index 97% rename from clang-tools-extra/pseudo/lib/LRTable.cpp rename to clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp index b9ff7e4aca6a9..957d17a503cf0 100644 --- a/clang-tools-extra/pseudo/lib/LRTable.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/LRTable.h" -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/Pseudo/LRTable.h" +#include "clang/Tooling/Syntax/Pseudo/Grammar.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ErrorHandling.h" @@ -15,6 +15,7 @@ #include "llvm/Support/raw_ostream.h" namespace clang { +namespace syntax { namespace pseudo { llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const LRTable::Action &A) { @@ -121,4 +122,5 @@ llvm::ArrayRef<LRTable::Action> LRTable::find(StateID Src, SymbolID ID) const { } } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/LRTableBuild.cpp b/clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp similarity index 88% rename from clang-tools-extra/pseudo/lib/LRTableBuild.cpp rename to clang/lib/Tooling/Syntax/Pseudo/LRTableBuild.cpp index cb4ea698c4bb8..aaf9cad31961f 100644 --- a/clang-tools-extra/pseudo/lib/LRTableBuild.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/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::pseudo::LRTable::Entry> { - using Entry = clang::pseudo::LRTable::Entry; +template <> struct DenseMapInfo<clang::syntax::pseudo::LRTable::Entry> { + using Entry = clang::syntax::pseudo::LRTable::Entry; static inline Entry getEmptyKey() { - static Entry E{static_cast<clang::pseudo::SymbolID>(-1), 0, - clang::pseudo::LRTable::Action::sentinel()}; + static Entry E{static_cast<clang::syntax::pseudo::SymbolID>(-1), 0, + clang::syntax::pseudo::LRTable::Action::sentinel()}; return E; } static inline Entry getTombstoneKey() { - static Entry E{static_cast<clang::pseudo::SymbolID>(-2), 0, - clang::pseudo::LRTable::Action::sentinel()}; + static Entry E{static_cast<clang::syntax::pseudo::SymbolID>(-2), 0, + clang::syntax::pseudo::LRTable::Action::sentinel()}; return E; } static unsigned getHashValue(const Entry &I) { @@ -36,6 +36,7 @@ template <> struct DenseMapInfo<clang::pseudo::LRTable::Entry> { } // namespace llvm namespace clang { +namespace syntax { namespace pseudo { class LRTable::Builder { @@ -138,4 +139,5 @@ LRTable LRTable::buildSLR(const Grammar &G) { } } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/Lex.cpp b/clang/lib/Tooling/Syntax/Pseudo/Lex.cpp similarity index 97% rename from clang-tools-extra/pseudo/lib/Lex.cpp rename to clang/lib/Tooling/Syntax/Pseudo/Lex.cpp index f5a239533c532..ac0120cb9e473 100644 --- a/clang-tools-extra/pseudo/lib/Lex.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/Lex.cpp @@ -6,13 +6,14 @@ // //===----------------------------------------------------------------------===// -#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) { @@ -109,4 +110,5 @@ TokenStream cook(const TokenStream &Code, const LangOptions &LangOpts) { } } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/README.md b/clang/lib/Tooling/Syntax/Pseudo/README.md similarity index 100% rename from clang-tools-extra/pseudo/README.md rename to clang/lib/Tooling/Syntax/Pseudo/README.md diff --git a/clang-tools-extra/pseudo/lib/Token.cpp b/clang/lib/Tooling/Syntax/Pseudo/Token.cpp similarity index 97% rename from clang-tools-extra/pseudo/lib/Token.cpp rename to clang/lib/Tooling/Syntax/Pseudo/Token.cpp index f07c1d1b272df..e7a572a0c5d90 100644 --- a/clang-tools-extra/pseudo/lib/Token.cpp +++ b/clang/lib/Tooling/Syntax/Pseudo/Token.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/Token.h" +#include "clang/Tooling/Syntax/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) { @@ -104,4 +105,5 @@ TokenStream stripComments(const TokenStream &Input) { } } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/lib/cxx.bnf b/clang/lib/Tooling/Syntax/Pseudo/cxx.bnf similarity index 100% rename from clang-tools-extra/pseudo/lib/cxx.bnf rename to clang/lib/Tooling/Syntax/Pseudo/cxx.bnf diff --git a/clang-tools-extra/pseudo/test/check-cxx-bnf.test b/clang/test/Syntax/check-cxx-bnf.test similarity index 100% rename from clang-tools-extra/pseudo/test/check-cxx-bnf.test rename to clang/test/Syntax/check-cxx-bnf.test diff --git a/clang-tools-extra/pseudo/test/lex.c b/clang/test/Syntax/lex.c similarity index 100% rename from clang-tools-extra/pseudo/test/lex.c rename to clang/test/Syntax/lex.c diff --git a/clang/test/Syntax/lit.local.cfg b/clang/test/Syntax/lit.local.cfg new file mode 100644 index 0000000000000..5a2e1cd0efd03 --- /dev/null +++ b/clang/test/Syntax/lit.local.cfg @@ -0,0 +1,4 @@ +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-extra/pseudo/test/lr-build-basic.test b/clang/test/Syntax/lr-build-basic.test similarity index 100% rename from clang-tools-extra/pseudo/test/lr-build-basic.test rename to clang/test/Syntax/lr-build-basic.test diff --git a/clang-tools-extra/pseudo/test/lr-build-conflicts.test b/clang/test/Syntax/lr-build-conflicts.test similarity index 100% rename from clang-tools-extra/pseudo/test/lr-build-conflicts.test rename to clang/test/Syntax/lr-build-conflicts.test diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt index b071a776b32ae..933b428d8ca62 100644 --- a/clang/tools/CMakeLists.txt +++ b/clang/tools/CMakeLists.txt @@ -14,6 +14,7 @@ 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-tools-extra/pseudo/tool/CMakeLists.txt b/clang/tools/clang-pseudo/CMakeLists.txt similarity index 66% rename from clang-tools-extra/pseudo/tool/CMakeLists.txt rename to clang/tools/clang-pseudo/CMakeLists.txt index bf73f89d4e1dd..c03c8c62d4cd5 100644 --- a/clang-tools-extra/pseudo/tool/CMakeLists.txt +++ b/clang/tools/clang-pseudo/CMakeLists.txt @@ -4,13 +4,12 @@ add_clang_tool(clang-pseudo ClangPseudo.cpp ) -clang_target_link_libraries(clang-pseudo - PRIVATE +set(CLANG_PSEUDO_LIB_DEPS clangBasic + clangToolingSyntaxPseudo ) -target_link_libraries(clang-pseudo +clang_target_link_libraries(clang-pseudo PRIVATE - clangPseudo + ${CLANG_PSEUDO_LIB_DEPS} ) - diff --git a/clang-tools-extra/pseudo/tool/ClangPseudo.cpp b/clang/tools/clang-pseudo/ClangPseudo.cpp similarity index 81% rename from clang-tools-extra/pseudo/tool/ClangPseudo.cpp rename to clang/tools/clang-pseudo/ClangPseudo.cpp index 076ec5b733326..c03cc0aaf8d91 100644 --- a/clang-tools-extra/pseudo/tool/ClangPseudo.cpp +++ b/clang/tools/clang-pseudo/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::pseudo::Grammar; +using clang::syntax::pseudo::Grammar; using llvm::cl::desc; using llvm::cl::init; using llvm::cl::opt; @@ -64,17 +64,19 @@ int main(int argc, char *argv[]) { if (PrintGrammar) llvm::outs() << G->dump(); if (PrintGraph) - llvm::outs() << clang::pseudo::LRGraph::buildLR0(*G).dumpForTests(*G); + llvm::outs() << clang::syntax::pseudo::LRGraph::buildLR0(*G).dumpForTests( + *G); if (PrintTable) - llvm::outs() << clang::pseudo::LRTable::buildSLR(*G).dumpForTests(*G); + llvm::outs() << clang::syntax::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::pseudo::lex(Text, LangOpts); - auto Structure = clang::pseudo::DirectiveMap::parse(Stream); + auto Stream = clang::syntax::pseudo::lex(Text, LangOpts); + auto Structure = clang::syntax::pseudo::DirectiveMap::parse(Stream); if (PrintDirectiveMap) llvm::outs() << Structure; diff --git a/clang/unittests/Tooling/Syntax/CMakeLists.txt b/clang/unittests/Tooling/Syntax/CMakeLists.txt index 174f3e7bf5732..a21d558c481cb 100644 --- a/clang/unittests/Tooling/Syntax/CMakeLists.txt +++ b/clang/unittests/Tooling/Syntax/CMakeLists.txt @@ -28,3 +28,5 @@ target_link_libraries(SyntaxTests PRIVATE LLVMTestingSupport ) + +add_subdirectory(Pseudo) diff --git a/clang-tools-extra/pseudo/unittests/CMakeLists.txt b/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt similarity index 72% rename from clang-tools-extra/pseudo/unittests/CMakeLists.txt rename to clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt index e4919f8a12212..0ece44ac19e62 100644 --- a/clang-tools-extra/pseudo/unittests/CMakeLists.txt +++ b/clang/unittests/Tooling/Syntax/Pseudo/CMakeLists.txt @@ -2,8 +2,7 @@ set(LLVM_LINK_COMPONENTS Support ) -add_custom_target(ClangPseudoUnitTests) -add_unittest(ClangPseudoUnitTests ClangPseudoTests +add_clang_unittest(ClangPseudoTests DirectiveMapTest.cpp GrammarTest.cpp LRTableTest.cpp @@ -14,10 +13,11 @@ clang_target_link_libraries(ClangPseudoTests PRIVATE clangBasic clangLex + clangToolingSyntaxPseudo clangTesting ) target_link_libraries(ClangPseudoTests PRIVATE - clangPseudo + LLVMTestingSupport ) diff --git a/clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp b/clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp similarity index 97% rename from clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp rename to clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp index 1feae342655be..1c3220b364738 100644 --- a/clang-tools-extra/pseudo/unittests/DirectiveMapTest.cpp +++ b/clang/unittests/Tooling/Syntax/Pseudo/DirectiveMapTest.cpp @@ -6,17 +6,18 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/DirectiveMap.h" +#include "clang/Tooling/Syntax/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 { @@ -147,4 +148,5 @@ TEST(DirectiveMap, ParseBroken) { } // namespace } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/unittests/GrammarTest.cpp b/clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp similarity index 98% rename from clang-tools-extra/pseudo/unittests/GrammarTest.cpp rename to clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp index 2a107063fd679..1b928b34062a5 100644 --- a/clang-tools-extra/pseudo/unittests/GrammarTest.cpp +++ b/clang/unittests/Tooling/Syntax/Pseudo/GrammarTest.cpp @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/Pseudo/Grammar.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include <memory> namespace clang { +namespace syntax { namespace pseudo { namespace { @@ -156,4 +157,5 @@ simple-type-specifier := INT } // namespace } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/unittests/LRTableTest.cpp b/clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp similarity index 93% rename from clang-tools-extra/pseudo/unittests/LRTableTest.cpp rename to clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp index 9823159e5517a..88ac697ce250d 100644 --- a/clang-tools-extra/pseudo/unittests/LRTableTest.cpp +++ b/clang/unittests/Tooling/Syntax/Pseudo/LRTableTest.cpp @@ -6,14 +6,15 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/LRTable.h" -#include "clang-pseudo/Grammar.h" +#include "clang/Tooling/Syntax/Pseudo/LRTable.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 { @@ -51,4 +52,5 @@ TEST(LRTable, Builder) { } // namespace } // namespace pseudo +} // namespace syntax } // namespace clang diff --git a/clang-tools-extra/pseudo/unittests/TokenTest.cpp b/clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp similarity index 98% rename from clang-tools-extra/pseudo/unittests/TokenTest.cpp rename to clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp index 1357d23501193..c4314570f2e9e 100644 --- a/clang-tools-extra/pseudo/unittests/TokenTest.cpp +++ b/clang/unittests/Tooling/Syntax/Pseudo/TokenTest.cpp @@ -6,13 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "clang-pseudo/Token.h" +#include "clang/Tooling/Syntax/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 { @@ -190,4 +191,5 @@ TEST(TokenTest, DropComments) { } // namespace } // namespace pseudo +} // namespace syntax } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits