[PATCH] D70410: Tablegen: Remove the error for duplicate include files.
River Riddle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 14:55:27 PST 2019
rriddle created this revision.
rriddle added a reviewer: mehdi_amini.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
rriddle edited the summary of this revision.
This error was originally added a while(7 years) ago when including multiple files was basically always an error. Tablegen now has preprocessor support, which allows for building nice c/c++ style include guards. With the current error being reported, we unfortunately need to double guard when including files:
- In user of MyFile.td
#ifndef MYFILE_TD
include MyFile.td
#endif
- In MyFile.td
#ifndef MYFILE_TD
#define MYFILE_TD
...
#endif
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70410
Files:
llvm/lib/TableGen/Main.cpp
llvm/lib/TableGen/TGLexer.cpp
llvm/lib/TableGen/TGLexer.h
llvm/lib/TableGen/TGParser.h
Index: llvm/lib/TableGen/TGParser.h
===================================================================
--- llvm/lib/TableGen/TGParser.h
+++ llvm/lib/TableGen/TGParser.h
@@ -129,7 +129,7 @@
bool TokError(const Twine &Msg) const {
return Error(Lex.getLoc(), Msg);
}
- const TGLexer::DependenciesMapTy &getDependencies() const {
+ const TGLexer::DependenciesSetTy &getDependencies() const {
return Lex.getDependencies();
}
Index: llvm/lib/TableGen/TGLexer.h
===================================================================
--- llvm/lib/TableGen/TGLexer.h
+++ llvm/lib/TableGen/TGLexer.h
@@ -19,7 +19,6 @@
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/SMLoc.h"
#include <cassert>
-#include <map>
#include <memory>
#include <string>
@@ -87,10 +86,11 @@
unsigned CurBuffer = 0;
public:
- typedef std::map<std::string, SMLoc> DependenciesMapTy;
+ typedef StringSet<> DependenciesSetTy;
+
private:
/// Dependencies - This is the list of all included files.
- DependenciesMapTy Dependencies;
+ DependenciesSetTy Dependencies;
public:
TGLexer(SourceMgr &SrcMgr, ArrayRef<std::string> Macros);
@@ -99,7 +99,7 @@
return CurCode = LexToken(CurPtr == CurBuf.begin());
}
- const DependenciesMapTy &getDependencies() const {
+ const DependenciesSetTy &getDependencies() const {
return Dependencies;
}
Index: llvm/lib/TableGen/TGLexer.cpp
===================================================================
--- llvm/lib/TableGen/TGLexer.cpp
+++ llvm/lib/TableGen/TGLexer.cpp
@@ -379,15 +379,7 @@
return true;
}
- DependenciesMapTy::const_iterator Found = Dependencies.find(IncludedFile);
- if (Found != Dependencies.end()) {
- PrintError(getLoc(),
- "File '" + IncludedFile + "' has already been included.");
- SrcMgr.PrintMessage(Found->second, SourceMgr::DK_Note,
- "previously included here");
- return true;
- }
- Dependencies.insert(std::make_pair(IncludedFile, getLoc()));
+ Dependencies.insert(IncludedFile);
// Save the line number and lex buffer of the includer.
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer();
CurPtr = CurBuf.begin();
Index: llvm/lib/TableGen/Main.cpp
===================================================================
--- llvm/lib/TableGen/Main.cpp
+++ llvm/lib/TableGen/Main.cpp
@@ -73,7 +73,7 @@
EC.message() + "\n");
DepOut.os() << OutputFilename << ":";
for (const auto &Dep : Parser.getDependencies()) {
- DepOut.os() << ' ' << Dep.first;
+ DepOut.os() << ' ' << Dep.first();
}
DepOut.os() << "\n";
DepOut.keep();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70410.229924.patch
Type: text/x-patch
Size: 2655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191118/91c610ea/attachment.bin>
More information about the llvm-commits
mailing list