From 48cd1f6b573e76aaffb38d2e919984b481705404 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 18 Sep 2012 11:45:00 +0000 Subject: [PATCH] With r164028 in LLVM we can remove the helper class. git-svn-id: http://root.cern.ch/svn/root/trunk@46012 27541ba8-7e3a-0410-8455-c3a389f83636 --- lib/Interpreter/LookupHelper.cpp | 169 ++++++++----------------------- 1 file changed, 43 insertions(+), 126 deletions(-) diff --git a/lib/Interpreter/LookupHelper.cpp b/lib/Interpreter/LookupHelper.cpp index 6e80f8f3..8a0712c2 100644 --- a/lib/Interpreter/LookupHelper.cpp +++ b/lib/Interpreter/LookupHelper.cpp @@ -19,84 +19,6 @@ using namespace clang; namespace cling { - ///\brief Helper class that allows us to call protected functions in the - /// Parser. This is especially useful for the string-based lookup. - /// - class ParserExt : public Parser { - public: - static TypeResult ParseTypeNameFwd(Parser* P, SourceRange *Range = 0, - Declarator::TheContext Context - = Declarator::TypeNameContext, - AccessSpecifier AS = AS_none, - Decl **OwnedType = 0) { - return ((ParserExt*)P)->ParseTypeName(Range, Context, AS, OwnedType); - } - - static const Token& NextTokenFwd(Parser* P) { - return ((ParserExt*)P)->NextToken(); - } - - static bool SkipUntilFwd(Parser* P, tok::TokenKind T, bool StopAtSemi = true, - bool DontConsume = false, - bool StopAtCodeCompletion = false) { - - return ((ParserExt*)P)->SkipUntil(T, StopAtSemi, DontConsume, - StopAtCodeCompletion); - } - - static bool TryAnnotateCXXScopeTokenFwd(Parser* P, - bool EnteringContext = false) { - - return ((ParserExt*)P)->TryAnnotateCXXScopeToken(EnteringContext); - } - static bool TryAnnotateTypeOrScopeTokenFwd(Parser* P, - bool EnteringContext = false, - bool NeedType = false) { - - return ((ParserExt*)P)->TryAnnotateTypeOrScopeToken(EnteringContext); - } - - static ParsedType getTypeAnnotationFwd(Token &Tok) { - return ParserExt::getTypeAnnotation(Tok); - } - - static SourceLocation ConsumeTokenFwd(Parser* P) { - return ((ParserExt*)P)->ConsumeToken(); - } - - static bool ParseUnqualifiedIdFwd(Parser* P, - CXXScopeSpec &SS, bool EnteringContext, - bool AllowDestructorName, - bool AllowConstructorName, - ParsedType ObjectType, - SourceLocation& TemplateKWLoc, - UnqualifiedId &Result) { - - return ((ParserExt*)P)->ParseUnqualifiedId(SS, EnteringContext, - AllowDestructorName, - AllowConstructorName, - ObjectType, - TemplateKWLoc, - Result); - } - - static ExprResult ParseAssignmentExpressionFwd(Parser* P, - TypeCastState isTypeCast - = NotTypeCast) { - return ((ParserExt*)P)->ParseAssignmentExpression(isTypeCast); - - } - - - static void EnterScopeFwd(Parser* P, unsigned ScopeFlags) { - ((ParserExt*)P)->EnterScope(ScopeFlags); - } - - static void ExitScopeFwd(Parser* P) { - ((ParserExt*)P)->ExitScope(); - } - }; - ///\brief Cleanup Parser state after a failed lookup. /// /// After a failed lookup we need to discard the remaining unparsed input, @@ -130,9 +52,8 @@ namespace cling { // // Note: Consuming the EOF token will pop the include stack. // - ParserExt::SkipUntilFwd(P, tok::eof, /*StopAtSemi*/false, - /*DontConsume*/false, - /*StopAtCodeCompletion*/false); + P->SkipUntil(tok::eof, /*StopAtSemi*/false, /*DontConsume*/false, + /*StopAtCodeCompletion*/false); if (ResetIncrementalProcessing) { PP.enableIncrementalProcessing(false); } @@ -197,10 +118,10 @@ namespace cling { // // Try parsing the type name. // - TypeResult Res(ParserExt::ParseTypeNameFwd(&P)); + TypeResult Res(P.ParseTypeName()); if (Res.isUsable()) { // Accept it only if the whole name was parsed. - if (ParserExt::NextTokenFwd(&P).getKind() == clang::tok::eof) { + if (P.NextToken().getKind() == clang::tok::eof) { TypeSourceInfo* TSI = 0; // The QualType returned by the parser is an odd QualType // (type + TypeSourceInfo) and cannot be used directly. @@ -212,9 +133,8 @@ namespace cling { // // Note: Consuming the EOF token will pop the include stack. // - ParserExt::SkipUntilFwd(&P, tok::eof, /*StopAtSemi*/false, - /*DontConsume*/false, - /*StopAtCodeCompletion*/false); + P.SkipUntil(tok::eof, /*StopAtSemi*/false, /*DontConsume*/false, + /*StopAtCodeCompletion*/false); if (ResetIncrementalProcessing) { PP.enableIncrementalProcessing(false); } @@ -300,7 +220,7 @@ namespace cling { // if (!P.getCurToken().is(clang::tok::identifier) && !P.getCurToken(). is(clang::tok::coloncolon) && !(P.getCurToken().is( - clang::tok::annot_template_id) && ParserExt::NextTokenFwd(&P).is( + clang::tok::annot_template_id) && P.NextToken().is( clang::tok::coloncolon)) && !P.getCurToken().is( clang::tok::kw_decltype)) { // error path @@ -309,7 +229,7 @@ namespace cling { // // Try parsing the name as a nested-name-specifier. // - if (ParserExt::TryAnnotateCXXScopeTokenFwd(&P, false)) { + if (P.TryAnnotateCXXScopeToken(false)) { // error path return TheDecl; } @@ -322,7 +242,7 @@ namespace cling { NestedNameSpecifier* NNS = SS.getScopeRep(); NestedNameSpecifier::SpecifierKind Kind = NNS->getKind(); // Only accept the parse if we consumed all of the name. - if (ParserExt::NextTokenFwd(&P).getKind() == clang::tok::eof) { + if (P.NextToken().getKind() == clang::tok::eof) { // // Be careful, not all nested name specifiers refer to classes // and namespaces, and those are the only things we want. @@ -393,8 +313,8 @@ namespace cling { // // Cleanup after failed parse as a nested-name-specifier. // - ParserExt::SkipUntilFwd(&P,clang::tok::eof, /*StopAtSemi*/false, - /*DontConsume*/false, /*StopAtCodeCompletion*/false); + P.SkipUntil(clang::tok::eof, /*StopAtSemi*/false, /*DontConsume*/false, + /*StopAtCodeCompletion*/false); DClient->EndSourceFile(); S.getDiagnostics().Reset(); // @@ -412,15 +332,14 @@ namespace cling { // // Now try to parse the name as a type. // - if (ParserExt::TryAnnotateTypeOrScopeTokenFwd(&P, false, false)) { + if (P.TryAnnotateTypeOrScopeToken(false, false)) { // error path return TheDecl; } if (P.getCurToken().getKind() == tok::annot_typename) { - ParsedType T = ParserExt::getTypeAnnotationFwd( - const_cast(P.getCurToken())); + ParsedType T = P.getTypeAnnotation(const_cast(P.getCurToken())); // Only accept the parse if we consumed all of the name. - if (ParserExt::NextTokenFwd(&P).getKind() == clang::tok::eof) { + if (P.NextToken().getKind() == clang::tok::eof) { QualType QT = T.get(); if (const EnumType* ET = QT->getAs()) { EnumDecl* ED = ET->getDecl(); @@ -553,7 +472,7 @@ namespace cling { llvm::SmallVector GivenArgTypes; llvm::SmallVector GivenArgs; while (P.getCurToken().isNot(tok::eof)) { - TypeResult Res(ParserExt::ParseTypeNameFwd(&P)); + TypeResult Res(P.ParseTypeName()); if (!Res.isUsable()) { // Bad parse, done. return TheDecl; @@ -576,7 +495,7 @@ namespace cling { break; } // Eat the comma. - ParserExt::ConsumeTokenFwd(&P); + P.ConsumeToken(); } if (P.getCurToken().isNot(tok::eof)) { // We did not consume all of the prototype, bad parse. @@ -585,8 +504,8 @@ namespace cling { // // Cleanup after prototype parse. // - ParserExt::SkipUntilFwd(&P, clang::tok::eof, /*StopAtSemi*/false, - /*DontConsume*/false, /*StopAtCodeCompletion*/false); + P.SkipUntil(clang::tok::eof, /*StopAtSemi*/false, /*DontConsume*/false, + /*StopAtCodeCompletion*/false); DClient->EndSourceFile(); S.getDiagnostics().Reset(); // @@ -615,18 +534,18 @@ namespace cling { // and may be able to remove it in the future if // the way constructors are looked up changes. // - ParserExt::EnterScopeFwd(&P, Scope::DeclScope); + P.EnterScope(Scope::DeclScope); S.EnterDeclaratorContext(P.getCurScope(), foundDC); - if (ParserExt::ParseUnqualifiedIdFwd(&P, SS, /*EnteringContext*/false, - /*AllowDestructorName*/true, - /*AllowConstructorName*/true, - clang::ParsedType(), TemplateKWLoc, - FuncId)) { + if (P.ParseUnqualifiedId(SS, /*EnteringContext*/false, + /*AllowDestructorName*/true, + /*AllowConstructorName*/true, + clang::ParsedType(), TemplateKWLoc, + FuncId)) { // Bad parse. // Destroy the scope we created first, and // restore the original. S.ExitDeclaratorContext(P.getCurScope()); - ParserExt::ExitScopeFwd(&P); + P.ExitScope(); // Then cleanup and exit. return TheDecl; @@ -651,14 +570,14 @@ namespace cling { // Destroy the scope we created first, and // restore the original. S.ExitDeclaratorContext(P.getCurScope()); - ParserExt::ExitScopeFwd(&P); + P.ExitScope(); // Then cleanup and exit. return TheDecl; } // Destroy the scope we created, and // restore the original. S.ExitDeclaratorContext(P.getCurScope()); - ParserExt::ExitScopeFwd(&P); + P.ExitScope(); // // Check for lookup failure. // @@ -862,7 +781,7 @@ namespace cling { { bool first_time = true; while (P.getCurToken().isNot(tok::eof)) { - ExprResult Res = ParserExt::ParseAssignmentExpressionFwd(&P); + ExprResult Res = P.ParseAssignmentExpression(); if (Res.isUsable()) { Expr* expr = Res.release(); GivenArgs.push_back(expr); @@ -884,7 +803,7 @@ namespace cling { if (!P.getCurToken().is(tok::comma)) { break; } - ParserExt::ConsumeTokenFwd(&P); + P.ConsumeToken(); } } } @@ -896,9 +815,8 @@ namespace cling { // // Cleanup after the arg list parse. // - ParserExt::SkipUntilFwd(&P, clang::tok::eof, /*StopAtSemi*/false, - /*DontConsume*/false, - /*StopAtCodeCompletion*/false); + P.SkipUntil(clang::tok::eof, /*StopAtSemi*/false, /*DontConsume*/false, + /*StopAtCodeCompletion*/false); DClient->EndSourceFile(); S.getDiagnostics().Reset(); // @@ -919,20 +837,20 @@ namespace cling { // and may be able to remove it in the future if // the way constructors are looked up changes. // - ParserExt::EnterScopeFwd(&P, Scope::DeclScope); + P.EnterScope(Scope::DeclScope); S.EnterDeclaratorContext(P.getCurScope(), foundDC); // // Parse the function name. // SourceLocation TemplateKWLoc; UnqualifiedId FuncId; - if (ParserExt::ParseUnqualifiedIdFwd(&P, SS, /*EnteringContext*/false, - /*AllowDestructorName*/true, - /*AllowConstructorName*/true, - ParsedType(), TemplateKWLoc, FuncId)){ + if (P.ParseUnqualifiedId(SS, /*EnteringContext*/false, + /*AllowDestructorName*/true, + /*AllowConstructorName*/true, + ParsedType(), TemplateKWLoc, FuncId)){ // Failed parse, cleanup. S.ExitDeclaratorContext(P.getCurScope()); - ParserExt::ExitScopeFwd(&P); + P.ExitScope(); return TheDecl; } // @@ -955,7 +873,7 @@ namespace cling { // Destroy the scope we created first, and // restore the original. S.ExitDeclaratorContext(P.getCurScope()); - ParserExt::ExitScopeFwd(&P); + P.ExitScope(); // Then cleanup and exit. return TheDecl; } @@ -963,7 +881,7 @@ namespace cling { // Destroy the scope we created, and restore the original. // S.ExitDeclaratorContext(P.getCurScope()); - ParserExt::ExitScopeFwd(&P); + P.ExitScope(); // // Check for lookup failure. // @@ -1180,7 +1098,7 @@ namespace cling { { bool hasUnusableResult = false; while (P.getCurToken().isNot(tok::eof)) { - ExprResult Res = ParserExt::ParseAssignmentExpressionFwd(&P); + ExprResult Res = P.ParseAssignmentExpression(); if (Res.isUsable()) { argExprs.push_back(Res.release()); } @@ -1191,7 +1109,7 @@ namespace cling { if (!P.getCurToken().is(tok::comma)) { break; } - ParserExt::ConsumeTokenFwd(&P); + P.ConsumeToken(); } if (hasUnusableResult) // if one of the arguments is not usable return empty. @@ -1202,9 +1120,8 @@ namespace cling { // // Note: Consuming the EOF token will pop the include stack. // - ParserExt::SkipUntilFwd(&P, tok::eof, /*StopAtSemi*/false, - /*DontConsume*/false, - /*StopAtCodeCompletion*/false); + P.SkipUntil(tok::eof, /*StopAtSemi*/false, /*DontConsume*/false, + /*StopAtCodeCompletion*/false); if (ResetIncrementalProcessing) { PP.enableIncrementalProcessing(false); }