2012-11-30 21:26:26 +04:00
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
// author: Vassil Vassilev <vvasilev@cern.ch>
2014-01-07 14:08:37 +04:00
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
2012-11-30 21:26:26 +04:00
//------------------------------------------------------------------------------
# include "MetaParser.h"
# include "MetaLexer.h"
# include "MetaSema.h"
2012-12-02 23:01:02 +04:00
# include "cling/Interpreter/Interpreter.h"
# include "cling/Interpreter/InvocationOptions.h"
2013-06-10 17:14:36 +04:00
# include "cling/Interpreter/StoredValueRef.h"
2012-12-02 23:01:02 +04:00
2012-11-30 21:26:26 +04:00
# include "llvm/ADT/StringRef.h"
# include "llvm/Support/Path.h"
2014-01-13 11:57:12 +04:00
# include "llvm/Support/raw_ostream.h"
2012-11-30 21:26:26 +04:00
namespace cling {
MetaParser : : MetaParser ( MetaSema * Actions ) {
m_Lexer . reset ( 0 ) ;
m_Actions . reset ( Actions ) ;
2012-12-02 23:01:02 +04:00
const InvocationOptions & Opts = Actions - > getInterpreter ( ) . getOptions ( ) ;
MetaLexer metaSymbolLexer ( Opts . MetaString ) ;
2012-12-02 23:05:24 +04:00
Token Tok ;
2012-12-02 23:01:02 +04:00
while ( true ) {
metaSymbolLexer . Lex ( Tok ) ;
if ( Tok . is ( tok : : eof ) )
break ;
m_MetaSymbolCache . push_back ( Tok ) ;
}
2012-11-30 21:26:26 +04:00
}
void MetaParser : : enterNewInputLine ( llvm : : StringRef Line ) {
m_Lexer . reset ( new MetaLexer ( Line ) ) ;
m_TokenCache . clear ( ) ;
}
void MetaParser : : consumeToken ( ) {
if ( m_TokenCache . size ( ) )
m_TokenCache . erase ( m_TokenCache . begin ( ) ) ;
2014-02-28 13:22:05 +04:00
2012-11-30 21:26:26 +04:00
lookAhead ( 0 ) ;
}
void MetaParser : : consumeAnyStringToken ( tok : : TokenKind stopAt /*=tok::space*/ ) {
consumeToken ( ) ;
// we have to merge the tokens from the queue until we reach eof token or
// space token
2013-02-28 14:55:45 +04:00
skipWhitespace ( ) ;
2012-11-30 21:26:26 +04:00
// Add the new token in which we will merge the others.
Token & MergedTok = m_TokenCache . front ( ) ;
2014-02-28 13:22:05 +04:00
if ( MergedTok . is ( stopAt ) | | MergedTok . is ( tok : : eof )
2012-11-30 21:26:26 +04:00
| | MergedTok . is ( tok : : comment ) )
return ;
Token Tok = lookAhead ( 1 ) ;
2012-12-01 04:54:25 +04:00
while ( Tok . isNot ( stopAt ) & & Tok . isNot ( tok : : eof ) ) {
2012-11-30 21:26:26 +04:00
//MergedTok.setLength(MergedTok.getLength() + Tok.getLength());
m_TokenCache . erase ( m_TokenCache . begin ( ) + 1 ) ;
Tok = lookAhead ( 1 ) ;
}
MergedTok . setKind ( tok : : raw_ident ) ;
MergedTok . setLength ( Tok . getBufStart ( ) - MergedTok . getBufStart ( ) ) ;
}
const Token & MetaParser : : lookAhead ( unsigned N ) {
if ( N < m_TokenCache . size ( ) )
return m_TokenCache [ N ] ;
for ( unsigned C = N + 1 - m_TokenCache . size ( ) ; C > 0 ; - - C ) {
m_TokenCache . push_back ( Token ( ) ) ;
m_Lexer - > Lex ( m_TokenCache . back ( ) ) ;
}
return m_TokenCache . back ( ) ;
}
2013-02-28 14:55:45 +04:00
void MetaParser : : skipWhitespace ( ) {
2012-11-30 21:26:26 +04:00
while ( getCurTok ( ) . is ( tok : : space ) )
consumeToken ( ) ;
}
2013-06-10 17:14:36 +04:00
bool MetaParser : : isMetaCommand ( MetaSema : : ActionResult & actionResult ,
StoredValueRef * resultValue ) {
return isCommandSymbol ( ) & & isCommand ( actionResult , resultValue ) ;
2012-11-30 21:26:26 +04:00
}
2014-02-28 13:22:05 +04:00
bool MetaParser : : isQuitRequested ( ) const {
return m_Actions - > isQuitRequested ( ) ;
2012-12-06 15:47:24 +04:00
}
2012-11-30 21:26:26 +04:00
bool MetaParser : : isCommandSymbol ( ) {
2012-12-02 23:01:02 +04:00
for ( size_t i = 0 ; i < m_MetaSymbolCache . size ( ) ; + + i ) {
if ( getCurTok ( ) . getKind ( ) ! = m_MetaSymbolCache [ i ] . getKind ( ) )
return false ;
consumeToken ( ) ;
}
return true ;
2012-11-30 21:26:26 +04:00
}
2013-06-10 17:14:36 +04:00
bool MetaParser : : isCommand ( MetaSema : : ActionResult & actionResult ,
StoredValueRef * resultValue ) {
if ( resultValue )
* resultValue = StoredValueRef : : invalidValue ( ) ;
2013-05-24 19:50:13 +04:00
return isLCommand ( actionResult )
2013-06-10 17:14:36 +04:00
| | isXCommand ( actionResult , resultValue )
2013-08-13 13:06:58 +04:00
| | isqCommand ( ) | | isUCommand ( actionResult ) | | isICommand ( )
| | isOCommand ( ) | | israwInputCommand ( ) | | isprintASTCommand ( )
2014-02-28 13:08:13 +04:00
| | isdynamicExtensionsCommand ( ) | | ishelpCommand ( ) | | isfileExCommand ( )
| | isfilesCommand ( ) | | isClassCommand ( ) | | isgCommand ( )
2014-02-28 19:48:36 +04:00
| | isTypedefCommand ( )
2014-02-28 13:08:13 +04:00
| | isShellCommand ( actionResult , resultValue ) | | isstoreStateCommand ( )
| | iscompareStateCommand ( ) | | isstatsCommand ( ) | | isundoCommand ( )
2013-12-10 15:03:26 +04:00
| | isRedirectCommand ( actionResult ) ;
2012-11-30 21:26:26 +04:00
}
// L := 'L' FilePath
// FilePath := AnyString
// AnyString := .*^(' ' | '\t')
2013-05-24 19:50:13 +04:00
bool MetaParser : : isLCommand ( MetaSema : : ActionResult & actionResult ) {
2012-11-30 21:26:26 +04:00
bool result = false ;
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " L " ) ) {
consumeAnyStringToken ( ) ;
if ( getCurTok ( ) . is ( tok : : raw_ident ) ) {
result = true ;
2013-09-11 17:13:37 +04:00
actionResult =
2013-09-19 19:03:30 +04:00
m_Actions - > actOnLCommand ( getCurTok ( ) . getIdent ( ) ) ;
2012-11-30 21:26:26 +04:00
consumeToken ( ) ;
if ( getCurTok ( ) . is ( tok : : comment ) ) {
consumeAnyStringToken ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnComment ( getCurTok ( ) . getIdent ( ) ) ;
2012-11-30 21:26:26 +04:00
}
}
}
// TODO: Some fine grained diagnostics
return result ;
}
2013-12-18 18:51:27 +04:00
// >RedirectCommand := '>' FilePath
2013-12-10 15:03:26 +04:00
// FilePath := AnyString
// AnyString := .*^(' ' | '\t')
bool MetaParser : : isRedirectCommand ( MetaSema : : ActionResult & actionResult ) {
2013-12-16 19:18:27 +04:00
2014-01-14 12:58:35 +04:00
unsigned constant_FD = 0 ;
2013-12-16 19:18:27 +04:00
// Default redirect is stdout.
2014-01-13 11:57:12 +04:00
MetaProcessor : : RedirectionScope stream = MetaProcessor : : kSTDOUT ;
2014-01-14 12:58:35 +04:00
2013-12-10 15:03:26 +04:00
if ( getCurTok ( ) . is ( tok : : constant ) ) {
// > or 1> the redirection is for stdout stream
// 2> redirection for stderr stream
2014-01-14 12:58:35 +04:00
constant_FD = getCurTok ( ) . getConstant ( ) ;
if ( constant_FD = = 2 ) {
2013-12-18 18:51:27 +04:00
stream = MetaProcessor : : kSTDERR ;
2014-01-14 12:58:35 +04:00
// Wrong constant_FD, do not redirect.
} else if ( constant_FD ! = 1 ) {
2014-01-15 18:27:58 +04:00
llvm : : errs ( ) < < " cling::MetaParser::isRedirectCommand(): "
< < " invalid file descriptor number " < < constant_FD < < " \n " ;
2014-01-13 11:57:12 +04:00
return true ;
2013-12-10 15:03:26 +04:00
}
2013-12-17 15:17:01 +04:00
consumeToken ( ) ;
}
2013-12-18 18:51:27 +04:00
// &> redirection for both stdout & stderr
2013-12-17 15:17:01 +04:00
if ( getCurTok ( ) . is ( tok : : ampersand ) ) {
2014-01-14 12:58:35 +04:00
if ( constant_FD ! = 2 ) {
stream = MetaProcessor : : kSTDBOTH ;
}
2013-12-17 20:34:53 +04:00
consumeToken ( ) ;
2013-12-10 15:03:26 +04:00
}
2013-12-17 15:17:01 +04:00
if ( getCurTok ( ) . is ( tok : : greater ) ) {
2013-12-16 19:18:27 +04:00
bool append = false ;
2013-12-10 15:03:26 +04:00
consumeToken ( ) ;
2014-01-14 12:58:35 +04:00
// check for syntax like: 2>&1
if ( getCurTok ( ) . is ( tok : : ampersand ) ) {
if ( constant_FD ! = 2 ) {
stream = MetaProcessor : : kSTDBOTH ;
}
consumeToken ( ) ;
} else {
// check whether we have >>
if ( getCurTok ( ) . is ( tok : : greater ) ) {
append = true ;
2013-12-10 15:03:26 +04:00
consumeToken ( ) ;
}
2014-01-14 12:58:35 +04:00
}
llvm : : StringRef file ;
if ( getCurTok ( ) . is ( tok : : constant ) & & getCurTok ( ) . getConstant ( ) = = 1 ) {
file = llvm : : StringRef ( " _IO_2_1_stdout_ " ) ;
} else {
if ( getCurTok ( ) . is ( tok : : eof ) ) {
2013-12-10 15:03:26 +04:00
file = llvm : : StringRef ( ) ;
2014-01-14 12:58:35 +04:00
} else {
consumeAnyStringToken ( ) ;
if ( getCurTok ( ) . is ( tok : : raw_ident ) ) {
file = getCurTok ( ) . getIdent ( ) ;
consumeToken ( ) ;
}
else {
file = llvm : : StringRef ( ) ;
}
2013-12-10 15:03:26 +04:00
}
}
2013-12-18 18:51:27 +04:00
// Empty file means std.
2013-12-10 15:03:26 +04:00
actionResult =
m_Actions - > actOnRedirectCommand ( file /*file*/ ,
stream /*which stream to redirect*/ ,
append /*append mode*/ ) ;
return true ;
2014-02-28 13:22:05 +04:00
}
2013-12-10 15:03:26 +04:00
return false ;
}
2012-12-01 20:48:33 +04:00
// XCommand := 'x' FilePath[ArgList] | 'X' FilePath[ArgList]
2012-11-30 21:26:26 +04:00
// FilePath := AnyString
// ArgList := (ExtraArgList) ' ' [ArgList]
// ExtraArgList := AnyString [, ExtraArgList]
2013-06-10 17:14:36 +04:00
bool MetaParser : : isXCommand ( MetaSema : : ActionResult & actionResult ,
StoredValueRef * resultValue ) {
if ( resultValue )
* resultValue = StoredValueRef : : invalidValue ( ) ;
2012-12-01 20:48:33 +04:00
const Token & Tok = getCurTok ( ) ;
if ( Tok . is ( tok : : ident ) & & ( Tok . getIdent ( ) . equals ( " x " )
| | Tok . getIdent ( ) . equals ( " X " ) ) ) {
2012-11-30 21:26:26 +04:00
// There might be ArgList
consumeAnyStringToken ( tok : : l_paren ) ;
2013-09-19 19:03:30 +04:00
llvm : : StringRef file ( getCurTok ( ) . getIdent ( ) ) ;
2012-11-30 21:26:26 +04:00
llvm : : StringRef args ;
consumeToken ( ) ;
if ( getCurTok ( ) . is ( tok : : l_paren ) & & isExtraArgList ( ) ) {
args = getCurTok ( ) . getIdent ( ) ;
consumeToken ( ) ; // consume the closing paren
}
2013-05-24 19:50:13 +04:00
actionResult = m_Actions - > actOnxCommand ( file , args , resultValue ) ;
2012-11-30 21:26:26 +04:00
if ( getCurTok ( ) . is ( tok : : comment ) ) {
consumeAnyStringToken ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnComment ( getCurTok ( ) . getIdent ( ) ) ;
2012-11-30 21:26:26 +04:00
}
2013-06-07 16:09:13 +04:00
return true ;
2012-11-30 21:26:26 +04:00
}
2013-06-07 16:09:13 +04:00
return false ;
2012-11-30 21:26:26 +04:00
}
// ExtraArgList := AnyString [, ExtraArgList]
bool MetaParser : : isExtraArgList ( ) {
// This might be expanded if we need better arg parsing.
consumeAnyStringToken ( tok : : r_paren ) ;
2014-02-28 13:22:05 +04:00
2012-11-30 21:26:26 +04:00
return getCurTok ( ) . is ( tok : : raw_ident ) ;
}
bool MetaParser : : isqCommand ( ) {
bool result = false ;
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " q " ) ) {
result = true ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnqCommand ( ) ;
2012-11-30 21:26:26 +04:00
}
return result ;
}
2013-05-24 19:50:13 +04:00
bool MetaParser : : isUCommand ( MetaSema : : ActionResult & actionResult ) {
actionResult = MetaSema : : AR_Failure ;
2012-12-02 23:31:08 +04:00
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " U " ) ) {
2013-05-24 19:50:13 +04:00
actionResult = m_Actions - > actOnUCommand ( ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
bool MetaParser : : isICommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " I " ) ) {
consumeAnyStringToken ( ) ;
2013-09-19 19:03:30 +04:00
llvm : : StringRef path ;
2012-11-30 21:26:26 +04:00
if ( getCurTok ( ) . is ( tok : : raw_ident ) )
path = getCurTok ( ) . getIdent ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnICommand ( path ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
2014-02-28 13:22:05 +04:00
2013-08-13 13:06:58 +04:00
bool MetaParser : : isOCommand ( ) {
const Token & currTok = getCurTok ( ) ;
if ( currTok . is ( tok : : ident ) ) {
llvm : : StringRef ident = currTok . getIdent ( ) ;
if ( ident . startswith ( " O " ) ) {
if ( ident . size ( ) > 1 ) {
int level = 0 ;
if ( ! ident . substr ( 1 ) . getAsInteger ( 10 , level ) & & level > = 0 ) {
consumeAnyStringToken ( tok : : eof ) ;
if ( getCurTok ( ) . is ( tok : : raw_ident ) )
return false ;
//TODO: Process .OXXX here as .O with level XXX.
return true ;
}
} else {
consumeAnyStringToken ( tok : : eof ) ;
const Token & lastStringToken = getCurTok ( ) ;
2014-01-15 18:27:58 +04:00
if ( lastStringToken . is ( tok : : raw_ident )
& & lastStringToken . getLength ( ) ) {
2013-08-13 13:06:58 +04:00
int level = 0 ;
if ( ! lastStringToken . getIdent ( ) . getAsInteger ( 10 , level ) & & level > = 0 ) {
//TODO: process .O XXX
return true ;
}
} else {
//TODO: process .O
return true ;
}
}
}
}
return false ;
}
2012-11-30 21:26:26 +04:00
bool MetaParser : : israwInputCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " rawInput " ) ) {
MetaSema : : SwitchMode mode = MetaSema : : kToggle ;
consumeToken ( ) ;
2013-02-28 14:55:45 +04:00
skipWhitespace ( ) ;
2012-11-30 21:26:26 +04:00
if ( getCurTok ( ) . is ( tok : : constant ) )
2013-10-29 07:13:39 +04:00
mode = ( MetaSema : : SwitchMode ) getCurTok ( ) . getConstantAsBool ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnrawInputCommand ( mode ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
bool MetaParser : : isprintASTCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " printAST " ) ) {
MetaSema : : SwitchMode mode = MetaSema : : kToggle ;
consumeToken ( ) ;
2013-02-28 14:55:45 +04:00
skipWhitespace ( ) ;
2012-11-30 21:26:26 +04:00
if ( getCurTok ( ) . is ( tok : : constant ) )
2013-10-29 07:13:39 +04:00
mode = ( MetaSema : : SwitchMode ) getCurTok ( ) . getConstantAsBool ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnprintASTCommand ( mode ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
2013-08-21 14:25:48 +04:00
bool MetaParser : : isstoreStateCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " storeState " ) ) {
//MetaSema::SwitchMode mode = MetaSema::kToggle;
consumeToken ( ) ;
skipWhitespace ( ) ;
if ( ! getCurTok ( ) . is ( tok : : quote ) )
2014-02-28 13:22:05 +04:00
return false ; // FIXME: Issue proper diagnostics
2013-08-21 14:25:48 +04:00
consumeToken ( ) ;
if ( ! getCurTok ( ) . is ( tok : : ident ) )
2014-02-28 13:22:05 +04:00
return false ; // FIXME: Issue proper diagnostics
2013-08-21 14:25:48 +04:00
std : : string ident = getCurTok ( ) . getIdent ( ) ;
consumeToken ( ) ;
if ( ! getCurTok ( ) . is ( tok : : quote ) )
2014-02-28 13:22:05 +04:00
return false ; // FIXME: Issue proper diagnostics
2013-08-21 14:25:48 +04:00
m_Actions - > actOnstoreStateCommand ( ident ) ;
return true ;
}
return false ;
}
bool MetaParser : : iscompareStateCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " compareState " ) ) {
//MetaSema::SwitchMode mode = MetaSema::kToggle;
consumeToken ( ) ;
skipWhitespace ( ) ;
if ( ! getCurTok ( ) . is ( tok : : quote ) )
2014-02-28 13:22:05 +04:00
return false ; // FIXME: Issue proper diagnostics
2013-08-21 14:25:48 +04:00
consumeToken ( ) ;
if ( ! getCurTok ( ) . is ( tok : : ident ) )
2014-02-28 13:22:05 +04:00
return false ; // FIXME: Issue proper diagnostics
2013-08-21 14:25:48 +04:00
std : : string ident = getCurTok ( ) . getIdent ( ) ;
consumeToken ( ) ;
if ( ! getCurTok ( ) . is ( tok : : quote ) )
2014-02-28 13:22:05 +04:00
return false ; // FIXME: Issue proper diagnostics
2013-08-21 14:25:48 +04:00
m_Actions - > actOncompareStateCommand ( ident ) ;
return true ;
}
return false ;
}
2014-02-28 13:08:13 +04:00
bool MetaParser : : isstatsCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " stats " ) ) {
consumeToken ( ) ;
skipWhitespace ( ) ;
if ( ! getCurTok ( ) . is ( tok : : ident ) )
return false ; // FIXME: Issue proper diagnostics
std : : string ident = getCurTok ( ) . getIdent ( ) ;
consumeToken ( ) ;
m_Actions - > actOnstatsCommand ( ident ) ;
return true ;
}
return false ;
}
2013-10-29 08:19:37 +04:00
bool MetaParser : : isundoCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " undo " ) ) {
2014-02-28 13:22:05 +04:00
consumeToken ( ) ;
2013-10-29 08:19:37 +04:00
skipWhitespace ( ) ;
const Token & next = getCurTok ( ) ;
if ( next . is ( tok : : constant ) )
m_Actions - > actOnUCommand ( next . getConstant ( ) ) ;
2013-10-29 08:23:02 +04:00
else
m_Actions - > actOnUCommand ( ) ;
2013-10-29 08:19:37 +04:00
return true ;
}
return false ;
}
2012-11-30 21:26:26 +04:00
bool MetaParser : : isdynamicExtensionsCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & &
getCurTok ( ) . getIdent ( ) . equals ( " dynamicExtensions " ) ) {
MetaSema : : SwitchMode mode = MetaSema : : kToggle ;
consumeToken ( ) ;
2013-02-28 14:55:45 +04:00
skipWhitespace ( ) ;
2012-11-30 21:26:26 +04:00
if ( getCurTok ( ) . is ( tok : : constant ) )
2013-10-29 07:13:39 +04:00
mode = ( MetaSema : : SwitchMode ) getCurTok ( ) . getConstantAsBool ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOndynamicExtensionsCommand ( mode ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
bool MetaParser : : ishelpCommand ( ) {
2013-01-15 14:11:52 +04:00
const Token & Tok = getCurTok ( ) ;
2014-02-28 13:22:05 +04:00
if ( Tok . is ( tok : : quest_mark ) | |
2013-01-15 14:11:52 +04:00
( Tok . is ( tok : : ident ) & & Tok . getIdent ( ) . equals ( " help " ) ) ) {
2012-12-01 18:07:57 +04:00
m_Actions - > actOnhelpCommand ( ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
bool MetaParser : : isfileExCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " fileEx " ) ) {
2012-12-01 18:07:57 +04:00
m_Actions - > actOnfileExCommand ( ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
bool MetaParser : : isfilesCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " files " ) ) {
2012-12-01 18:07:57 +04:00
m_Actions - > actOnfilesCommand ( ) ;
2012-11-30 21:26:26 +04:00
return true ;
}
return false ;
}
2012-12-01 17:46:50 +04:00
bool MetaParser : : isClassCommand ( ) {
const Token & Tok = getCurTok ( ) ;
if ( Tok . is ( tok : : ident ) ) {
if ( Tok . getIdent ( ) . equals ( " class " ) ) {
2012-12-05 20:36:42 +04:00
consumeAnyStringToken ( tok : : eof ) ;
2012-12-01 17:46:50 +04:00
const Token & NextTok = getCurTok ( ) ;
llvm : : StringRef className ;
if ( NextTok . is ( tok : : raw_ident ) )
2012-12-05 20:36:42 +04:00
className = NextTok . getIdent ( ) ;
2012-12-01 18:07:57 +04:00
m_Actions - > actOnclassCommand ( className ) ;
2012-12-01 17:46:50 +04:00
return true ;
}
else if ( Tok . getIdent ( ) . equals ( " Class " ) ) {
2012-12-01 18:07:57 +04:00
m_Actions - > actOnClassCommand ( ) ;
2012-12-01 17:46:50 +04:00
return true ;
}
}
return false ;
}
2012-12-03 00:14:02 +04:00
bool MetaParser : : isgCommand ( ) {
if ( getCurTok ( ) . is ( tok : : ident ) & & getCurTok ( ) . getIdent ( ) . equals ( " g " ) ) {
consumeToken ( ) ;
2013-02-28 14:55:45 +04:00
skipWhitespace ( ) ;
2012-12-03 00:14:02 +04:00
llvm : : StringRef varName ;
if ( getCurTok ( ) . is ( tok : : ident ) )
varName = getCurTok ( ) . getIdent ( ) ;
m_Actions - > actOngCommand ( varName ) ;
return true ;
}
return false ;
}
2014-02-28 13:22:05 +04:00
2012-12-05 17:20:58 +04:00
bool MetaParser : : isTypedefCommand ( ) {
const Token & Tok = getCurTok ( ) ;
if ( Tok . is ( tok : : ident ) ) {
if ( Tok . getIdent ( ) . equals ( " typedef " ) ) {
2012-12-11 13:19:50 +04:00
consumeAnyStringToken ( tok : : eof ) ;
2012-12-05 17:20:58 +04:00
const Token & NextTok = getCurTok ( ) ;
llvm : : StringRef typedefName ;
if ( NextTok . is ( tok : : raw_ident ) )
typedefName = NextTok . getIdent ( ) ;
m_Actions - > actOnTypedefCommand ( typedefName ) ;
return true ;
}
}
return false ;
}
2014-02-28 13:22:05 +04:00
2013-06-10 17:14:36 +04:00
bool MetaParser : : isShellCommand ( MetaSema : : ActionResult & actionResult ,
StoredValueRef * resultValue ) {
if ( resultValue )
* resultValue = StoredValueRef : : invalidValue ( ) ;
2013-05-24 19:50:13 +04:00
actionResult = MetaSema : : AR_Failure ;
2012-12-11 13:19:50 +04:00
const Token & Tok = getCurTok ( ) ;
if ( Tok . is ( tok : : excl_mark ) ) {
consumeAnyStringToken ( tok : : eof ) ;
const Token & NextTok = getCurTok ( ) ;
if ( NextTok . is ( tok : : raw_ident ) ) {
llvm : : StringRef commandLine ( NextTok . getIdent ( ) ) ;
if ( ! commandLine . empty ( ) )
2013-05-24 19:50:13 +04:00
actionResult = m_Actions - > actOnShellCommand ( commandLine ,
resultValue ) ;
2012-12-11 13:19:50 +04:00
}
return true ;
}
return false ;
}
2012-12-03 00:14:02 +04:00
2012-11-30 21:26:26 +04:00
} // end namespace cling