diff options
Diffstat (limited to 'lib/Sema')
40 files changed, 63 insertions, 7400 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 3d2c45f3f8..c8e8357afc 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -13,8 +13,8 @@ // //===----------------------------------------------------------------------===// -#include "Sema.h" -#include "AnalysisBasedWarnings.h" +#include "clang/Sema/Sema.h" +#include "clang/Sema/AnalysisBasedWarnings.h" #include "clang/Basic/SourceManager.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/ExprCXX.h" diff --git a/lib/Sema/AnalysisBasedWarnings.h b/lib/Sema/AnalysisBasedWarnings.h deleted file mode 100644 index dea19ba28c..0000000000 --- a/lib/Sema/AnalysisBasedWarnings.h +++ /dev/null @@ -1,55 +0,0 @@ -//=- AnalysisBasedWarnings.h - Sema warnings based on libAnalysis -*- C++ -*-=// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines AnalysisBasedWarnings, a worker object used by Sema -// that issues warnings based on dataflow-analysis. -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_SEMA_ANALYSIS_WARNINGS_H -#define LLVM_CLANG_SEMA_ANALYSIS_WARNINGS_H - -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/DenseMap.h" - -namespace clang { - -class Sema; - -namespace sema { - -class AnalysisBasedWarnings { -public: - class Policy { - friend class AnalysisBasedWarnings; - // The warnings to run. - unsigned enableCheckFallThrough : 1; - unsigned enableCheckUnreachable : 1; - public: - Policy(); - void disableCheckFallThrough() { enableCheckFallThrough = 0; } - }; - -private: - Sema &S; - Policy DefaultPolicy; - - enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 }; - llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD; - -public: - AnalysisBasedWarnings(Sema &s); - - Policy getDefaultPolicy() { return DefaultPolicy; } - - void IssueWarnings(Policy P, const Decl *D, QualType BlockTy = QualType()); -}; - -}} // end namespace clang::sema - -#endif diff --git a/lib/Sema/CXXFieldCollector.h b/lib/Sema/CXXFieldCollector.h deleted file mode 100644 index 63c6ee3f74..0000000000 --- a/lib/Sema/CXXFieldCollector.h +++ /dev/null @@ -1,79 +0,0 @@ -//===- CXXFieldCollector.h - Utility class for C++ class semantic analysis ===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file provides CXXFieldCollector that is used during parsing & semantic -// analysis of C++ classes. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H -#define LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H - -#include "llvm/ADT/SmallVector.h" - -namespace clang { - class FieldDecl; - -/// CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of -/// C++ classes. -class CXXFieldCollector { - /// Fields - Contains all FieldDecls collected during parsing of a C++ - /// class. When a nested class is entered, its fields are appended to the - /// fields of its parent class, when it is exited its fields are removed. - llvm::SmallVector<FieldDecl*, 32> Fields; - - /// FieldCount - Each entry represents the number of fields collected during - /// the parsing of a C++ class. When a nested class is entered, a new field - /// count is pushed, when it is exited, the field count is popped. - llvm::SmallVector<size_t, 4> FieldCount; - - // Example: - // - // class C { - // int x,y; - // class NC { - // int q; - // // At this point, Fields contains [x,y,q] decls and FieldCount contains - // // [2,1]. - // }; - // int z; - // // At this point, Fields contains [x,y,z] decls and FieldCount contains - // // [3]. - // }; - -public: - /// StartClass - Called by Sema::ActOnStartCXXClassDef. - void StartClass() { FieldCount.push_back(0); } - - /// Add - Called by Sema::ActOnCXXMemberDeclarator. - void Add(FieldDecl *D) { - Fields.push_back(D); - ++FieldCount.back(); - } - - /// getCurNumField - The number of fields added to the currently parsed class. - size_t getCurNumFields() const { - assert(!FieldCount.empty() && "no currently-parsed class"); - return FieldCount.back(); - } - - /// getCurFields - Pointer to array of fields added to the currently parsed - /// class. - FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); } - - /// FinishClass - Called by Sema::ActOnFinishCXXClassDef. - void FinishClass() { - Fields.resize(Fields.size() - getCurNumFields()); - FieldCount.pop_back(); - } -}; - -} // end namespace clang - -#endif diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index a7eca6a804..6f4e1839e3 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// #include "clang/Sema/CodeCompleteConsumer.h" +#include "clang/Sema/Sema.h" #include "clang/AST/DeclCXX.h" #include "clang/Parse/Scope.h" #include "clang/Lex/Preprocessor.h" #include "clang-c/Index.h" -#include "Sema.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index 62df1a7c2c..2e33c1e6a4 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#include "IdentifierResolver.h" +#include "clang/Sema/IdentifierResolver.h" #include "clang/Basic/LangOptions.h" using namespace clang; diff --git a/lib/Sema/IdentifierResolver.h b/lib/Sema/IdentifierResolver.h deleted file mode 100644 index 59bd834073..0000000000 --- a/lib/Sema/IdentifierResolver.h +++ /dev/null @@ -1,203 +0,0 @@ -//===- IdentifierResolver.h - Lexical Scope Name lookup ---------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the IdentifierResolver class, which is used for lexical -// scoped lookup, based on declaration names. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_AST_SEMA_IDENTIFIERRESOLVER_H -#define LLVM_CLANG_AST_SEMA_IDENTIFIERRESOLVER_H - -#include "clang/Basic/IdentifierTable.h" -#include "clang/Parse/Scope.h" -#include "clang/AST/Decl.h" -#include "clang/AST/DeclarationName.h" -#include "clang/AST/DeclCXX.h" - -namespace clang { - -/// IdentifierResolver - Keeps track of shadowed decls on enclosing -/// scopes. It manages the shadowing chains of declaration names and -/// implements efficent decl lookup based on a declaration name. -class IdentifierResolver { - - /// IdDeclInfo - Keeps track of information about decls associated - /// to a particular declaration name. IdDeclInfos are lazily - /// constructed and assigned to a declaration name the first time a - /// decl with that declaration name is shadowed in some scope. - class IdDeclInfo { - public: - typedef llvm::SmallVector<NamedDecl*, 2> DeclsTy; - - inline DeclsTy::iterator decls_begin() { return Decls.begin(); } - inline DeclsTy::iterator decls_end() { return Decls.end(); } - - void AddDecl(NamedDecl *D) { Decls.push_back(D); } - - /// RemoveDecl - Remove the decl from the scope chain. - /// The decl must already be part of the decl chain. - void RemoveDecl(NamedDecl *D); - - /// Replaces the Old declaration with the New declaration. If the - /// replacement is successful, returns true. If the old - /// declaration was not found, returns false. - bool ReplaceDecl(NamedDecl *Old, NamedDecl *New); - - private: - DeclsTy Decls; - }; - -public: - - /// iterator - Iterate over the decls of a specified declaration name. - /// It will walk or not the parent declaration contexts depending on how - /// it was instantiated. - class iterator { - public: - typedef NamedDecl * value_type; - typedef NamedDecl * reference; - typedef NamedDecl * pointer; - typedef std::input_iterator_tag iterator_category; - typedef std::ptrdiff_t difference_type; - - /// Ptr - There are 3 forms that 'Ptr' represents: - /// 1) A single NamedDecl. (Ptr & 0x1 == 0) - /// 2) A IdDeclInfo::DeclsTy::iterator that traverses only the decls of the - /// same declaration context. (Ptr & 0x3 == 0x1) - /// 3) A IdDeclInfo::DeclsTy::iterator that traverses the decls of parent - /// declaration contexts too. (Ptr & 0x3 == 0x3) - uintptr_t Ptr; - typedef IdDeclInfo::DeclsTy::iterator BaseIter; - - /// A single NamedDecl. (Ptr & 0x1 == 0) - iterator(NamedDecl *D) { - Ptr = reinterpret_cast<uintptr_t>(D); - assert((Ptr & 0x1) == 0 && "Invalid Ptr!"); - } - /// A IdDeclInfo::DeclsTy::iterator that walks or not the parent declaration - /// contexts depending on 'LookInParentCtx'. - iterator(BaseIter I) { - Ptr = reinterpret_cast<uintptr_t>(I) | 0x1; - } - - bool isIterator() const { return (Ptr & 0x1); } - - BaseIter getIterator() const { - assert(isIterator() && "Ptr not an iterator!"); - return reinterpret_cast<BaseIter>(Ptr & ~0x3); - } - - friend class IdentifierResolver; - public: - iterator() : Ptr(0) {} - - NamedDecl *operator*() const { - if (isIterator()) - return *getIterator(); - else - return reinterpret_cast<NamedDecl*>(Ptr); - } - - bool operator==(const iterator &RHS) const { - return Ptr == RHS.Ptr; - } - bool operator!=(const iterator &RHS) const { - return Ptr != RHS.Ptr; - } - - // Preincrement. - iterator& operator++() { - if (!isIterator()) // common case. - Ptr = 0; - else { - NamedDecl *D = **this; - void *InfoPtr = D->getDeclName().getFETokenInfo<void>(); - assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?"); - IdDeclInfo *Info = toIdDeclInfo(InfoPtr); - - BaseIter I = getIterator(); - if (I != Info->decls_begin()) - *this = iterator(I-1); - else // No more decls. - *this = iterator(); - } - return *this; - } - - uintptr_t getAsOpaqueValue() const { return Ptr; } - - static iterator getFromOpaqueValue(uintptr_t P) { - iterator Result; - Result.Ptr = P; - return Result; - } - }; - - /// begin - Returns an iterator for decls with the name 'Name'. - static iterator begin(DeclarationName Name); - - /// end - Returns an iterator that has 'finished'. - static iterator end() { - return iterator(); - } - - /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true - /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns - /// true if 'D' belongs to the given declaration context. - bool isDeclInScope(Decl *D, DeclContext *Ctx, ASTContext &Context, - Scope *S = 0) const; - - /// AddDecl - Link the decl to its shadowed decl chain. - void AddDecl(NamedDecl *D); - - /// RemoveDecl - Unlink the decl from its shadowed decl chain. - /// The decl must already be part of the decl chain. - void RemoveDecl(NamedDecl *D); - - /// Replace the decl Old with the new declaration New on its - /// identifier chain. Returns true if the old declaration was found - /// (and, therefore, replaced). - bool ReplaceDecl(NamedDecl *Old, NamedDecl *New); - - /// \brief Link the declaration into the chain of declarations for - /// the given identifier. - /// - /// This is a lower-level routine used by the PCH reader to link a - /// declaration into a specific IdentifierInfo before the - /// declaration actually has a name. - void AddDeclToIdentifierChain(IdentifierInfo *II, NamedDecl *D); - - explicit IdentifierResolver(const LangOptions &LangOpt); - ~IdentifierResolver(); - -private: - const LangOptions &LangOpt; - - class IdDeclInfoMap; - IdDeclInfoMap *IdDeclInfos; - - /// FETokenInfo contains a Decl pointer if lower bit == 0. - static inline bool isDeclPtr(void *Ptr) { - return (reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 0; - } - - /// FETokenInfo contains a IdDeclInfo pointer if lower bit == 1. - static inline IdDeclInfo *toIdDeclInfo(void *Ptr) { - assert((reinterpret_cast<uintptr_t>(Ptr) & 0x1) == 1 - && "Ptr not a IdDeclInfo* !"); - return reinterpret_cast<IdDeclInfo*>( - reinterpret_cast<uintptr_t>(Ptr) & ~0x1 - ); - } -}; - -} // end namespace clang - -#endif diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 866a358e13..f3dc6ceafe 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -12,11 +12,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/BitVector.h" -#include "Sema.h" +#include "clang/Sema/Sema.h" #include "clang/AST/Expr.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtCXX.h" +#include "llvm/ADT/BitVector.h" using namespace clang; namespace { diff --git a/lib/Sema/Lookup.h b/lib/Sema/Lookup.h deleted file mode 100644 index b63873402f..0000000000 --- a/lib/Sema/Lookup.h +++ /dev/null @@ -1,681 +0,0 @@ -//===--- Lookup.h - Classes for name lookup ---------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the LookupResult class, which is integral to -// Sema's name-lookup subsystem. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_SEMA_LOOKUP_H -#define LLVM_CLANG_SEMA_LOOKUP_H - -#include "Sema.h" - -namespace clang { - -/// @brief Represents the results of name lookup. -/// -/// An instance of the LookupResult class captures the results of a -/// single name lookup, which can return no result (nothing found), -/// a single declaration, a set of overloaded functions, or an -/// ambiguity. Use the getKind() method to determine which of these -/// results occurred for a given lookup. -class LookupResult { -public: - enum LookupResultKind { - /// @brief No entity found met the criteria. - NotFound = 0, - - /// @brief No entity found met the criteria within the current - /// instantiation,, but there were dependent base classes of the - /// current instantiation that could not be searched. - NotFoundInCurrentInstantiation, - - /// @brief Name lookup found a single declaration that met the - /// criteria. getFoundDecl() will return this declaration. - Found, - - /// @brief Name lookup found a set of overloaded functions that - /// met the criteria. - FoundOverloaded, - - /// @brief Name lookup found an unresolvable value declaration - /// and cannot yet complete. This only happens in C++ dependent - /// contexts with dependent using declarations. - FoundUnresolvedValue, - - /// @brief Name lookup results in an ambiguity; use - /// getAmbiguityKind to figure out what kind of ambiguity - /// we have. - Ambiguous - }; - - enum AmbiguityKind { - /// Name lookup results in an ambiguity because multiple - /// entities that meet the lookup criteria were found in - /// subobjects of different types. For example: - /// @code - /// struct A { void f(int); } - /// struct B { void f(double); } - /// struct C : A, B { }; - /// void test(C c) { - /// c.f(0); // error: A::f and B::f come from subobjects of different - /// // types. overload resolution is not performed. - /// } - /// @endcode - AmbiguousBaseSubobjectTypes, - - /// Name lookup results in an ambiguity because multiple - /// nonstatic entities that meet the lookup criteria were found - /// in different subobjects of the same type. For example: - /// @code - /// struct A { int x; }; - /// struct B : A { }; - /// struct C : A { }; - /// struct D : B, C { }; - /// int test(D d) { - /// return d.x; // error: 'x' is found in two A subobjects (of B and C) - /// } - /// @endcode - AmbiguousBaseSubobjects, - - /// Name lookup results in an ambiguity because multiple definitions - /// of entity that meet the lookup criteria were found in different - /// declaration contexts. - /// @code - /// namespace A { - /// int i; - /// namespace B { int i; } - /// int test() { - /// using namespace B; - /// return i; // error 'i' is found in namespace A and A::B - /// } - /// } - /// @endcode - AmbiguousReference, - - /// Name lookup results in an ambiguity because an entity with a - /// tag name was hidden by an entity with an ordinary name from - /// a different context. - /// @code - /// namespace A { struct Foo {}; } - /// namespace B { void Foo(); } - /// namespace C { - /// using namespace A; - /// using namespace B; - /// } - /// void test() { - /// C::Foo(); // error: tag 'A::Foo' is hidden by an object in a - /// // different namespace - /// } - /// @endcode - AmbiguousTagHiding - }; - - /// A little identifier for flagging temporary lookup results. - enum TemporaryToken { - Temporary - }; - - typedef UnresolvedSetImpl::iterator iterator; - - LookupResult(Sema &SemaRef, const DeclarationNameInfo &NameInfo, - Sema::LookupNameKind LookupKind, - Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration) - : ResultKind(NotFound), - Paths(0), - NamingClass(0), - SemaRef(SemaRef), - NameInfo(NameInfo), - LookupKind(LookupKind), - IDNS(0), - Redecl(Redecl != Sema::NotForRedeclaration), - HideTags(true), - Diagnose(Redecl == Sema::NotForRedeclaration) - { - configure(); - } - - // TODO: consider whether this constructor should be restricted to take - // as input a const IndentifierInfo* (instead of Name), - // forcing other cases towards the constructor taking a DNInfo. - LookupResult(Sema &SemaRef, DeclarationName Name, - SourceLocation NameLoc, Sema::LookupNameKind LookupKind, - Sema::RedeclarationKind Redecl = Sema::NotForRedeclaration) - : ResultKind(NotFound), - Paths(0), - NamingClass(0), - SemaRef(SemaRef), - NameInfo(Name, NameLoc), - LookupKind(LookupKind), - IDNS(0), - Redecl(Redecl != Sema::NotForRedeclaration), - HideTags(true), - Diagnose(Redecl == Sema::NotForRedeclaration) - { - configure(); - } - - /// Creates a temporary lookup result, initializing its core data - /// using the information from another result. Diagnostics are always - /// disabled. - LookupResult(TemporaryToken _, const LookupResult &Other) - : ResultKind(NotFound), - Paths(0), - NamingClass(0), - SemaRef(Other.SemaRef), - NameInfo(Other.NameInfo), - LookupKind(Other.LookupKind), - IDNS(Other.IDNS), - Redecl(Other.Redecl), - HideTags(Other.HideTags), - Diagnose(false) - {} - - ~LookupResult() { - if (Diagnose) diagnose(); - if (Paths) deletePaths(Paths); - } - - /// Gets the name info to look up. - const DeclarationNameInfo &getLookupNameInfo() const { - return NameInfo; - } - - /// \brief Sets the name info to look up. - void setLookupNameInfo(const DeclarationNameInfo &NameInfo) { - this->NameInfo = NameInfo; - } - - /// Gets the name to look up. - DeclarationName getLookupName() const { - return NameInfo.getName(); - } - - /// \brief Sets the name to look up. - void setLookupName(DeclarationName Name) { - NameInfo.setName(Name); - } - - /// Gets the kind of lookup to perform. - Sema::LookupNameKind getLookupKind() const { - return LookupKind; - } - - /// True if this lookup is just looking for an existing declaration. - bool isForRedeclaration() const { - return Redecl; - } - - /// Sets whether tag declarations should be hidden by non-tag - /// declarations during resolution. The default is true. - void setHideTags(bool Hide) { - HideTags = Hide; - } - - bool isAmbiguous() const { - return getResultKind() == Ambiguous; - } - - /// Determines if this names a single result which is not an - /// unresolved value using decl. If so, it is safe to call - /// getFoundDecl(). - bool isSingleResult() const { - return getResultKind() == Found; - } - - /// Determines if the results are overloaded. - bool isOverloadedResult() const { - return getResultKind() == FoundOverloaded; - } - - bool isUnresolvableResult() const { - return getResultKind() == FoundUnresolvedValue; - } - - LookupResultKind getResultKind() const { - sanity(); - return ResultKind; - } - - AmbiguityKind getAmbiguityKind() const { - assert(isAmbiguous()); - return Ambiguity; - } - - const UnresolvedSetImpl &asUnresolvedSet() const { - return Decls; - } - - iterator begin() const { return iterator(Decls.begin()); } - iterator end() const { return iterator(Decls.end()); } - - /// \brief Return true if no decls were found - bool empty() const { return Decls.empty(); } - - /// \brief Return the base paths structure that's associated with - /// these results, or null if none is. - CXXBasePaths *getBasePaths() const { - return Paths; - } - - /// \brief Tests whether the given declaration is acceptable. - bool isAcceptableDecl(NamedDecl *D) const { - return D->isInIdentifierNamespace(IDNS); - } - - /// \brief Returns the identifier namespace mask for this lookup. - unsigned getIdentifierNamespace() const { - return IDNS; - } - - /// \brief Returns whether these results arose from performing a - /// lookup into a class. - bool isClassLookup() const { - return NamingClass != 0; - } - - /// \brief Returns the 'naming class' for this lookup, i.e. the - /// class which was looked into to find these results. - /// - /// C++0x [class.access.base]p5: - /// The access to a member is affected by the class in which the - /// member is named. This naming class is the class in which the - /// member name was looked up and found. [Note: this class can be - /// explicit, e.g., when a qualified-id is used, or implicit, - /// e.g., when a class member access operator (5.2.5) is used - /// (including cases where an implicit "this->" is added). If both - /// a class member access operator and a qualified-id are used to - /// name the member (as in p->T::m), the class naming the member - /// is the class named by the nested-name-specifier of the - /// qualified-id (that is, T). -- end note ] - /// - /// This is set by the lookup routines when they find results in a class. - CXXRecordDecl *getNamingClass() const { - return NamingClass; - } - - /// \brief Sets the 'naming class' for this lookup. - void setNamingClass(CXXRecordDecl *Record) { - NamingClass = Record; - } - - /// \brief Returns the base object type associated with this lookup; - /// important for [class.protected]. Most lookups do not have an - /// associated base object. - QualType getBaseObjectType() const { - return BaseObjectType; - } - - /// \brief Sets the base object type for this lookup. - void setBaseObjectType(QualType T) { - BaseObjectType = T; - } - - /// \brief Add a declaration to these results with its natural access. - /// Does not test the acceptance criteria. - void addDecl(NamedDecl *D) { - addDecl(D, D->getAccess()); - } - - /// \brief Add a declaration to these results with the given access. - /// Does not test the acceptance criteria. - void addDecl(NamedDecl *D, AccessSpecifier AS) { - Decls.addDecl(D, AS); - ResultKind = Found; - } - - /// \brief Add all the declarations from another set of lookup - /// results. - void addAllDecls(const LookupResult &Other) { - Decls.append(Other.Decls.begin(), Other.Decls.end()); - ResultKind = Found; - } - |