//===--- Action.h - Parser Action Interface ---------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the Action and EmptyAction interface.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_PARSE_ACTION_H
#define LLVM_CLANG_PARSE_ACTION_H
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Parse/AccessSpecifier.h"
namespace clang {
// Semantic.
class DeclSpec;
class ObjCDeclSpec;
class CXXScopeSpec;
class Declarator;
class AttributeList;
struct FieldDeclarator;
// Parse.
class Scope;
class Action;
class Selector;
class InitListDesignations;
// Lex.
class Preprocessor;
class Token;
// Basic.
class DiagnosticBuilder;
/// Action - As the parser reads the input file and recognizes the productions
/// of the grammar, it invokes methods on this class to turn the parsed input
/// into something useful: e.g. a parse tree.
///
/// The callback methods that this class provides are phrased as actions that
/// the parser has just done or is about to do when the method is called. They
/// are not requests that the actions module do the specified action.
///
/// All of the methods here are optional except isTypeName() 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.
class Action {
public:
/// Out-of-line virtual destructor to provide home for this class.
virtual ~Action();
// Types - Though these don't actually enforce strong typing, they document
// what types are required to be identical for the actions.
typedef void ExprTy;
typedef void StmtTy;
typedef void DeclTy;
typedef void TypeTy;
typedef void AttrTy;
typedef void BaseTy;
typedef void MemInitTy;
typedef void CXXScopeTy;
/// ActionResult - This structure is used while parsing/acting on expressions,
/// stmts, etc. It encapsulates both the object returned by the action, plus
/// a sense of whether or not it is valid.
template<unsigned UID>
struct ActionResult {
void *Val;
bool isInvalid;
ActionResult(bool Invalid = false) : Val(0), isInvalid(Invalid) {}
template<typename ActualExprTy>
ActionResult(ActualExprTy *val) : Val(val), isInvalid(false) {}
ActionResult(const DiagnosticBuilder &) : Val(0), isInvalid(true) {}
const ActionResult &operator=(void *RHS) {
Val = RHS;
isInvalid = false;
return *this;
}
};
/// Expr/Stmt/Type/BaseResult - Provide a unique type to wrap
/// ExprTy/StmtTy/TypeTy/BaseTy, providing strong typing and
/// allowing for failure.
typedef ActionResult<0> ExprResult;
typedef ActionResult<1> StmtResult;
typedef ActionResult<2> TypeResult;
typedef ActionResult<3> BaseResult;
typedef ActionResult<4> MemInitResult;
/// Deletion callbacks - Since the parser doesn't know the concrete types of
/// the AST nodes being generated, it must do callbacks to delete objects when
/// recovering from errors.
virtual void DeleteExpr(ExprTy *E) {}
virtual void DeleteStmt(StmtTy *E) {}
/// Statistics.
virtual void PrintStats() const {}
//===--------------------------------------------------------------------===//
// Declaration Tracking Callbacks.
//===--------------------------------------------------------------------===//
/// isTypeName - Return non-null if the specified identifier is a typedef name
/// in the current scope.
/// An optional CXXScopeSpec can be passed to indicate the C++ scope (class or
/// namespace) that the identifier must be a member of.
/// i.e. for "foo::bar", 'II' will be "bar" and 'SS' will be "foo::".
virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S,
const CXXScopeSpec *SS = 0) = 0;
/// isCurrentClassName - Return true if the specified name is the
/// name of the innermost C++ class type currently being defined.
virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
const CXXScopeSpec *SS = 0) = 0;
/// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
/// global scope