2006-11-06 02:44:26 +08:00
|
|
|
//===--- MinimalAction.cpp - Implement the MinimalAction class ------------===//
|
2006-08-14 08:38:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-08-14 08:38:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-11-06 02:44:26 +08:00
|
|
|
// This file implements the MinimalAction interface.
|
2006-08-14 08:38:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Parse/Parser.h"
|
2006-11-12 07:03:42 +08:00
|
|
|
#include "clang/Parse/DeclSpec.h"
|
2006-08-14 09:28:29 +08:00
|
|
|
#include "clang/Parse/Scope.h"
|
2009-05-02 00:33:20 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2009-01-18 17:39:41 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include "llvm/Support/RecyclingAllocator.h"
|
2009-03-05 09:25:28 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-08-14 08:38:06 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2009-03-16 01:47:39 +08:00
|
|
|
/// Out-of-line virtual destructor to provide home for ActionBase class.
|
2009-03-05 15:24:28 +08:00
|
|
|
ActionBase::~ActionBase() {}
|
|
|
|
|
|
|
|
/// Out-of-line virtual destructor to provide home for Action class.
|
|
|
|
Action::~Action() {}
|
|
|
|
|
|
|
|
// Defined out-of-line here because of dependecy on AttributeList
|
2009-03-29 03:18:32 +08:00
|
|
|
Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope,
|
|
|
|
SourceLocation UsingLoc,
|
|
|
|
SourceLocation NamespcLoc,
|
2010-04-09 00:38:48 +08:00
|
|
|
CXXScopeSpec &SS,
|
2009-03-29 03:18:32 +08:00
|
|
|
SourceLocation IdentLoc,
|
|
|
|
IdentifierInfo *NamespcName,
|
|
|
|
AttributeList *AttrList) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-05 15:24:28 +08:00
|
|
|
// FIXME: Parser seems to assume that Action::ActOn* takes ownership over
|
|
|
|
// passed AttributeList, however other actions don't free it, is it
|
|
|
|
// temporary state or bug?
|
|
|
|
delete AttrList;
|
2009-06-20 08:51:54 +08:00
|
|
|
return DeclPtrTy();
|
|
|
|
}
|
|
|
|
|
2009-11-05 00:30:06 +08:00
|
|
|
// Defined out-of-line here because of dependency on AttributeList
|
2009-06-20 08:51:54 +08:00
|
|
|
Action::DeclPtrTy Action::ActOnUsingDeclaration(Scope *CurScope,
|
2009-08-30 03:54:19 +08:00
|
|
|
AccessSpecifier AS,
|
2009-12-11 10:10:03 +08:00
|
|
|
bool HasUsingKeyword,
|
2009-08-30 03:54:19 +08:00
|
|
|
SourceLocation UsingLoc,
|
2010-04-09 00:38:48 +08:00
|
|
|
CXXScopeSpec &SS,
|
2009-11-05 00:30:06 +08:00
|
|
|
UnqualifiedId &Name,
|
2009-08-30 03:54:19 +08:00
|
|
|
AttributeList *AttrList,
|
2009-11-18 10:36:19 +08:00
|
|
|
bool IsTypeName,
|
|
|
|
SourceLocation TypenameLoc) {
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-20 08:51:54 +08:00
|
|
|
// FIXME: Parser seems to assume that Action::ActOn* takes ownership over
|
|
|
|
// passed AttributeList, however other actions don't free it, is it
|
|
|
|
// temporary state or bug?
|
|
|
|
delete AttrList;
|
2009-03-29 03:18:32 +08:00
|
|
|
return DeclPtrTy();
|
2009-03-05 15:24:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-05 16:00:35 +08:00
|
|
|
void PrettyStackTraceActionsDecl::print(llvm::raw_ostream &OS) const {
|
2009-03-05 09:25:28 +08:00
|
|
|
if (Loc.isValid()) {
|
|
|
|
Loc.print(OS, SM);
|
|
|
|
OS << ": ";
|
|
|
|
}
|
|
|
|
OS << Message;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-05 09:25:28 +08:00
|
|
|
std::string Name = Actions.getDeclName(TheDecl);
|
|
|
|
if (!Name.empty())
|
|
|
|
OS << " '" << Name << '\'';
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-05 09:25:28 +08:00
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
/// TypeNameInfo - A link exists here for each scope that an identifier is
|
2006-08-14 09:28:29 +08:00
|
|
|
/// defined.
|
2009-01-18 17:39:41 +08:00
|
|
|
namespace {
|
|
|
|
struct TypeNameInfo {
|
|
|
|
TypeNameInfo *Prev;
|
|
|
|
bool isTypeName;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-18 17:39:41 +08:00
|
|
|
TypeNameInfo(bool istypename, TypeNameInfo *prev) {
|
|
|
|
isTypeName = istypename;
|
|
|
|
Prev = prev;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TypeNameInfoTable {
|
|
|
|
llvm::RecyclingAllocator<llvm::BumpPtrAllocator, TypeNameInfo> Allocator;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-18 17:39:41 +08:00
|
|
|
void AddEntry(bool isTypename, IdentifierInfo *II) {
|
|
|
|
TypeNameInfo *TI = Allocator.Allocate<TypeNameInfo>();
|
2009-03-25 01:05:27 +08:00
|
|
|
new (TI) TypeNameInfo(isTypename, II->getFETokenInfo<TypeNameInfo>());
|
2009-01-18 17:39:41 +08:00
|
|
|
II->setFETokenInfo(TI);
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-01-18 17:39:41 +08:00
|
|
|
void DeleteEntry(TypeNameInfo *Entry) {
|
|
|
|
Entry->~TypeNameInfo();
|
|
|
|
Allocator.Deallocate(Entry);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static TypeNameInfoTable *getTable(void *TP) {
|
|
|
|
return static_cast<TypeNameInfoTable*>(TP);
|
|
|
|
}
|
2006-08-14 09:28:29 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
MinimalAction::MinimalAction(Preprocessor &pp)
|
2009-01-18 17:39:41 +08:00
|
|
|
: Idents(pp.getIdentifierTable()), PP(pp) {
|
|
|
|
TypeNameInfoTablePtr = new TypeNameInfoTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
MinimalAction::~MinimalAction() {
|
|
|
|
delete getTable(TypeNameInfoTablePtr);
|
|
|
|
}
|
2008-10-31 16:56:51 +08:00
|
|
|
|
|
|
|
void MinimalAction::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
|
2007-11-01 02:42:27 +08:00
|
|
|
TUScope = S;
|
2009-01-18 17:39:41 +08:00
|
|
|
|
|
|
|
TypeNameInfoTable &TNIT = *getTable(TypeNameInfoTablePtr);
|
2009-05-02 00:33:20 +08:00
|
|
|
|
|
|
|
if (PP.getTargetInfo().getPointerWidth(0) >= 64) {
|
|
|
|
// Install [u]int128_t for 64-bit targets.
|
|
|
|
TNIT.AddEntry(true, &Idents.get("__int128_t"));
|
|
|
|
TNIT.AddEntry(true, &Idents.get("__uint128_t"));
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-02 00:33:20 +08:00
|
|
|
if (PP.getLangOptions().ObjC1) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// Recognize the ObjC built-in type identifiers as types.
|
2009-05-02 00:33:20 +08:00
|
|
|
TNIT.AddEntry(true, &Idents.get("id"));
|
|
|
|
TNIT.AddEntry(true, &Idents.get("SEL"));
|
|
|
|
TNIT.AddEntry(true, &Idents.get("Class"));
|
|
|
|
TNIT.AddEntry(true, &Idents.get("Protocol"));
|
|
|
|
}
|
2007-11-01 02:42:27 +08:00
|
|
|
}
|
|
|
|
|
2006-11-03 15:35:12 +08:00
|
|
|
/// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
|
|
|
|
/// determine whether the name is a type name (objc class name or typedef) or
|
|
|
|
/// not in this scope.
|
2008-11-09 00:45:02 +08:00
|
|
|
///
|
|
|
|
/// FIXME: Use the passed CXXScopeSpec for accurate C++ type checking.
|
2008-08-01 18:35:27 +08:00
|
|
|
Action::TypeTy *
|
2009-02-05 01:00:24 +08:00
|
|
|
MinimalAction::getTypeName(IdentifierInfo &II, SourceLocation Loc,
|
2010-04-09 00:38:48 +08:00
|
|
|
Scope *S, CXXScopeSpec *SS,
|
2009-11-21 06:03:38 +08:00
|
|
|
bool isClassName, TypeTy *ObjectType) {
|
2006-11-20 09:29:42 +08:00
|
|
|
if (TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>())
|
|
|
|
if (TI->isTypeName)
|
|
|
|
return TI;
|
|
|
|
return 0;
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|
|
|
|
|
2008-10-31 17:07:45 +08:00
|
|
|
/// isCurrentClassName - Always returns false, because MinimalAction
|
|
|
|
/// does not support C++ classes with constructors.
|
2008-11-09 00:45:02 +08:00
|
|
|
bool MinimalAction::isCurrentClassName(const IdentifierInfo &, Scope *,
|
|
|
|
const CXXScopeSpec *) {
|
2008-10-31 17:07:45 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
TemplateNameKind
|
2009-09-03 06:59:36 +08:00
|
|
|
MinimalAction::isTemplateName(Scope *S,
|
2010-04-09 00:38:48 +08:00
|
|
|
CXXScopeSpec &SS,
|
2009-11-04 07:16:33 +08:00
|
|
|
UnqualifiedId &Name,
|
2009-09-09 23:08:12 +08:00
|
|
|
TypeTy *ObjectType,
|
Improve support for out-of-line definitions of nested templates and
their members, including member class template, member function
templates, and member classes and functions of member templates.
To actually parse the nested-name-specifiers that qualify the name of
an out-of-line definition of a member template, e.g.,
template<typename X> template<typename Y>
X Outer<X>::Inner1<Y>::foo(Y) {
return X();
}
we need to look for the template names (e.g., "Inner1") as a member of
the current instantiation (Outer<X>), even before we have entered the
scope of the current instantiation. Since we can't do this in general
(i.e., we should not be looking into all dependent
nested-name-specifiers as if they were the current instantiation), we
rely on the parser to tell us when it is parsing a declaration
specifier sequence, and, therefore, when we should consider the
current scope specifier to be a current instantiation.
Printing of complicated, dependent nested-name-specifiers may be
somewhat broken by this commit; I'll add tests for this issue and fix
the problem (if it still exists) in a subsequent commit.
llvm-svn: 80044
2009-08-26 06:51:20 +08:00
|
|
|
bool EnteringScope,
|
|
|
|
TemplateTy &TemplateDecl) {
|
2009-02-10 02:46:07 +08:00
|
|
|
return TNK_Non_template;
|
2008-12-19 03:37:40 +08:00
|
|
|
}
|
|
|
|
|
2007-09-16 02:49:24 +08:00
|
|
|
/// ActOnDeclarator - If this is a typedef declarator, we modify the
|
2006-08-14 08:38:06 +08:00
|
|
|
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
|
|
|
|
/// popped.
|
2009-03-29 03:18:32 +08:00
|
|
|
Action::DeclPtrTy
|
2009-03-30 00:50:03 +08:00
|
|
|
MinimalAction::ActOnDeclarator(Scope *S, Declarator &D) {
|
2006-10-28 07:18:49 +08:00
|
|
|
IdentifierInfo *II = D.getIdentifier();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-14 09:28:29 +08:00
|
|
|
// If there is no identifier associated with this declarator, bail out.
|
2009-03-29 03:18:32 +08:00
|
|
|
if (II == 0) return DeclPtrTy();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo<TypeNameInfo>();
|
2006-11-28 12:28:12 +08:00
|
|
|
bool isTypeName =
|
|
|
|
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef;
|
2006-08-14 09:28:29 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
// this check avoids creating TypeNameInfo objects for the common case.
|
2008-08-05 06:51:42 +08:00
|
|
|
// It does need to handle the uncommon case of shadowing a typedef name with a
|
2006-10-28 07:18:49 +08:00
|
|
|
// non-typedef name. e.g. { typedef int a; a xx; { int a; } }
|
|
|
|
if (weCurrentlyHaveTypeInfo || isTypeName) {
|
2009-01-18 17:39:41 +08:00
|
|
|
// Allocate and add the 'TypeNameInfo' "decl".
|
|
|
|
getTable(TypeNameInfoTablePtr)->AddEntry(isTypeName, II);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
2009-03-29 03:18:32 +08:00
|
|
|
S->AddDecl(DeclPtrTy::make(II));
|
2009-09-09 23:08:12 +08:00
|
|
|
}
|
2009-03-29 03:18:32 +08:00
|
|
|
return DeclPtrTy();
|
2006-10-28 07:18:49 +08:00
|
|
|
}
|
|
|
|
|
2009-03-29 03:18:32 +08:00
|
|
|
Action::DeclPtrTy
|
2008-07-21 15:13:18 +08:00
|
|
|
MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
|
2008-07-26 12:13:19 +08:00
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *SuperName,
|
|
|
|
SourceLocation SuperLoc,
|
2009-03-29 03:18:32 +08:00
|
|
|
const DeclPtrTy *ProtoRefs,
|
2008-07-26 12:13:19 +08:00
|
|
|
unsigned NumProtocols,
|
2010-01-16 23:02:53 +08:00
|
|
|
const SourceLocation *ProtoLocs,
|
2008-07-26 12:13:19 +08:00
|
|
|
SourceLocation EndProtoLoc,
|
|
|
|
AttributeList *AttrList) {
|
2009-01-18 17:39:41 +08:00
|
|
|
// Allocate and add the 'TypeNameInfo' "decl".
|
|
|
|
getTable(TypeNameInfoTablePtr)->AddEntry(true, ClassName);
|
2009-03-29 03:18:32 +08:00
|
|
|
return DeclPtrTy();
|
2007-09-07 05:24:23 +08:00
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// ActOnForwardClassDeclaration -
|
|
|
|
/// Scope will always be top level file scope.
|
2009-03-29 03:18:32 +08:00
|
|
|
Action::DeclPtrTy
|
2007-10-11 01:32:04 +08:00
|
|
|
MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
|
2009-11-18 07:12:20 +08:00
|
|
|
IdentifierInfo **IdentList,
|
|
|
|
SourceLocation *IdentLocs,
|
|
|
|
unsigned NumElts) {
|
2006-11-03 15:35:12 +08:00
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
2009-01-18 17:39:41 +08:00
|
|
|
// Allocate and add the 'TypeNameInfo' "decl".
|
|
|
|
getTable(TypeNameInfoTablePtr)->AddEntry(true, IdentList[i]);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
2009-03-29 03:18:32 +08:00
|
|
|
TUScope->AddDecl(DeclPtrTy::make(IdentList[i]));
|
2006-10-28 07:18:49 +08:00
|
|
|
}
|
2009-03-29 03:18:32 +08:00
|
|
|
return DeclPtrTy();
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|
|
|
|
|
2008-08-05 06:51:42 +08:00
|
|
|
/// ActOnPopScope - When a scope is popped, if any typedefs are now
|
|
|
|
/// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field.
|
2007-10-11 01:45:44 +08:00
|
|
|
void MinimalAction::ActOnPopScope(SourceLocation Loc, Scope *S) {
|
2009-01-18 17:39:41 +08:00
|
|
|
TypeNameInfoTable &Table = *getTable(TypeNameInfoTablePtr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-08-14 09:28:29 +08:00
|
|
|
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
|
|
|
|
I != E; ++I) {
|
2009-03-29 03:18:32 +08:00
|
|
|
IdentifierInfo &II = *(*I).getAs<IdentifierInfo>();
|
2006-10-28 07:18:49 +08:00
|
|
|
TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>();
|
2006-08-14 09:28:29 +08:00
|
|
|
assert(TI && "This decl didn't get pushed??");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-11-06 02:44:26 +08:00
|
|
|
if (TI) {
|
2006-10-28 07:18:49 +08:00
|
|
|
TypeNameInfo *Next = TI->Prev;
|
2009-01-18 17:39:41 +08:00
|
|
|
Table.DeleteEntry(TI);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
II.setFETokenInfo(Next);
|
2006-11-06 02:44:26 +08:00
|
|
|
}
|
2006-08-14 09:28:29 +08:00
|
|
|
}
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|