[llvm] r222957 - Replace std::map<K, V*> with std::map<K, V> to handle ownership and deletion of the values.
Craig Topper
craig.topper at gmail.com
Sat Nov 29 10:12:59 PST 2014
Author: ctopper
Date: Sat Nov 29 12:12:59 2014
New Revision: 222957
URL: http://llvm.org/viewvc/llvm-project?rev=222957&view=rev
Log:
Replace std::map<K, V*> with std::map<K, V> to handle ownership and deletion of the values.
Modified:
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/lib/TableGen/TGParser.h
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=222957&r1=222956&r2=222957&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Sat Nov 29 12:12:59 2014
@@ -459,12 +459,12 @@ MultiClass *TGParser::ParseMultiClassID(
return nullptr;
}
- MultiClass *Result = MultiClasses[Lex.getCurStrVal()];
- if (!Result)
+ auto it = MultiClasses.find(Lex.getCurStrVal());
+ if (it == MultiClasses.end())
TokError("Couldn't find multiclass '" + Lex.getCurStrVal() + "'");
Lex.Lex();
- return Result;
+ return &it->second;
}
/// ParseSubClassReference - Parse a reference to a subclass or to a templated
@@ -2290,11 +2290,13 @@ bool TGParser::ParseMultiClass() {
return TokError("expected identifier after multiclass for name");
std::string Name = Lex.getCurStrVal();
- if (MultiClasses.count(Name))
+ auto Result =
+ MultiClasses.insert(std::make_pair(Name,
+ MultiClass(Name, Lex.getLoc(),Records)));
+ if (!Result.second)
return TokError("multiclass '" + Name + "' already defined");
+ CurMultiClass = &Result.first->second;
- CurMultiClass = MultiClasses[Name] = new MultiClass(Name,
- Lex.getLoc(), Records);
Lex.Lex(); // Eat the identifier.
// If there are template args, parse them.
@@ -2555,8 +2557,9 @@ bool TGParser::ParseDefm(MultiClass *Cur
// To instantiate a multiclass, we need to first get the multiclass, then
// instantiate each def contained in the multiclass with the SubClassRef
// template parameters.
- MultiClass *MC = MultiClasses[Ref.Rec->getName()];
- assert(MC && "Didn't lookup multiclass correctly?");
+ auto it = MultiClasses.find(Ref.Rec->getName());
+ assert(it != MultiClasses.end() && "Didn't lookup multiclass correctly?");
+ MultiClass *MC = &it->second;
std::vector<Init*> &TemplateVals = Ref.TemplateArgs;
// Verify that the correct number of template arguments were specified.
Modified: llvm/trunk/lib/TableGen/TGParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.h?rev=222957&r1=222956&r2=222957&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.h (original)
+++ llvm/trunk/lib/TableGen/TGParser.h Sat Nov 29 12:12:59 2014
@@ -55,7 +55,7 @@ namespace llvm {
class TGParser {
TGLexer Lex;
std::vector<std::vector<LetRecord> > LetStack;
- std::map<std::string, MultiClass*> MultiClasses;
+ std::map<std::string, MultiClass> MultiClasses;
/// Loops - Keep track of any foreach loops we are within.
///
More information about the llvm-commits
mailing list