diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2019-08-09 02:01:10 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2019-08-09 02:01:10 +0000 |
commit | 1861f4ea25844a1a6b2f940e9f12acbaa5d63f4d (patch) | |
tree | 6b7410c06a43ba0de020062464316f1c1786d450 /clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp | |
parent | 179dc276ebc1e592fb831bb4716e1b70c7f13cd4 (diff) | |
download | bcm5719-llvm-1861f4ea25844a1a6b2f940e9f12acbaa5d63f4d.tar.gz bcm5719-llvm-1861f4ea25844a1a6b2f940e9f12acbaa5d63f4d.zip |
[clang-scan-deps] Add minimizer support for C++20 modules.
This only adds support to the minimizer, it doesn't actually capture the dependencies yet.
llvm-svn: 368381
Diffstat (limited to 'clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp')
-rw-r--r-- | clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp index 2e8c5f3a51a..4ed15ce63bc 100644 --- a/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp +++ b/clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp @@ -59,6 +59,7 @@ private: LLVM_NODISCARD bool minimizeImpl(const char *First, const char *const End); LLVM_NODISCARD bool lexPPLine(const char *&First, const char *const End); LLVM_NODISCARD bool lexAt(const char *&First, const char *const End); + LLVM_NODISCARD bool lexModule(const char *&First, const char *const End); LLVM_NODISCARD bool lexDefine(const char *&First, const char *const End); LLVM_NODISCARD bool lexPragma(const char *&First, const char *const End); LLVM_NODISCARD bool lexEndif(const char *&First, const char *const End); @@ -576,6 +577,59 @@ bool Minimizer::lexAt(const char *&First, const char *const End) { return false; } +bool Minimizer::lexModule(const char *&First, const char *const End) { + IdInfo Id = lexIdentifier(First, End); + First = Id.Last; + bool Export = false; + if (Id.Name == "export") { + Export = true; + skipWhitespace(First, End); + if (!isIdentifierBody(*First)) { + skipLine(First, End); + return false; + } + Id = lexIdentifier(First, End); + First = Id.Last; + } + + if (Id.Name != "module" && Id.Name != "import") { + skipLine(First, End); + return false; + } + + skipWhitespace(First, End); + + // Ignore this as a module directive if the next character can't be part of + // an import. + + switch (*First) { + case ':': + case '<': + case '"': + break; + default: + if (!isIdentifierBody(*First)) { + skipLine(First, End); + return false; + } + } + + if (Export) { + makeToken(cxx_export_decl); + append("export "); + } + + if (Id.Name == "module") + makeToken(cxx_module_decl); + else + makeToken(cxx_import_decl); + append(Id.Name); + append(" "); + printToNewline(First, End); + append("\n"); + return false; +} + bool Minimizer::lexDefine(const char *&First, const char *const End) { makeToken(pp_define); append("#define "); @@ -677,6 +731,18 @@ bool Minimizer::lexDefault(TokenKind Kind, StringRef Directive, return false; } +static bool isStartOfRelevantLine(char First) { + switch (First) { + case '#': + case '@': + case 'i': + case 'e': + case 'm': + return true; + } + return false; +} + bool Minimizer::lexPPLine(const char *&First, const char *const End) { assert(First != End); @@ -685,7 +751,7 @@ bool Minimizer::lexPPLine(const char *&First, const char *const End) { if (First == End) return false; - if (*First != '#' && *First != '@') { + if (!isStartOfRelevantLine(*First)) { skipLine(First, End); assert(First <= End); return false; @@ -695,6 +761,9 @@ bool Minimizer::lexPPLine(const char *&First, const char *const End) { if (*First == '@') return lexAt(First, End); + if (*First == 'i' || *First == 'e' || *First == 'm') + return lexModule(First, End); + // Handle preprocessing directives. ++First; // Skip over '#'. skipWhitespace(First, End); |