From: Douglas Gregor Date: Mon, 26 Jul 2010 04:08:02 +0000 (+0000) Subject: Eliminate the "minimal" and printing parser actions, which only ever X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87c300738174924453648c3b2d6f366c8284fac4;p=clang Eliminate the "minimal" and printing parser actions, which only ever worked for C anyway. Also kills the -cc1 options -parse-noop and -parse-print-callbacks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109392 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 72dca18fcd..36fdbf74d9 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -294,16 +294,12 @@ def dump_tokens : Flag<"-dump-tokens">, HelpText<"Run preprocessor, dump internal rep of tokens">; def init_only : Flag<"-init-only">, HelpText<"Only execute frontend initialization">; -def parse_noop : Flag<"-parse-noop">, - HelpText<"Run parser with noop callbacks (for timings)">; def fsyntax_only : Flag<"-fsyntax-only">, HelpText<"Run parser and perform semantic analysis">; def fixit : Flag<"-fixit">, HelpText<"Apply fix-it advice to the input source">; def fixit_EQ : Joined<"-fixit=">, HelpText<"Apply fix-it advice creating a file with the given suffix">; -def parse_print_callbacks : Flag<"-parse-print-callbacks">, - HelpText<"Run parser and print each callback invoked">; def print_preamble : Flag<"-print-preamble">, HelpText<"Print the \"preamble\" of a file, which is a candidate for implicit" " precompiled headers.">; diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h index c172066e03..efa8e91cab 100644 --- a/include/clang/Frontend/FrontendActions.h +++ b/include/clang/Frontend/FrontendActions.h @@ -163,21 +163,11 @@ protected: void ExecuteAction(); }; -class ParseOnlyAction : public PreprocessorFrontendAction { -protected: - void ExecuteAction(); -}; - class PreprocessOnlyAction : public PreprocessorFrontendAction { protected: void ExecuteAction(); }; -class PrintParseAction : public PreprocessorFrontendAction { -protected: - void ExecuteAction(); -}; - class PrintPreprocessedAction : public PreprocessorFrontendAction { protected: void ExecuteAction(); diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 263e571af4..7040b5c1f8 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -39,8 +39,6 @@ namespace frontend { GeneratePTH, ///< Generate pre-tokenized header. InheritanceView, ///< View C++ inheritance for a specified class. InitOnly, ///< Only execute frontend initialization. - ParseNoop, ///< Parse with noop callbacks. - ParsePrintCallbacks, ///< Parse and print each callback. ParseSyntaxOnly, ///< Parse and perform semantic analysis. PluginAction, ///< Run a plugin action, \see ActionName. PrintDeclContext, ///< Print DeclContext and their Decls. diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index f37cc01a27..c8b1daf0b7 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -31,7 +31,6 @@ class HeaderSearch; class HeaderSearchOptions; class IdentifierTable; class LangOptions; -class MinimalAction; class Preprocessor; class PreprocessorOptions; class PreprocessorOutputOptions; @@ -65,11 +64,6 @@ void ProcessWarningOptions(Diagnostic &Diags, const DiagnosticOptions &Opts); void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS, const PreprocessorOutputOptions &Opts); -/// CreatePrintParserActionsAction - Return the actions implementation that -/// implements the -parse-print-callbacks option. -MinimalAction *CreatePrintParserActionsAction(Preprocessor &PP, - llvm::raw_ostream* OS); - /// CheckDiagnostics - Gather the expected diagnostics and check them. bool CheckDiagnostics(Preprocessor &PP); diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index dbb1b0667b..d5cbd0cde3 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -61,8 +61,7 @@ namespace clang { /// /// All of the methods here are optional except getTypeName() and /// isCurrentClassName(), which must be specified in order for the -/// parse to complete accurately. The MinimalAction class does this -/// bare-minimum of tracking to implement this functionality. +/// parse to complete accurately. class Action : public ActionBase { /// \brief The parser's current scope. /// @@ -3182,90 +3181,6 @@ public: //@} }; -/// MinimalAction - Minimal actions are used by light-weight clients of the -/// parser that do not need name resolution or significant semantic analysis to -/// be performed. The actions implemented here are in the form of unresolved -/// identifiers. By using a simpler interface than the SemanticAction class, -/// the parser doesn't have to build complex data structures and thus runs more -/// quickly. -class MinimalAction : public Action { - /// Translation Unit Scope - useful to Objective-C actions that need - /// to lookup file scope declarations in the "ordinary" C decl namespace. - /// For example, user-defined classes, built-in "id" type, etc. - Scope *TUScope; - IdentifierTable &Idents; - Preprocessor &PP; - void *TypeNameInfoTablePtr; -public: - MinimalAction(Preprocessor &pp); - ~MinimalAction(); - - /// getTypeName - This looks at the IdentifierInfo::FETokenInfo field to - /// determine whether the name is a typedef or not in this scope. - /// - /// \param II the identifier for which we are performing name lookup - /// - /// \param NameLoc the location of the identifier - /// - /// \param S the scope in which this name lookup occurs - /// - /// \param SS if non-NULL, the C++ scope specifier that precedes the - /// identifier - /// - /// \param isClassName whether this is a C++ class-name production, in - /// which we can end up referring to a member of an unknown specialization - /// that we know (from the grammar) is supposed to be a type. For example, - /// this occurs when deriving from "std::vector::allocator_type", where T - /// is a template parameter. - /// - /// \returns the type referred to by this identifier, or NULL if the type - /// does not name an identifier. - virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, - Scope *S, CXXScopeSpec *SS, - bool isClassName = false, - TypeTy *ObjectType = 0); - - /// isCurrentClassName - Always returns false, because MinimalAction - /// does not support C++ classes with constructors. - virtual bool isCurrentClassName(const IdentifierInfo& II, Scope *S, - const CXXScopeSpec *SS); - - virtual TemplateNameKind isTemplateName(Scope *S, - CXXScopeSpec &SS, - UnqualifiedId &Name, - TypeTy *ObjectType, - bool EnteringContext, - TemplateTy &Template, - bool &MemberOfUnknownSpecialization); - - - /// ActOnDeclarator - If this is a typedef declarator, we modify the - /// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is - /// popped. - virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D); - - /// ActOnPopScope - When a scope is popped, if any typedefs are now - /// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field. - virtual void ActOnPopScope(SourceLocation Loc, Scope *S); - virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S); - - virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation AtClassLoc, - IdentifierInfo **IdentList, - SourceLocation *SLocs, - unsigned NumElts); - - virtual DeclPtrTy ActOnStartClassInterface(SourceLocation interLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperName, - SourceLocation SuperLoc, - const DeclPtrTy *ProtoRefs, - unsigned NumProtoRefs, - const SourceLocation *ProtoLocs, - SourceLocation EndProtoLoc, - AttributeList *AttrList); -}; - /// PrettyStackTraceActionsDecl - If a crash occurs in the parser while parsing /// something related to a virtualized decl, include that virtualized decl in /// the stack trace. @@ -3275,11 +3190,12 @@ class PrettyStackTraceActionsDecl : public llvm::PrettyStackTraceEntry { Action &Actions; SourceManager &SM; const char *Message; + public: PrettyStackTraceActionsDecl(Action::DeclPtrTy Decl, SourceLocation L, Action &actions, SourceManager &sm, const char *Msg) - : TheDecl(Decl), Loc(L), Actions(actions), SM(sm), Message(Msg) {} + : TheDecl(Decl), Loc(L), Actions(actions), SM(sm), Message(Msg) {} virtual void print(llvm::raw_ostream &OS) const; }; @@ -3291,7 +3207,7 @@ class EnterExpressionEvaluationContext { public: EnterExpressionEvaluationContext(Action &Actions, - Action::ExpressionEvaluationContext NewContext) + Action::ExpressionEvaluationContext NewContext) : Actions(Actions) { Actions.PushExpressionEvaluationContext(NewContext); } @@ -3301,6 +3217,7 @@ public: } }; + } // end namespace clang #endif diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index c23adb60d2..76aa7df524 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -90,8 +90,7 @@ class Parser { unsigned short ParenCount, BracketCount, BraceCount; /// Actions - These are the callbacks we invoke as we parse various constructs - /// in the file. This refers to the common base class between MinimalActions - /// and SemaActions for those uses that don't matter. + /// in the file. Action &Actions; Diagnostic &Diags; diff --git a/lib/Frontend/CMakeLists.txt b/lib/Frontend/CMakeLists.txt index 8757e2c9e3..b2e0518424 100644 --- a/lib/Frontend/CMakeLists.txt +++ b/lib/Frontend/CMakeLists.txt @@ -25,7 +25,6 @@ add_clang_library(clangFrontend PCHWriter.cpp PCHWriterDecl.cpp PCHWriterStmt.cpp - PrintParserCallbacks.cpp PrintPreprocessedOutput.cpp StmtXML.cpp TextDiagnosticBuffer.cpp diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index b007ac4bd3..a0c7c7c76d 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -327,8 +327,6 @@ static const char *getActionName(frontend::ActionKind Kind) { case frontend::GeneratePCH: return "-emit-pch"; case frontend::GeneratePTH: return "-emit-pth"; case frontend::InitOnly: return "-init-only"; - case frontend::ParseNoop: return "-parse-noop"; - case frontend::ParsePrintCallbacks: return "-parse-print-callbacks"; case frontend::ParseSyntaxOnly: return "-fsyntax-only"; case frontend::PrintDeclContext: return "-print-decl-contexts"; case frontend::PrintPreamble: return "-print-preamble"; @@ -982,10 +980,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Opts.ProgramAction = frontend::GeneratePTH; break; case OPT_init_only: Opts.ProgramAction = frontend::InitOnly; break; - case OPT_parse_noop: - Opts.ProgramAction = frontend::ParseNoop; break; - case OPT_parse_print_callbacks: - Opts.ProgramAction = frontend::ParsePrintCallbacks; break; case OPT_fsyntax_only: Opts.ProgramAction = frontend::ParseSyntaxOnly; break; case OPT_print_decl_contexts: diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 4db9c11ee3..2c0132ad2d 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -147,15 +147,6 @@ void GeneratePTHAction::ExecuteAction() { CacheTokens(CI.getPreprocessor(), OS); } -void ParseOnlyAction::ExecuteAction() { - Preprocessor &PP = getCompilerInstance().getPreprocessor(); - llvm::OwningPtr PA(new MinimalAction(PP)); - - Parser P(PP, *PA); - PP.EnterMainSourceFile(); - P.ParseTranslationUnit(); -} - void PreprocessOnlyAction::ExecuteAction() { Preprocessor &PP = getCompilerInstance().getPreprocessor(); @@ -170,19 +161,6 @@ void PreprocessOnlyAction::ExecuteAction() { } while (Tok.isNot(tok::eof)); } -void PrintParseAction::ExecuteAction() { - CompilerInstance &CI = getCompilerInstance(); - Preprocessor &PP = getCompilerInstance().getPreprocessor(); - llvm::raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile()); - if (!OS) return; - - llvm::OwningPtr PA(CreatePrintParserActionsAction(PP, OS)); - - Parser P(PP, *PA); - PP.EnterMainSourceFile(); - P.ParseTranslationUnit(); -} - void PrintPreprocessedAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); // Output file needs to be set to 'Binary', to avoid converting Unix style diff --git a/lib/Frontend/PrintParserCallbacks.cpp b/lib/Frontend/PrintParserCallbacks.cpp deleted file mode 100644 index 9220677483..0000000000 --- a/lib/Frontend/PrintParserCallbacks.cpp +++ /dev/null @@ -1,852 +0,0 @@ -//===--- PrintParserActions.cpp - Implement -parse-print-callbacks mode ---===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This code simply runs the preprocessor on the input file and prints out the -// result. This is the traditional behavior of the -E option. -// -//===----------------------------------------------------------------------===// - -#include "clang/Frontend/Utils.h" -#include "clang/Parse/Action.h" -#include "clang/Parse/DeclSpec.h" -#include "llvm/Support/raw_ostream.h" -using namespace clang; - -namespace { - class ParserPrintActions : public MinimalAction { - llvm::raw_ostream& Out; - - public: - ParserPrintActions(Preprocessor &PP, llvm::raw_ostream& OS) - : MinimalAction(PP), Out(OS) {} - - // Printing Functions which also must call MinimalAction - - /// ActOnDeclarator - This callback is invoked when a declarator is parsed - /// and 'Init' specifies the initializer if any. This is for things like: - /// "int X = 4" or "typedef int foo". - virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D) { - Out << __FUNCTION__ << " "; - if (IdentifierInfo *II = D.getIdentifier()) { - Out << "'" << II->getName() << "'"; - } else { - Out << ""; - } - Out << "\n"; - - // Pass up to EmptyActions so that the symbol table is maintained right. - return MinimalAction::ActOnDeclarator(S, D); - } - /// ActOnPopScope - This callback is called immediately before the specified - /// scope is popped and deleted. - virtual void ActOnPopScope(SourceLocation Loc, Scope *S) { - Out << __FUNCTION__ << "\n"; - return MinimalAction::ActOnPopScope(Loc, S); - } - - /// ActOnTranslationUnitScope - This callback is called once, immediately - /// after creating the translation unit scope (in Parser::Initialize). - virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { - Out << __FUNCTION__ << "\n"; - MinimalAction::ActOnTranslationUnitScope(Loc, S); - } - - - Action::DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperName, - SourceLocation SuperLoc, - const DeclPtrTy *ProtoRefs, - unsigned NumProtocols, - const SourceLocation *ProtoLocs, - SourceLocation EndProtoLoc, - AttributeList *AttrList) { - Out << __FUNCTION__ << "\n"; - return MinimalAction::ActOnStartClassInterface(AtInterfaceLoc, - ClassName, ClassLoc, - SuperName, SuperLoc, - ProtoRefs, NumProtocols, - ProtoLocs, EndProtoLoc, - AttrList); - } - - /// ActOnForwardClassDeclaration - - /// Scope will always be top level file scope. - Action::DeclPtrTy ActOnForwardClassDeclaration(SourceLocation AtClassLoc, - IdentifierInfo **IdentList, - SourceLocation *IdentLocs, - unsigned NumElts) { - Out << __FUNCTION__ << "\n"; - return MinimalAction::ActOnForwardClassDeclaration(AtClassLoc, IdentList, - IdentLocs, NumElts); - } - - // Pure Printing - - /// ActOnParamDeclarator - This callback is invoked when a parameter - /// declarator is parsed. This callback only occurs for functions - /// with prototypes. S is the function prototype scope for the - /// parameters (C++ [basic.scope.proto]). - virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D) { - Out << __FUNCTION__ << " "; - if (IdentifierInfo *II = D.getIdentifier()) { - Out << "'" << II->getName() << "'"; - } else { - Out << ""; - } - Out << "\n"; - return DeclPtrTy(); - } - - /// AddInitializerToDecl - This action is called immediately after - /// ParseDeclarator (when an initializer is present). The code is factored - /// this way to make sure we are able to handle the following: - /// void func() { int xx = xx; } - /// This allows ActOnDeclarator to register "xx" prior to parsing the - /// initializer. The declaration above should still result in a warning, - /// since the reference to "xx" is uninitialized. - virtual void AddInitializerToDecl(DeclPtrTy Dcl, ExprArg Init) { - Out << __FUNCTION__ << "\n"; - } - - /// FinalizeDeclaratorGroup - After a sequence of declarators are parsed, - /// this gives the actions implementation a chance to process the group as - /// a whole. - virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec& DS, - DeclPtrTy *Group, - unsigned NumDecls) { - Out << __FUNCTION__ << "\n"; - return DeclGroupPtrTy(); - } - - /// ActOnStartOfFunctionDef - This is called at the start of a function - /// definition, instead of calling ActOnDeclarator. The Declarator includes - /// information about formal arguments that are part of this function. - virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *FnBodyScope, - Declarator &D){ - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - /// ActOnStartOfFunctionDef - This is called at the start of a function - /// definition, after the FunctionDecl has already been created. - virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual void ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { - Out << __FUNCTION__ << "\n"; - } - - /// ActOnFunctionDefBody - This is called when a function body has completed - /// parsing. Decl is the DeclTy returned by ParseStartOfFunctionDef. - virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, - ExprArg AsmString) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with - /// no declarator (e.g. "struct foo;") is parsed. - virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, - DeclSpec &DS) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - /// ActOnLinkageSpec - Parsed a C++ linkage-specification that - /// contained braces. Lang/StrSize contains the language string that - /// was parsed at location Loc. Decls/NumDecls provides the - /// declarations parsed inside the linkage specification. - virtual DeclPtrTy ActOnLinkageSpec(SourceLocation Loc, - SourceLocation LBrace, - SourceLocation RBrace, const char *Lang, - unsigned StrSize, - DeclPtrTy *Decls, unsigned NumDecls) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - /// ActOnLinkageSpec - Parsed a C++ linkage-specification without - /// braces. Lang/StrSize contains the language string that was - /// parsed at location Loc. D is the declaration parsed. - virtual DeclPtrTy ActOnLinkageSpec(SourceLocation Loc, const char *Lang, - unsigned StrSize, DeclPtrTy D) { - return DeclPtrTy(); - } - - //===------------------------------------------------------------------===// - // Type Parsing Callbacks. - //===------------------------------------------------------------------===// - - virtual TypeResult ActOnTypeName(Scope *S, Declarator &D) { - Out << __FUNCTION__ << "\n"; - return TypeResult(); - } - - virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, - SourceLocation KWLoc, CXXScopeSpec &SS, - IdentifierInfo *Name, SourceLocation NameLoc, - AttributeList *Attr, AccessSpecifier AS, - MultiTemplateParamsArg TemplateParameterLists, - bool &OwnedDecl, bool &IsDependent) { - // TagType is an instance of DeclSpec::TST, indicating what kind of tag this - // is (struct/union/enum/class). - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - /// Act on @defs() element found when parsing a structure. ClassName is the - /// name of the referenced class. - virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, - IdentifierInfo *ClassName, - llvm::SmallVectorImpl &Decls) { - Out << __FUNCTION__ << "\n"; - } - - virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD, - SourceLocation DeclStart, - Declarator &D, ExprTy *BitfieldWidth) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart, - DeclPtrTy IntfDecl, - Declarator &D, ExprTy *BitfieldWidth, - tok::ObjCKeywordKind visibility) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual void ActOnFields(Scope* S, SourceLocation RecLoc, DeclPtrTy TagDecl, - DeclPtrTy *Fields, unsigned NumFields, - SourceLocation LBrac, SourceLocation RBrac, - AttributeList *AttrList) { - Out << __FUNCTION__ << "\n"; - } - - virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl, - DeclPtrTy LastEnumConstant, - SourceLocation IdLoc,IdentifierInfo *Id, - SourceLocation EqualLoc, ExprTy *Val) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual void ActOnEnumBody(SourceLocation EnumLoc, SourceLocation LBraceLoc, - SourceLocation RBraceLoc, DeclPtrTy EnumDecl, - DeclPtrTy *Elements, unsigned NumElements, - Scope *S, AttributeList *AttrList) { - Out << __FUNCTION__ << "\n"; - } - - //===------------------------------------------------------------------===// - // Statement Parsing Callbacks. - //===------------------------------------------------------------------===// - - virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, - SourceLocation R, - MultiStmtArg Elts, - bool isStmtExpr) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, - SourceLocation StartLoc, - SourceLocation EndLoc) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnExprStmt(FullExprArg Expr) { - Out << __FUNCTION__ << "\n"; - return OwningStmtResult(*this, Expr->release()); - } - - /// ActOnCaseStmt - Note that this handles the GNU 'case 1 ... 4' extension, - /// which can specify an RHS value. - virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, - ExprArg LHSVal, - SourceLocation DotDotDotLoc, - ExprArg RHSVal, - SourceLocation ColonLoc) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, - SourceLocation ColonLoc, - StmtArg SubStmt, Scope *CurScope){ - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc, - IdentifierInfo *II, - SourceLocation ColonLoc, - StmtArg SubStmt) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, - FullExprArg CondVal, DeclPtrTy CondVar, - StmtArg ThenVal, - SourceLocation ElseLoc, - StmtArg ElseVal) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, - ExprArg Cond, - DeclPtrTy CondVar) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, - StmtArg Switch, - StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, - FullExprArg Cond, DeclPtrTy CondVar, - StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body, - SourceLocation WhileLoc, - SourceLocation LPLoc, ExprArg Cond, - SourceLocation RPLoc){ - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc, - SourceLocation LParenLoc, - StmtArg First, FullExprArg Second, - DeclPtrTy SecondVar, - FullExprArg Third, - SourceLocation RParenLoc, - StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnObjCForCollectionStmt( - SourceLocation ForColLoc, - SourceLocation LParenLoc, - StmtArg First, ExprArg Second, - SourceLocation RParenLoc, StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc, - SourceLocation LabelLoc, - IdentifierInfo *LabelII) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, - SourceLocation StarLoc, - ExprArg DestExp) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc, - Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc, - Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc, - ExprArg RetValExp) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc, - bool IsSimple, - bool IsVolatile, - unsigned NumOutputs, - unsigned NumInputs, - IdentifierInfo **Names, - MultiExprArg Constraints, - MultiExprArg Exprs, - ExprArg AsmString, - MultiExprArg Clobbers, - SourceLocation RParenLoc, - bool MSAsm) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - // Objective-c statements - virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, - SourceLocation RParen, - DeclPtrTy Parm, - StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, - StmtArg Body) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, - StmtArg Try, - MultiStmtArg CatchStmts, - StmtArg Finally) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, - ExprArg Throw, - Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, - ExprArg SynchExpr, - StmtArg SynchBody) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - // C++ Statements - virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, - DeclPtrTy ExceptionDecl, - StmtArg HandlerBlock) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc, - StmtArg TryBlock, - MultiStmtArg Handlers) { - Out << __FUNCTION__ << "\n"; - return StmtEmpty(); - } - - //===------------------------------------------------------------------===// - // Expression Parsing Callbacks. - //===------------------------------------------------------------------===// - - // Primary Expressions. - - /// ActOnIdentifierExpr - Parse an identifier in expression context. - /// 'HasTrailingLParen' indicates whether or not the identifier has a '(' - /// token immediately after it. - virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc, - IdentifierInfo &II, - bool HasTrailingLParen, - const CXXScopeSpec *SS, - bool isAddressOfOperand) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr( - Scope *S, SourceLocation OperatorLoc, - OverloadedOperatorKind Op, - bool HasTrailingLParen, const CXXScopeSpec &SS, - bool isAddressOfOperand) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXConversionFunctionExpr( - Scope *S, SourceLocation OperatorLoc, - TypeTy *Type, bool HasTrailingLParen, - const CXXScopeSpec &SS,bool isAddressOfOperand) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc, - tok::TokenKind Kind) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCharacterConstant(const Token &) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnNumericConstant(const Token &) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - /// ActOnStringLiteral - The specified tokens were lexed as pasted string - /// fragments (e.g. "foo" "bar" L"baz"). - virtual OwningExprResult ActOnStringLiteral(const Token *Toks, - unsigned NumToks) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, - ExprArg Val) { - Out << __FUNCTION__ << "\n"; - return move(Val); // Default impl returns operand. - } - - // Postfix Expressions. - virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, - tok::TokenKind Kind, - ExprArg Input) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base, - SourceLocation LLoc, - ExprArg Idx, - SourceLocation RLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base, - SourceLocation OpLoc, - tok::TokenKind OpKind, - SourceLocation MemberLoc, - IdentifierInfo &Member, - DeclPtrTy ImplDecl, - const CXXScopeSpec *SS=0) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn, - SourceLocation LParenLoc, - MultiExprArg Args, - SourceLocation *CommaLocs, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - // Unary Operators. 'Tok' is the token for the operator. - virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, - tok::TokenKind Op, ExprArg Input) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - virtual OwningExprResult - ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType, - void *TyOrEx, const SourceRange &ArgRange) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParen, - TypeTy *Ty, - SourceLocation RParen, - ExprArg Op) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc, - MultiExprArg InitList, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - virtual OwningExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, - TypeTy *Ty, SourceLocation RParenLoc, - ExprArg Op) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, - tok::TokenKind Kind, - ExprArg LHS, ExprArg RHS) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null - /// in the case of a the GNU conditional expr extension. - virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc, - SourceLocation ColonLoc, - ExprArg Cond, ExprArg LHS, - ExprArg RHS) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - //===--------------------- GNU Extension Expressions ------------------===// - - virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc, - SourceLocation LabLoc, - IdentifierInfo *LabelII) {// "&&foo" - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, - StmtArg SubStmt, - SourceLocation RPLoc) { // "({..})" - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S, - SourceLocation BuiltinLoc, - SourceLocation TypeLoc, - TypeTy *Arg1, - OffsetOfComponent *CompPtr, - unsigned NumComponents, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - // __builtin_types_compatible_p(type1, type2) - virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc, - TypeTy *arg1,TypeTy *arg2, - SourceLocation RPLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - // __builtin_choose_expr(constExpr, expr1, expr2) - virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, - ExprArg cond, ExprArg expr1, - ExprArg expr2, - SourceLocation RPLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - // __builtin_va_arg(expr, type) - virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc, - ExprArg expr, TypeTy *type, - SourceLocation RPLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - } - - virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - } - - virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - } - - virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, - StmtArg Body, - Scope *CurScope) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc, - IdentifierInfo *Ident, - SourceLocation LBrace, - AttributeList *AttrList) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace) { - Out << __FUNCTION__ << "\n"; - return; - } - -#if 0 - // FIXME: AttrList should be deleted by this function, but the definition - // would have to be available. - virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope, - SourceLocation UsingLoc, - SourceLocation NamespcLoc, - const CXXScopeSpec &SS, - SourceLocation IdentLoc, - IdentifierInfo *NamespcName, - AttributeList *AttrList) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } -#endif - - virtual void ActOnParamDefaultArgument(DeclPtrTy param, - SourceLocation EqualLoc, - ExprArg defarg) { - Out << __FUNCTION__ << "\n"; - } - - virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param, - SourceLocation EqualLoc, - SourceLocation ArgLoc) { - Out << __FUNCTION__ << "\n"; - } - - virtual void ActOnParamDefaultArgumentError(DeclPtrTy param) { - Out << __FUNCTION__ << "\n"; - } - - virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, - SourceLocation LParenLoc, - MultiExprArg Exprs, - SourceLocation *CommaLocs, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return; - } - - virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, - DeclPtrTy Method) { - Out << __FUNCTION__ << "\n"; - } - - virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param) { - Out << __FUNCTION__ << "\n"; - } - - virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, - DeclPtrTy Method) { - Out << __FUNCTION__ << "\n"; - } - - virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc, - ExprArg AssertExpr, - ExprArg AssertMessageExpr) { - Out << __FUNCTION__ << "\n"; - return DeclPtrTy(); - } - - virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc, - tok::TokenKind Kind, - SourceLocation LAngleBracketLoc, - TypeTy *Ty, - SourceLocation RAngleBracketLoc, - SourceLocation LParenLoc, - ExprArg Op, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc, - SourceLocation LParenLoc, - bool isType, void *TyOrExpr, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, - tok::TokenKind Kind) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc, ExprArg Op) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange, - TypeTy *TypeRep, - SourceLocation LParenLoc, - MultiExprArg Exprs, - SourceLocation *CommaLocs, - SourceLocation RParenLoc) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S, - SourceLocation StartLoc, - Declarator &D, - SourceLocation EqualLoc, - ExprArg AssignExprVal) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, - bool UseGlobal, - SourceLocation PlacementLParen, - MultiExprArg PlacementArgs, - SourceLocation PlacementRParen, - SourceRange TypeIdParens, - Declarator &D, - SourceLocation ConstructorLParen, - MultiExprArg ConstructorArgs, - SourceLocation ConstructorRParen) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc, - bool UseGlobal, bool ArrayForm, - ExprArg Operand) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - - virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT, - SourceLocation KWLoc, - SourceLocation LParen, - TypeTy *Ty, - SourceLocation RParen) { - Out << __FUNCTION__ << "\n"; - return ExprEmpty(); - } - }; -} - -MinimalAction *clang::CreatePrintParserActionsAction(Preprocessor &PP, - llvm::raw_ostream* OS) { - return new ParserPrintActions(PP, *OS); -} diff --git a/lib/Parse/Action.cpp b/lib/Parse/Action.cpp new file mode 100644 index 0000000000..b34d14f50a --- /dev/null +++ b/lib/Parse/Action.cpp @@ -0,0 +1,104 @@ +//===--- Action.cpp - Implement the Action class --------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the Action interface. +// +//===----------------------------------------------------------------------===// + +#include "clang/Parse/Parser.h" +#include "clang/Parse/DeclSpec.h" +#include "clang/Parse/Scope.h" +#include "clang/Basic/TargetInfo.h" +#include "llvm/Support/Allocator.h" +#include "llvm/Support/RecyclingAllocator.h" +#include "llvm/Support/raw_ostream.h" +using namespace clang; + +void PrettyStackTraceActionsDecl::print(llvm::raw_ostream &OS) const { + if (Loc.isValid()) { + Loc.print(OS, SM); + OS << ": "; + } + OS << Message; + + std::string Name = Actions.getDeclName(TheDecl); + if (!Name.empty()) + OS << " '" << Name << '\''; + + OS << '\n'; +} + +/// Out-of-line virtual destructor to provide home for ActionBase class. +ActionBase::~ActionBase() {} + +/// Out-of-line virtual destructor to provide home for Action class. +Action::~Action() {} + +Action::ObjCMessageKind Action::getObjCMessageKind(Scope *S, + IdentifierInfo *Name, + SourceLocation NameLoc, + bool IsSuper, + bool HasTrailingDot, + TypeTy *&ReceiverType) { + ReceiverType = 0; + + if (IsSuper && !HasTrailingDot && S->isInObjcMethodScope()) + return ObjCSuperMessage; + + if (TypeTy *TyName = getTypeName(*Name, NameLoc, S)) { + DeclSpec DS; + const char *PrevSpec = 0; + unsigned DiagID = 0; + if (!DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec, + DiagID, TyName)) { + DS.SetRangeEnd(NameLoc); + Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); + TypeResult Ty = ActOnTypeName(S, DeclaratorInfo); + if (!Ty.isInvalid()) + ReceiverType = Ty.get(); + } + return ObjCClassMessage; + } + + return ObjCInstanceMessage; +} + +// Defined out-of-line here because of dependecy on AttributeList +Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope, + SourceLocation UsingLoc, + SourceLocation NamespcLoc, + CXXScopeSpec &SS, + SourceLocation IdentLoc, + IdentifierInfo *NamespcName, + AttributeList *AttrList) { + + // FIXME: Parser seems to assume that Action::ActOn* takes ownership over + // passed AttributeList, however other actions don't free it, is it + // temporary state or bug? + delete AttrList; + return DeclPtrTy(); +} + +// Defined out-of-line here because of dependency on AttributeList +Action::DeclPtrTy Action::ActOnUsingDeclaration(Scope *CurScope, + AccessSpecifier AS, + bool HasUsingKeyword, + SourceLocation UsingLoc, + CXXScopeSpec &SS, + UnqualifiedId &Name, + AttributeList *AttrList, + bool IsTypeName, + SourceLocation TypenameLoc) { + + // FIXME: Parser seems to assume that Action::ActOn* takes ownership over + // passed AttributeList, however other actions don't free it, is it + // temporary state or bug? + delete AttrList; + return DeclPtrTy(); +} diff --git a/lib/Parse/CMakeLists.txt b/lib/Parse/CMakeLists.txt index fafcf77b00..ca62f1558d 100644 --- a/lib/Parse/CMakeLists.txt +++ b/lib/Parse/CMakeLists.txt @@ -1,9 +1,9 @@ set(LLVM_NO_RTTI 1) add_clang_library(clangParse + Action.cpp AttributeList.cpp DeclSpec.cpp - MinimalAction.cpp ParseCXXInlineMethods.cpp ParseDecl.cpp ParseDeclCXX.cpp diff --git a/lib/Parse/MinimalAction.cpp b/lib/Parse/MinimalAction.cpp deleted file mode 100644 index b7205160c1..0000000000 --- a/lib/Parse/MinimalAction.cpp +++ /dev/null @@ -1,281 +0,0 @@ -//===--- MinimalAction.cpp - Implement the MinimalAction class ------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the MinimalAction interface. -// -//===----------------------------------------------------------------------===// - -#include "clang/Parse/Parser.h" -#include "clang/Parse/DeclSpec.h" -#include "clang/Parse/Scope.h" -#include "clang/Basic/TargetInfo.h" -#include "llvm/Support/Allocator.h" -#include "llvm/Support/RecyclingAllocator.h" -#include "llvm/Support/raw_ostream.h" -using namespace clang; - -/// Out-of-line virtual destructor to provide home for ActionBase class. -ActionBase::~ActionBase() {} - -/// Out-of-line virtual destructor to provide home for Action class. -Action::~Action() {} - -Action::ObjCMessageKind Action::getObjCMessageKind(Scope *S, - IdentifierInfo *Name, - SourceLocation NameLoc, - bool IsSuper, - bool HasTrailingDot, - TypeTy *&ReceiverType) { - ReceiverType = 0; - - if (IsSuper && !HasTrailingDot && S->isInObjcMethodScope()) - return ObjCSuperMessage; - - if (TypeTy *TyName = getTypeName(*Name, NameLoc, S)) { - DeclSpec DS; - const char *PrevSpec = 0; - unsigned DiagID = 0; - if (!DS.SetTypeSpecType(DeclSpec::TST_typename, NameLoc, PrevSpec, - DiagID, TyName)) { - DS.SetRangeEnd(NameLoc); - Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); - TypeResult Ty = ActOnTypeName(S, DeclaratorInfo); - if (!Ty.isInvalid()) - ReceiverType = Ty.get(); - } - return ObjCClassMessage; - } - - return ObjCInstanceMessage; -} - -// Defined out-of-line here because of dependecy on AttributeList -Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope, - SourceLocation UsingLoc, - SourceLocation NamespcLoc, - CXXScopeSpec &SS, - SourceLocation IdentLoc, - IdentifierInfo *NamespcName, - AttributeList *AttrList) { - - // FIXME: Parser seems to assume that Action::ActOn* takes ownership over - // passed AttributeList, however other actions don't free it, is it - // temporary state or bug? - delete AttrList; - return DeclPtrTy(); -} - -// Defined out-of-line here because of dependency on AttributeList -Action::DeclPtrTy Action::ActOnUsingDeclaration(Scope *CurScope, - AccessSpecifier AS, - bool HasUsingKeyword, - SourceLocation UsingLoc, - CXXScopeSpec &SS, - UnqualifiedId &Name, - AttributeList *AttrList, - bool IsTypeName, - SourceLocation TypenameLoc) { - - // FIXME: Parser seems to assume that Action::ActOn* takes ownership over - // passed AttributeList, however other actions don't free it, is it - // temporary state or bug? - delete AttrList; - return DeclPtrTy(); -} - - -void PrettyStackTraceActionsDecl::print(llvm::raw_ostream &OS) const { - if (Loc.isValid()) { - Loc.print(OS, SM); - OS << ": "; - } - OS << Message; - - std::string Name = Actions.getDeclName(TheDecl); - if (!Name.empty()) - OS << " '" << Name << '\''; - - OS << '\n'; -} - -/// TypeNameInfo - A link exists here for each scope that an identifier is -/// defined. -namespace { - struct TypeNameInfo { - TypeNameInfo *Prev; - bool isTypeName; - - TypeNameInfo(bool istypename, TypeNameInfo *prev) { - isTypeName = istypename; - Prev = prev; - } - }; - - struct TypeNameInfoTable { - llvm::RecyclingAllocator Allocator; - - void AddEntry(bool isTypename, IdentifierInfo *II) { - TypeNameInfo *TI = Allocator.Allocate(); - new (TI) TypeNameInfo(isTypename, II->getFETokenInfo()); - II->setFETokenInfo(TI); - } - - void DeleteEntry(TypeNameInfo *Entry) { - Entry->~TypeNameInfo(); - Allocator.Deallocate(Entry); - } - }; -} - -static TypeNameInfoTable *getTable(void *TP) { - return static_cast(TP); -} - -MinimalAction::MinimalAction(Preprocessor &pp) - : Idents(pp.getIdentifierTable()), PP(pp) { - TypeNameInfoTablePtr = new TypeNameInfoTable(); -} - -MinimalAction::~MinimalAction() { - delete getTable(TypeNameInfoTablePtr); -} - -void MinimalAction::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { - TUScope = S; - - TypeNameInfoTable &TNIT = *getTable(TypeNameInfoTablePtr); - - if (PP.getTargetInfo().getPointerWidth(0) >= 64) { - // Install [u]int128_t for 64-bit targets. - TNIT.AddEntry(true, &Idents.get("__int128_t")); - TNIT.AddEntry(true, &Idents.get("__uint128_t")); - } - - if (PP.getLangOptions().ObjC1) { - // Recognize the ObjC built-in type identifiers as types. - TNIT.AddEntry(true, &Idents.get("id")); - TNIT.AddEntry(true, &Idents.get("SEL")); - TNIT.AddEntry(true, &Idents.get("Class")); - TNIT.AddEntry(true, &Idents.get("Protocol")); - } -} - -/// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to -/// determine whether the name is a type name (objc class name or typedef) or -/// not in this scope. -/// -/// FIXME: Use the passed CXXScopeSpec for accurate C++ type checking. -Action::TypeTy * -MinimalAction::getTypeName(IdentifierInfo &II, SourceLocation Loc, - Scope *S, CXXScopeSpec *SS, - bool isClassName, TypeTy *ObjectType) { - if (TypeNameInfo *TI = II.getFETokenInfo()) - if (TI->isTypeName) - return TI; - return 0; -} - -/// isCurrentClassName - Always returns false, because MinimalAction -/// does not support C++ classes with constructors. -bool MinimalAction::isCurrentClassName(const IdentifierInfo &, Scope *, - const CXXScopeSpec *) { - return false; -} - -TemplateNameKind -MinimalAction::isTemplateName(Scope *S, - CXXScopeSpec &SS, - UnqualifiedId &Name, - TypeTy *ObjectType, - bool EnteringScope, - TemplateTy &TemplateDecl, - bool &MemberOfUnknownSpecialization) { - MemberOfUnknownSpecialization = false; - return TNK_Non_template; -} - -/// ActOnDeclarator - If this is a typedef declarator, we modify the -/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is -/// popped. -Action::DeclPtrTy -MinimalAction::ActOnDeclarator(Scope *S, Declarator &D) { - IdentifierInfo *II = D.getIdentifier(); - - // If there is no identifier associated with this declarator, bail out. - if (II == 0) return DeclPtrTy(); - - TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo(); - bool isTypeName = - D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef; - - // this check avoids creating TypeNameInfo objects for the common case. - // It does need to handle the uncommon case of shadowing a typedef name with a - // non-typedef name. e.g. { typedef int a; a xx; { int a; } } - if (weCurrentlyHaveTypeInfo || isTypeName) { - // Allocate and add the 'TypeNameInfo' "decl". - getTable(TypeNameInfoTablePtr)->AddEntry(isTypeName, II); - - // Remember that this needs to be removed when the scope is popped. - S->AddDecl(DeclPtrTy::make(II)); - } - return DeclPtrTy(); -} - -Action::DeclPtrTy -MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperName, - SourceLocation SuperLoc, - const DeclPtrTy *ProtoRefs, - unsigned NumProtocols, - const SourceLocation *ProtoLocs, - SourceLocation EndProtoLoc, - AttributeList *AttrList) { - // Allocate and add the 'TypeNameInfo' "decl". - getTable(TypeNameInfoTablePtr)->AddEntry(true, ClassName); - return DeclPtrTy(); -} - -/// ActOnForwardClassDeclaration - -/// Scope will always be top level file scope. -Action::DeclPtrTy -MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, - IdentifierInfo **IdentList, - SourceLocation *IdentLocs, - unsigned NumElts) { - for (unsigned i = 0; i != NumElts; ++i) { - // Allocate and add the 'TypeNameInfo' "decl". - getTable(TypeNameInfoTablePtr)->AddEntry(true, IdentList[i]); - - // Remember that this needs to be removed when the scope is popped. - TUScope->AddDecl(DeclPtrTy::make(IdentList[i])); - } - return DeclPtrTy(); -} - -/// ActOnPopScope - When a scope is popped, if any typedefs are now -/// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field. -void MinimalAction::ActOnPopScope(SourceLocation Loc, Scope *S) { - TypeNameInfoTable &Table = *getTable(TypeNameInfoTablePtr); - - for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end(); - I != E; ++I) { - IdentifierInfo &II = *(*I).getAs(); - TypeNameInfo *TI = II.getFETokenInfo(); - assert(TI && "This decl didn't get pushed??"); - - if (TI) { - TypeNameInfo *Next = TI->Prev; - Table.DeleteEntry(TI); - - II.setFETokenInfo(Next); - } - } -} diff --git a/test/Coverage/parse-callbacks.c b/test/Coverage/parse-callbacks.c deleted file mode 100644 index 02f3a8374b..0000000000 --- a/test/Coverage/parse-callbacks.c +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -parse-noop %s -// RUN: %clang_cc1 -parse-print-callbacks %s - -#include "c-language-features.inc" diff --git a/test/Coverage/parse-callbacks.m b/test/Coverage/parse-callbacks.m deleted file mode 100644 index f023d3d064..0000000000 --- a/test/Coverage/parse-callbacks.m +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -parse-noop %s -// RUN: %clang_cc1 -parse-print-callbacks %s - -#include "objc-language-features.inc" diff --git a/test/Parser/2008-10-31-parse-noop-failure.c b/test/Parser/2008-10-31-parse-noop-failure.c deleted file mode 100755 index 6df508ee4d..0000000000 --- a/test/Parser/2008-10-31-parse-noop-failure.c +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -verify -parse-noop %s - -void add_attribute(id) int id; {} - diff --git a/test/Parser/block-block-storageclass.c b/test/Parser/block-block-storageclass.c index a4efc44b18..97ba113492 100644 --- a/test/Parser/block-block-storageclass.c +++ b/test/Parser/block-block-storageclass.c @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -parse-noop %s -#if 0 +// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s int printf(const char *, ...); void _Block_byref_release(void*src){} @@ -16,4 +15,3 @@ int main() { return X; } -#endif diff --git a/test/Parser/block-pointer-decl.c b/test/Parser/block-pointer-decl.c index 2979b012c4..a8cc258ca3 100644 --- a/test/Parser/block-pointer-decl.c +++ b/test/Parser/block-pointer-decl.c @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -parse-noop -fblocks %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s + +int printf(char const *, ...); struct blockStruct { int (^a)(float, int); diff --git a/test/Parser/cxx-condition.cpp b/test/Parser/cxx-condition.cpp index a3991c45f2..552d823624 100644 --- a/test/Parser/cxx-condition.cpp +++ b/test/Parser/cxx-condition.cpp @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -parse-noop -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s void f() { int a; while (a) ; while (int x) ; // expected-error {{expected '=' after declarator}} while (float x = 0) ; - if (const int x = a) ; + if (const int x = a) ; // expected-warning{{empty body}} switch (int x = a+10) {} for (; int x = ++a; ) ; } diff --git a/test/Parser/cxx-namespace-alias.cpp b/test/Parser/cxx-namespace-alias.cpp index 2e4d7af6bf..9b90aabb86 100644 --- a/test/Parser/cxx-namespace-alias.cpp +++ b/test/Parser/cxx-namespace-alias.cpp @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 -parse-noop -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -namespace A = B; +namespace A = B; // expected-error{{namespace name}} namespace A = !; // expected-error {{expected namespace name}} -namespace A = A::!; // expected-error {{expected namespace name}} +namespace A = A::!; // expected-error {{expected namespace name}} \ + // expected-error{{use of undeclared identifier 'A'}} diff --git a/test/Parser/expressions.c b/test/Parser/expressions.c index 44ebe661be..ffc5c83a0a 100644 --- a/test/Parser/expressions.c +++ b/test/Parser/expressions.c @@ -1,19 +1,17 @@ -// RUN: %clang_cc1 -parse-noop -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s void test1() { - if (sizeof (int){ 1}); // sizeof compound literal - if (sizeof (int)); // sizeof type + if (sizeof (int){ 1}) {} // sizeof compound literal + if (sizeof (int)) {} // sizeof type - (int)4; // cast. - (int){4}; // compound literal. + (void)(int)4; // cast. + (void)(int){4}; // compound literal. - // FIXME: change this to the struct version when we can. - //int A = (struct{ int a;}){ 1}.a; - int A = (int){ 1}.a; + int A = (struct{ int a;}){ 1}.a; } int test2(int a, int b) { - return a ? a,b : a; + return a ? (void)a,b : a; } int test3(int a, int b, int c) { @@ -22,23 +20,27 @@ int test3(int a, int b, int c) { int test4() { test4(); + return 0; } +struct X0 { struct { struct { int c[10][9]; } b; } a; }; + int test_offsetof() { - // FIXME: change into something that is semantically correct. - __builtin_offsetof(int, a.b.c[4][5]); + (void)__builtin_offsetof(struct X0, a.b.c[4][5]); + return 0; } void test_sizeof(){ int arr[10]; - sizeof arr[0]; - sizeof(arr[0]); - sizeof(arr)[0]; + (void)sizeof arr[0]; + (void)sizeof(arr[0]); + (void)sizeof(arr)[0]; } // PR3418 int test_leading_extension() { __extension__ (*(char*)0) = 1; + return 0; } // PR3972 diff --git a/test/Parser/expressions.m b/test/Parser/expressions.m index e27f405069..1f1005a792 100644 --- a/test/Parser/expressions.m +++ b/test/Parser/expressions.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -parse-noop %s +// RUN: %clang_cc1 -fsyntax-only -verify %s void test1() { @"s"; // expected-warning {{expression result unused}} diff --git a/test/Parser/method-prototype-1.m b/test/Parser/method-prototype-1.m index d2d9563a2e..a32bc2ec27 100644 --- a/test/Parser/method-prototype-1.m +++ b/test/Parser/method-prototype-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -parse-noop +// RUN: %clang_cc1 %s -fsyntax-only @interface MyObject - (void) bycopy : (int) woodo, ... ; - (void) break : (int) woodo, ... ; diff --git a/test/Parser/objc-messaging-1.m b/test/Parser/objc-messaging-1.m index 511290eabf..82450df9f2 100644 --- a/test/Parser/objc-messaging-1.m +++ b/test/Parser/objc-messaging-1.m @@ -1,19 +1,26 @@ -// RUN: %clang_cc1 %s -parse-noop +// RUN: %clang_cc1 %s -fsyntax-only -verify int main () { int i,j; struct S *p; id a, b, c; - [p ii]; - [p if: 1 :2]; - [p inout: 1 :2 another:(2,3,4)]; - [p inout: 1 :2 another:(2,3,4), 6,6,8]; - [p inout: 1 :2 another:(2,3,4), (6,4,5),6,8]; - [p inout: 1 :2 another:(i+10), (i,j-1,5),6,8]; - [p long: 1 :2 another:(i+10), (i,j-1,5),6,8]; - [p : "Hello\n" :2 another:(i+10), (i,j-1,5),6,8]; + [a ii]; // expected-warning{{not found}} + [a if: 1 :2]; // expected-warning{{not found}} + [a inout: 1 :2 another:(2,3,4)]; // expected-warning{{not found}} \ + // expected-warning 2{{expression result unused}} + [a inout: 1 :2 another:(2,3,4), 6,6,8]; // expected-warning{{not found}} \ + // expected-warning 2{{expression result unused}} + [a inout: 1 :2 another:(2,3,4), (6,4,5),6,8]; // expected-warning{{not found}} \ + // expected-warning 4{{expression result unused}} + [a inout: 1 :2 another:(i+10), (i,j-1,5),6,8]; // expected-warning{{not found}} \ + // expected-warning 2{{expression result unused}} + [a long: 1 :2 another:(i+10), (i,j-1,5),6,8]; // expected-warning{{not found}} \ + // expected-warning 2{{expression result unused}} + [a : "Hello\n" :2 another:(i+10), (i,j-1,5),6,8]; // expected-warning{{not found}} \ + // expected-warning 2{{expression result unused}} // Comma expression as receiver (rdar://6222856) - [a, b, c foo]; + [a, b, c foo]; // expected-warning{{not found}} \ + // expected-warning 2{{expression result unused}} } diff --git a/test/Parser/selector-1.m b/test/Parser/selector-1.m index 1f9cad62ae..0f35ce79b2 100644 --- a/test/Parser/selector-1.m +++ b/test/Parser/selector-1.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -parse-noop %s +// RUN: %clang_cc1 -fsyntax-only -verify %s int main() { SEL s = @selector(retain); diff --git a/test/Parser/types.c b/test/Parser/types.c index 0e8a63d81f..53b9dd5e9e 100644 --- a/test/Parser/types.c +++ b/test/Parser/types.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -parse-noop +// RUN: %clang_cc1 %s -fsyntax-only -verify // Test the X can be overloaded inside the struct. typedef int X; diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index 3b13f0c736..0942be1e46 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -80,8 +80,6 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) { case GeneratePTH: return new GeneratePTHAction(); case InheritanceView: return new InheritanceViewAction(); case InitOnly: return new InitOnlyAction(); - case ParseNoop: return new ParseOnlyAction(); - case ParsePrintCallbacks: return new PrintParseAction(); case ParseSyntaxOnly: return new SyntaxOnlyAction(); case PluginAction: {