diff options
author | Sean Silva <silvas@purdue.edu> | 2013-02-07 04:30:39 +0000 |
---|---|---|
committer | Sean Silva <silvas@purdue.edu> | 2013-02-07 04:30:39 +0000 |
commit | a170f520a990a50c35f72d81b4415dc4c3ec50de (patch) | |
tree | 084dfdbf7d3e80652163e3fa993cd57aff148c5c /lib/TableGen/TGLexer.cpp | |
parent | 65c46b0cff2a7bcefff9b58895cdf8d710e3b6f7 (diff) | |
download | llvm-a170f520a990a50c35f72d81b4415dc4c3ec50de.tar.gz llvm-a170f520a990a50c35f72d81b4415dc4c3ec50de.tar.bz2 llvm-a170f520a990a50c35f72d81b4415dc4c3ec50de.tar.xz |
tblgen: Diagnose duplicate includes.
A double inclusion will pretty much always be an error in TableGen, so
there's no point going on just to die with "def already defined" or
whatnot.
I'm not too thrilled about the "public: ... private: ..." to expose the
DependenciesMapTy, but I really didn't see a better way to keep that
type centralized. It's a smell that indicates that some refactoring is
needed to make this code more loosely coupled.
This should avoid all bugs of the same nature as PR15189.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174582 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen/TGLexer.cpp')
-rw-r--r-- | lib/TableGen/TGLexer.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/TableGen/TGLexer.cpp b/lib/TableGen/TGLexer.cpp index e75abcfa38..c6be4f8a11 100644 --- a/lib/TableGen/TGLexer.cpp +++ b/lib/TableGen/TGLexer.cpp @@ -309,7 +309,15 @@ bool TGLexer::LexInclude() { return true; } - Dependencies.push_back(IncludedFile); + 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())); // Save the line number and lex buffer of the includer. CurBuf = SrcMgr.getMemoryBuffer(CurBuffer); CurPtr = CurBuf->getBufferStart(); |