From 26dd2205bacbb6fc6fb10ea77943181dfb4d1298 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Nov 2014 05:11:47 +0000 Subject: [PATCH] Add const. NFC. This adds const to a few methods that already return const references or creates a const version when they reterun non-const references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221666 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCParser/MCAsmLexer.h | 2 +- include/llvm/MC/MCParser/MCAsmParser.h | 5 ++++- include/llvm/MC/MCParser/MCAsmParserExtension.h | 9 +++++++++ lib/MC/MCParser/MCAsmParser.cpp | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/llvm/MC/MCParser/MCAsmLexer.h b/include/llvm/MC/MCParser/MCAsmLexer.h index f7e73f9c1d9..b05891c1325 100644 --- a/include/llvm/MC/MCParser/MCAsmLexer.h +++ b/include/llvm/MC/MCParser/MCAsmLexer.h @@ -157,7 +157,7 @@ public: SMLoc getLoc() const; /// Get the current (last) lexed token. - const AsmToken &getTok() { + const AsmToken &getTok() const { return CurTok; } diff --git a/include/llvm/MC/MCParser/MCAsmParser.h b/include/llvm/MC/MCParser/MCAsmParser.h index d3be208eb82..34188e66e62 100644 --- a/include/llvm/MC/MCParser/MCAsmParser.h +++ b/include/llvm/MC/MCParser/MCAsmParser.h @@ -87,6 +87,9 @@ public: virtual SourceMgr &getSourceManager() = 0; virtual MCAsmLexer &getLexer() = 0; + const MCAsmLexer &getLexer() const { + return const_cast(this)->getLexer(); + } virtual MCContext &getContext() = 0; @@ -138,7 +141,7 @@ public: virtual const AsmToken &Lex() = 0; /// Get the current AsmToken from the stream. - const AsmToken &getTok(); + const AsmToken &getTok() const; /// \brief Report an error at the current lexer location. bool TokError(const Twine &Msg, ArrayRef Ranges = None); diff --git a/include/llvm/MC/MCParser/MCAsmParserExtension.h b/include/llvm/MC/MCParser/MCAsmParserExtension.h index 2eda3a9a214..bfc0afa132b 100644 --- a/include/llvm/MC/MCParser/MCAsmParserExtension.h +++ b/include/llvm/MC/MCParser/MCAsmParserExtension.h @@ -52,8 +52,17 @@ public: /// @{ MCContext &getContext() { return getParser().getContext(); } + MCAsmLexer &getLexer() { return getParser().getLexer(); } + const MCAsmLexer &getLexer() const { + return const_cast(this)->getLexer(); + } + MCAsmParser &getParser() { return *Parser; } + const MCAsmParser &getParser() const { + return const_cast(this)->getParser(); + } + SourceMgr &getSourceManager() { return getParser().getSourceManager(); } MCStreamer &getStreamer() { return getParser().getStreamer(); } bool Warning(SMLoc L, const Twine &Msg) { diff --git a/lib/MC/MCParser/MCAsmParser.cpp b/lib/MC/MCParser/MCAsmParser.cpp index e417aa97716..290dcb29774 100644 --- a/lib/MC/MCParser/MCAsmParser.cpp +++ b/lib/MC/MCParser/MCAsmParser.cpp @@ -29,7 +29,7 @@ void MCAsmParser::setTargetParser(MCTargetAsmParser &P) { TargetParser->Initialize(*this); } -const AsmToken &MCAsmParser::getTok() { +const AsmToken &MCAsmParser::getTok() const { return getLexer().getTok(); }