Encapsulate the MacroEnabled flag in AsmParser behind accessor methods.

The methods are also exposed via the MCAsmParser interface, which allows more
than one client to control them. Previously, GenericAsmParser was playing with
a member var in AsmParser directly (by virtue of being its friend).

llvm-svn: 172440
This commit is contained in:
Eli Bendersky 2013-01-14 18:08:41 +00:00
parent 11dfe6fe3d
commit c2f6f920b9
2 changed files with 11 additions and 4 deletions

View File

@ -136,6 +136,10 @@ public:
/// recovery.
virtual void EatToEndOfStatement() = 0;
/// Control a flag in the parser that enables or disables macros.
virtual bool MacrosEnabled() = 0;
virtual void SetMacrosEnabled(bool flag) = 0;
/// ParseExpression - Parse an arbitrary expression.
///
/// @param Res - The value of the expression. The result is undefined

View File

@ -151,7 +151,7 @@ private:
std::vector<MacroInstantiation*> ActiveMacros;
/// Boolean tracking whether macro substitution is enabled.
unsigned MacrosEnabled : 1;
unsigned MacrosEnabledFlag : 1;
/// Flag tracking whether any errors have been encountered.
unsigned HadError : 1;
@ -231,6 +231,9 @@ public:
virtual bool ParseIdentifier(StringRef &Res);
virtual void EatToEndOfStatement();
virtual bool MacrosEnabled() {return MacrosEnabledFlag;}
virtual void SetMacrosEnabled(bool flag) {MacrosEnabledFlag = flag;}
/// }
private:
@ -503,7 +506,7 @@ AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx,
MCStreamer &_Out, const MCAsmInfo &_MAI)
: Lexer(_MAI), Ctx(_Ctx), Out(_Out), MAI(_MAI), SrcMgr(_SM),
GenericParser(new GenericAsmParser), PlatformParser(0),
CurBuffer(0), MacrosEnabled(true), CppHashLineNumber(0),
CurBuffer(0), MacrosEnabledFlag(true), CppHashLineNumber(0),
AssemblerDialect(~0U), IsDarwin(false), ParsingInlineAsm(false) {
// Save the old handler.
SavedDiagHandler = SrcMgr.getDiagHandler();
@ -1278,7 +1281,7 @@ bool AsmParser::ParseStatement(ParseStatementInfo &Info) {
}
// If macros are enabled, check to see if this is a macro instantiation.
if (MacrosEnabled)
if (MacrosEnabled())
if (const Macro *M = MacroMap.lookup(IDVal))
return HandleMacroEntry(IDVal, IDLoc, M);
@ -3489,7 +3492,7 @@ bool GenericAsmParser::ParseDirectiveMacrosOnOff(StringRef Directive,
return Error(getLexer().getLoc(),
"unexpected token in '" + Directive + "' directive");
getParser().MacrosEnabled = Directive == ".macros_on";
getParser().SetMacrosEnabled(Directive == ".macros_on");
return false;
}