sink abstract typedefs like Action::ExprTy from the Action class

down to the ActionBase class.  This eliminates dependencies of (e.g.)
DeclSpec.h on Action.h, meaning that action.h can now include these
headers and use their types directly in the actions interfaces.

This is a refactoring to support a future change, no functionality
change.

llvm-svn: 68869
This commit is contained in:
Chris Lattner 2009-04-11 18:48:18 +00:00
parent 225dd6c830
commit 7e0fe4458c
6 changed files with 58 additions and 50 deletions

View File

@ -19,6 +19,7 @@
#include "clang/Basic/TemplateKinds.h" #include "clang/Basic/TemplateKinds.h"
#include "clang/Basic/TypeTraits.h" #include "clang/Basic/TypeTraits.h"
#include "clang/Parse/AccessSpecifier.h" #include "clang/Parse/AccessSpecifier.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/Ownership.h" #include "clang/Parse/Ownership.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
@ -70,15 +71,6 @@ public:
// what types are required to be identical for the actions. // what types are required to be identical for the actions.
typedef ActionBase::ExprTy ExprTy; typedef ActionBase::ExprTy ExprTy;
typedef ActionBase::StmtTy StmtTy; typedef ActionBase::StmtTy StmtTy;
typedef OpaquePtr<0> DeclPtrTy;
typedef OpaquePtr<1> DeclGroupPtrTy;
typedef void TypeTy; // FIXME: Change TypeTy to use OpaquePtr<N>.
typedef OpaquePtr<2> TemplateTy;
typedef void AttrTy;
typedef void BaseTy;
typedef void MemInitTy;
typedef void CXXScopeTy;
typedef void TemplateParamsTy;
/// Expr/Stmt/Type/BaseResult - Provide a unique type to wrap /// Expr/Stmt/Type/BaseResult - Provide a unique type to wrap
/// ExprTy/StmtTy/TypeTy/BaseTy, providing strong typing and /// ExprTy/StmtTy/TypeTy/BaseTy, providing strong typing and

View File

@ -14,10 +14,13 @@
#ifndef LLVM_CLANG_ATTRLIST_H #ifndef LLVM_CLANG_ATTRLIST_H
#define LLVM_CLANG_ATTRLIST_H #define LLVM_CLANG_ATTRLIST_H
#include "clang/Parse/Action.h" #include "clang/Parse/Ownership.h"
#include "clang/Basic/SourceLocation.h"
#include <cassert> #include <cassert>
namespace clang { namespace clang {
class IdentifierInfo;
class Action;
/// AttributeList - Represents GCC's __attribute__ declaration. There are /// AttributeList - Represents GCC's __attribute__ declaration. There are
/// 4 forms of this construct...they are: /// 4 forms of this construct...they are:
@ -32,7 +35,7 @@ class AttributeList {
SourceLocation AttrLoc; SourceLocation AttrLoc;
IdentifierInfo *ParmName; IdentifierInfo *ParmName;
SourceLocation ParmLoc; SourceLocation ParmLoc;
Action::ExprTy **Args; ActionBase::ExprTy **Args;
unsigned NumArgs; unsigned NumArgs;
AttributeList *Next; AttributeList *Next;
AttributeList(const AttributeList &); // DO NOT IMPLEMENT AttributeList(const AttributeList &); // DO NOT IMPLEMENT
@ -40,7 +43,8 @@ class AttributeList {
public: public:
AttributeList(IdentifierInfo *AttrName, SourceLocation AttrLoc, AttributeList(IdentifierInfo *AttrName, SourceLocation AttrLoc,
IdentifierInfo *ParmName, SourceLocation ParmLoc, IdentifierInfo *ParmName, SourceLocation ParmLoc,
Action::ExprTy **args, unsigned numargs, AttributeList *Next); ActionBase::ExprTy **args, unsigned numargs,
AttributeList *Next);
~AttributeList(); ~AttributeList();
enum Kind { // Please keep this list alphabetized. enum Kind { // Please keep this list alphabetized.
@ -115,16 +119,16 @@ public:
unsigned getNumArgs() const { return NumArgs; } unsigned getNumArgs() const { return NumArgs; }
/// getArg - Return the specified argument. /// getArg - Return the specified argument.
Action::ExprTy *getArg(unsigned Arg) const { ActionBase::ExprTy *getArg(unsigned Arg) const {
assert(Arg < NumArgs && "Arg access out of range!"); assert(Arg < NumArgs && "Arg access out of range!");
return Args[Arg]; return Args[Arg];
} }
class arg_iterator { class arg_iterator {
Action::ExprTy** X; ActionBase::ExprTy** X;
unsigned Idx; unsigned Idx;
public: public:
arg_iterator(Action::ExprTy** x, unsigned idx) : X(x), Idx(idx) {} arg_iterator(ActionBase::ExprTy** x, unsigned idx) : X(x), Idx(idx) {}
arg_iterator& operator++() { arg_iterator& operator++() {
++Idx; ++Idx;
@ -141,7 +145,7 @@ public:
return !operator==(I); return !operator==(I);
} }
Action::ExprTy* operator*() const { ActionBase::ExprTy* operator*() const {
return X[Idx]; return X[Idx];
} }

View File

@ -14,15 +14,17 @@
#ifndef LLVM_CLANG_PARSE_DECLSPEC_H #ifndef LLVM_CLANG_PARSE_DECLSPEC_H
#define LLVM_CLANG_PARSE_DECLSPEC_H #define LLVM_CLANG_PARSE_DECLSPEC_H
#include "clang/Parse/Action.h"
#include "clang/Parse/AttributeList.h" #include "clang/Parse/AttributeList.h"
#include "clang/Lex/Token.h" #include "clang/Lex/Token.h"
#include "clang/Basic/OperatorKinds.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
namespace clang { namespace clang {
class LangOptions; class LangOptions;
class Diagnostic; class Diagnostic;
class IdentifierInfo; class IdentifierInfo;
class Preprocessor;
class Declarator;
/// DeclSpec - This class captures information about "declaration specifiers", /// DeclSpec - This class captures information about "declaration specifiers",
/// which encompasses storage-class-specifiers, type-specifiers, /// which encompasses storage-class-specifiers, type-specifiers,
@ -124,7 +126,7 @@ private:
/// TypeRep - This contains action-specific information about a specific TST. /// TypeRep - This contains action-specific information about a specific TST.
/// For example, for a typedef or struct, it might contain the declaration for /// For example, for a typedef or struct, it might contain the declaration for
/// these. /// these.
Action::TypeTy *TypeRep; ActionBase::TypeTy *TypeRep;
// attributes. // attributes.
AttributeList *AttrList; AttributeList *AttrList;
@ -132,7 +134,7 @@ private:
// List of protocol qualifiers for objective-c classes. Used for // List of protocol qualifiers for objective-c classes. Used for
// protocol-qualified interfaces "NString<foo>" and protocol-qualified id // protocol-qualified interfaces "NString<foo>" and protocol-qualified id
// "id<foo>". // "id<foo>".
const Action::DeclPtrTy *ProtocolQualifiers; const ActionBase::DeclPtrTy *ProtocolQualifiers;
unsigned NumProtocolQualifiers; unsigned NumProtocolQualifiers;
// SourceLocation info. These are null if the item wasn't specified or if // SourceLocation info. These are null if the item wasn't specified or if
@ -307,17 +309,17 @@ public:
return AL; return AL;
} }
typedef const Action::DeclPtrTy *ProtocolQualifierListTy; typedef const ActionBase::DeclPtrTy *ProtocolQualifierListTy;
ProtocolQualifierListTy getProtocolQualifiers() const { ProtocolQualifierListTy getProtocolQualifiers() const {
return ProtocolQualifiers; return ProtocolQualifiers;
} }
unsigned getNumProtocolQualifiers() const { unsigned getNumProtocolQualifiers() const {
return NumProtocolQualifiers; return NumProtocolQualifiers;
} }
void setProtocolQualifiers(const Action::DeclPtrTy *Protos, unsigned NP) { void setProtocolQualifiers(const ActionBase::DeclPtrTy *Protos, unsigned NP) {
if (NP == 0) return; if (NP == 0) return;
ProtocolQualifiers = new Action::DeclPtrTy[NP]; ProtocolQualifiers = new ActionBase::DeclPtrTy[NP];
memcpy((void*)ProtocolQualifiers, Protos, sizeof(Action::DeclPtrTy)*NP); memcpy((void*)ProtocolQualifiers, Protos, sizeof(ActionBase::DeclPtrTy)*NP);
NumProtocolQualifiers = NP; NumProtocolQualifiers = NP;
} }
@ -408,8 +410,8 @@ public:
SourceLocation getBeginLoc() const { return Range.getBegin(); } SourceLocation getBeginLoc() const { return Range.getBegin(); }
SourceLocation getEndLoc() const { return Range.getEnd(); } SourceLocation getEndLoc() const { return Range.getEnd(); }
Action::CXXScopeTy *getScopeRep() const { return ScopeRep; } ActionBase::CXXScopeTy *getScopeRep() const { return ScopeRep; }
void setScopeRep(Action::CXXScopeTy *S) { ScopeRep = S; } void setScopeRep(ActionBase::CXXScopeTy *S) { ScopeRep = S; }
bool isEmpty() const { return !Range.isValid(); } bool isEmpty() const { return !Range.isValid(); }
bool isNotEmpty() const { return !isEmpty(); } bool isNotEmpty() const { return !isEmpty(); }
@ -475,7 +477,7 @@ struct DeclaratorChunk {
/// This is the size of the array, or null if [] or [*] was specified. /// This is the size of the array, or null if [] or [*] was specified.
/// Since the parser is multi-purpose, and we don't want to impose a root /// Since the parser is multi-purpose, and we don't want to impose a root
/// expression class on all clients, NumElts is untyped. /// expression class on all clients, NumElts is untyped.
Action::ExprTy *NumElts; ActionBase::ExprTy *NumElts;
void destroy() {} void destroy() {}
}; };
@ -488,7 +490,7 @@ struct DeclaratorChunk {
struct ParamInfo { struct ParamInfo {
IdentifierInfo *Ident; IdentifierInfo *Ident;
SourceLocation IdentLoc; SourceLocation IdentLoc;
Action::DeclPtrTy Param; ActionBase::DeclPtrTy Param;
/// DefaultArgTokens - When the parameter's default argument /// DefaultArgTokens - When the parameter's default argument
/// cannot be parsed immediately (because it occurs within the /// cannot be parsed immediately (because it occurs within the
@ -499,7 +501,7 @@ struct DeclaratorChunk {
ParamInfo() {} ParamInfo() {}
ParamInfo(IdentifierInfo *ident, SourceLocation iloc, ParamInfo(IdentifierInfo *ident, SourceLocation iloc,
Action::DeclPtrTy param, ActionBase::DeclPtrTy param,
CachedTokens *DefArgTokens = 0) CachedTokens *DefArgTokens = 0)
: Ident(ident), IdentLoc(iloc), Param(param), : Ident(ident), IdentLoc(iloc), Param(param),
DefaultArgTokens(DefArgTokens) {} DefaultArgTokens(DefArgTokens) {}
@ -760,13 +762,13 @@ private:
AttributeList *AttrList; AttributeList *AttrList;
/// AsmLabel - The asm label, if specified. /// AsmLabel - The asm label, if specified.
Action::ExprTy *AsmLabel; ActionBase::ExprTy *AsmLabel;
union { union {
// When Kind is DK_Constructor, DK_Destructor, or DK_Conversion, the // When Kind is DK_Constructor, DK_Destructor, or DK_Conversion, the
// type associated with the constructor, destructor, or conversion // type associated with the constructor, destructor, or conversion
// operator. // operator.
Action::TypeTy *Type; ActionBase::TypeTy *Type;
/// When Kind is DK_Operator, this is the actual overloaded /// When Kind is DK_Operator, this is the actual overloaded
/// operator that this declarator names. /// operator that this declarator names.
@ -906,7 +908,7 @@ public:
/// setConstructor - Set this declarator to be a C++ constructor /// setConstructor - Set this declarator to be a C++ constructor
/// declarator. Also extends the range. /// declarator. Also extends the range.
void setConstructor(Action::TypeTy *Ty, SourceLocation Loc) { void setConstructor(ActionBase::TypeTy *Ty, SourceLocation Loc) {
IdentifierLoc = Loc; IdentifierLoc = Loc;
Kind = DK_Constructor; Kind = DK_Constructor;
Type = Ty; Type = Ty;
@ -916,9 +918,8 @@ public:
/// setDestructor - Set this declarator to be a C++ destructor /// setDestructor - Set this declarator to be a C++ destructor
/// declarator. Also extends the range to End, which should be the identifier /// declarator. Also extends the range to End, which should be the identifier
/// token. /// token.
void setDestructor(Action::TypeTy *Ty, SourceLocation Loc, void setDestructor(ActionBase::TypeTy *Ty, SourceLocation Loc,
SourceLocation EndLoc) SourceLocation EndLoc) {
{
IdentifierLoc = Loc; IdentifierLoc = Loc;
Kind = DK_Destructor; Kind = DK_Destructor;
Type = Ty; Type = Ty;
@ -930,7 +931,7 @@ public:
/// conversion function declarator (e.g., @c operator int const *). /// conversion function declarator (e.g., @c operator int const *).
/// Also extends the range to EndLoc, which should be the last token of the /// Also extends the range to EndLoc, which should be the last token of the
/// type name. /// type name.
void setConversionFunction(Action::TypeTy *Ty, SourceLocation Loc, void setConversionFunction(ActionBase::TypeTy *Ty, SourceLocation Loc,
SourceLocation EndLoc) { SourceLocation EndLoc) {
Identifier = 0; Identifier = 0;
IdentifierLoc = Loc; IdentifierLoc = Loc;
@ -1005,10 +1006,10 @@ public:
const AttributeList *getAttributes() const { return AttrList; } const AttributeList *getAttributes() const { return AttrList; }
AttributeList *getAttributes() { return AttrList; } AttributeList *getAttributes() { return AttrList; }
void setAsmLabel(Action::ExprTy *E) { AsmLabel = E; } void setAsmLabel(ActionBase::ExprTy *E) { AsmLabel = E; }
Action::ExprTy *getAsmLabel() const { return AsmLabel; } ActionBase::ExprTy *getAsmLabel() const { return AsmLabel; }
Action::TypeTy *getDeclaratorIdType() const { return Type; } ActionBase::TypeTy *getDeclaratorIdType() const { return Type; }
OverloadedOperatorKind getOverloadedOperator() const { return OperatorKind; } OverloadedOperatorKind getOverloadedOperator() const { return OperatorKind; }
@ -1025,7 +1026,7 @@ public:
/// structure field declarators, which is basically just a bitfield size. /// structure field declarators, which is basically just a bitfield size.
struct FieldDeclarator { struct FieldDeclarator {
Declarator D; Declarator D;
Action::ExprTy *BitfieldSize; ActionBase::ExprTy *BitfieldSize;
explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) { explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) {
BitfieldSize = 0; BitfieldSize = 0;
} }

View File

@ -18,7 +18,7 @@
#include "clang/Parse/Action.h" #include "clang/Parse/Action.h"
namespace clang { namespace clang {
/// Designator - This class is a discriminated union which holds the various /// Designator - This class is a discriminated union which holds the various
/// different sorts of designators possible. A Designation is an array of /// different sorts of designators possible. A Designation is an array of
/// these. An example of a designator are things like this: /// these. An example of a designator are things like this:
@ -41,12 +41,12 @@ private:
unsigned NameLoc; unsigned NameLoc;
}; };
struct ArrayDesignatorInfo { struct ArrayDesignatorInfo {
Action::ExprTy *Index; ActionBase::ExprTy *Index;
unsigned LBracketLoc; unsigned LBracketLoc;
mutable unsigned RBracketLoc; mutable unsigned RBracketLoc;
}; };
struct ArrayRangeDesignatorInfo { struct ArrayRangeDesignatorInfo {
Action::ExprTy *Start, *End; ActionBase::ExprTy *Start, *End;
unsigned LBracketLoc, EllipsisLoc; unsigned LBracketLoc, EllipsisLoc;
mutable unsigned RBracketLoc; mutable unsigned RBracketLoc;
}; };
@ -79,16 +79,16 @@ public:
return SourceLocation::getFromRawEncoding(FieldInfo.NameLoc); return SourceLocation::getFromRawEncoding(FieldInfo.NameLoc);
} }
Action::ExprTy *getArrayIndex() const { ActionBase::ExprTy *getArrayIndex() const {
assert(isArrayDesignator() && "Invalid accessor"); assert(isArrayDesignator() && "Invalid accessor");
return ArrayInfo.Index; return ArrayInfo.Index;
} }
Action::ExprTy *getArrayRangeStart() const { ActionBase::ExprTy *getArrayRangeStart() const {
assert(isArrayRangeDesignator() && "Invalid accessor"); assert(isArrayRangeDesignator() && "Invalid accessor");
return ArrayRangeInfo.Start; return ArrayRangeInfo.Start;
} }
Action::ExprTy *getArrayRangeEnd() const { ActionBase::ExprTy *getArrayRangeEnd() const {
assert(isArrayRangeDesignator() && "Invalid accessor"); assert(isArrayRangeDesignator() && "Invalid accessor");
return ArrayRangeInfo.End; return ArrayRangeInfo.End;
} }
@ -126,7 +126,8 @@ public:
return D; return D;
} }
static Designator getArray(Action::ExprTy *Index, SourceLocation LBracketLoc) { static Designator getArray(ActionBase::ExprTy *Index,
SourceLocation LBracketLoc) {
Designator D; Designator D;
D.Kind = ArrayDesignator; D.Kind = ArrayDesignator;
D.ArrayInfo.Index = Index; D.ArrayInfo.Index = Index;
@ -135,7 +136,8 @@ public:
return D; return D;
} }
static Designator getArrayRange(Action::ExprTy *Start, Action::ExprTy *End, static Designator getArrayRange(ActionBase::ExprTy *Start,
ActionBase::ExprTy *End,
SourceLocation LBracketLoc, SourceLocation LBracketLoc,
SourceLocation EllipsisLoc) { SourceLocation EllipsisLoc) {
Designator D; Designator D;

View File

@ -201,9 +201,17 @@ namespace clang {
// Types - Though these don't actually enforce strong typing, they document // Types - Though these don't actually enforce strong typing, they document
// what types are required to be identical for the actions. // what types are required to be identical for the actions.
typedef OpaquePtr<0> DeclPtrTy;
typedef OpaquePtr<1> DeclGroupPtrTy;
typedef OpaquePtr<2> TemplateTy;
typedef void AttrTy;
typedef void BaseTy;
typedef void MemInitTy;
typedef void ExprTy; typedef void ExprTy;
typedef void StmtTy; typedef void StmtTy;
typedef void TemplateParamsTy; typedef void TemplateParamsTy;
typedef void CXXScopeTy;
typedef void TypeTy; // FIXME: Change TypeTy to use OpaquePtr<N>.
/// ActionResult - This structure is used while parsing/acting on /// ActionResult - This structure is used while parsing/acting on
/// expressions, stmts, etc. It encapsulates both the object returned by /// expressions, stmts, etc. It encapsulates both the object returned by

View File

@ -12,11 +12,12 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "clang/Parse/AttributeList.h" #include "clang/Parse/AttributeList.h"
#include "clang/Basic/IdentifierTable.h"
using namespace clang; using namespace clang;
AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc, AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
IdentifierInfo *pName, SourceLocation pLoc, IdentifierInfo *pName, SourceLocation pLoc,
Action::ExprTy **ExprList, unsigned numArgs, ActionBase::ExprTy **ExprList, unsigned numArgs,
AttributeList *n) AttributeList *n)
: AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc), : AttrName(aName), AttrLoc(aLoc), ParmName(pName), ParmLoc(pLoc),
NumArgs(numArgs), Next(n) { NumArgs(numArgs), Next(n) {
@ -24,7 +25,7 @@ AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
if (numArgs == 0) if (numArgs == 0)
Args = 0; Args = 0;
else { else {
Args = new Action::ExprTy*[numArgs]; Args = new ActionBase::ExprTy*[numArgs];
memcpy(Args, ExprList, numArgs*sizeof(Args[0])); memcpy(Args, ExprList, numArgs*sizeof(Args[0]));
} }
} }
@ -32,7 +33,7 @@ AttributeList::AttributeList(IdentifierInfo *aName, SourceLocation aLoc,
AttributeList::~AttributeList() { AttributeList::~AttributeList() {
if (Args) { if (Args) {
// FIXME: before we delete the vector, we need to make sure the Expr's // FIXME: before we delete the vector, we need to make sure the Expr's
// have been deleted. Since Action::ExprTy is "void", we are dependent // have been deleted. Since ActionBase::ExprTy is "void", we are dependent
// on the actions module for actually freeing the memory. The specific // on the actions module for actually freeing the memory. The specific
// hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType, // hooks are ActOnDeclarator, ActOnTypeName, ActOnParamDeclaratorType,
// ParseField, ParseTag. Once these routines have freed the expression, // ParseField, ParseTag. Once these routines have freed the expression,