Out << "asm(";
AD->getAsmString()->printPretty(Out);
Out << ")\n";
- } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
- Out << "Read top-level variable decl: '" << SD->getNameAsString() << "'\n";
+ } else if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
+ Out << "Read top-level variable decl: '" << ND->getNameAsString() << "'\n";
} else {
assert(0 && "Unknown decl type!");
}
}
} else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
PrintTypeDefDecl(TD);
- } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
- Out << "Read top-level variable decl: '" << SD->getNameAsString()
+ } else if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
+ Out << "Read top-level variable decl: '" << ND->getNameAsString()
<< "'\n";
} else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) {
Out << "Read objc interface '" << OID->getNameAsString() << "'\n";
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI) {
- ScopedDecl *SD = *DI;
+ Decl *SD = *DI;
if (ValueDecl *ND = dyn_cast<ValueDecl>(SD)) {
if (isBlockPointerType(ND->getType()))
RewriteBlockPointerDecl(ND);
ObjCImplementationDecl *IMD,
ObjCCategoryImplDecl *CID);
void RewriteInterfaceDecl(ObjCInterfaceDecl *Dcl);
- void RewriteImplementationDecl(NamedDecl *Dcl);
+ void RewriteImplementationDecl(Decl *Dcl);
void RewriteObjCMethodDecl(ObjCMethodDecl *MDecl, std::string &ResultStr);
void RewriteCategoryDecl(ObjCCategoryDecl *Dcl);
void RewriteProtocolDecl(ObjCProtocolDecl *Dcl);
}
}
}
-void RewriteObjC::RewriteImplementationDecl(NamedDecl *OID) {
+void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
ObjCImplementationDecl *IMD = dyn_cast<ObjCImplementationDecl>(OID);
ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID);
buf = "\n{\n\t";
if (DeclStmt *DS = dyn_cast<DeclStmt>(S->getElement())) {
// type elem;
- ScopedDecl* D = DS->getSolitaryDecl();
+ NamedDecl* D = cast<NamedDecl>(DS->getSolitaryDecl());
QualType ElementType = cast<ValueDecl>(D)->getType();
elementTypeAsString = ElementType.getAsString();
buf += elementTypeAsString;
SelGetUidFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
SelGetUidIdent, getFuncType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthGetProtocolFunctionDecl - Protocol objc_getProtocol(const char *proto);
GetProtocolFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
SelGetProtoIdent, getFuncType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
void RewriteObjC::RewriteFunctionDecl(FunctionDecl *FD) {
SuperContructorFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthMsgSendFunctionDecl - id objc_msgSend(id self, SEL op, ...);
MsgSendFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthMsgSendSuperFunctionDecl - id objc_msgSendSuper(struct objc_super *, SEL op, ...);
MsgSendSuperFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthMsgSendStretFunctionDecl - id objc_msgSend_stret(id self, SEL op, ...);
MsgSendStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthMsgSendSuperStretFunctionDecl -
MsgSendSuperStretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthMsgSendFpretFunctionDecl - double objc_msgSend_fpret(id self, SEL op, ...);
MsgSendFpretFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
msgSendIdent, msgSendType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthGetClassFunctionDecl - id objc_getClass(const char *name);
GetClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
getClassIdent, getClassType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
// SynthGetMetaClassFunctionDecl - id objc_getClass(const char *name);
GetMetaClassFunctionDecl = FunctionDecl::Create(*Context, TUDecl,
SourceLocation(),
getClassIdent, getClassType,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
}
Stmt *RewriteObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
VarDecl *NewVD = VarDecl::Create(*Context, TUDecl, SourceLocation(),
&Context->Idents.get(S.c_str()), strType,
- VarDecl::Static, NULL);
+ VarDecl::Static);
DeclRefExpr *DRE = new DeclRefExpr(NewVD, strType, SourceLocation());
Expr *Unop = new UnaryOperator(DRE, UnaryOperator::AddrOf,
Context->getPointerType(DRE->getType()),
SuperStructDecl->addDecl(FieldDecl::Create(*Context, SuperStructDecl,
SourceLocation(), 0,
FieldTypes[i], /*BitWidth=*/0,
- /*Mutable=*/false, 0));
+ /*Mutable=*/false));
}
SuperStructDecl->completeDefinition(*Context);
SourceLocation(), 0,
FieldTypes[i],
/*BitWidth=*/0,
- /*Mutable=*/true, 0));
+ /*Mutable=*/true));
}
ConstantStringDecl->completeDefinition(*Context);
FieldDecl *FD = FieldDecl::Create(*Context, 0, SourceLocation(),
&Context->Idents.get("FuncPtr"), Context->VoidPtrTy,
- /*BitWidth=*/0, /*Mutable=*/true, 0);
+ /*BitWidth=*/0, /*Mutable=*/true);
MemberExpr *ME = new MemberExpr(PE, true, FD, SourceLocation(), FD->getType());
CastExpr *FunkCast = new CStyleCastExpr(PtrToFuncCastType, ME, PtrToFuncCastType, SourceLocation(), SourceLocation());
IdentifierInfo *ID = &Context->Idents.get(name);
QualType FType = Context->getFunctionTypeNoProto(Context->VoidPtrTy);
return FunctionDecl::Create(*Context, TUDecl,SourceLocation(),
- ID, FType, FunctionDecl::Extern, false, 0);
+ ID, FType, FunctionDecl::Extern, false);
}
Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp) {
// Blocks rewrite rules.
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI) {
- ScopedDecl *SD = *DI;
+ Decl *SD = *DI;
if (ValueDecl *ND = dyn_cast<ValueDecl>(SD)) {
if (isTopLevelBlockPointerType(ND->getType()))
RewriteBlockPointerDecl(ND);
(de-)serialization.</dd>
</dl>
-<p>The declarations stored within each declaration context are
- called <i>scoped declarations</i> and the AST nodes for each of
- these declarations are
- derived from the <code>ScopedDecl</code> class, which provides
- information about the context in which that declaration lives. One
+<p>All declarations are stored within a declaration context, and one
+ can query
+ information about the context in which each declaration lives. One
can retrieve the <code>DeclContext</code> that contains a
- particular <code>ScopedDecl</code>
- using <code>ScopedDecl::getDeclContext</code>. However, see the
+ particular <code>Decl</code>
+ using <code>Decl::getDeclContext</code>. However, see the
section <a href="#LexicalAndSemanticContexts">Lexical and Semantic
Contexts</a> for more information about how to interpret this
context information.</p>
primarily use this semantics-centric view.</p>
<h4 id="LexicalAndSemanticContexts">Lexical and Semantic Contexts</h4>
-<p>Each scoped declaration (whose AST node derived
- from <code>ScopedDecl</code>) has two potentially different
+<p>Each declaration has two potentially different
declaration contexts: a <i>lexical</i> context, which corresponds to
the source-centric view of the declaration context, and
a <i>semantic</i> context, which corresponds to the
semantics-centric view. The lexical context is accessible
- via <code>ScopedDecl::getLexicalDeclContext</code> while the
+ via <code>Decl::getLexicalDeclContext</code> while the
semantic context is accessible
- via <code>ScopedDecl::getDeclContext</code>, both of which return
+ via <code>Decl::getDeclContext</code>, both of which return
<code>DeclContext</code> pointers. For most declarations, the two
contexts are identical. For example:</p>
/// HandleTopLevelDecl - Handle the specified top-level declaration. This is
/// called by the parser to process every top-level Decl*. Note that D can
/// be the head of a chain of Decls (e.g. for `int a, b` the chain will have
- /// two elements). Use ScopedDecl::getNextDeclarator() to walk the chain.
+ /// two elements). Use Decl::getNextDeclarator() to walk the chain.
virtual void HandleTopLevelDecl(Decl *D) {}
/// HandleTranslationUnit - This method is called when the ASTs for entire
/// FIXME: The TranslationUnit class should probably be modified to serve as
/// the top decl context. It would have ownership of the top decls so that the
/// AST is self-contained and easily de/serializable.
+/// FIXME: TranslationUnitDecl isn't really a Decl (!)
class TranslationUnitDecl : public Decl, public DeclContext {
TranslationUnitDecl()
- : Decl(TranslationUnit, SourceLocation()),
+ : Decl(TranslationUnit, 0, SourceLocation()),
DeclContext(TranslationUnit) {}
public:
static TranslationUnitDecl *Create(ASTContext &C);
DeclarationName Name;
protected:
- NamedDecl(Kind DK, SourceLocation L, DeclarationName N)
- : Decl(DK, L), Name(N) {}
+ NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
+ : Decl(DK, DC, L), Name(N) {}
-public:
- NamedDecl(Kind DK, SourceLocation L, IdentifierInfo *Id)
- : Decl(DK, L), Name(Id) {}
+ NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
+ : Decl(DK, DC, L), Name(Id) {}
+public:
/// getIdentifier - Get the identifier that names this declaration,
/// if there is one. This will return NULL if this declaration has
/// no name (e.g., for an unnamed class) or if the name is a special
/// For simple declarations, getNameAsCString() should suffice.
std::string getNameAsString() const { return Name.getAsString(); }
- static bool classof(const Decl *D) {
- return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
- }
- static bool classof(const NamedDecl *D) { return true; }
-
-protected:
- void EmitInRec(llvm::Serializer& S) const;
- void ReadInRec(llvm::Deserializer& D, ASTContext& C);
-};
-
-/// ScopedDecl - Represent lexically scoped names, used for all ValueDecl's
-/// and TypeDecl's.
-class ScopedDecl : public NamedDecl {
- /// NextDeclarator - If this decl was part of a multi-declarator declaration,
- /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
- ScopedDecl *NextDeclarator;
-
- /// NextDeclInScope - The next declaration within the same lexical
- /// DeclContext. These pointers form the linked list that is
- /// traversed via DeclContext's decls_begin()/decls_end().
- /// FIXME: If NextDeclarator is non-NULL, will it always be the same
- /// as NextDeclInScope? If so, we can use a
- /// PointerIntPair<ScopedDecl*, 1> to make ScopedDecl smaller.
- ScopedDecl *NextDeclInScope;
-
- friend class DeclContext;
- friend class DeclContext::decl_iterator;
-
- /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
- /// For declarations that don't contain C++ scope specifiers, it contains
- /// the DeclContext where the ScopedDecl was declared.
- /// For declarations with C++ scope specifiers, it contains a MultipleDC*
- /// with the context where it semantically belongs (SemanticDC) and the
- /// context where it was lexically declared (LexicalDC).
- /// e.g.:
- ///
- /// namespace A {
- /// void f(); // SemanticDC == LexicalDC == 'namespace A'
- /// }
- /// void A::f(); // SemanticDC == namespace 'A'
- /// // LexicalDC == global namespace
- uintptr_t DeclCtx;
-
- struct MultipleDC {
- DeclContext *SemanticDC;
- DeclContext *LexicalDC;
- };
-
- inline bool isInSemaDC() const { return (DeclCtx & 0x1) == 0; }
- inline bool isOutOfSemaDC() const { return (DeclCtx & 0x1) != 0; }
- inline MultipleDC *getMultipleDC() const {
- return reinterpret_cast<MultipleDC*>(DeclCtx & ~0x1);
- }
-
-protected:
- ScopedDecl(Kind DK, DeclContext *DC, SourceLocation L,
- DeclarationName N, ScopedDecl *PrevDecl = 0)
- : NamedDecl(DK, L, N), NextDeclarator(PrevDecl), NextDeclInScope(0),
- DeclCtx(reinterpret_cast<uintptr_t>(DC)) {}
-
- virtual ~ScopedDecl();
-
- /// setDeclContext - Set both the semantic and lexical DeclContext
- /// to DC.
- void setDeclContext(DeclContext *DC);
-
-public:
- const DeclContext *getDeclContext() const {
- if (isInSemaDC())
- return reinterpret_cast<DeclContext*>(DeclCtx);
- return getMultipleDC()->SemanticDC;
- }
- DeclContext *getDeclContext() {
- return const_cast<DeclContext*>(
- const_cast<const ScopedDecl*>(this)->getDeclContext());
- }
-
- void setAccess(AccessSpecifier AS) { Access = AS; }
- AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
-
- /// getLexicalDeclContext - The declaration context where this ScopedDecl was
- /// lexically declared (LexicalDC). May be different from
- /// getDeclContext() (SemanticDC).
- /// e.g.:
- ///
- /// namespace A {
- /// void f(); // SemanticDC == LexicalDC == 'namespace A'
- /// }
- /// void A::f(); // SemanticDC == namespace 'A'
- /// // LexicalDC == global namespace
- const DeclContext *getLexicalDeclContext() const {
- if (isInSemaDC())
- return reinterpret_cast<DeclContext*>(DeclCtx);
- return getMultipleDC()->LexicalDC;
- }
- DeclContext *getLexicalDeclContext() {
- return const_cast<DeclContext*>(
- const_cast<const ScopedDecl*>(this)->getLexicalDeclContext());
- }
-
- void setLexicalDeclContext(DeclContext *DC);
-
- /// getNextDeclarator - If this decl was part of a multi-declarator
- /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
- /// declarator. Otherwise it returns null.
- ScopedDecl *getNextDeclarator() { return NextDeclarator; }
- const ScopedDecl *getNextDeclarator() const { return NextDeclarator; }
- void setNextDeclarator(ScopedDecl *N) { NextDeclarator = N; }
-
- // isDefinedOutsideFunctionOrMethod - This predicate returns true if this
- // scoped decl is defined outside the current function or method. This is
- // roughly global variables and functions, but also handles enums (which could
- // be defined inside or outside a function etc).
- bool isDefinedOutsideFunctionOrMethod() const {
- if (getDeclContext())
- return !getDeclContext()->getLookupContext()->isFunctionOrMethod();
- else
- return true;
- }
-
/// declarationReplaces - Determine whether this declaration, if
/// known to be well-formed within its context, will replace the
/// declaration OldD if introduced into scope. A declaration will
/// overloaded function.
bool declarationReplaces(NamedDecl *OldD) const;
- // Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
- return D->getKind() >= ScopedFirst && D->getKind() <= ScopedLast;
+ return D->getKind() >= NamedFirst && D->getKind() <= NamedLast;
}
- static bool classof(const ScopedDecl *D) { return true; }
+ static bool classof(const NamedDecl *D) { return true; }
protected:
void EmitInRec(llvm::Serializer& S) const;
void ReadInRec(llvm::Deserializer& D, ASTContext& C);
-
- void EmitOutRec(llvm::Serializer& S) const;
- void ReadOutRec(llvm::Deserializer& D, ASTContext& C);
-
- friend void Decl::Destroy(ASTContext& C);
};
/// NamespaceDecl - Represent a C++ namespace.
-class NamespaceDecl : public ScopedDecl, public DeclContext {
+class NamespaceDecl : public NamedDecl, public DeclContext {
SourceLocation LBracLoc, RBracLoc;
// For extended namespace definitions:
NamespaceDecl *OrigNamespace;
NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
- : ScopedDecl(Namespace, DC, L, Id, 0), DeclContext(Namespace) {
+ : NamedDecl(Namespace, DC, L, Id), DeclContext(Namespace) {
OrigNamespace = this;
}
public:
/// ValueDecl - Represent the declaration of a variable (in which case it is
/// an lvalue) a function (in which case it is a function designator) or
/// an enum constant.
-class ValueDecl : public ScopedDecl {
+class ValueDecl : public NamedDecl {
QualType DeclType;
protected:
ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
- DeclarationName N, QualType T, ScopedDecl *PrevDecl)
- : ScopedDecl(DK, DC, L, N, PrevDecl), DeclType(T) {}
+ DeclarationName N, QualType T)
+ : NamedDecl(DK, DC, L, N), DeclType(T) {}
public:
QualType getType() const { return DeclType; }
void setType(QualType newType) { DeclType = newType; }
friend class StmtIteratorBase;
protected:
VarDecl(Kind DK, DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
- QualType T, StorageClass SC, ScopedDecl *PrevDecl,
- SourceLocation TSSL = SourceLocation())
- : ValueDecl(DK, DC, L, Id, T, PrevDecl), Init(0),
+ QualType T, StorageClass SC, SourceLocation TSSL = SourceLocation())
+ : ValueDecl(DK, DC, L, Id, T), Init(0),
ThreadSpecified(false), HasCXXDirectInit(false),
DeclaredInCondition(false), TypeSpecStartLoc(TSSL) {
SClass = SC;
public:
static VarDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
- QualType T, StorageClass S, ScopedDecl *PrevDecl,
+ QualType T, StorageClass S,
SourceLocation TypeSpecStartLoc = SourceLocation());
virtual ~VarDecl();
class ImplicitParamDecl : public VarDecl {
protected:
ImplicitParamDecl(Kind DK, DeclContext *DC, SourceLocation L,
- IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl)
- : VarDecl(DK, DC, L, Id, T, VarDecl::None, PrevDecl) {}
+ IdentifierInfo *Id, QualType Tw)
+ : VarDecl(DK, DC, L, Id, Tw, VarDecl::None) {}
public:
static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
- QualType T, ScopedDecl *PrevDecl);
+ QualType T);
// Implement isa/cast/dyncast/etc.
static bool classof(const ImplicitParamDecl *D) { return true; }
static bool classof(const Decl *D) { return D->getKind() == ImplicitParam; }
protected:
ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T, StorageClass S,
- Expr *DefArg, ScopedDecl *PrevDecl)
- : VarDecl(DK, DC, L, Id, T, S, PrevDecl),
+ Expr *DefArg)
+ : VarDecl(DK, DC, L, Id, T, S),
objcDeclQualifier(OBJC_TQ_None), DefaultArg(DefArg) {}
public:
static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L,IdentifierInfo *Id,
- QualType T, StorageClass S, Expr *DefArg,
- ScopedDecl *PrevDecl);
+ QualType T, StorageClass S, Expr *DefArg);
ObjCDeclQualifier getObjCDeclQualifier() const {
return ObjCDeclQualifier(objcDeclQualifier);
ParmVarWithOriginalTypeDecl(DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T,
QualType OT, StorageClass S,
- Expr *DefArg, ScopedDecl *PrevDecl)
- : ParmVarDecl(OriginalParmVar,
- DC, L, Id, T, S, DefArg, PrevDecl), OriginalType(OT) {}
+ Expr *DefArg)
+ : ParmVarDecl(OriginalParmVar, DC, L, Id, T, S, DefArg), OriginalType(OT) {}
public:
static ParmVarWithOriginalTypeDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L,IdentifierInfo *Id,
QualType T, QualType OT,
- StorageClass S, Expr *DefArg,
- ScopedDecl *PrevDecl);
+ StorageClass S, Expr *DefArg);
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == OriginalParmVar; }
protected:
FunctionDecl(Kind DK, DeclContext *DC, SourceLocation L,
DeclarationName N, QualType T,
- StorageClass S, bool isInline, ScopedDecl *PrevDecl,
+ StorageClass S, bool isInline,
SourceLocation TSSL = SourceLocation())
- : ValueDecl(DK, DC, L, N, T, PrevDecl),
+ : ValueDecl(DK, DC, L, N, T),
DeclContext(DK),
ParamInfo(0), Body(0), PreviousDeclaration(0),
SClass(S), IsInline(isInline), IsVirtual(false), IsPure(false),
public:
static FunctionDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
DeclarationName N, QualType T,
- StorageClass S = None, bool isInline = false,
- ScopedDecl *PrevDecl = 0,
+ StorageClass S = None, bool isInline = false,
SourceLocation TSStartLoc = SourceLocation());
SourceLocation getTypeSpecStartLoc() const { return TypeSpecStartLoc; }
/// FieldDecl - An instance of this class is created by Sema::ActOnField to
/// represent a member of a struct/union/class.
-class FieldDecl : public ScopedDecl {
+class FieldDecl : public NamedDecl {
bool Mutable : 1;
QualType DeclType;
Expr *BitWidth;
protected:
FieldDecl(Kind DK, DeclContext *DC, SourceLocation L,
- IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable,
- ScopedDecl *PrevDecl)
- : ScopedDecl(DK, DC, L, Id, PrevDecl), Mutable(Mutable), DeclType(T),
+ IdentifierInfo *Id, QualType T, Expr *BW, bool Mutable)
+ : NamedDecl(DK, DC, L, Id), Mutable(Mutable), DeclType(T),
BitWidth(BW)
{ }
public:
static FieldDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *BW,
- bool Mutable, ScopedDecl *PrevDecl);
+ bool Mutable);
QualType getType() const { return DeclType; }
protected:
EnumConstantDecl(DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *E,
- const llvm::APSInt &V, ScopedDecl *PrevDecl)
- : ValueDecl(EnumConstant, DC, L, Id, T, PrevDecl), Init((Stmt*)E), Val(V) {}
+ const llvm::APSInt &V)
+ : ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
virtual ~EnumConstantDecl() {}
public:
static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
SourceLocation L, IdentifierInfo *Id,
QualType T, Expr *E,
- const llvm::APSInt &V, ScopedDecl *PrevDecl);
+ const llvm::APSInt &V);
virtual void Destroy(ASTContext& C);
/// TypeDecl - Represents a declaration of a type.
///
-class TypeDecl : public ScopedDecl {
+class TypeDecl : public NamedDecl {
/// TypeForDecl - This indicates the Type object that represents this
/// TypeDecl. It is a cache maintained by ASTContext::getTypedefType,
/// ASTContext::getTagDeclType, and ASTContext::getTemplateTypeParmType.
protected:
TypeDecl(Kind DK, DeclContext *DC, SourceLocation L,
- IdentifierInfo *Id, ScopedDecl *PrevDecl)
- : ScopedDecl(DK, DC, L, Id, PrevDecl), TypeForDecl(0) {}
+ IdentifierInfo *Id)
+ : NamedDecl(DK, DC, L, Id), TypeForDecl(0) {}
public:
// Implement isa/cast/dyncast/etc.
/// UnderlyingType - This is the type the typedef is set to.
QualType UnderlyingType;
TypedefDecl(DeclContext *DC, SourceLocation L,
- IdentifierInfo *Id, QualType T, ScopedDecl *PD)
- : TypeDecl(Typedef, DC, L, Id, PD), UnderlyingType(T) {}
+ IdentifierInfo *Id, QualType T)
+ : TypeDecl(Typedef, DC, L, Id), UnderlyingType(T) {}
virtual ~TypedefDecl() {}
public:
static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L,IdentifierInfo *Id,
- QualType T, ScopedDecl *PD);
+ QualType T);
QualType getUnderlyingType() const { return UnderlyingType; }
void setUnderlyingType(QualType newType) { UnderlyingType = newType; }
bool IsDefinition : 1;
protected:
TagDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
- IdentifierInfo *Id, ScopedDecl *PrevDecl)
- : TypeDecl(DK, DC, L, Id, PrevDecl), DeclContext(DK) {
+ IdentifierInfo *Id)
+ : TypeDecl(DK, DC, L, Id), DeclContext(DK) {
assert((DK != Enum || TK == TK_enum) &&"EnumDecl not matched with TK_enum");
TagDeclKind = TK;
IsDefinition = false;
QualType IntegerType;
EnumDecl(DeclContext *DC, SourceLocation L,
- IdentifierInfo *Id, ScopedDecl *PrevDecl)
- : TagDecl(Enum, TK_enum, DC, L, Id, PrevDecl) {
+ IdentifierInfo *Id)
+ : TagDecl(Enum, TK_enum, DC, L, Id) {
IntegerType = QualType();
}
public:
class FileScopeAsmDecl : public Decl {
StringLiteral *AsmString;
- FileScopeAsmDecl(SourceLocation L, StringLiteral *asmstring)
- : Decl(FileScopeAsm, L), AsmString(asmstring) {}
+ FileScopeAsmDecl(DeclContext *DC, SourceLocation L, StringLiteral *asmstring)
+ : Decl(FileScopeAsm, DC, L), AsmString(asmstring) {}
public:
- static FileScopeAsmDecl *Create(ASTContext &C, SourceLocation L,
- StringLiteral *Str);
+ static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
+ SourceLocation L, StringLiteral *Str);
const StringLiteral *getAsmString() const { return AsmString; }
StringLiteral *getAsmString() { return AsmString; }
llvm::SmallVector<ParmVarDecl*, 8> Args;
Stmt *Body;
- // Since BlockDecl's aren't named/scoped, we need to store the context.
- DeclContext *ParentContext;
protected:
BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
- : Decl(Block, CaretLoc), DeclContext(Block), Body(0), ParentContext(DC) {}
+ : Decl(Block, DC, CaretLoc), DeclContext(Block), Body(0) {}
virtual ~BlockDecl();
virtual void Destroy(ASTContext& C);
Args.clear();
Args.insert(Args.begin(), args, args+numargs);
}
- const DeclContext *getParentContext() const { return ParentContext; }
- DeclContext *getParentContext() { return ParentContext; }
/// arg_iterator - Iterate over the ParmVarDecl's for this block.
typedef llvm::SmallVector<ParmVarDecl*, 8>::const_iterator param_iterator;
friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
};
-inline DeclContext::decl_iterator& DeclContext::decl_iterator::operator++() {
- Current = Current->NextDeclInScope;
- return *this;
-}
-
} // end namespace clang
#endif
#include "clang/AST/Attr.h"
#include "clang/AST/Type.h"
+// FIXME: Layering violation
+#include "clang/Parse/AccessSpecifier.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/PointerIntPair.h"
class TranslationUnitDecl;
class NamespaceDecl;
class NamedDecl;
-class ScopedDecl;
class FunctionDecl;
class CXXRecordDecl;
class EnumDecl;
TranslationUnit, // [DeclContext]
// NamedDecl
OverloadedFunction,
- // ScopedDecl
- Field,
- ObjCIvar,
- ObjCAtDefsField,
- Namespace, // [DeclContext]
- // TypeDecl
- Typedef,
- // TagDecl // [DeclContext]
- Enum,
- Record,
- CXXRecord,
- TemplateTypeParm,
- // ValueDecl
- EnumConstant,
- Function, // [DeclContext]
- CXXMethod,
- CXXConstructor,
- CXXDestructor,
- CXXConversion,
- Var,
- ImplicitParam,
- CXXClassVar,
- ParmVar,
- OriginalParmVar,
- NonTypeTemplateParm,
- LinkageSpec, // [DeclContext]
- ObjCMethod, // [DeclContext]
+ Field,
+ ObjCIvar,
+ ObjCAtDefsField,
+ Namespace, // [DeclContext]
+ // TypeDecl
+ Typedef,
+ // TagDecl // [DeclContext]
+ Enum,
+ Record,
+ CXXRecord,
+ TemplateTypeParm,
+ // ValueDecl
+ EnumConstant,
+ Function, // [DeclContext]
+ CXXMethod,
+ CXXConstructor,
+ CXXDestructor,
+ CXXConversion,
+ Var,
+ ImplicitParam,
+ CXXClassVar,
+ ParmVar,
+ OriginalParmVar,
+ NonTypeTemplateParm,
+ ObjCMethod, // [DeclContext]
ObjCContainer, // [DeclContext]
ObjCCategory,
ObjCProtocol,
ObjCInterface,
ObjCCategoryImpl, // [DeclContext]
- ObjCImplementation, // [DeclContext]
ObjCProperty,
ObjCCompatibleAlias,
- ObjCClass,
- ObjCForwardProtocol,
- ObjCPropertyImpl,
+ LinkageSpec, // [DeclContext]
+ ObjCPropertyImpl,
+ ObjCImplementation, // [DeclContext]
+ ObjCForwardProtocol,
+ ObjCClass,
FileScopeAsm,
- Block, // [DeclContext]
+ Block, // [DeclContext]
// For each non-leaf class, we now define a mapping to the first/last member
// of the class, to allow efficient classof.
- NamedFirst = OverloadedFunction, NamedLast = NonTypeTemplateParm,
+ NamedFirst = OverloadedFunction, NamedLast = ObjCCompatibleAlias,
ObjCContainerFirst = ObjCContainer, ObjCContainerLast = ObjCInterface,
FieldFirst = Field , FieldLast = ObjCAtDefsField,
- ScopedFirst = Field , ScopedLast = ObjCPropertyImpl,
TypeFirst = Typedef , TypeLast = TemplateTypeParm,
TagFirst = Enum , TagLast = CXXRecord,
RecordFirst = Record , RecordLast = CXXRecord,
/// Loc - The location that this decl.
SourceLocation Loc;
+ /// NextDeclarator - If this decl was part of a multi-declarator declaration,
+ /// such as "int X, Y, *Z;" this indicates Decl for the next declarator.
+ Decl *NextDeclarator;
+
+ /// NextDeclInScope - The next declaration within the same lexical
+ /// DeclContext. These pointers form the linked list that is
+ /// traversed via DeclContext's decls_begin()/decls_end().
+ /// FIXME: If NextDeclarator is non-NULL, will it always be the same
+ /// as NextDeclInScope? If so, we can use a
+ /// PointerIntPair<Decl*, 1> to make Decl smaller.
+ Decl *NextDeclInScope;
+
+ friend class DeclContext;
+
+ /// DeclCtx - Holds either a DeclContext* or a MultipleDC*.
+ /// For declarations that don't contain C++ scope specifiers, it contains
+ /// the DeclContext where the Decl was declared.
+ /// For declarations with C++ scope specifiers, it contains a MultipleDC*
+ /// with the context where it semantically belongs (SemanticDC) and the
+ /// context where it was lexically declared (LexicalDC).
+ /// e.g.:
+ ///
+ /// namespace A {
+ /// void f(); // SemanticDC == LexicalDC == 'namespace A'
+ /// }
+ /// void A::f(); // SemanticDC == namespace 'A'
+ /// // LexicalDC == global namespace
+ uintptr_t DeclCtx;
+
+ struct MultipleDC {
+ DeclContext *SemanticDC;
+ DeclContext *LexicalDC;
+ };
+
+ inline bool isInSemaDC() const { return (DeclCtx & 0x1) == 0; }
+ inline bool isOutOfSemaDC() const { return (DeclCtx & 0x1) != 0; }
+ inline MultipleDC *getMultipleDC() const {
+ return reinterpret_cast<MultipleDC*>(DeclCtx & ~0x1);
+ }
+
/// DeclKind - This indicates which class this is.
Kind DeclKind : 8;
/// the implementation rather than explicitly written by the user.
bool Implicit : 1;
- protected:
+protected:
/// Access - Used by C++ decls for the access specifier.
// NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
unsigned Access : 2;
friend class CXXClassMemberWrapper;
- Decl(Kind DK, SourceLocation L) : Loc(L), DeclKind(DK), InvalidDecl(0),
- HasAttrs(false), Implicit(false) {
+ Decl(Kind DK, DeclContext *DC, SourceLocation L)
+ : Loc(L), NextDeclarator(0), NextDeclInScope(0),
+ DeclCtx(reinterpret_cast<uintptr_t>(DC)), DeclKind(DK), InvalidDecl(0),
+ HasAttrs(false), Implicit(false) {
if (Decl::CollectingStats()) addDeclKind(DK);
}
virtual ~Decl();
+ /// setDeclContext - Set both the semantic and lexical DeclContext
+ /// to DC.
+ void setDeclContext(DeclContext *DC);
+
public:
SourceLocation getLocation() const { return Loc; }
void setLocation(SourceLocation L) { Loc = L; }
Kind getKind() const { return DeclKind; }
const char *getDeclKindName() const;
+ const DeclContext *getDeclContext() const {
+ if (isInSemaDC())
+ return reinterpret_cast<DeclContext*>(DeclCtx);
+ return getMultipleDC()->SemanticDC;
+ }
+ DeclContext *getDeclContext() {
+ return const_cast<DeclContext*>(
+ const_cast<const Decl*>(this)->getDeclContext());
+ }
+
+ void setAccess(AccessSpecifier AS) { Access = AS; }
+ AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
+
void addAttr(Attr *attr);
const Attr *getAttrs() const;
void swapAttrs(Decl *D);
return getIdentifierNamespace() & NS;
}
+ /// getLexicalDeclContext - The declaration context where this Decl was
+ /// lexically declared (LexicalDC). May be different from
+ /// getDeclContext() (SemanticDC).
+ /// e.g.:
+ ///
+ /// namespace A {
+ /// void f(); // SemanticDC == LexicalDC == 'namespace A'
+ /// }
+ /// void A::f(); // SemanticDC == namespace 'A'
+ /// // LexicalDC == global namespace
+ const DeclContext *getLexicalDeclContext() const {
+ if (isInSemaDC())
+ return reinterpret_cast<DeclContext*>(DeclCtx);
+ return getMultipleDC()->LexicalDC;
+ }
+ DeclContext *getLexicalDeclContext() {
+ return const_cast<DeclContext*>(
+ const_cast<const Decl*>(this)->getLexicalDeclContext());
+ }
+
+ void setLexicalDeclContext(DeclContext *DC);
+
+ /// getNextDeclarator - If this decl was part of a multi-declarator
+ /// declaration, such as "int X, Y, *Z;" this returns the decl for the next
+ /// declarator. Otherwise it returns null.
+ Decl *getNextDeclarator() { return NextDeclarator; }
+ const Decl *getNextDeclarator() const { return NextDeclarator; }
+ void setNextDeclarator(Decl *N) { NextDeclarator = N; }
+
+ // isDefinedOutsideFunctionOrMethod - This predicate returns true if this
+ // scoped decl is defined outside the current function or method. This is
+ // roughly global variables and functions, but also handles enums (which could
+ // be defined inside or outside a function etc).
+ bool isDefinedOutsideFunctionOrMethod() const;
+
// getBody - If this Decl represents a declaration for a body of code,
// such as a function or method definition, this method returns the top-level
// Stmt* of that body. Otherwise this method returns null.
// FIXME: This will eventually be a pure virtual function.
assert (false && "Not implemented.");
}
-
- void EmitInRec(llvm::Serializer& S) const;
- void ReadInRec(llvm::Deserializer& D, ASTContext& C);
};
/// DeclContext - This is used only as base class of specific decl types that
/// declarations within this context. If the context contains fewer
/// than seven declarations, the number of declarations is provided
/// in the 3 lowest-order bits and the upper bits are treated as a
- /// pointer to an array of ScopedDecl pointers. If the context
+ /// pointer to an array of NamedDecl pointers. If the context
/// contains seven or more declarations, the upper bits are treated
- /// as a pointer to a DenseMap<DeclarationName, std::vector<ScopedDecl>>.
+ /// as a pointer to a DenseMap<DeclarationName, std::vector<NamedDecl*>>.
/// FIXME: We need a better data structure for this.
llvm::PointerIntPair<void*, 3> LookupPtr;
/// FirstDecl - The first declaration stored within this declaration
/// context.
- ScopedDecl *FirstDecl;
+ Decl *FirstDecl;
/// LastDecl - The last declaration stored within this declaration
/// context. FIXME: We could probably cache this value somewhere
/// outside of the DeclContext, to reduce the size of DeclContext by
/// another pointer.
- ScopedDecl *LastDecl;
+ Decl *LastDecl;
// Used in the CastTo template to get the DeclKind
// from a Decl or a DeclContext. DeclContext doesn't have a getKind() method
return DeclKind;
}
- /// getParent - Returns the containing DeclContext if this is a ScopedDecl,
+ /// getParent - Returns the containing DeclContext if this is a Decl,
/// else returns NULL.
const DeclContext *getParent() const;
DeclContext *getParent() {
/// within this context.
class decl_iterator {
/// Current - The current declaration.
- ScopedDecl *Current;
+ Decl *Current;
public:
- typedef ScopedDecl* value_type;
- typedef ScopedDecl* reference;
- typedef ScopedDecl* pointer;
+ typedef Decl* value_type;
+ typedef Decl* reference;
+ typedef Decl* pointer;
typedef std::forward_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
decl_iterator() : Current(0) { }
- explicit decl_iterator(ScopedDecl *C) : Current(C) { }
+ explicit decl_iterator(Decl *C) : Current(C) { }
reference operator*() const { return Current; }
pointer operator->() const { return Current; }
/// addDecl - Add the declaration D to this scope, and into data structure
/// for name lookup.
- void addDecl(ScopedDecl *D);
+ void addDecl(Decl *D);
void buildLookup(DeclContext *DCtx);
/// lookup_iterator - An iterator that provides access to the results
/// of looking up a name within this context.
- typedef ScopedDecl **lookup_iterator;
+ typedef NamedDecl **lookup_iterator;
/// lookup_const_iterator - An iterator that provides non-mutable
/// access to the results of lookup up a name within this context.
- typedef ScopedDecl * const * lookup_const_iterator;
+ typedef NamedDecl * const * lookup_const_iterator;
typedef std::pair<lookup_iterator, lookup_iterator> lookup_result;
typedef std::pair<lookup_const_iterator, lookup_const_iterator>
/// that this replacement is semantically correct, e.g., that
/// declarations are only replaced by later declarations of the same
/// entity and not a declaration of some other kind of entity.
- void insert(ScopedDecl *D);
+ void insert(NamedDecl *D);
static bool classof(const Decl *D) {
switch (D->getKind()) {
static bool classof(const BlockDecl *D) { return true; }
private:
- void insertImpl(ScopedDecl *D);
+ void insertImpl(NamedDecl *D);
void EmitOutRec(llvm::Serializer& S) const;
void ReadOutRec(llvm::Deserializer& D, ASTContext& C);
return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm;
}
+inline bool Decl::isDefinedOutsideFunctionOrMethod() const {
+ if (getDeclContext())
+ return !getDeclContext()->getLookupContext()->isFunctionOrMethod();
+ else
+ return true;
+}
+
+inline DeclContext::decl_iterator& DeclContext::decl_iterator::operator++() {
+ Current = Current->NextDeclInScope;
+ return *this;
+}
+
} // end clang.
namespace llvm {
TemplateTypeParmDecl(DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, bool Typename)
- : TypeDecl(TemplateTypeParm, DC, L, Id, 0), Typename(Typename) { }
+ : TypeDecl(TemplateTypeParm, DC, L, Id), Typename(Typename) { }
public:
static TemplateTypeParmDecl *Create(ASTContext &C, DeclContext *DC,
NonTypeTemplateParmDecl(DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T,
SourceLocation TSSL = SourceLocation())
- : VarDecl(NonTypeTemplateParm, DC, L, Id, T, VarDecl::None, 0, TSSL) { }
+ : VarDecl(NonTypeTemplateParm, DC, L, Id, T, VarDecl::None, TSSL) { }
public:
static NonTypeTemplateParmDecl *
class OverloadedFunctionDecl : public NamedDecl {
protected:
OverloadedFunctionDecl(DeclContext *DC, DeclarationName N)
- : NamedDecl(OverloadedFunction, SourceLocation(), N) { }
+ : NamedDecl(OverloadedFunction, DC, SourceLocation(), N) { }
/// Functions - the set of overloaded functions contained in this
/// overload set.
protected:
CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T,
- bool isStatic, bool isInline, ScopedDecl *PrevDecl)
+ bool isStatic, bool isInline)
: FunctionDecl(DK, RD, L, N, T, (isStatic ? Static : None),
- isInline, PrevDecl) {}
+ isInline) {}
public:
static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
QualType T, bool isStatic = false,
- bool isInline = false, ScopedDecl *PrevDecl = 0);
+ bool isInline = false);
bool isStatic() const { return getStorageClass() == Static; }
bool isInstance() const { return !isStatic(); }
CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T,
bool isExplicit, bool isInline, bool isImplicitlyDeclared)
- : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline,
- /*PrevDecl=*/0),
+ : CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline),
Explicit(isExplicit), ImplicitlyDefined(false) {
setImplicit(isImplicitlyDeclared);
}
CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T,
bool isInline, bool isImplicitlyDeclared)
- : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline,
- /*PrevDecl=*/0),
+ : CXXMethodDecl(CXXDestructor, RD, L, N, T, false, isInline),
ImplicitlyDefined(false) {
setImplicit(isImplicitlyDeclared);
}
CXXConversionDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T,
bool isInline, bool isExplicit)
- : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline,
- /*PrevDecl=*/0),
+ : CXXMethodDecl(CXXConversion, RD, L, N, T, false, isInline),
Explicit(isExplicit) { }
public:
class CXXClassVarDecl : public VarDecl {
CXXClassVarDecl(CXXRecordDecl *RD, SourceLocation L,
- IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl)
- : VarDecl(CXXClassVar, RD, L, Id, T, None, PrevDecl) {}
+ IdentifierInfo *Id, QualType T)
+ : VarDecl(CXXClassVar, RD, L, Id, T, None) {}
public:
static CXXClassVarDecl *Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L,IdentifierInfo *Id,
- QualType T, ScopedDecl *PrevDecl);
+ QualType T);
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == CXXClassVar; }
/// CXXClassMemberWrapper - A wrapper class for C++ class member decls.
/// Common functions like set/getAccess are included here to avoid bloating
/// the interface of non-C++ specific decl classes, like NamedDecl.
+/// FIXME: Doug would like to remove this class.
class CXXClassMemberWrapper {
Decl *MD;
}
CXXRecordDecl *getParent() const {
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(MD)) {
- return cast<CXXRecordDecl>(SD->getDeclContext());
- }
- return cast<CXXRecordDecl>(cast<FieldDecl>(MD)->getDeclContext());
+ return dyn_cast<CXXRecordDecl>(MD->getDeclContext());
}
static bool isMember(Decl *D) {
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
- return isa<CXXRecordDecl>(SD->getDeclContext());
- }
- return isa<FieldDecl>(D);
+ return isa<CXXRecordDecl>(D->getDeclContext());
}
};
/// LinkageSpecDecl - This represents a linkage specification. For example:
/// extern "C" void foo();
///
-class LinkageSpecDecl : public ScopedDecl, public DeclContext {
+class LinkageSpecDecl : public Decl, public DeclContext {
public:
/// LanguageIDs - Used to represent the language in a linkage
/// specification. The values are part of the serialization abi for
LinkageSpecDecl(DeclContext *DC, SourceLocation L, LanguageIDs lang,
bool Braces)
- : ScopedDecl(LinkageSpec, DC, L, DeclarationName(), 0),
+ : Decl(LinkageSpec, DC, L),
DeclContext(LinkageSpec), Language(lang), HadBraces(Braces) { }
public:
/// A selector represents a unique name for a method. The selector names for
/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
///
-class ObjCMethodDecl : public ScopedDecl, public DeclContext {
+class ObjCMethodDecl : public NamedDecl, public DeclContext {
public:
enum ImplementationControl { None, Required, Optional };
private:
bool isVariadic = false,
bool isSynthesized = false,
ImplementationControl impControl = None)
- : ScopedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo, 0),
+ : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
DeclContext(ObjCMethod),
IsInstance(isInstance), IsVariadic(isVariadic),
IsSynthesized(isSynthesized),
/// ObjCProtocolDecl.
/// FIXME: Use for ObjC implementation decls.
///
-class ObjCContainerDecl : public ScopedDecl, public DeclContext {
+class ObjCContainerDecl : public NamedDecl, public DeclContext {
SourceLocation AtEndLoc; // marks the end of the method container.
public:
ObjCContainerDecl(Kind DK, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id)
- : ScopedDecl(DK, DC, L, Id), DeclContext(DK) {}
+ : NamedDecl(DK, DC, L, Id), DeclContext(DK) {}
virtual ~ObjCContainerDecl();
private:
ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
AccessControl ac, Expr *BW)
- : FieldDecl(ObjCIvar, 0, L, Id, T, BW, /*Mutable=*/false, 0),
+ : FieldDecl(ObjCIvar, 0, L, Id, T, BW, /*Mutable=*/false),
DeclAccess(ac) {}
public:
private:
ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
QualType T, Expr *BW)
- : FieldDecl(ObjCAtDefsField, DC, L, Id, T, BW, /*Mutable=*/false, 0) {}
+ : FieldDecl(ObjCAtDefsField, DC, L, Id, T, BW, /*Mutable=*/false) {}
public:
static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
/// @class NSCursor, NSImage, NSPasteboard, NSWindow;
///
/// FIXME: This could be a transparent DeclContext (!)
-class ObjCClassDecl : public ScopedDecl {
+class ObjCClassDecl : public Decl {
ObjCInterfaceDecl **ForwardDecls;
unsigned NumForwardDecls;
ObjCClassDecl(DeclContext *DC, SourceLocation L,
ObjCInterfaceDecl **Elts, unsigned nElts)
- : ScopedDecl(ObjCClass, DC, L, DeclarationName()) {
+ : Decl(ObjCClass, DC, L) {
if (nElts) {
ForwardDecls = new ObjCInterfaceDecl*[nElts];
memcpy(ForwardDecls, Elts, nElts*sizeof(ObjCInterfaceDecl*));
/// @protocol NSTextInput, NSChangeSpelling, NSDraggingInfo;
///
/// FIXME: Should this be a transparent DeclContext?
-class ObjCForwardProtocolDecl : public ScopedDecl {
+class ObjCForwardProtocolDecl : public Decl {
ObjCProtocolDecl **ReferencedProtocols;
unsigned NumReferencedProtocols;
ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
ObjCProtocolDecl **Elts, unsigned nElts)
- : ScopedDecl(ObjCForwardProtocol, DC, L, DeclarationName()) {
+ : Decl(ObjCForwardProtocol, DC, L) {
NumReferencedProtocols = nElts;
if (nElts) {
ReferencedProtocols = new ObjCProtocolDecl*[nElts];
/// @dynamic p1,d1;
/// @end
///
-class ObjCCategoryImplDecl : public ScopedDecl, public DeclContext {
+class ObjCCategoryImplDecl : public NamedDecl, public DeclContext {
/// Class interface for this category implementation
ObjCInterfaceDecl *ClassInterface;
ObjCCategoryImplDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
ObjCInterfaceDecl *classInterface)
- : ScopedDecl(ObjCCategoryImpl, DC, L, Id), DeclContext(ObjCCategoryImpl),
+ : NamedDecl(ObjCCategoryImpl, DC, L, Id), DeclContext(ObjCCategoryImpl),
ClassInterface(classInterface) {}
public:
static ObjCCategoryImplDecl *Create(ASTContext &C, DeclContext *DC,
/// the legacy semantics and allow developers to move private ivar declarations
/// from the class interface to the class implementation (but I digress:-)
///
-class ObjCImplementationDecl : public ScopedDecl, public DeclContext {
+class ObjCImplementationDecl : public Decl, public DeclContext {
/// Class interface for this implementation
ObjCInterfaceDecl *ClassInterface;
SourceLocation EndLoc;
- ObjCImplementationDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
+ ObjCImplementationDecl(DeclContext *DC, SourceLocation L,
ObjCInterfaceDecl *classInterface,
ObjCInterfaceDecl *superDecl)
- : ScopedDecl(ObjCImplementation, DC, L, Id), DeclContext(ObjCImplementation),
+ : Decl(ObjCImplementation, DC, L), DeclContext(ObjCImplementation),
ClassInterface(classInterface), SuperClass(superDecl),
Ivars(0), NumIvars(0) {}
public:
static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, IdentifierInfo *Id,
+ SourceLocation L,
ObjCInterfaceDecl *classInterface,
ObjCInterfaceDecl *superDecl);
SourceLocation getLocEnd() const { return EndLoc; }
void setLocEnd(SourceLocation LE) { EndLoc = LE; };
+ /// getIdentifier - Get the identifier that names the class
+ /// interface associated with this implementation.
+ IdentifierInfo *getIdentifier() const {
+ return getClassInterface()->getIdentifier();
+ }
+
+ /// getNameAsCString - Get the name of identifier for the class
+ /// interface associated with this implementation as a C string
+ /// (const char*).
+ const char *getNameAsCString() const {
+ assert(getIdentifier() && "Name is not a simple identifier");
+ return getIdentifier()->getName();
+ }
+
+ /// @brief Get the name of the class associated with this interface.
+ std::string getNameAsString() const {
+ return getClassInterface()->getNameAsString();
+ }
+
const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
/// declared as @compatibility_alias alias class.
-class ObjCCompatibleAliasDecl : public ScopedDecl {
+class ObjCCompatibleAliasDecl : public NamedDecl {
/// Class that this is an alias of.
ObjCInterfaceDecl *AliasedClass;
ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
ObjCInterfaceDecl* aliasedClass)
- : ScopedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
+ : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
public:
static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
/// For example:
/// @property (assign, readwrite) int MyProperty;
///
-class ObjCPropertyDecl : public ScopedDecl {
+class ObjCPropertyDecl : public NamedDecl {
public:
enum PropertyAttributeKind {
OBJC_PR_noattr = 0x00,
ObjCPropertyDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
QualType T)
- : ScopedDecl(ObjCProperty, DC, L, Id), DeclType(T),
+ : NamedDecl(ObjCProperty, DC, L, Id), DeclType(T),
PropertyAttributes(OBJC_PR_noattr), PropertyImplementation(None),
GetterName(Selector()),
SetterName(Selector()),
/// in a class or category implementation block. For example:
/// @synthesize prop1 = ivar1;
///
-class ObjCPropertyImplDecl : public ScopedDecl {
+class ObjCPropertyImplDecl : public Decl {
public:
enum Kind {
Synthesize,
ObjCPropertyDecl *property,
Kind PK,
ObjCIvarDecl *ivarDecl)
- : ScopedDecl(ObjCPropertyImpl, DC, L, DeclarationName()), AtLoc(atLoc),
+ : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
assert (PK == Dynamic || PropertyIvarDecl);
}
class ASTContext;
class Expr;
class Decl;
- class ScopedDecl;
class QualType;
class IdentifierInfo;
class SourceManager;
return DG.hasSolitaryDecl();
}
- const ScopedDecl* getSolitaryDecl() const {
+ const Decl* getSolitaryDecl() const {
assert (hasSolitaryDecl() &&
"Caller assumes this DeclStmt points to one Decl*");
- return llvm::cast<ScopedDecl>(*DG.begin());
+ return llvm::cast<Decl>(*DG.begin());
}
- ScopedDecl* getSolitaryDecl() {
+ Decl* getSolitaryDecl() {
assert (hasSolitaryDecl() &&
"Caller assumes this DeclStmt points to one Decl*");
- return llvm::cast<ScopedDecl>(*DG.begin());
+ return llvm::cast<Decl>(*DG.begin());
}
SourceLocation getStartLoc() const { return StartLoc; }
bool operator!=(const decl_iterator& R) const {
return R.I != I;
}
- ScopedDecl* operator*() const {
- return llvm::cast<ScopedDecl>(*I);
+ Decl* operator*() const {
+ return llvm::cast<Decl>(*I);
}
};
bool operator!=(const const_decl_iterator& R) const {
return R.I != I;
}
- ScopedDecl* operator*() const {
- return llvm::cast<ScopedDecl>(*I);
+ Decl* operator*() const {
+ return llvm::cast<Decl>(*I);
}
};
namespace clang {
class Stmt;
-class ScopedDecl;
class Decl;
class VariableArrayType;
enum { DeclMode = 0x1, SizeOfTypeVAMode = 0x2, DeclGroupMode = 0x3,
Flags = 0x3 };
- union { Stmt** stmt; ScopedDecl* decl; Decl** DGI; };
+ union { Stmt** stmt; Decl* decl; Decl** DGI; };
uintptr_t RawVAPtr;
Decl** DGE;
Stmt*& GetDeclExpr() const;
StmtIteratorBase(Stmt** s) : stmt(s), RawVAPtr(0) {}
- StmtIteratorBase(ScopedDecl* d);
+ StmtIteratorBase(Decl* d);
StmtIteratorBase(VariableArrayType* t);
StmtIteratorBase(Decl** dgi, Decl** dge);
StmtIteratorBase() : stmt(NULL), RawVAPtr(0) {}
StmtIteratorImpl() {}
StmtIteratorImpl(Stmt** s) : StmtIteratorBase(s) {}
StmtIteratorImpl(Decl** dgi, Decl** dge) : StmtIteratorBase(dgi, dge) {}
- StmtIteratorImpl(ScopedDecl* d) : StmtIteratorBase(d) {}
+ StmtIteratorImpl(Decl* d) : StmtIteratorBase(d) {}
StmtIteratorImpl(VariableArrayType* t) : StmtIteratorBase(t) {}
DERIVED& operator++() {
: StmtIteratorImpl<StmtIterator,Stmt*&>(dgi, dge) {}
StmtIterator(VariableArrayType* t):StmtIteratorImpl<StmtIterator,Stmt*&>(t) {}
- StmtIterator(ScopedDecl* D) : StmtIteratorImpl<StmtIterator,Stmt*&>(D) {}
+ StmtIterator(Decl* D) : StmtIteratorImpl<StmtIterator,Stmt*&>(D) {}
};
struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
#define LLVM_CLANG_STMTDECLBVDVAL_H
#include "clang/AST/CFG.h"
-#include "clang/AST/Decl.h" // for ScopedDecl* -> NamedDecl* conversion
+#include "clang/AST/Decl.h" // for Decl* -> NamedDecl* conversion
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
}
llvm::BitVector::reference
- operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) {
- return getBit(AD.getIdx(SD));
+ operator()(const NamedDecl* ND, const AnalysisDataTy& AD) {
+ return getBit(AD.getIdx(ND));
}
- bool operator()(const ScopedDecl* SD, const AnalysisDataTy& AD) const {
- return getBit(AD.getIdx(SD));
+ bool operator()(const NamedDecl* ND, const AnalysisDataTy& AD) const {
+ return getBit(AD.getIdx(ND));
}
llvm::BitVector::reference getDeclBit(unsigned i) { return DeclBV[i]; }
public:
void VisitDeclRefExpr(DeclRefExpr* DR) {
- for (ScopedDecl* D = dyn_cast<ScopedDecl>(DR->getDecl()); D != NULL;
- D = D->getNextDeclarator())
- static_cast<ImplClass*>(this)->VisitScopedDecl(D);
+ for (Decl* D = DR->getDecl(); D != NULL; D = D->getNextDeclarator())
+ static_cast<ImplClass*>(this)->VisitDecl(D);
}
void VisitDeclStmt(DeclStmt* DS) {
for (DeclStmt::decl_iterator DI = DS->decl_begin(), DE = DS->decl_end();
DI != DE; ++DI) {
- ScopedDecl* D = *DI;
- static_cast<ImplClass*>(this)->VisitScopedDecl(D);
+ Decl* D = *DI;
+ static_cast<ImplClass*>(this)->VisitDecl(D);
// Visit the initializer.
if (VarDecl* VD = dyn_cast<VarDecl>(D))
if (Expr* I = VD->getInit())
}
}
- void VisitScopedDecl(ScopedDecl* D) {
+ void VisitDecl(Decl* D) {
switch (D->getKind()) {
DISPATCH_CASE(Function,FunctionDecl)
DISPATCH_CASE(Var,VarDecl)
RecFields[i]->getLocation(),
RecFields[i]->getIdentifier(),
RecFields[i]->getType(),
- RecFields[i]->getBitWidth(), false, 0);
+ RecFields[i]->getBitWidth(), false);
NewRD->addDecl(Field);
}
NewRD->completeDefinition(*this);
FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl,
SourceLocation(), 0,
FieldTypes[i], /*BitWidth=*/0,
- /*Mutable=*/false, /*PrevDecl=*/0);
+ /*Mutable=*/false);
CFConstantStringTypeDecl->addDecl(Field);
}
ObjCFastEnumerationStateTypeDecl,
SourceLocation(), 0,
FieldTypes[i], /*BitWidth=*/0,
- /*Mutable=*/false, /*PrevDecl=*/0);
+ /*Mutable=*/false);
ObjCFastEnumerationStateTypeDecl->addDecl(Field);
}
T old_value;
};
-static SourceLocation GetEndLoc(ScopedDecl* D) {
+static SourceLocation GetEndLoc(Decl* D) {
if (VarDecl* VD = dyn_cast<VarDecl>(D))
if (Expr* Ex = VD->getInit())
return Ex->getSourceRange().getEnd();
CFGBlock* addStmt(Stmt* Terminator);
CFGBlock* WalkAST(Stmt* Terminator, bool AlwaysAddStmt);
CFGBlock* WalkAST_VisitChildren(Stmt* Terminator);
- CFGBlock* WalkAST_VisitDeclSubExpr(ScopedDecl* D);
+ CFGBlock* WalkAST_VisitDeclSubExpr(Decl* D);
CFGBlock* WalkAST_VisitStmtExpr(StmtExpr* Terminator);
void FinishBlock(CFGBlock* B);
return WalkAST_VisitDeclSubExpr(DS->getSolitaryDecl());
}
else {
- typedef llvm::SmallVector<ScopedDecl*,10> BufTy;
+ typedef llvm::SmallVector<Decl*,10> BufTy;
BufTy Buf;
CFGBlock* B = 0;
// that Decl* will not get deallocated because the destroy method
// of DG is never called.
DeclGroupOwningRef DG(*I);
- ScopedDecl* D = *I;
+ Decl* D = *I;
void* Mem = cfg->getAllocator().Allocate(sizeof(DeclStmt), A);
DeclStmt* DS = new (Mem) DeclStmt(DG, D->getLocation(),
/// WalkAST_VisitDeclSubExpr - Utility method to add block-level expressions
/// for initializers in Decls.
-CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(ScopedDecl* D) {
+CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(Decl* D) {
VarDecl* VD = dyn_cast<VarDecl>(D);
if (!VD)
ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation L, IdentifierInfo *Id, QualType T, ScopedDecl *PrevDecl) {
+ SourceLocation L, IdentifierInfo *Id, QualType T) {
void *Mem = C.getAllocator().Allocate<ImplicitParamDecl>();
- return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T, PrevDecl);
+ return new (Mem) ImplicitParamDecl(ImplicitParam, DC, L, Id, T);
}
ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
QualType T, StorageClass S,
- Expr *DefArg, ScopedDecl *PrevDecl) {
+ Expr *DefArg) {
void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
- return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg, PrevDecl);
+ return new (Mem) ParmVarDecl(ParmVar, DC, L, Id, T, S, DefArg);
}
QualType ParmVarDecl::getOriginalType() const {
ASTContext &C, DeclContext *DC,
SourceLocation L, IdentifierInfo *Id,
QualType T, QualType OT, StorageClass S,
- Expr *DefArg, ScopedDecl *PrevDecl) {
+ Expr *DefArg) {
void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>();
- return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S,
- DefArg, PrevDecl);
+ return new (Mem) ParmVarWithOriginalTypeDecl(DC, L, Id, T, OT, S, DefArg);
}
FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
DeclarationName N, QualType T,
StorageClass S, bool isInline,
- ScopedDecl *PrevDecl,
SourceLocation TypeSpecStartLoc) {
void *Mem = C.getAllocator().Allocate<FunctionDecl>();
- return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, PrevDecl,
+ return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline,
TypeSpecStartLoc);
}
FieldDecl *FieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *BW,
- bool Mutable, ScopedDecl *PrevDecl) {
+ bool Mutable) {
void *Mem = C.getAllocator().Allocate<FieldDecl>();
- return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable, PrevDecl);
+ return new (Mem) FieldDecl(Decl::Field, DC, L, Id, T, BW, Mutable);
}
bool FieldDecl::isAnonymousStructOrUnion() const {
EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
SourceLocation L,
IdentifierInfo *Id, QualType T,
- Expr *E, const llvm::APSInt &V,
- ScopedDecl *PrevDecl){
+ Expr *E, const llvm::APSInt &V) {
void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
- return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V, PrevDecl);
+ return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V);
}
void EnumConstantDecl::Destroy(ASTContext& C) {
TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
- IdentifierInfo *Id, QualType T,
- ScopedDecl *PD) {
+ IdentifierInfo *Id, QualType T) {
void *Mem = C.getAllocator().Allocate<TypedefDecl>();
- return new (Mem) TypedefDecl(DC, L, Id, T, PD);
+ return new (Mem) TypedefDecl(DC, L, Id, T);
}
EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id,
EnumDecl *PrevDecl) {
void *Mem = C.getAllocator().Allocate<EnumDecl>();
- EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id, 0);
+ EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id);
C.getTypeDeclType(Enum, PrevDecl);
return Enum;
}
TagDecl::completeDefinition();
}
-FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C,
+FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
StringLiteral *Str) {
void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>();
- return new (Mem) FileScopeAsmDecl(L, Str);
+ return new (Mem) FileScopeAsmDecl(DC, L, Str);
}
//===----------------------------------------------------------------------===//
-// ScopedDecl Implementation
+// NamedDecl Implementation
//===----------------------------------------------------------------------===//
-void ScopedDecl::setDeclContext(DeclContext *DC) {
- if (isOutOfSemaDC())
- delete getMultipleDC();
-
- DeclCtx = reinterpret_cast<uintptr_t>(DC);
-}
-
-void ScopedDecl::setLexicalDeclContext(DeclContext *DC) {
- if (DC == getLexicalDeclContext())
- return;
-
- if (isInSemaDC()) {
- MultipleDC *MDC = new MultipleDC();
- MDC->SemanticDC = getDeclContext();
- MDC->LexicalDC = DC;
- DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
- } else {
- getMultipleDC()->LexicalDC = DC;
- }
-}
-
-ScopedDecl::~ScopedDecl() {
- if (isOutOfSemaDC())
- delete getMultipleDC();
-}
-
-bool ScopedDecl::declarationReplaces(NamedDecl *OldD) const {
+bool NamedDecl::declarationReplaces(NamedDecl *OldD) const {
assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
return this->getKind() == OldD->getKind();
}
+
//===----------------------------------------------------------------------===//
// VarDecl Implementation
//===----------------------------------------------------------------------===//
-VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation L,
- IdentifierInfo *Id, QualType T,
- StorageClass S, ScopedDecl *PrevDecl,
+VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
+ IdentifierInfo *Id, QualType T, StorageClass S,
SourceLocation TypeSpecStartLoc) {
void *Mem = C.getAllocator().Allocate<VarDecl>();
- return new (Mem) VarDecl(Var, DC, L, Id, T, S, PrevDecl, TypeSpecStartLoc);
+ return new (Mem) VarDecl(Var, DC, L, Id, T, S, TypeSpecStartLoc);
}
void VarDecl::Destroy(ASTContext& C) {
RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id)
- : TagDecl(DK, TK, DC, L, Id, 0) {
+ : TagDecl(DK, TK, DC, L, Id) {
HasFlexibleArrayMember = false;
AnonymousStructOrUnion = false;
assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
// Decl Implementation
//===----------------------------------------------------------------------===//
+void Decl::setDeclContext(DeclContext *DC) {
+ if (isOutOfSemaDC())
+ delete getMultipleDC();
+
+ DeclCtx = reinterpret_cast<uintptr_t>(DC);
+}
+
+void Decl::setLexicalDeclContext(DeclContext *DC) {
+ if (DC == getLexicalDeclContext())
+ return;
+
+ if (isInSemaDC()) {
+ MultipleDC *MDC = new MultipleDC();
+ MDC->SemanticDC = getDeclContext();
+ MDC->LexicalDC = DC;
+ DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
+ } else {
+ getMultipleDC()->LexicalDC = DC;
+ }
+}
+
// Out-of-line virtual method providing a home for Decl.
Decl::~Decl() {
+ if (isOutOfSemaDC())
+ delete getMultipleDC();
+
if (!HasAttrs)
return;
#if 0
// FIXME: This causes double-destroys in some cases, so it is
// disabled at the moment.
- if (ScopedDecl* SD = dyn_cast<ScopedDecl>(this)) {
- // Observe the unrolled recursion. By setting N->NextDeclarator = 0x0
- // within the loop, only the Destroy method for the first ScopedDecl
- // will deallocate all of the ScopedDecls in a chain.
-
- ScopedDecl* N = SD->getNextDeclarator();
-
- while (N) {
- ScopedDecl* Tmp = N->getNextDeclarator();
- N->NextDeclarator = 0x0;
- N->Destroy(C);
- N = Tmp;
- }
+ // Observe the unrolled recursion. By setting N->NextDeclarator = 0x0
+ // within the loop, only the Destroy method for the first Decl
+ // will deallocate all of the Decls in a chain.
+
+ Decl* N = SD->getNextDeclarator();
+
+ while (N) {
+ Decl* Tmp = N->getNextDeclarator();
+ N->NextDeclarator = 0x0;
+ N->Destroy(C);
+ N = Tmp;
}
#endif
//===----------------------------------------------------------------------===//
const DeclContext *DeclContext::getParent() const {
- if (const ScopedDecl *SD = dyn_cast<ScopedDecl>(this))
- return SD->getDeclContext();
- else if (const BlockDecl *BD = dyn_cast<BlockDecl>(this))
- return BD->getParentContext();
- else
- return NULL;
+ if (const Decl *D = dyn_cast<Decl>(this))
+ return D->getDeclContext();
+
+ return NULL;
}
const DeclContext *DeclContext::getLexicalParent() const {
- if (const ScopedDecl *SD = dyn_cast<ScopedDecl>(this))
- return SD->getLexicalDeclContext();
+ if (const Decl *D = dyn_cast<Decl>(this))
+ return D->getLexicalDeclContext();
+
return getParent();
}
// implemented in terms of DenseMap anyway. However, this data
// structure is really space-inefficient, so we'll have to do
// something.
-typedef llvm::DenseMap<DeclarationName, std::vector<ScopedDecl*> >
+typedef llvm::DenseMap<DeclarationName, std::vector<NamedDecl*> >
StoredDeclsMap;
DeclContext::~DeclContext() {
StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(LookupPtr.getPointer());
delete Map;
} else {
- ScopedDecl **Array = static_cast<ScopedDecl**>(LookupPtr.getPointer());
+ NamedDecl **Array = static_cast<NamedDecl**>(LookupPtr.getPointer());
delete [] Array;
}
}
}
}
-void DeclContext::addDecl(ScopedDecl *D) {
+void DeclContext::addDecl(Decl *D) {
assert(D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context");
assert(!D->NextDeclInScope && D != LastDecl &&
"Decl already inserted into a DeclContext");
} else {
FirstDecl = LastDecl = D;
}
- D->getDeclContext()->insert(D);
+
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
+ ND->getDeclContext()->insert(ND);
}
/// buildLookup - Build the lookup data structure with all of the
for (decl_iterator D = DCtx->decls_begin(), DEnd = DCtx->decls_end();
D != DEnd; ++D) {
// Insert this declaration into the lookup structure
- insertImpl(*D);
+ if (NamedDecl *ND = dyn_cast<NamedDecl>(*D))
+ insertImpl(ND);
// If this declaration is itself a transparent declaration context,
// add its members (recursively).
// We have a small array. Look into it.
unsigned Size = LookupPtr.getInt();
- ScopedDecl **Array = static_cast<ScopedDecl**>(LookupPtr.getPointer());
+ NamedDecl **Array = static_cast<NamedDecl**>(LookupPtr.getPointer());
for (unsigned Idx = 0; Idx != Size; ++Idx)
if (Array[Idx]->getDeclName() == Name) {
unsigned Last = Idx + 1;
return Ctx;
}
-void DeclContext::insert(ScopedDecl *D) {
+void DeclContext::insert(NamedDecl *D) {
DeclContext *PrimaryContext = getPrimaryContext();
if (PrimaryContext != this) {
PrimaryContext->insert(D);
getParent()->insert(D);
}
-void DeclContext::insertImpl(ScopedDecl *D) {
+void DeclContext::insertImpl(NamedDecl *D) {
// Skip unnamed declarations.
if (!D->getDeclName())
return;
// The lookup data is stored as an array. Search through the array
// to find the insertion location.
- ScopedDecl **Array;
+ NamedDecl **Array;
if (Size == 0) {
- Array = new ScopedDecl*[LookupIsMap - 1];
+ Array = new NamedDecl*[LookupIsMap - 1];
LookupPtr.setPointer(Array);
} else {
- Array = static_cast<ScopedDecl **>(LookupPtr.getPointer());
+ Array = static_cast<NamedDecl **>(LookupPtr.getPointer());
}
// We always keep declarations of the same name next to each other
if (Pos != Map->end()) {
if (MayBeRedeclaration) {
// Determine if this declaration is actually a redeclaration.
- std::vector<ScopedDecl *>::iterator Redecl
+ std::vector<NamedDecl *>::iterator Redecl
= std::find_if(Pos->second.begin(), Pos->second.end(),
- std::bind1st(std::mem_fun(&ScopedDecl::declarationReplaces),
+ std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
D));
if (Redecl != Pos->second.end()) {
*Redecl = D;
if (D->getIdentifierNamespace() == Decl::IDNS_Tag || Pos->second.empty())
Pos->second.push_back(D);
else if (Pos->second.back()->getIdentifierNamespace() == Decl::IDNS_Tag) {
- ScopedDecl *TagD = Pos->second.back();
+ NamedDecl *TagD = Pos->second.back();
Pos->second.back() = D;
Pos->second.push_back(TagD);
} else
CXXMethodDecl *
CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, DeclarationName N,
- QualType T, bool isStatic, bool isInline,
- ScopedDecl *PrevDecl) {
+ QualType T, bool isStatic, bool isInline) {
void *Mem = C.getAllocator().Allocate<CXXMethodDecl>();
- return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline,
- PrevDecl);
+ return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline);
}
QualType CXXMethodDecl::getThisType(ASTContext &C) const {
CXXClassVarDecl *CXXClassVarDecl::Create(ASTContext &C, CXXRecordDecl *RD,
SourceLocation L, IdentifierInfo *Id,
- QualType T, ScopedDecl *PrevDecl) {
+ QualType T) {
void *Mem = C.getAllocator().Allocate<CXXClassVarDecl>();
- return new (Mem) CXXClassVarDecl(RD, L, Id, T, PrevDecl);
+ return new (Mem) CXXClassVarDecl(RD, L, Id, T);
}
OverloadedFunctionDecl *
ObjCImplementationDecl *
ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
- IdentifierInfo *Id,
ObjCInterfaceDecl *ClassInterface,
ObjCInterfaceDecl *SuperDecl) {
void *Mem = C.getAllocator().Allocate<ObjCImplementationDecl>();
- return new (Mem) ObjCImplementationDecl(DC, L, Id, ClassInterface, SuperDecl);
+ return new (Mem) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
}
ObjCCompatibleAliasDecl *
SelfDecl = ImplicitParamDecl::Create(Context, this,
SourceLocation(),
&Context.Idents.get("self"),
- selfTy, 0);
+ selfTy);
CmdDecl = ImplicitParamDecl::Create(Context, this,
SourceLocation(),
&Context.Idents.get("_cmd"),
- Context.getObjCSelType(), 0);
+ Context.getObjCSelType());
}
void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
void Decl::Emit(Serializer& S) const {
S.EmitInt(getKind());
EmitImpl(S);
+ S.Emit(getLocation());
+ S.EmitBool(InvalidDecl);
+ // FIXME: HasAttrs?
+ S.EmitBool(Implicit);
+ S.EmitInt(Access);
+ S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From Decl.
+ S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From Decl.
+ S.EmitPtr(NextDeclarator);
if (const DeclContext *DC = dyn_cast<const DeclContext>(this))
DC->EmitOutRec(S);
+
+ if (getDeclContext() &&
+ !getDeclContext()->isFunctionOrMethod()) {
+ S.EmitBool(true);
+ S.EmitOwnedPtr(NextDeclInScope);
+ } else {
+ S.EmitBool(false);
+ S.EmitPtr(NextDeclInScope);
+ }
}
Decl* Decl::Create(Deserializer& D, ASTContext& C) {
break;
}
- if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
- DC->ReadOutRec(D, C);
+ Dcl->Loc = SourceLocation::ReadVal(D); // From Decl.
+ Dcl->InvalidDecl = D.ReadBool();
+ // FIXME: HasAttrs?
+ Dcl->Implicit = D.ReadBool();
+ Dcl->Access = D.ReadInt();
- return Dcl;
-}
-
-//===----------------------------------------------------------------------===//
-// Common serialization logic for subclasses of Decl.
-//===----------------------------------------------------------------------===//
+ assert(Dcl->DeclCtx == 0);
-void Decl::EmitInRec(Serializer& S) const {
- S.Emit(getLocation()); // From Decl.
-}
+ const SerializedPtrID &SemaDCPtrID = D.ReadPtrID();
+ const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID();
-void Decl::ReadInRec(Deserializer& D, ASTContext& C) {
- Loc = SourceLocation::ReadVal(D); // From Decl.
+ if (SemaDCPtrID == LexicalDCPtrID) {
+ // Allow back-patching. Observe that we register the variable of the
+ // *object* for back-patching. Its actual value will get filled in later.
+ D.ReadUIntPtr(Dcl->DeclCtx, SemaDCPtrID);
+ }
+ else {
+ MultipleDC *MDC = new MultipleDC();
+ Dcl->DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
+ // Allow back-patching. Observe that we register the variable of the
+ // *object* for back-patching. Its actual value will get filled in later.
+ D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
+ D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
+ }
+ D.ReadPtr(Dcl->NextDeclarator);
+ if (DeclContext *DC = dyn_cast<DeclContext>(Dcl))
+ DC->ReadOutRec(D, C);
+ bool OwnsNext = D.ReadBool();
+ if (OwnsNext)
+ Dcl->NextDeclInScope = D.ReadOwnedPtr<Decl>(C);
+ else
+ D.ReadPtr(Dcl->NextDeclInScope);
+ return Dcl;
}
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
void DeclContext::EmitOutRec(Serializer& S) const {
-#if 0
- // FIXME: it would be far easier to just serialize FirstDecl and let
- // ScopedDecl do the work of serializing NextDeclInScope.
- S.EmitInt(Decls.size());
- for (decl_iterator D = decls_begin(); D != decls_end(); ++D) {
- bool Owned = ((*D)->getLexicalDeclContext() == this &&
- DeclKind != Decl::TranslationUnit &&
- !isFunctionOrMethod());
- S.EmitBool(Owned);
- if (Owned)
- S.EmitOwnedPtr(*D);
- else
- S.EmitPtr(*D);
- }
-#endif
+ bool Owned = !isFunctionOrMethod();
+ S.EmitBool(Owned);
+ if (Owned)
+ S.EmitOwnedPtr(FirstDecl);
+ else
+ S.EmitPtr(FirstDecl);
+ S.EmitPtr(LastDecl);
}
void DeclContext::ReadOutRec(Deserializer& D, ASTContext& C) {
-#if 0
- // FIXME: See comment in DeclContext::EmitOutRec
- unsigned NumDecls = D.ReadInt();
- Decls.resize(NumDecls);
- for (unsigned Idx = 0; Idx < NumDecls; ++Idx) {
- bool Owned = D.ReadBool();
- if (Owned)
- Decls[Idx] = cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C));
- else
- D.ReadPtr<ScopedDecl>(Decls[Idx]);
- }
-#endif
+ bool Owned = D.ReadBool();
+ if (Owned)
+ FirstDecl = cast_or_null<Decl>(D.ReadOwnedPtr<Decl>(C));
+ else
+ D.ReadPtr(FirstDecl);
+ D.ReadPtr(LastDecl);
}
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
void NamedDecl::EmitInRec(Serializer& S) const {
- Decl::EmitInRec(S);
S.EmitInt(Name.getNameKind());
switch (Name.getNameKind()) {
}
void NamedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
- Decl::ReadInRec(D, C);
-
DeclarationName::NameKind Kind
= static_cast<DeclarationName::NameKind>(D.ReadInt());
switch (Kind) {
}
}
-//===----------------------------------------------------------------------===//
-// Common serialization logic for subclasses of ScopedDecl.
-//===----------------------------------------------------------------------===//
-
-void ScopedDecl::EmitInRec(Serializer& S) const {
- NamedDecl::EmitInRec(S);
- S.EmitPtr(cast_or_null<Decl>(getDeclContext())); // From ScopedDecl.
- S.EmitPtr(cast_or_null<Decl>(getLexicalDeclContext())); // From ScopedDecl.
-}
-
-void ScopedDecl::ReadInRec(Deserializer& D, ASTContext& C) {
- NamedDecl::ReadInRec(D, C);
-
- assert(DeclCtx == 0);
-
- const SerializedPtrID &SemaDCPtrID = D.ReadPtrID();
- const SerializedPtrID &LexicalDCPtrID = D.ReadPtrID();
-
- if (SemaDCPtrID == LexicalDCPtrID) {
- // Allow back-patching. Observe that we register the variable of the
- // *object* for back-patching. Its actual value will get filled in later.
- D.ReadUIntPtr(DeclCtx, SemaDCPtrID);
- }
- else {
- MultipleDC *MDC = new MultipleDC();
- DeclCtx = reinterpret_cast<uintptr_t>(MDC) | 0x1;
- // Allow back-patching. Observe that we register the variable of the
- // *object* for back-patching. Its actual value will get filled in later.
- D.ReadPtr(MDC->SemanticDC, SemaDCPtrID);
- D.ReadPtr(MDC->LexicalDC, LexicalDCPtrID);
- }
-}
-
- //===------------------------------------------------------------===//
- // NOTE: Not all subclasses of ScopedDecl will use the "OutRec" //
- // methods. This is because owned pointers are usually "batched" //
- // together for efficiency. //
- //===------------------------------------------------------------===//
-
-void ScopedDecl::EmitOutRec(Serializer& S) const {
- S.EmitOwnedPtr(getNextDeclarator()); // From ScopedDecl.
-}
-
-void ScopedDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
- NextDeclarator =
- cast_or_null<ScopedDecl>(D.ReadOwnedPtr<Decl>(C)); // From ScopedDecl.
-}
-
//===----------------------------------------------------------------------===//
// Common serialization logic for subclasses of ValueDecl.
//===----------------------------------------------------------------------===//
void ValueDecl::EmitInRec(Serializer& S) const {
- ScopedDecl::EmitInRec(S);
+ NamedDecl::EmitInRec(S);
S.Emit(getType()); // From ValueDecl.
}
void ValueDecl::ReadInRec(Deserializer& D, ASTContext& C) {
- ScopedDecl::ReadInRec(D, C);
+ NamedDecl::ReadInRec(D, C);
DeclType = QualType::ReadVal(D); // From ValueDecl.
}
SClass = static_cast<StorageClass>(D.ReadInt()); // From VarDecl.
}
- //===------------------------------------------------------------===//
- // NOTE: VarDecl has its own "OutRec" methods that doesn't use //
- // the one define in ScopedDecl. This is to batch emit the //
- // owned pointers, which results in a smaller output.
- //===------------------------------------------------------------===//
-
void VarDecl::EmitOutRec(Serializer& S) const {
- // Emit these last because they will create records of their own.
- S.BatchEmitOwnedPtrs(getInit(), // From VarDecl.
- getNextDeclarator()); // From ScopedDecl.
+ // Emit this last because it will create a record of its own.
+ S.EmitOwnedPtr(getInit());
}
void VarDecl::ReadOutRec(Deserializer& D, ASTContext& C) {
- Decl* next_declarator;
-
- D.BatchReadOwnedPtrs(Init, // From VarDecl.
- next_declarator, // From ScopedDecl.
- C);
-
- setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
+ Init = D.ReadOwnedPtr<Stmt>(C);
}
void TranslationUnitDecl::EmitImpl(llvm::Serializer& S) const
{
- Decl::EmitInRec(S);
}
TranslationUnitDecl* TranslationUnitDecl::CreateImpl(Deserializer& D,
void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>();
TranslationUnitDecl* decl = new (Mem) TranslationUnitDecl();
- decl->Decl::ReadInRec(D, C);
-
return decl;
}
void NamespaceDecl::EmitImpl(llvm::Serializer& S) const
{
- ScopedDecl::EmitInRec(S);
+ NamedDecl::EmitInRec(S);
S.Emit(getLBracLoc());
S.Emit(getRBracLoc());
- ScopedDecl::EmitOutRec(S);
}
NamespaceDecl* NamespaceDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<NamespaceDecl>();
NamespaceDecl* decl = new (Mem) NamespaceDecl(0, SourceLocation(), 0);
- decl->ScopedDecl::ReadInRec(D, C);
+ decl->NamedDecl::ReadInRec(D, C);
decl->LBracLoc = SourceLocation::ReadVal(D);
decl->RBracLoc = SourceLocation::ReadVal(D);
- decl->ScopedDecl::ReadOutRec(D, C);
return decl;
}
VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<VarDecl>();
VarDecl* decl =
- new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None, NULL);
+ new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None);
decl->VarDecl::ReadImpl(D, C);
return decl;
void *Mem = C.getAllocator().Allocate<ParmVarDecl>();
ParmVarDecl* decl = new (Mem)
ParmVarDecl(ParmVar,
- 0, SourceLocation(), NULL, QualType(), None, NULL, NULL);
+ 0, SourceLocation(), NULL, QualType(), None, NULL);
decl->VarDecl::ReadImpl(D, C);
decl->objcDeclQualifier = static_cast<ObjCDeclQualifier>(D.ReadInt());
void *Mem = C.getAllocator().Allocate<ParmVarWithOriginalTypeDecl>();
ParmVarWithOriginalTypeDecl* decl = new (Mem)
ParmVarWithOriginalTypeDecl(0, SourceLocation(), NULL, QualType(),
- QualType(), None, NULL, NULL);
+ QualType(), None, NULL);
decl->ParmVarDecl::ReadImpl(D, C);
decl->OriginalType = QualType::ReadVal(D);
//===----------------------------------------------------------------------===//
void EnumDecl::EmitImpl(Serializer& S) const {
- ScopedDecl::EmitInRec(S);
+ NamedDecl::EmitInRec(S);
S.EmitBool(isDefinition());
S.Emit(IntegerType);
- S.EmitOwnedPtr(getNextDeclarator());
}
EnumDecl* EnumDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<EnumDecl>();
- EnumDecl* decl = new (Mem) EnumDecl(0, SourceLocation(), NULL, NULL);
+ EnumDecl* decl = new (Mem) EnumDecl(0, SourceLocation(), NULL);
- decl->ScopedDecl::ReadInRec(D, C);
+ decl->NamedDecl::ReadInRec(D, C);
decl->setDefinition(D.ReadBool());
decl->IntegerType = QualType::ReadVal(D);
- Decl* next_declarator = D.ReadOwnedPtr<Decl>(C);
- decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
-
return decl;
}
void EnumConstantDecl::EmitImpl(Serializer& S) const {
S.Emit(Val);
ValueDecl::EmitInRec(S);
- S.BatchEmitOwnedPtrs(getNextDeclarator(),Init);
+ S.EmitOwnedPtr(Init);
}
EnumConstantDecl* EnumConstantDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<EnumConstantDecl>();
EnumConstantDecl* decl = new (Mem)
- EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val, NULL);
+ EnumConstantDecl(0, SourceLocation(), NULL, QualType(), NULL, val);
decl->ValueDecl::ReadInRec(D, C);
-
- Decl* next_declarator;
-
- D.BatchReadOwnedPtrs(next_declarator, decl->Init, C);
-
- decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
-
+ decl->Init = D.ReadOwnedPtr<Stmt>(C);
return decl;
}
void FieldDecl::EmitImpl(Serializer& S) const {
S.EmitBool(Mutable);
S.Emit(getType());
- ScopedDecl::EmitInRec(S);
+ NamedDecl::EmitInRec(S);
S.EmitOwnedPtr(BitWidth);
}
FieldDecl* FieldDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<FieldDecl>();
FieldDecl* decl = new (Mem) FieldDecl(Field, 0, SourceLocation(), NULL,
- QualType(), 0, false, 0);
+ QualType(), 0, false);
decl->Mutable = D.ReadBool();
decl->DeclType.ReadBackpatch(D);
decl->ReadInRec(D, C);
if (ParamInfo != NULL) {
S.EmitBool(true);
S.EmitInt(getNumParams());
- S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body,
- getNextDeclarator());
+ S.BatchEmitOwnedPtrs(getNumParams(),&ParamInfo[0], Body);
}
else {
S.EmitBool(false);
- S.BatchEmitOwnedPtrs(Body,getNextDeclarator());
+ S.EmitOwnedPtr(Body);
}
}
void *Mem = C.getAllocator().Allocate<FunctionDecl>();
FunctionDecl* decl = new (Mem)
FunctionDecl(Function, 0, SourceLocation(), DeclarationName(),
- QualType(), SClass, IsInline, 0);
+ QualType(), SClass, IsInline);
decl->ValueDecl::ReadInRec(D, C);
D.ReadPtr(decl->PreviousDeclaration);
- Decl* next_declarator;
-
int numParams = 0;
bool hasParamDecls = D.ReadBool();
if (hasParamDecls)
if (hasParamDecls)
D.BatchReadOwnedPtrs(numParams,
reinterpret_cast<Decl**>(&decl->ParamInfo[0]),
- decl->Body, next_declarator, C);
+ decl->Body, C);
else
- D.BatchReadOwnedPtrs(decl->Body, next_declarator, C);
-
- decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));
+ decl->Body = D.ReadOwnedPtr<Stmt>(C);
return decl;
}
void RecordDecl::EmitImpl(Serializer& S) const {
S.EmitInt(getTagKind());
- ScopedDecl::EmitInRec(S);
+ NamedDecl::EmitInRec(S);
S.EmitBool(isDefinition());
S.EmitBool(hasFlexibleArrayMember());
S.EmitBool(isAnonymousStructOrUnion());
- ScopedDecl::EmitOutRec(S);
}
RecordDecl* RecordDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<RecordDecl>();
RecordDecl* decl = new (Mem) RecordDecl(Record, TK, 0, SourceLocation(), NULL);
- decl->ScopedDecl::ReadInRec(D, C);
+ decl->NamedDecl::ReadInRec(D, C);
decl->setDefinition(D.ReadBool());
decl->setHasFlexibleArrayMember(D.ReadBool());
decl->setAnonymousStructOrUnion(D.ReadBool());
- decl->ScopedDecl::ReadOutRec(D, C);
return decl;
}
void TypedefDecl::EmitImpl(Serializer& S) const {
S.Emit(UnderlyingType);
- ScopedDecl::EmitInRec(S);
- ScopedDecl::EmitOutRec(S);
+ NamedDecl::EmitInRec(S);
}
TypedefDecl* TypedefDecl::CreateImpl(Deserializer& D, ASTContext& C) {
QualType T = QualType::ReadVal(D);
void *Mem = C.getAllocator().Allocate<TypedefDecl>();
- TypedefDecl* decl = new (Mem) TypedefDecl(0, SourceLocation(), NULL, T, NULL);
+ TypedefDecl* decl = new (Mem) TypedefDecl(0, SourceLocation(), NULL, T);
- decl->ScopedDecl::ReadInRec(D, C);
- decl->ScopedDecl::ReadOutRec(D, C);
+ decl->NamedDecl::ReadInRec(D, C);
return decl;
}
void TemplateTypeParmDecl::EmitImpl(Serializer& S) const {
S.EmitBool(Typename);
- ScopedDecl::EmitInRec(S);
- ScopedDecl::EmitOutRec(S);
+ NamedDecl::EmitInRec(S);
}
TemplateTypeParmDecl *
void *Mem = C.getAllocator().Allocate<TemplateTypeParmDecl>();
TemplateTypeParmDecl *decl
= new (Mem) TemplateTypeParmDecl(0, SourceLocation(), NULL, Typename);
- decl->ScopedDecl::ReadInRec(D, C);
- decl->ScopedDecl::ReadOutRec(D, C);
+ decl->NamedDecl::ReadInRec(D, C);
return decl;
}
//===----------------------------------------------------------------------===//
void LinkageSpecDecl::EmitInRec(Serializer& S) const {
- Decl::EmitInRec(S);
S.EmitInt(getLanguage());
S.EmitBool(HadBraces);
}
void LinkageSpecDecl::ReadInRec(Deserializer& D, ASTContext& C) {
- Decl::ReadInRec(D, C);
Language = static_cast<LanguageIDs>(D.ReadInt());
HadBraces = D.ReadBool();
}
void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
{
- Decl::EmitInRec(S);
S.EmitOwnedPtr(AsmString);
}
FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D, ASTContext& C) {
void *Mem = C.getAllocator().Allocate<FileScopeAsmDecl>();
- FileScopeAsmDecl* decl = new (Mem) FileScopeAsmDecl(SourceLocation(), 0);
+ FileScopeAsmDecl* decl = new (Mem) FileScopeAsmDecl(0, SourceLocation(), 0);
- decl->Decl::ReadInRec(D, C);
decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>(C));
// D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
fprintf(F,"\n");
for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
DI != DE; ++DI) {
- ScopedDecl* D = *DI;
+ Decl* D = *DI;
++IndentLevel;
Indent();
fprintf(F, "%p ", (void*) D);
return false;
}
-StmtIteratorBase::StmtIteratorBase(ScopedDecl* d)
+StmtIteratorBase::StmtIteratorBase(Decl* d)
: decl(d), RawVAPtr(DeclMode) {
assert (decl);
NextDecl(false);
NamedDecl *D = Node->getDecl();
// Build up a stack of contexts.
- DeclContext *Ctx = 0;
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D))
- Ctx = SD->getDeclContext();
- else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D))
- Ctx = Ovl->getDeclContext();
+ DeclContext *Ctx = D->getDeclContext();
for (; Ctx; Ctx = Ctx->getParent())
if (!Ctx->isTransparentContext())
Contexts.push_back(Ctx);
DeclContext *Ctx = Contexts.back();
if (isa<TranslationUnitDecl>(Ctx))
OS << "::";
- else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(Ctx))
- OS << SD->getNameAsString() << "::";
+ else if (NamedDecl *ND = dyn_cast<NamedDecl>(Ctx))
+ OS << ND->getNameAsString() << "::";
Contexts.pop_back();
}
void DeclRefExpr::EmitImpl(Serializer& S) const {
S.Emit(Loc);
S.Emit(getType());
-
- // Some DeclRefExprs can actually hold the owning reference to a FunctionDecl.
- // This occurs when an implicitly defined function is called, and
- // the decl does not appear in the source file. We thus check if the
- // decl pointer has been registered, and if not, emit an owned pointer.
-
- // FIXME: While this will work for serialization, it won't work for
- // memory management. The only reason this works for serialization is
- // because we are tracking all serialized pointers. Either DeclRefExpr
- // needs an explicit bit indicating that it owns the the object,
- // or we need a different ownership model.
-
- const Decl* d = getDecl();
-
- if (!S.isRegistered(d)) {
- assert (isa<FunctionDecl>(d)
- && "DeclRefExpr can only own FunctionDecls for implicitly def. funcs.");
-
- S.EmitBool(true);
- S.EmitOwnedPtr(d);
- }
- else {
- S.EmitBool(false);
- S.EmitPtr(d);
- }
+ S.EmitPtr(getDecl());
}
DeclRefExpr* DeclRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
SourceLocation Loc = SourceLocation::ReadVal(D);
QualType T = QualType::ReadVal(D);
- bool OwnsDecl = D.ReadBool();
- NamedDecl* decl;
-
- if (!OwnsDecl)
- D.ReadPtr(decl,false); // No backpatching.
- else
- decl = cast<NamedDecl>(D.ReadOwnedPtr<Decl>(C));
-
- return new DeclRefExpr(decl,T,Loc);
+ DeclRefExpr *DRE = new DeclRefExpr(0, T, Loc);
+ D.ReadPtr(DRE->D);
+ return DRE;
}
void DefaultStmt::EmitImpl(Serializer& S) const {
void GRExprEngine::VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst) {
// The CFG has one DeclStmt per Decl.
- ScopedDecl* D = *DS->decl_begin();
+ Decl* D = *DS->decl_begin();
if (!D || !isa<VarDecl>(D))
return;
if (const DeclStmt *SD = dyn_cast<DeclStmt>(S.getElement())) {
EmitStmt(SD);
assert(HaveInsertPoint() && "DeclStmt destroyed insert point!");
- const ScopedDecl* D = SD->getSolitaryDecl();
+ const Decl* D = SD->getSolitaryDecl();
ElementTy = cast<ValueDecl>(D)->getType();
DeclAddress = LocalDeclMap[D];
} else {
SourceLocation(),
&Ctx.Idents.get("_objc_super"));
RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), 0,
- Ctx.getObjCIdType(), 0, false, 0));
+ Ctx.getObjCIdType(), 0, false));
RD->addDecl(FieldDecl::Create(Ctx, RD, SourceLocation(), 0,
- Ctx.getObjCClassType(), 0, false, 0));
+ Ctx.getObjCClassType(), 0, false));
RD->completeDefinition(Ctx);
SuperCTy = Ctx.getTagDeclType(RD);
}
virtual void HandleTopLevelDecl(Decl *D) {
- // Make sure to emit all elements of a ScopedDecl.
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
+ // Make sure to emit all elements of a Decl.
+ if (Decl *SD = dyn_cast<Decl>(D)) {
for (; SD; SD = SD->getNextDeclarator())
Builder->EmitTopLevelDecl(SD);
} else {
// LookupContext Implementation
//===----------------------------------------------------------------------===//
-/// getContext - Returns translation unit context for non ScopedDecls and
+/// getContext - Returns translation unit context for non Decls and
/// for EnumConstantDecls returns the parent context of their EnumDecl.
DeclContext *IdentifierResolver::LookupContext::getContext(Decl *D) {
- DeclContext *Ctx;
-
- if (EnumConstantDecl *EnumD = dyn_cast<EnumConstantDecl>(D)) {
- Ctx = EnumD->getDeclContext()->getParent();
- } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D))
- Ctx = SD->getDeclContext();
- else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D))
- Ctx = Ovl->getDeclContext();
- else
- return TUCtx();
+ DeclContext *Ctx = D->getDeclContext();
if (!Ctx) // FIXME: HACK! We shouldn't end up with a NULL context here.
return TUCtx();
class IdentifierResolver {
/// LookupContext - A wrapper for DeclContext. DeclContext is only part of
- /// ScopedDecls, LookupContext can be used with all decls (assumes
- /// translation unit context for non ScopedDecls).
+ /// Decls, LookupContext can be used with all decls (assumes
+ /// translation unit context for non Decls).
class LookupContext {
const DeclContext *Ctx;
return reinterpret_cast<DeclContext*>(-1);
}
- /// getContext - Returns translation unit context for non ScopedDecls and
+ /// getContext - Returns translation unit context for non Decls and
/// for EnumConstantDecls returns the parent context of their EnumDecl.
static DeclContext *getContext(Decl *D);
TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext,
SourceLocation(),
&Context.Idents.get("SEL"),
- SelT, 0);
+ SelT);
PushOnScopeChains(SelTypedef, TUScope);
Context.setObjCSelType(SelTypedef);
QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag));
TypedefDecl *ClassTypedef =
TypedefDecl::Create(Context, CurContext, SourceLocation(),
- &Context.Idents.get("Class"), ClassT, 0);
+ &Context.Idents.get("Class"), ClassT);
PushOnScopeChains(ClassTag, TUScope);
PushOnScopeChains(ClassTypedef, TUScope);
Context.setObjCClassType(ClassTypedef);
TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext,
SourceLocation(),
&Context.Idents.get("id"),
- ObjT, 0);
+ ObjT);
PushOnScopeChains(IdTypedef, TUScope);
Context.setObjCIdType(IdTypedef);
}
while (isa<BlockDecl>(DC))
DC = DC->getParent();
if (isa<ObjCMethodDecl>(DC) || isa<FunctionDecl>(DC))
- return cast<ScopedDecl>(DC);
+ return cast<NamedDecl>(DC);
return 0;
}
class DeclContext;
class DeclSpec;
class NamedDecl;
- class ScopedDecl;
class Stmt;
class Expr;
class InitListExpr;
}
DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
bool IsFunctionDefinition);
- ScopedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
- QualType R, ScopedDecl* LastDeclarator,
- Decl* PrevDecl, bool& InvalidDecl);
- ScopedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
- QualType R, ScopedDecl* LastDeclarator,
+ NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
+ QualType R, Decl* LastDeclarator,
+ Decl* PrevDecl, bool& InvalidDecl);
+ NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
+ QualType R, Decl* LastDeclarator,
Decl* PrevDecl, bool& InvalidDecl);
- ScopedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
- QualType R, ScopedDecl *LastDeclarator,
- Decl* PrevDecl, bool IsFunctionDefinition,
- bool& InvalidDecl);
+ NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
+ QualType R, Decl *LastDeclarator,
+ Decl* PrevDecl, bool IsFunctionDefinition,
+ bool& InvalidDecl);
virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
virtual void ActOnParamDefaultArgument(DeclTy *param,
SourceLocation EqualLoc,
/// Subroutines of ActOnDeclarator().
TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
- ScopedDecl *LastDecl);
+ Decl *LastDecl);
TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old,
bool &Redeclaration);
//@}
ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
- ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
- Scope *S);
- ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
+ NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Scope *S);
+ NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
+ Scope *S);
// More parsing and symbol table subroutines.
if (isa<ObjCMethodDecl>(DC))
return Context.getTranslationUnitDecl();
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(DC))
- return SD->getLexicalDeclContext();
+ if (Decl *D = dyn_cast<Decl>(DC))
+ return D->getLexicalDeclContext();
return DC->getLexicalParent();
}
// Add scoped declarations into their context, so that they can be
// found later. Declarations without a context won't be inserted
// into any context.
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D))
- CurContext->addDecl(SD);
+ CurContext->addDecl(D);
// C++ [basic.scope]p4:
// -- exactly one declaration shall declare a class name or
= std::find_if(IdResolver.begin(FD->getDeclName(), DC,
false/*LookInParentCtx*/),
IdResolver.end(),
- std::bind1st(std::mem_fun(&ScopedDecl::declarationReplaces),
+ std::bind1st(std::mem_fun(&NamedDecl::declarationReplaces),
FD));
if (Redecl != IdResolver.end()) {
// There is already a declaration of a function on our
/// LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
/// lazily create a decl for it.
-ScopedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid,
- Scope *S) {
+NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid,
+ Scope *S) {
Builtin::ID BID = (Builtin::ID)bid;
if (Context.BuiltinInfo.hasVAListUse(BID))
FunctionDecl *New = FunctionDecl::Create(Context,
Context.getTranslationUnitDecl(),
SourceLocation(), II, R,
- FunctionDecl::Extern, false, 0);
+ FunctionDecl::Extern, false);
// Create Decl objects for each parameter, adding them to the
// FunctionDecl.
llvm::SmallVector<ParmVarDecl*, 16> Params;
for (unsigned i = 0, e = FT->getNumArgs(); i != e; ++i)
Params.push_back(ParmVarDecl::Create(Context, New, SourceLocation(), 0,
- FT->getArgType(i), VarDecl::None, 0,
- 0));
+ FT->getArgType(i), VarDecl::None, 0));
New->setParams(Context, &Params[0], Params.size());
}
}
// Create a declaration for this anonymous struct/union.
- ScopedDecl *Anon = 0;
+ NamedDecl *Anon = 0;
if (RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) {
Anon = FieldDecl::Create(Context, OwningClass, Record->getLocation(),
/*IdentifierInfo=*/0,
Context.getTypeDeclType(Record),
- /*BitWidth=*/0, /*Mutable=*/false,
- /*PrevDecl=*/0);
+ /*BitWidth=*/0, /*Mutable=*/false);
Anon->setAccess(AS_public);
if (getLangOptions().CPlusPlus)
FieldCollector->Add(cast<FieldDecl>(Anon));
Anon = VarDecl::Create(Context, Owner, Record->getLocation(),
/*IdentifierInfo=*/0,
Context.getTypeDeclType(Record),
- SC, /*FIXME:LastDeclarator=*/0,
- DS.getSourceRange().getBegin());
+ SC, DS.getSourceRange().getBegin());
}
Anon->setImplicit();
Sema::DeclTy *
Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl,
bool IsFunctionDefinition) {
- ScopedDecl *LastDeclarator = dyn_cast_or_null<ScopedDecl>((Decl *)lastDecl);
+ NamedDecl *LastDeclarator = dyn_cast_or_null<NamedDecl>((Decl *)lastDecl);
DeclarationName Name = GetNameForDeclarator(D);
// All of these full declarators require an identifier. If it doesn't have
DeclContext *DC;
Decl *PrevDecl;
- ScopedDecl *New;
+ NamedDecl *New;
bool InvalidDecl = false;
// See if this is a redefinition of a variable in the same scope.
return New;
}
-ScopedDecl*
+NamedDecl*
Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
- QualType R, ScopedDecl* LastDeclarator,
+ QualType R, Decl* LastDeclarator,
Decl* PrevDecl, bool& InvalidDecl) {
// Typedef declarators cannot be qualified (C++ [dcl.meaning]p1).
if (D.getCXXScopeSpec().isSet()) {
return NewTD;
}
-ScopedDecl*
+NamedDecl*
Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
- QualType R, ScopedDecl* LastDeclarator,
+ QualType R, Decl* LastDeclarator,
Decl* PrevDecl, bool& InvalidDecl) {
DeclarationName Name = GetNameForDeclarator(D);
// This is a static data member for a C++ class.
NewVD = CXXClassVarDecl::Create(Context, cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), II,
- R, LastDeclarator);
+ R);
} else {
bool ThreadSpecified = D.getDeclSpec().isThreadSpecified();
if (S->getFnParent() == 0) {
}
}
NewVD = VarDecl::Create(Context, DC, D.getIdentifierLoc(),
- II, R, SC, LastDeclarator,
+ II, R, SC,
// FIXME: Move to DeclGroup...
D.getDeclSpec().getSourceRange().getBegin());
NewVD->setThreadSpecified(ThreadSpecified);
}
+ NewVD->setNextDeclarator(LastDeclarator);
+
// Handle attributes prior to checking for duplicates in MergeVarDecl
ProcessDeclAttributes(NewVD, D);
return NewVD;
}
-ScopedDecl*
+NamedDecl*
Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
- QualType R, ScopedDecl *LastDeclarator,
+ QualType R, Decl *LastDeclarator,
Decl* PrevDecl, bool IsFunctionDefinition,
bool& InvalidDecl) {
assert(R.getTypePtr()->isFunctionType());
// Create a FunctionDecl to satisfy the function definition parsing
// code path.
NewFD = FunctionDecl::Create(Context, DC, D.getIdentifierLoc(),
- Name, R, SC, isInline, LastDeclarator,
+ Name, R, SC, isInline,
// FIXME: Move to DeclGroup...
D.getDeclSpec().getSourceRange().getBegin());
InvalidDecl = true;
// This is a C++ method declaration.
NewFD = CXXMethodDecl::Create(Context, cast<CXXRecordDecl>(DC),
D.getIdentifierLoc(), Name, R,
- (SC == FunctionDecl::Static), isInline,
- LastDeclarator);
+ (SC == FunctionDecl::Static), isInline);
} else {
NewFD = FunctionDecl::Create(Context, DC,
D.getIdentifierLoc(),
- Name, R, SC, isInline, LastDeclarator,
+ Name, R, SC, isInline,
// FIXME: Move to DeclGroup...
D.getDeclSpec().getSourceRange().getBegin());
}
+ NewFD->setNextDeclarator(LastDeclarator);
// Set the lexical context. If the declarator has a C++
// scope specifier, the lexical context will be different
Params.push_back(ParmVarDecl::Create(Context, DC,
SourceLocation(), 0,
*ArgType, VarDecl::None,
- 0, 0));
+ 0));
}
NewFD->setParams(Context, &Params[0], Params.size());
VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
if (!VDecl) {
- Diag(dyn_cast<ScopedDecl>(RealDecl)->getLocation(),
- diag::err_illegal_initializer);
+ Diag(RealDecl->getLocation(), diag::err_illegal_initializer);
RealDecl->setInvalidDecl();
return;
}
if (GroupDecl == 0)
return 0;
- ScopedDecl *Group = dyn_cast<ScopedDecl>(GroupDecl);
- ScopedDecl *NewGroup = 0;
+ Decl *Group = dyn_cast<Decl>(GroupDecl);
+ Decl *NewGroup = 0;
if (Group->getNextDeclarator() == 0)
NewGroup = Group;
else { // reverse the list.
while (Group) {
- ScopedDecl *Next = Group->getNextDeclarator();
+ Decl *Next = Group->getNextDeclarator();
Group->setNextDeclarator(NewGroup);
NewGroup = Group;
Group = Next;
}
// Perform semantic analysis that depends on having fully processed both
// the declarator and initializer.
- for (ScopedDecl *ID = NewGroup; ID; ID = ID->getNextDeclarator()) {
+ for (Decl *ID = NewGroup; ID; ID = ID->getNextDeclarator()) {
VarDecl *IDecl = dyn_cast<VarDecl>(ID);
if (!IDecl)
continue;
ParmVarDecl *New = ParmVarDecl::Create(Context, CurContext,
D.getIdentifierLoc(), II,
parmDeclType, StorageClass,
- 0, 0);
+ 0);
if (D.getInvalidType())
New->setInvalidDecl();
/// ImplicitlyDefineFunction - An undeclared identifier was used in a function
/// call, forming a call to an implicitly defined function (per C99 6.5.1p2).
-ScopedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
- IdentifierInfo &II, Scope *S) {
+NamedDecl *Sema::ImplicitlyDefineFunction(SourceLocation Loc,
+ IdentifierInfo &II, Scope *S) {
// Extension in C99. Legal in C90, but warn about it.
if (getLangOptions().C99)
Diag(Loc, diag::ext_implicit_function_decl) << &II;
TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
- ScopedDecl *LastDeclarator) {
+ Decl *LastDeclarator) {
assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
TypedefDecl *NewTD = TypedefDecl::Create(Context, CurContext,
D.getIdentifierLoc(),
D.getIdentifier(),
- T, LastDeclarator);
+ T);
+ NewTD->setNextDeclarator(LastDeclarator);
if (D.getInvalidType())
NewTD->setInvalidDecl();
return NewTD;
DeclContext *SearchDC = CurContext;
DeclContext *DC = CurContext;
DeclContext *LexicalContext = CurContext;
- ScopedDecl *PrevDecl = 0;
+ Decl *PrevDecl = 0;
bool Invalid = false;
} else {
// If this is a named struct, check to see if there was a previous forward
// declaration or definition.
- // Use ScopedDecl instead of TagDecl, because a NamespaceDecl may come up.
- PrevDecl = dyn_cast_or_null<ScopedDecl>(LookupDecl(Name, Decl::IDNS_Tag,S)
- .getAsDecl());
+ PrevDecl = dyn_cast_or_null<NamedDecl>(LookupDecl(Name, Decl::IDNS_Tag,S)
+ .getAsDecl());
if (!getLangOptions().CPlusPlus && TK != TK_Reference) {
// FIXME: This makes sure that we ignore the contexts associated
NewFD = FieldDecl::Create(Context, Record,
Loc, II, T, BitWidth,
D.getDeclSpec().getStorageClassSpec() ==
- DeclSpec::SCS_mutable,
- /*PrevDecl=*/0);
+ DeclSpec::SCS_mutable);
if (II) {
Decl *PrevDecl
EnumConstantDecl *New =
EnumConstantDecl::Create(Context, TheEnumDecl, IdLoc, Id, EltTy,
- Val, EnumVal,
- LastEnumConst);
+ Val, EnumVal);
// Register this decl in the current scope stack.
PushOnScopeChains(New, S);
ExprArg expr) {
StringLiteral *AsmString = cast<StringLiteral>((Expr*)expr.release());
- return FileScopeAsmDecl::Create(Context, Loc, AsmString);
+ return FileScopeAsmDecl::Create(Context, CurContext, Loc, AsmString);
}
/// bitfield width if there is one and 'InitExpr' specifies the initializer if
/// any. 'LastInGroup' is non-null for cases where one declspec has multiple
/// declarators on it.
-///
-/// FIXME: The note below is out-of-date.
-/// NOTE: Because of CXXFieldDecl's inability to be chained like ScopedDecls, if
-/// an instance field is declared, a new CXXFieldDecl is created but the method
-/// does *not* return it; it returns LastInGroup instead. The other C++ members
-/// (which are all ScopedDecls) are returned after appending them to
-/// LastInGroup.
Sema::DeclTy *
Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
ExprTy *BW, ExprTy *InitExpr,
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyConstructor,
ClassDecl->getLocation(),
/*IdentifierInfo=*/0,
- ArgType, VarDecl::None, 0, 0);
+ ArgType, VarDecl::None, 0);
CopyConstructor->setParams(Context, &FromParam, 1);
ClassDecl->addedConstructor(Context, CopyConstructor);
CXXMethodDecl::Create(Context, ClassDecl, ClassDecl->getLocation(), Name,
Context.getFunctionType(RetType, &ArgType, 1,
false, 0),
- /*isStatic=*/false, /*isInline=*/true, 0);
+ /*isStatic=*/false, /*isInline=*/true);
CopyAssignment->setAccess(AS_public);
CopyAssignment->setImplicit();
ParmVarDecl *FromParam = ParmVarDecl::Create(Context, CopyAssignment,
ClassDecl->getLocation(),
/*IdentifierInfo=*/0,
- ArgType, VarDecl::None, 0, 0);
+ ArgType, VarDecl::None, 0);
CopyAssignment->setParams(Context, &FromParam, 1);
// Don't call addedAssignmentOperator. There is no way to distinguish an
}
VarDecl *ExDecl = VarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
- II, ExDeclType, VarDecl::None, 0, Begin);
+ II, ExDeclType, VarDecl::None, Begin);
if (D.getInvalidType() || Invalid)
ExDecl->setInvalidDecl();
ObjCImplementationDecl* IMPDecl =
ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc,
- ClassName, IDecl, SDecl);
+ IDecl, SDecl);
// FIXME: PushOnScopeChains?
CurContext->addDecl(IMPDecl);
ObjCIvarDecl **ivars, unsigned numIvars,
SourceLocation RBrace) {
assert(ImpDecl && "missing implementation decl");
- ObjCInterfaceDecl* IDecl = getObjCInterfaceDecl(ImpDecl->getIdentifier());
+ ObjCInterfaceDecl* IDecl = ImpDecl->getClassInterface();
if (!IDecl)
return;
/// Check case of non-existing @interface decl.
property->getIdentifier(),
property->getType(),
VarDecl::None,
- 0, 0);
+ 0);
SetterMethod->setMethodParams(&Argument, 1);
CD->addDecl(SetterMethod);
} else
}
if (ObjCImplementationDecl *IC=dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
IC->setLocEnd(AtEndLoc);
- if (ObjCInterfaceDecl* IDecl = getObjCInterfaceDecl(IC->getIdentifier()))
+ if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
ImplMethodsVsClassMethods(IC, IDecl);
} else if (ObjCCategoryImplDecl* CatImplClass =
dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
Param = ParmVarDecl::Create(Context, ObjCMethod,
SourceLocation(/*FIXME*/),
ArgNames[i], argType,
- VarDecl::None, 0, 0);
+ VarDecl::None, 0);
else
Param = ParmVarWithOriginalTypeDecl::Create(Context, ObjCMethod,
SourceLocation(/*FIXME*/),
ArgNames[i], argType, originalArgType,
- VarDecl::None, 0, 0);
+ VarDecl::None, 0);
Param->setObjCDeclQualifier(
CvtQTToAstBitMask(ArgQT[i].getObjCDeclQualifier()));
FD.D.getIdentifier(),
T,
VarDecl::None,
- 0, 0);
+ 0);
SetterDecl->setMethodParams(&Argument, 1);
PIDecl->setSetterMethodDecl(SetterDecl);
}
ObjCImplementationDecl *IC = 0;
ObjCCategoryImplDecl* CatImplClass = 0;
if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
- IDecl = getObjCInterfaceDecl(IC->getIdentifier());
+ IDecl = IC->getClassInterface();
// We always synthesize an interface for an implementation
// without an interface decl. So, IDecl is always non-zero.
assert(IDecl &&
/// getObjectForAnonymousRecordDecl - Retrieve the (unnamed) field or
/// variable corresponding to the anonymous union or struct whose type
/// is Record.
-static ScopedDecl *getObjectForAnonymousRecordDecl(RecordDecl *Record) {
+static Decl *getObjectForAnonymousRecordDecl(RecordDecl *Record) {
assert(Record->isAnonymousStructOrUnion() &&
"Record must be an anonymous struct or union!");
- // FIXME: Once ScopedDecls are directly linked together, this will
+ // FIXME: Once Decls are directly linked together, this will
// be an O(1) operation rather than a slow walk through DeclContext's
// vector (which itself will be eliminated). DeclGroups might make
// this even better.
// follows its type in the list of declarations.
++D;
assert(D != DEnd && "Missing object for anonymous record");
- assert(!cast<ScopedDecl>(*D)->getDeclName() && "Decl should be unnamed");
+ assert(!cast<NamedDecl>(*D)->getDeclName() && "Decl should be unnamed");
return *D;
}
}
DeclContext *Ctx = Field->getDeclContext();
do {
RecordDecl *Record = cast<RecordDecl>(Ctx);
- ScopedDecl *AnonObject = getObjectForAnonymousRecordDecl(Record);
+ Decl *AnonObject = getObjectForAnonymousRecordDecl(Record);
if (FieldDecl *AnonField = dyn_cast<FieldDecl>(AnonObject))
AnonFields.push_back(AnonField);
else {
// well.
IdentifierInfo *II = Name.getAsIdentifierInfo();
if (II && getCurMethodDecl()) {
- ScopedDecl *SD = dyn_cast_or_null<ScopedDecl>(D);
// There are two cases to handle here. 1) scoped lookup could have failed,
// in which case we should look for an ivar. 2) scoped lookup could have
// found a decl, but that decl is outside the current method (i.e. a global
// variable). In these two cases, we do a lookup for an ivar with this
// name, if the lookup suceeds, we replace it our current decl.
- if (SD == 0 || SD->isDefinedOutsideFunctionOrMethod()) {
+ if (D == 0 || D->isDefinedOutsideFunctionOrMethod()) {
ObjCInterfaceDecl *IFace = getCurMethodDecl()->getClassInterface();
if (ObjCIvarDecl *IV = IFace->lookupInstanceVariable(II)) {
// FIXME: This should use a new expr for a direct reference, don't turn
}
}
// Needed to implement property "super.method" notation.
- if (SD == 0 && II->isStr("super")) {
+ if (D == 0 && II->isStr("super")) {
QualType T = Context.getPointerType(Context.getObjCInterfaceType(
getCurMethodDecl()->getClassInterface()));
return Owned(new ObjCSuperExpr(Loc, T));
QualType FnType = Context.getFunctionType(Return, &Argument, 1, false, 0);
FunctionDecl *Alloc =
FunctionDecl::Create(Context, GlobalCtx, SourceLocation(), Name,
- FnType, FunctionDecl::None, false, 0,
+ FnType, FunctionDecl::None, false,
SourceLocation());
Alloc->setImplicit();
ParmVarDecl *Param = ParmVarDecl::Create(Context, Alloc, SourceLocation(),
- 0, Argument, VarDecl::None, 0, 0);
+ 0, Argument, VarDecl::None, 0);
Alloc->setParams(Context, &Param, 1);
// FIXME: Also add this declaration to the IdentifierResolver, but
// FIXME: We leak this overload set. Eventually, we want to
// stop building the declarations for these overload sets, so
// there will be nothing to leak.
- Ovl = OverloadedFunctionDecl::Create(Context,
- cast<ScopedDecl>(*I)->getDeclContext(),
+ Ovl = OverloadedFunctionDecl::Create(Context, (*I)->getDeclContext(),
(*I)->getDeclName());
Ovl->addOverload(cast<FunctionDecl>(*I));
}
// A static member, a nested type or an enumerator defined in
// a base class T can unambiguously be found even if an object
// has more than one base class subobject of type T.
- ScopedDecl *FirstDecl = *Path->Decls.first;
+ Decl *FirstDecl = *Path->Decls.first;
if (isa<VarDecl>(FirstDecl) ||
isa<TypeDecl>(FirstDecl) ||
isa<EnumConstantDecl>(FirstDecl))
Diag(NameLoc, diag::err_ambiguous_member_multiple_subobject_types)
<< Name << LookupRange;
- std::set<ScopedDecl *> DeclsPrinted;
+ std::set<Decl *> DeclsPrinted;
for (BasePaths::paths_iterator Path = Paths->begin(), PathEnd = Paths->end();
Path != PathEnd; ++Path) {
- ScopedDecl *D = *Path->Decls.first;
+ Decl *D = *Path->Decls.first;
if (DeclsPrinted.insert(D).second)
Diag(D->getLocation(), diag::note_ambiguous_member_found);
}
// operator names can only be ordinary identifiers.
// Ignore member functions.
- if (ScopedDecl *SD = dyn_cast<ScopedDecl>(*I)) {
- if (SD->getDeclContext()->isRecord())
- continue;
- }
+ if ((*I)->getDeclContext()->isRecord())
+ continue;
// We found something with this name. We're done.
break;
}
- if (I != IEnd && isa<ScopedDecl>(*I)) {
- ScopedDecl *FirstDecl = cast<ScopedDecl>(*I);
+ if (I != IEnd) {
+ Decl *FirstDecl = *I;
for (; I != IEnd; ++I) {
- ScopedDecl *SD = cast<ScopedDecl>(*I);
- if (FirstDecl->getDeclContext() != SD->getDeclContext())
+ if (FirstDecl->getDeclContext() != (*I)->getDeclContext())
break;
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(*I))
if (decl == 0)
return StmtError();
- ScopedDecl *SD = cast<ScopedDecl>(static_cast<Decl *>(decl));
+ Decl *D = static_cast<Decl *>(decl);
// This is a temporary hack until we are always passing around
// DeclGroupRefs.
llvm::SmallVector<Decl*, 10> decls;
- while (SD) {
- ScopedDecl* d = SD;
- SD = SD->getNextDeclarator();
+ while (D) {
+ Decl* d = D;
+ D = D->getNextDeclarator();
d->setNextDeclarator(0);
decls.push_back(d);
}
/*empty*/;
if (i != NumElts) {
- ScopedDecl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
+ Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
Diag(D->getLocation(), diag::ext_mixed_decls_code);
}
}
return StmtError(Diag((*DS->decl_begin())->getLocation(),
diag::err_toomany_element_decls));
- ScopedDecl *D = DS->getSolitaryDecl();
+ Decl *D = DS->getSolitaryDecl();
FirstType = cast<ValueDecl>(D)->getType();
// C99 6.8.5p3: The declaration part of a 'for' statement shall only
// declare identifiers for objects having storage class 'auto' or
// RUN: clang %s --test-pickling 2>&1 | grep -q 'SUCCESS'
+// XFAIL
int main(void)
{
// RUN: clang %s --test-pickling 2>&1 | grep -q 'SUCCESS'
-
+// XFAIL
typedef unsigned __uint32_t;
#define __byte_swap_int_var(x) \
int test(int _x) {
return (__byte_swap_int_var(_x));
-}
\ No newline at end of file
+}