@@ -39,17 +39,24 @@ class AsmCommentConsumer {
3939 virtual void HandleComment (SMLoc Loc, StringRef CommentText) = 0;
4040};
4141
42- // / Generic assembler lexer interface, for use by target specific assembly
43- // / lexers.
44- class MCAsmLexer {
42+ class AsmLexer {
4543 // / The current token, stored in the base class for faster access.
4644 SmallVector<AsmToken, 1 > CurTok;
4745
46+ const char *CurPtr = nullptr ;
47+ StringRef CurBuf;
48+
4849 // / The location and description of the current error
4950 SMLoc ErrLoc;
5051 std::string Err;
5152
52- protected: // Can only create subclasses.
53+ const MCAsmInfo &MAI;
54+
55+ bool IsAtStartOfLine = true ;
56+ bool AtStartOfStatement = true ;
57+ bool IsPeeking = false ;
58+ bool EndStatementAtEOF = true ;
59+
5360 const char *TokStart = nullptr ;
5461 bool SkipSpace = true ;
5562 bool AllowAtInIdentifier = false ;
@@ -65,19 +72,17 @@ class MCAsmLexer {
6572 bool LexHLASMStrings = false ;
6673 AsmCommentConsumer *CommentConsumer = nullptr ;
6774
68- MCAsmLexer ();
69-
70- virtual AsmToken LexToken () = 0;
75+ AsmToken LexToken ();
7176
7277 void SetError (SMLoc errLoc, const std::string &err) {
7378 ErrLoc = errLoc;
7479 Err = err;
7580 }
7681
7782public:
78- MCAsmLexer (const MCAsmLexer &) = delete ;
79- MCAsmLexer & operator = (const MCAsmLexer &) = delete ;
80- virtual ~MCAsmLexer () ;
83+ AsmLexer (const MCAsmInfo &MAI) ;
84+ AsmLexer (const AsmLexer &) = delete ;
85+ AsmLexer & operator =( const AsmLexer &) = delete ;
8186
8287 // / Consume the next token from the input stream and return it.
8388 // /
@@ -86,7 +91,7 @@ class MCAsmLexer {
8691 const AsmToken &Lex () {
8792 assert (!CurTok.empty ());
8893 // Mark if we parsing out a EndOfStatement.
89- IsAtStartOfStatement = CurTok.front ().getKind () == AsmToken::EndOfStatement;
94+ AtStartOfStatement = CurTok.front ().getKind () == AsmToken::EndOfStatement;
9095 CurTok.erase (CurTok.begin ());
9196 // LexToken may generate multiple tokens via UnLex but will always return
9297 // the first one. Place returned value at head of CurTok vector.
@@ -98,16 +103,16 @@ class MCAsmLexer {
98103 }
99104
100105 void UnLex (AsmToken const &Token) {
101- IsAtStartOfStatement = false ;
106+ AtStartOfStatement = false ;
102107 CurTok.insert (CurTok.begin (), Token);
103108 }
104109
105- bool isAtStartOfStatement () { return IsAtStartOfStatement ; }
110+ bool isAtStartOfStatement () { return AtStartOfStatement ; }
106111
107- virtual StringRef LexUntilEndOfStatement () = 0 ;
112+ StringRef LexUntilEndOfStatement ();
108113
109114 // / Get the current source location.
110- SMLoc getLoc () const ;
115+ SMLoc getLoc () const { return SMLoc::getFromPointer (TokStart); }
111116
112117 // / Get the current (last) lexed token.
113118 const AsmToken &getTok () const { return CurTok[0 ]; }
@@ -126,8 +131,7 @@ class MCAsmLexer {
126131 }
127132
128133 // / Look ahead an arbitrary number of tokens.
129- virtual size_t peekTokens (MutableArrayRef<AsmToken> Buf,
130- bool ShouldSkipSpace = true ) = 0;
134+ size_t peekTokens (MutableArrayRef<AsmToken> Buf, bool ShouldSkipSpace = true );
131135
132136 // / Get the current error location
133137 SMLoc getErrLoc () { return ErrLoc; }
@@ -185,37 +189,10 @@ class MCAsmLexer {
185189 // / setting this option to true, will disable lexing for character and string
186190 // / literals.
187191 void setLexHLASMStrings (bool V) { LexHLASMStrings = V; }
188- };
189-
190- // / AsmLexer - Lexer class for assembly files.
191- class AsmLexer final : public MCAsmLexer {
192- const MCAsmInfo &MAI;
193-
194- const char *CurPtr = nullptr ;
195- StringRef CurBuf;
196- bool IsAtStartOfLine = true ;
197- bool IsAtStartOfStatement = true ;
198- bool IsPeeking = false ;
199- bool EndStatementAtEOF = true ;
200-
201- protected:
202- // / LexToken - Read the next token and return its code.
203- AsmToken LexToken () override ;
204-
205- public:
206- AsmLexer (const MCAsmInfo &MAI);
207- AsmLexer (const AsmLexer &) = delete ;
208- AsmLexer &operator =(const AsmLexer &) = delete ;
209- ~AsmLexer () override ;
210192
211193 void setBuffer (StringRef Buf, const char *ptr = nullptr ,
212194 bool EndStatementAtEOF = true );
213195
214- StringRef LexUntilEndOfStatement () override ;
215-
216- size_t peekTokens (MutableArrayRef<AsmToken> Buf,
217- bool ShouldSkipSpace = true ) override ;
218-
219196 const MCAsmInfo &getMAI () const { return MAI; }
220197
221198private:
@@ -237,6 +214,8 @@ class AsmLexer final : public MCAsmLexer {
237214 StringRef LexUntilEndOfLine ();
238215};
239216
217+ using MCAsmLexer = AsmLexer;
218+
240219} // end namespace llvm
241220
242221#endif // LLVM_MC_MCPARSER_ASMLEXER_H
0 commit comments