llvm.org GIT mirror llvm / 3c5eaff
MCParser: Modernize memory handling. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218998 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
1 changed file(s) with 28 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
6868 MCAsmMacroParameters Parameters;
6969
7070 public:
71 MCAsmMacro(StringRef N, StringRef B, ArrayRef P) :
72 Name(N), Body(B), Parameters(P) {}
71 MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
72 : Name(N), Body(B), Parameters(std::move(P)) {}
7373 };
7474
7575 /// \brief Helper class for storing information about an active macro
120120 SourceMgr &SrcMgr;
121121 SourceMgr::DiagHandlerTy SavedDiagHandler;
122122 void *SavedDiagContext;
123 MCAsmParserExtension *PlatformParser;
123 std::unique_ptr PlatformParser;
124124
125125 /// This is the current buffer index we're lexing from as managed by the
126126 /// SourceMgr object.
135135 StringMap ExtensionDirectiveMap;
136136
137137 /// \brief Map of currently defined macros.
138 StringMap*> MacroMap;
138 StringMap> MacroMap;
139139
140140 /// \brief Stack of active macro instantiations.
141141 std::vector ActiveMacros;
261261 const MCAsmMacro* lookupMacro(StringRef Name);
262262
263263 /// \brief Define a new macro with the given name and information.
264 void defineMacro(StringRef Name, const MCAsmMacro& Macro);
264 void defineMacro(StringRef Name, MCAsmMacro Macro);
265265
266266 /// \brief Undefine a macro. If no such macro was defined, it's a no-op.
267267 void undefineMacro(StringRef Name);
501501 // Initialize the platform / file format parser.
502502 switch (_Ctx.getObjectFileInfo()->getObjectFileType()) {
503503 case MCObjectFileInfo::IsCOFF:
504 PlatformParser = createCOFFAsmParser();
505 PlatformParser->Initialize(*this);
506 break;
504 PlatformParser.reset(createCOFFAsmParser());
505 break;
507506 case MCObjectFileInfo::IsMachO:
508 PlatformParser = createDarwinAsmParser();
509 PlatformParser->Initialize(*this);
510 IsDarwin = true;
511 break;
507 PlatformParser.reset(createDarwinAsmParser());
508 IsDarwin = true;
509 break;
512510 case MCObjectFileInfo::IsELF:
513 PlatformParser = createELFAsmParser();
514 PlatformParser->Initialize(*this);
515 break;
516 }
517
511 PlatformParser.reset(createELFAsmParser());
512 break;
513 }
514
515 PlatformParser->Initialize(*this);
518516 initializeDirectiveKindMap();
519517 }
520518
521519 AsmParser::~AsmParser() {
522520 assert((HadError || ActiveMacros.empty()) &&
523521 "Unexpected active macro instantiation!");
524
525 // Destroy any macros.
526 for (StringMap::iterator it = MacroMap.begin(),
527 ie = MacroMap.end();
528 it != ie; ++it)
529 delete it->getValue();
530
531 delete PlatformParser;
532522 }
533523
534524 void AsmParser::printMacroInstantiations() {
20872077 }
20882078
20892079 const MCAsmMacro *AsmParser::lookupMacro(StringRef Name) {
2090 StringMap::iterator I = MacroMap.find(Name);
2091 return (I == MacroMap.end()) ? nullptr : I->getValue();
2092 }
2093
2094 void AsmParser::defineMacro(StringRef Name, const MCAsmMacro &Macro) {
2095 MacroMap[Name] = new MCAsmMacro(Macro);
2096 }
2097
2098 void AsmParser::undefineMacro(StringRef Name) {
2099 StringMap::iterator I = MacroMap.find(Name);
2100 if (I != MacroMap.end()) {
2101 delete I->getValue();
2102 MacroMap.erase(I);
2103 }
2104 }
2080 StringMap::iterator I = MacroMap.find(Name);
2081 return (I == MacroMap.end()) ? nullptr : &I->getValue();
2082 }
2083
2084 void AsmParser::defineMacro(StringRef Name, MCAsmMacro Macro) {
2085 MacroMap.insert(std::make_pair(Name, std::move(Macro)));
2086 }
2087
2088 void AsmParser::undefineMacro(StringRef Name) { MacroMap.erase(Name); }
21052089
21062090 bool AsmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) {
21072091 // Arbitrarily limit macro nesting depth, to match 'as'. We can eliminate
33243308 "'" + Parameter.Name + "' in macro '" + Name + "'");
33253309 }
33263310
3327 Parameters.push_back(Parameter);
3311 Parameters.push_back(std::move(Parameter));
33283312
33293313 if (getLexer().is(AsmToken::Comma))
33303314 Lex();
33763360 const char *BodyEnd = EndToken.getLoc().getPointer();
33773361 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
33783362 checkForBadMacro(DirectiveLoc, Name, Body, Parameters);
3379 defineMacro(Name, MCAsmMacro(Name, Body, Parameters));
3363 defineMacro(Name, MCAsmMacro(Name, Body, std::move(Parameters)));
33803364 return false;
33813365 }
33823366
43054289 StringRef Body = StringRef(BodyStart, BodyEnd - BodyStart);
43064290
43074291 // We Are Anonymous.
4308 MacroLikeBodies.push_back(MCAsmMacro(StringRef(), Body, None));
4292 MacroLikeBodies.push_back(
4293 MCAsmMacro(StringRef(), Body, MCAsmMacroParameters()));
43094294 return &MacroLikeBodies.back();
43104295 }
43114296