summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Zelenko <eugene.zelenko@gmail.com>2018-02-20 02:16:28 +0000
committerEugene Zelenko <eugene.zelenko@gmail.com>2018-02-20 02:16:28 +0000
commitc05a0c0240fcfc2d7d463326482a715ebbba6c1c (patch)
tree02b13426f5980a473a9d1b9c428df7241aa7ee87
parent473c57f91b94aa44b9c2b3739d9ee32156944e86 (diff)
[Sema] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325544 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Sema/AttributeList.h208
-rw-r--r--include/clang/Sema/CodeCompleteConsumer.h244
-rw-r--r--include/clang/Sema/Ownership.h93
-rw-r--r--lib/Sema/AttributeList.cpp19
-rw-r--r--lib/Sema/CodeCompleteConsumer.cpp63
5 files changed, 370 insertions, 257 deletions
diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h
index 4e806116c4..6b5bb1f901 100644
--- a/include/clang/Sema/AttributeList.h
+++ b/include/clang/Sema/AttributeList.h
@@ -1,4 +1,4 @@
-//===--- AttributeList.h - Parsed attribute sets ----------------*- C++ -*-===//
+//===- AttributeList.h - Parsed attribute sets ------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -24,11 +24,17 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Allocator.h"
#include <cassert>
+#include <cstddef>
+#include <cstring>
+#include <utility>
namespace clang {
- class ASTContext;
- class IdentifierInfo;
- class Expr;
+
+class ASTContext;
+class Decl;
+class Expr;
+class IdentifierInfo;
+class LangOptions;
/// \brief Represents information about a change in availability for
/// an entity, which is part of the encoding of the 'availability'
@@ -48,6 +54,7 @@ struct AvailabilityChange {
};
namespace {
+
enum AvailabilitySlot {
IntroducedSlot, DeprecatedSlot, ObsoletedSlot, NumAvailabilitySlots
};
@@ -57,6 +64,7 @@ struct AvailabilityData {
AvailabilityChange Changes[NumAvailabilitySlots];
SourceLocation StrictLoc;
const Expr *Replacement;
+
AvailabilityData(const AvailabilityChange &Introduced,
const AvailabilityChange &Deprecated,
const AvailabilityChange &Obsoleted,
@@ -67,7 +75,8 @@ struct AvailabilityData {
Changes[ObsoletedSlot] = Obsoleted;
}
};
-}
+
+} // namespace
/// \brief Wraps an identifier and optional source location for the identifier.
struct IdentifierLoc {
@@ -80,8 +89,8 @@ struct IdentifierLoc {
/// \brief A union of the various pointer types that can be passed to an
/// AttributeList as an argument.
-typedef llvm::PointerUnion<Expr*, IdentifierLoc*> ArgsUnion;
-typedef llvm::SmallVector<ArgsUnion, 12U> ArgsVector;
+using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
+using ArgsVector = llvm::SmallVector<ArgsUnion, 12U>;
/// AttributeList - Represents a syntactic attribute.
///
@@ -98,18 +107,25 @@ public:
enum Syntax {
/// __attribute__((...))
AS_GNU,
+
/// [[...]]
AS_CXX11,
+
/// [[...]]
AS_C2x,
+
/// __declspec(...)
AS_Declspec,
+
/// [uuid("...")] class Foo
AS_Microsoft,
+
/// __ptr16, alignas(...), etc.
AS_Keyword,
+
/// #pragma ...
AS_Pragma,
+
// Note TableGen depends on the order above. Do not add or change the order
// without adding related code to TableGen/ClangAttrEmitter.cpp.
/// Context-sensitive version of a keyword attribute.
@@ -166,10 +182,10 @@ private:
const Expr *MessageExpr;
/// The next attribute in the current position.
- AttributeList *NextInPosition;
+ AttributeList *NextInPosition = nullptr;
/// The next attribute allocated in the current Pool.
- AttributeList *NextInPool;
+ AttributeList *NextInPool = nullptr;
/// Arguments, if any, are stored immediately following the object.
ArgsUnion *getArgsBuffer() { return reinterpret_cast<ArgsUnion *>(this + 1); }
@@ -194,63 +210,25 @@ public:
};
struct PropertyData {
IdentifierInfo *GetterId, *SetterId;
+
PropertyData(IdentifierInfo *getterId, IdentifierInfo *setterId)
- : GetterId(getterId), SetterId(setterId) {}
+ : GetterId(getterId), SetterId(setterId) {}
};
private:
- /// Type tag information is stored immediately following the arguments, if
- /// any, at the end of the object. They are mutually exlusive with
- /// availability slots.
- TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
- return *reinterpret_cast<TypeTagForDatatypeData*>(getArgsBuffer()+NumArgs);
- }
-
- const TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() const {
- return *reinterpret_cast<const TypeTagForDatatypeData*>(getArgsBuffer()
- + NumArgs);
- }
-
- /// The type buffer immediately follows the object and are mutually exclusive
- /// with arguments.
- ParsedType &getTypeBuffer() {
- return *reinterpret_cast<ParsedType *>(this + 1);
- }
-
- const ParsedType &getTypeBuffer() const {
- return *reinterpret_cast<const ParsedType *>(this + 1);
- }
-
- /// The property data immediately follows the object is is mutually exclusive
- /// with arguments.
- PropertyData &getPropertyDataBuffer() {
- assert(IsProperty);
- return *reinterpret_cast<PropertyData*>(this + 1);
- }
-
- const PropertyData &getPropertyDataBuffer() const {
- assert(IsProperty);
- return *reinterpret_cast<const PropertyData*>(this + 1);
- }
-
- AttributeList(const AttributeList &) = delete;
- void operator=(const AttributeList &) = delete;
- void operator delete(void *) = delete;
- ~AttributeList() = delete;
-
- size_t allocated_size() const;
+ friend class AttributeFactory;
+ friend class AttributePool;
/// Constructor for attributes with expression arguments.
AttributeList(IdentifierInfo *attrName, SourceRange attrRange,
IdentifierInfo *scopeName, SourceLocation scopeLoc,
ArgsUnion *args, unsigned numArgs,
Syntax syntaxUsed, SourceLocation ellipsisLoc)
- : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
- ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs),
- SyntaxUsed(syntaxUsed), Invalid(false), UsedAsTypeAttr(false),
- IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false),
- HasParsedType(false), HasProcessingCache(false),
- NextInPosition(nullptr), NextInPool(nullptr) {
+ : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
+ ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs),
+ SyntaxUsed(syntaxUsed), Invalid(false), UsedAsTypeAttr(false),
+ IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false),
+ HasParsedType(false), HasProcessingCache(false) {
if (numArgs) memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion));
AttrKind = getKind(getName(), getScopeName(), syntaxUsed);
}
@@ -265,12 +243,12 @@ private:
const Expr *messageExpr,
Syntax syntaxUsed, SourceLocation strict,
const Expr *replacementExpr)
- : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
- ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
- Invalid(false), UsedAsTypeAttr(false), IsAvailability(true),
- IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
- HasProcessingCache(false), UnavailableLoc(unavailable),
- MessageExpr(messageExpr), NextInPosition(nullptr), NextInPool(nullptr) {
+ : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
+ ScopeLoc(scopeLoc), NumArgs(1), SyntaxUsed(syntaxUsed), Invalid(false),
+ UsedAsTypeAttr(false), IsAvailability(true),
+ IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
+ HasProcessingCache(false), UnavailableLoc(unavailable),
+ MessageExpr(messageExpr) {
ArgsUnion PVal(Parm);
memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
new (getAvailabilityData()) AvailabilityData(
@@ -285,11 +263,11 @@ private:
IdentifierLoc *Parm2,
IdentifierLoc *Parm3,
Syntax syntaxUsed)
- : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
- ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(3), SyntaxUsed(syntaxUsed),
- Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
- IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
- HasProcessingCache(false), NextInPosition(nullptr), NextInPool(nullptr) {
+ : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
+ ScopeLoc(scopeLoc), NumArgs(3), SyntaxUsed(syntaxUsed), Invalid(false),
+ UsedAsTypeAttr(false), IsAvailability(false),
+ IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false),
+ HasProcessingCache(false) {
ArgsUnion *Args = getArgsBuffer();
Args[0] = Parm1;
Args[1] = Parm2;
@@ -302,11 +280,11 @@ private:
IdentifierInfo *scopeName, SourceLocation scopeLoc,
IdentifierLoc *ArgKind, ParsedType matchingCType,
bool layoutCompatible, bool mustBeNull, Syntax syntaxUsed)
- : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
- ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(1), SyntaxUsed(syntaxUsed),
- Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
- IsTypeTagForDatatype(true), IsProperty(false), HasParsedType(false),
- HasProcessingCache(false), NextInPosition(nullptr), NextInPool(nullptr) {
+ : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
+ ScopeLoc(scopeLoc), NumArgs(1), SyntaxUsed(syntaxUsed), Invalid(false),
+ UsedAsTypeAttr(false), IsAvailability(false),
+ IsTypeTagForDatatype(true), IsProperty(false), HasParsedType(false),
+ HasProcessingCache(false) {
ArgsUnion PVal(ArgKind);
memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion));
TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot();
@@ -321,10 +299,10 @@ private:
IdentifierInfo *scopeName, SourceLocation scopeLoc,
ParsedType typeArg, Syntax syntaxUsed)
: AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
- ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
- Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
+ ScopeLoc(scopeLoc), NumArgs(0), SyntaxUsed(syntaxUsed), Invalid(false),
+ UsedAsTypeAttr(false), IsAvailability(false),
IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(true),
- HasProcessingCache(false), NextInPosition(nullptr), NextInPool(nullptr){
+ HasProcessingCache(false) {
new (&getTypeBuffer()) ParsedType(typeArg);
AttrKind = getKind(getName(), getScopeName(), syntaxUsed);
}
@@ -334,19 +312,55 @@ private:
IdentifierInfo *scopeName, SourceLocation scopeLoc,
IdentifierInfo *getterId, IdentifierInfo *setterId,
Syntax syntaxUsed)
- : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
- ScopeLoc(scopeLoc), EllipsisLoc(), NumArgs(0), SyntaxUsed(syntaxUsed),
- Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
- IsTypeTagForDatatype(false), IsProperty(true), HasParsedType(false),
- HasProcessingCache(false), NextInPosition(nullptr), NextInPool(nullptr) {
+ : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange),
+ ScopeLoc(scopeLoc), NumArgs(0), SyntaxUsed(syntaxUsed),
+ Invalid(false), UsedAsTypeAttr(false), IsAvailability(false),
+ IsTypeTagForDatatype(false), IsProperty(true), HasParsedType(false),
+ HasProcessingCache(false) {
new (&getPropertyDataBuffer()) PropertyData(getterId, setterId);
AttrKind = getKind(getName(), getScopeName(), syntaxUsed);
}
- friend class AttributePool;
- friend class AttributeFactory;
+ /// Type tag information is stored immediately following the arguments, if
+ /// any, at the end of the object. They are mutually exlusive with
+ /// availability slots.
+ TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() {
+ return *reinterpret_cast<TypeTagForDatatypeData*>(getArgsBuffer()+NumArgs);
+ }
+ const TypeTagForDatatypeData &getTypeTagForDatatypeDataSlot() const {
+ return *reinterpret_cast<const TypeTagForDatatypeData*>(getArgsBuffer()
+ + NumArgs);
+ }
+
+ /// The type buffer immediately follows the object and are mutually exclusive
+ /// with arguments.
+ ParsedType &getTypeBuffer() {
+ return *reinterpret_cast<ParsedType *>(this + 1);
+ }
+ const ParsedType &getTypeBuffer() const {
+ return *reinterpret_cast<const ParsedType *>(this + 1);
+ }
+
+ /// The property data immediately follows the object is is mutually exclusive
+ /// with arguments.
+ PropertyData &getPropertyDataBuffer() {
+ assert(IsProperty);
+ return *reinterpret_cast<PropertyData*>(this + 1);
+ }
+ const PropertyData &getPropertyDataBuffer() const {
+ assert(IsProperty);
+ return *reinterpret_cast<const PropertyData*>(this + 1);
+ }
+
+ size_t allocated_size() const;
public:
+ AttributeList(const AttributeList &) = delete;
+ AttributeList &operator=(const AttributeList &) = delete;
+ ~AttributeList() = delete;
+
+ void operator delete(void *) = delete;
+
enum Kind {
#define PARSED_ATTR(NAME) AT_##NAME,
#include "clang/Sema/AttrParsedAttrList.inc"
@@ -377,12 +391,15 @@ public:
bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; }
bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; }
+
bool isCXX11Attribute() const {
return SyntaxUsed == AS_CXX11 || isAlignasAttribute();
}
+
bool isC2xAttribute() const {
return SyntaxUsed == AS_C2x;
}
+
bool isKeywordAttribute() const {
return SyntaxUsed == AS_Keyword || SyntaxUsed == AS_ContextSensitiveKeyword;
}
@@ -395,10 +412,12 @@ public:
void setInvalid(bool b = true) const { Invalid = b; }
bool hasProcessingCache() const { return HasProcessingCache; }
+
unsigned getProcessingCache() const {
assert(hasProcessingCache());
return ProcessingCache;
}
+
void setProcessingCache(unsigned value) const {
ProcessingCache = value;
HasProcessingCache = true;
@@ -429,6 +448,7 @@ public:
bool isArgExpr(unsigned Arg) const {
return Arg < NumArgs && getArg(Arg).is<Expr*>();
}
+
Expr *getArgAsExpr(unsigned Arg) const {
return getArg(Arg).get<Expr*>();
}
@@ -436,6 +456,7 @@ public:
bool isArgIdent(unsigned Arg) const {
return Arg < NumArgs && getArg(Arg).is<IdentifierLoc*>();
}
+
IdentifierLoc *getArgAsIdent(unsigned Arg) const {
return getArg(Arg).get<IdentifierLoc*>();
}
@@ -596,7 +617,7 @@ public:
class AttributePool {
AttributeFactory &Factory;
- AttributeList *Head;
+ AttributeList *Head = nullptr;
void *allocate(size_t size) {
return Factory.allocate(size);
@@ -613,10 +634,14 @@ class AttributePool {
public:
/// Create a new pool for a factory.
- AttributePool(AttributeFactory &factory) : Factory(factory), Head(nullptr) {}
+ AttributePool(AttributeFactory &factory) : Factory(factory) {}
AttributePool(const AttributePool &) = delete;
+ ~AttributePool() {
+ if (Head) Factory.reclaimPool(Head);
+ }
+
/// Move the given pool's allocations to this pool.
AttributePool(AttributePool &&pool) : Factory(pool.Factory), Head(pool.Head) {
pool.Head = nullptr;
@@ -639,10 +664,6 @@ public:
}
}
- ~AttributePool() {
- if (Head) Factory.reclaimPool(Head);
- }
-
AttributeList *create(IdentifierInfo *attrName, SourceRange attrRange,
IdentifierInfo *scopeName, SourceLocation scopeLoc,
ArgsUnion *args, unsigned numArgs,
@@ -733,10 +754,7 @@ public:
/// is that this will become significantly more serious.
class ParsedAttributes {
public:
- ParsedAttributes(AttributeFactory &factory)
- : pool(factory), list(nullptr) {
- }
-
+ ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
ParsedAttributes(const ParsedAttributes &) = delete;
AttributePool &getPool() const { return pool; }
@@ -882,7 +900,7 @@ public:
private:
mutable AttributePool pool;
- AttributeList *list;
+ AttributeList *list = nullptr;
};
/// These constants match the enumerated choices of
@@ -913,6 +931,6 @@ enum AttributeDeclKind {
ExpectedForMaybeUnused,
};
-} // end namespace clang
+} // namespace clang
-#endif
+#endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h
index a966e73668..48e812966f 100644
--- a/include/clang/Sema/CodeCompleteConsumer.h
+++ b/include/clang/Sema/CodeCompleteConsumer.h
@@ -1,4 +1,4 @@
-//===---- CodeCompleteConsumer.h - Code Completion Interface ----*- C++ -*-===//
+//===- CodeCompleteConsumer.h - Code Completion Interface -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,25 +10,42 @@
// This file defines the CodeCompleteConsumer class.
//
//===----------------------------------------------------------------------===//
+
#ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
#define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
#include "clang-c/Index.h"
-#include "clang/AST/CanonicalType.h"
-#include "clang/AST/DeclBase.h"
#include "clang/AST/Type.h"
+#include "clang/Basic/LLVM.h"
#include "clang/Sema/CodeCompleteOptions.h"
#include "clang/Sema/DeclSpec.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/type_traits.h"
+#include <cassert>
+#include <memory>
#include <string>
#include <utility>
namespace clang {
+class ASTContext;
class Decl;
+class DeclContext;
+class FunctionDecl;
+class FunctionTemplateDecl;
+class IdentifierInfo;
+class LangOptions;
+class NamedDecl;
+class NestedNameSpecifier;
+class Preprocessor;
+class Sema;
/// \brief Default priority values for code-completion results based
/// on their kind.
@@ -36,31 +53,43 @@ enum {
/// \brief Priority for the next initialization in a constructor initializer
/// list.
CCP_NextInitializer = 7,
+
/// \brief Priority for an enumeration constant inside a switch whose
/// condition is of the enumeration type.
CCP_EnumInCase = 7,
+
/// \brief Priority for a send-to-super completion.
CCP_SuperCompletion = 20,
+
/// \brief Priority for a declaration that is in the local scope.
CCP_LocalDeclaration = 34,
+
/// \brief Priority for a member declaration found from the current
/// method or member function.
CCP_MemberDeclaration = 35,
+
/// \brief Priority for a language keyword (that isn't any of the other
/// categories).
CCP_Keyword = 40,
+
/// \brief Priority for a code pattern.
CCP_CodePattern = 40,
+
/// \brief Priority for a non-type declaration.
CCP_Declaration = 50,
+
/// \brief Priority for a type.
CCP_Type = CCP_Declaration,
+
/// \brief Priority for a constant value (e.g., enumerator).
CCP_Constant = 65,
+
/// \brief Priority for a preprocessor macro.
CCP_Macro = 70,
+
/// \brief Priority for a nested-name-specifier.
CCP_NestedNameSpecifier = 75,
+
/// \brief Priority for a result that isn't likely to be what the user wants,
/// but is included for completeness.
CCP_Unlikely = 80,
@@ -74,9 +103,11 @@ enum {
enum {
/// \brief The result is in a base class.
CCD_InBaseClass = 2,
+
/// \brief The result is a C++ non-static member function whose qualifiers
/// exactly match the object type on which the member function can be called.
CCD_ObjectQualifierMatch = -1,
+
/// \brief The selector of the given message exactly matches the selector
/// of the current method, which might imply that some kind of delegation
/// is occurring.
@@ -104,6 +135,7 @@ enum {
/// \brief Divide by this factor when a code-completion result's type exactly
/// matches the type we expect.
CCF_ExactTypeMatch = 4,
+
/// \brief Divide by this factor when a code-completion result's type is
/// similar to the type we expect (e.g., both arithmetic types, both
/// Objective-C object pointer types).
@@ -148,14 +180,6 @@ unsigned getMacroUsagePriority(StringRef MacroName,
/// declaration.
CXCursorKind getCursorKindForDecl(const Decl *D);
-class FunctionDecl;
-class FunctionType;
-class FunctionTemplateDecl;
-class IdentifierInfo;
-class NamedDecl;
-class NestedNameSpecifier;
-class Sema;
-
/// \brief The context in which code completion occurred, so that the
/// code-completion consumer can process the results accordingly.
class CodeCompletionContext {
@@ -163,31 +187,41 @@ public:
enum Kind {
/// \brief An unspecified code-completion context.
CCC_Other,
+
/// \brief An unspecified code-completion context where we should also add
/// macro completions.
CCC_OtherWithMacros,
+
/// \brief Code completion occurred within a "top-level" completion context,
/// e.g., at namespace or global scope.
CCC_TopLevel,
+
/// \brief Code completion occurred within an Objective-C interface,
/// protocol, or category interface.
CCC_ObjCInterface,
+
/// \brief Code completion occurred within an Objective-C implementation
/// or category implementation.
CCC_ObjCImplementation,
+
/// \brief Code completion occurred within the instance variable list of
/// an Objective-C interface, implementation, or category implementation.
CCC_ObjCIvarList,
+
/// \brief Code completion occurred within a class, struct, or union.
CCC_ClassStructUnion,
+
/// \brief Code completion occurred where a statement (or declaration) is
/// expected in a function, method, or block.
CCC_Statement,
+
/// \brief Code completion occurred where an expression is expected.
CCC_Expression,
+
/// \brief Code completion occurred where an Objective-C message receiver
/// is expected.
CCC_ObjCMessageReceiver,
+
/// \brief Code completion occurred on the right-hand side of a member
/// access expression using the dot operator.
///
@@ -195,6 +229,7 @@ public:
/// accessed. The type itself is available via
/// \c CodeCompletionContext::getType().
CCC_DotMemberAccess,
+
/// \brief Code completion occurred on the right-hand side of a member
/// access expression using the arrow operator.
///
@@ -202,6 +237,7 @@ public:
/// accessed. The type itself is available via
/// \c CodeCompletionContext::getType().
CCC_ArrowMemberAccess,
+
/// \brief Code completion occurred on the right-hand side of an Objective-C
/// property access expression.
///
@@ -209,66 +245,87 @@ public:
/// accessed. The type itself is available via
/// \c CodeCompletionContext::getType().
CCC_ObjCPropertyAccess,
+
/// \brief Code completion occurred after the "enum" keyword, to indicate
/// an enumeration name.
CCC_EnumTag,
+
/// \brief Code completion occurred after the "union" keyword, to indicate
/// a union name.
CCC_UnionTag,
+
/// \brief Code completion occurred after the "struct" or "class" keyword,
/// to indicate a struct or class name.
CCC_ClassOrStructTag,
+
/// \brief Code completion occurred where a protocol name is expected.
CCC_ObjCProtocolName,
+
/// \brief Code completion occurred where a namespace or namespace alias
/// is expected.
CCC_Namespace,
+
/// \brief Code completion occurred where a type name is expected.
CCC_Type,
+
/// \brief Code completion occurred where a new name is expected.
CCC_Name,
+
/// \brief Code completion occurred where a new name is expected and a
/// qualified name is permissible.
CCC_PotentiallyQualifiedName,
+
/// \brief Code completion occurred where an macro is being defined.
CCC_MacroName,
+
/// \brief Code completion occurred where a macro name is expected
/// (without any arguments, in the case of a function-like macro).
CCC_MacroNameUse,
+
/// \brief Code completion occurred within a preprocessor expression.
CCC_PreprocessorExpression,
+
/// \brief Code completion occurred where a preprocessor directive is
/// expected.
CCC_PreprocessorDirective,
+
/// \brief Code completion occurred in a context where natural language is
/// expected, e.g., a comment or string literal.
///
/// This context usually implies that no completions should be added,
/// unless they come from an appropriate natural-language dictionary.
CCC_NaturalLanguage,
+
/// \brief Code completion for a selector, as in an \@selector expression.
CCC_SelectorName,
+
/// \brief Code completion within a type-qualifier list.
CCC_TypeQualifiers,
+
/// \brief Code completion in a parenthesized expression, which means that
/// we may also have types here in C and Objective-C (as well as in C++).
CCC_ParenthesizedExpression,
+
/// \brief Code completion where an Objective-C instance message is
/// expected.
CCC_ObjCInstanceMessage,
+
/// \brief Code completion where an Objective-C class message is expected.
CCC_ObjCClassMessage,
+
/// \brief Code completion where the name of an Objective-C class is
/// expected.
CCC_ObjCInterfaceName,
+
/// \brief Code completion where an Objective-C category name is expected.
CCC_ObjCCategoryName,
+
/// \brief An unknown context, in which we are recovering from a parsing
/// error and don't know which completions we should give.
CCC_Recovery
};
- using VisitedContextSet = llvm::SmallPtrSet<DeclContext*, 8>;
+ using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>;
private:
Kind CCKind;
@@ -293,7 +350,7 @@ private:
public:
/// \brief Construct a new code-completion context of the given kind.
- CodeCompletionContext(Kind CCKind) : CCKind(CCKind), SelIdents(None) { }
+ CodeCompletionContext(Kind CCKind) : CCKind(CCKind), SelIdents(None) {}
/// \brief Construct a new code-completion context of the given kind.
CodeCompletionContext(Kind CCKind, QualType T,
@@ -334,7 +391,7 @@ public:
}
/// \brief Adds a visited context.
- void addVisitedContext(DeclContext* Ctx) {
+ void addVisitedContext(DeclContext *Ctx) {
VisitedContexts.insert(Ctx);
}
@@ -369,52 +426,71 @@ public:
/// match the code-completion string, typically a keyword or the name of a
/// declarator or macro.
CK_TypedText,
+
/// \brief A piece of text that should be placed in the buffer, e.g.,
/// parentheses or a comma in a function call.
CK_Text,
+
/// \brief A code completion string that is entirely optional. For example,
/// an optional code completion string that describes the default arguments
/// in a function call.
CK_Optional,
+
/// \brief A string that acts as a placeholder for, e.g., a function
/// call argument.
CK_Placeholder,
+
/// \brief A piece of text that describes something about the result but
/// should not be inserted into the buffer.
CK_Informative,
/// \brief A piece of text that describes the type of an entity or, for
/// functions and methods, the return type.
CK_ResultType,
+
/// \brief A piece of text that describes the parameter that corresponds
/// to the code-completion location within a function call, message send,
/// macro invocation, etc.
CK_CurrentParameter,
+
/// \brief A left parenthesis ('(').
CK_LeftParen,
+
/// \brief A right parenthesis (')').
CK_RightParen,
+
/// \brief A left bracket ('[').
CK_LeftBracket,
+
/// \brief A right bracket (']').
CK_RightBracket,
+
/// \brief A left brace ('{').
CK_LeftBrace,
+
/// \brief A right brace ('}').
CK_RightBrace,
+
/// \brief A left angle bracket ('<').
CK_LeftAngle,
+
/// \brief A right angle bracket ('>').
CK_RightAngle,
+
/// \brief A comma separator (',').
CK_Comma,
+
/// \brief A colon (':').
CK_Colon,
+
/// \brief A semicolon (';').
CK_SemiColon,
+
/// \brief An '=' sign.
CK_Equal,
+
/// \brief Horizontal whitespace (' ').
CK_HorizontalSpace,
+
/// \brief Vertical whitespace ('\\n' or '\\r\\n', depending on the
/// platform).
CK_VerticalSpace
@@ -424,7 +500,7 @@ public:
struct Chunk {
/// \brief The kind of data stored in this piece of the code completion
/// string.
- ChunkKind Kind;
+ ChunkKind Kind = CK_Text;
union {
/// \brief The text string associated with a CK_Text, CK_Placeholder,
@@ -439,7 +515,7 @@ public:
CodeCompletionString *Optional;
};
- Chunk() : Kind(CK_Text), Text(nullptr) { }
+ Chunk() : Text(nullptr) {}
explicit Chunk(ChunkKind Kind, const char *Text = "");
@@ -463,6 +539,9 @@ public:
};
private:
+ friend class CodeCompletionBuilder;
+ friend class CodeCompletionResult;
+
/// \brief The number of chunks stored in this string.
unsigned NumChunks : 16;
@@ -482,9 +561,6 @@ private:
/// entity being completed by this result.
const char *BriefComment;
- CodeCompletionString(const CodeCompletionString &) = delete;
- void operator=(const CodeCompletionString &) = delete;
-
CodeCompletionString(const Chunk *Chunks, unsigned NumChunks,
unsigned Priority, CXAvailabilityKind Availability,
const char **Annotations, unsigned NumAnnotations,
@@ -492,11 +568,12 @@ private:
const char *BriefComment);
~CodeCompletionString() = default;
- friend class CodeCompletionBuilder;
- friend class CodeCompletionResult;
-
public:
- typedef const Chunk *iterator;
+ CodeCompletionString(const CodeCompletionString &) = delete;
+ CodeCompletionString &operator=(const CodeCompletionString &) = delete;
+
+ using iterator = const Chunk *;
+
iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); }
iterator end() const { return begin() + NumChunks; }
bool empty() const { return NumChunks == 0; }
@@ -558,6 +635,7 @@ public:
std::shared_ptr<GlobalCodeCompletionAllocator> getAllocatorRef() const {
return AllocatorRef;
}
+
CodeCompletionAllocator &getAllocator() const {
assert(AllocatorRef);
return *AllocatorRef;
@@ -566,28 +644,30 @@ public:
StringRef getParentName(const DeclContext *DC);
};
-} // end namespace clang
+} // namespace clang
namespace llvm {
- template <> struct isPodLike<clang::CodeCompletionString::Chunk> {
- static const bool value = true;
- };
-}
+
+template <> struct isPodLike<clang::CodeCompletionString::Chunk> {
+ static const bool value = true;
+};
+
+} // namespace llvm
namespace clang {
/// \brief A builder class used to construct new code-completion strings.
class CodeCompletionBuilder {
public:
- typedef CodeCompletionString::Chunk Chunk;
+ using Chunk = CodeCompletionString::Chunk;
private:
CodeCompletionAllocator &Allocator;
CodeCompletionTUInfo &CCTUInfo;
- unsigned Priority;
- CXAvailabilityKind Availability;
+ unsigned Priority = 0;
+ CXAvailabilityKind Availability = CXAvailability_Available;
StringRef ParentName;
- const char *BriefComment;
+ const char *BriefComment = nullptr;
/// \brief The chunks stored in this string.
SmallVector<Chunk, 4> Chunks;
@@ -597,16 +677,13 @@ private:
public:
CodeCompletionBuilder(CodeCompletionAllocator &Allocator,
CodeCompletionTUInfo &CCTUInfo)
- : Allocator(Allocator), CCTUInfo(CCTUInfo),
- Priority(0), Availability(CXAvailability_Available),
- BriefComment(nullptr) { }
+ : Allocator(Allocator), CCTUInfo(CCTUInfo) {}
CodeCompletionBuilder(CodeCompletionAllocator &Allocator,
CodeCompletionTUInfo &CCTUInfo,
unsigned Priority, CXAvailabilityKind Availability)
- : Allocator(Allocator), CCTUInfo(CCTUInfo),
- Priority(Priority), Availability(Availability),
- BriefComment(nullptr) { }
+ : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),
+ Availability(Availability) {}
/// \brief Retrieve the allocator into which the code completion
/// strings should be allocated.
@@ -659,15 +736,22 @@ class CodeCompletionResult {
public:
/// \brief Describes the kind of result generated.
enum ResultKind {
- RK_Declaration = 0, ///< Refers to a declaration
- RK_Keyword, ///< Refers to a keyword or symbol.
- RK_Macro, ///< Refers to a macro
- RK_Pattern ///< Refers to a precomputed pattern.
+ /// Refers to a declaration.
+ RK_Declaration = 0,
+
+ /// Refers to a keyword or symbol.
+ RK_Keyword,
+
+ /// Refers to a macro.
+ RK_Macro,
+
+ /// Refers to a precomputed pattern.
+ RK_Pattern
};
/// \brief When Kind == RK_Declaration or RK_Pattern, the declaration we are
/// referring to. In the latter case, the declaration might be NULL.
- const NamedDecl *Declaration;
+ const NamedDecl *Declaration = nullptr;
union {
/// \brief When Kind == RK_Keyword, the string representing the keyword
@@ -687,7 +771,7 @@ public:
/// \brief Specifies which parameter (of a function, Objective-C method,
/// macro, etc.) we should start with when formatting the result.
- unsigned StartParameter;
+ unsigned StartParameter = 0;
/// \brief The kind of result stored here.
ResultKind Kind;
@@ -696,7 +780,7 @@ public:
CXCursorKind CursorKind;
/// \brief The availability of this result.
- CXAvailabilityKind Availability;
+ CXAvailabilityKind Availability = CXAvailability_Available;
/// \brief Whether this result is hidden by another name.
bool Hidden : 1;
@@ -719,7 +803,7 @@ public:
/// \brief If the result should have a nested-name-specifier, this is it.
/// When \c QualifierIsInformative, the nested-name-specifier is
/// informative rather than required.
- NestedNameSpecifier *Qualifier;
+ NestedNameSpecifier *Qualifier = nullptr;
/// \brief Build a result that refers to a declaration.
CodeCompletionResult(const NamedDecl *Declaration,
@@ -727,33 +811,27 @@ public:
NestedNameSpecifier *Qualifier = nullptr,
bool QualifierIsInformative = false,
bool Accessible = true)
- : Declaration(Declaration), Priority(Priority),
- StartParameter(0), Kind(RK_Declaration),
- Availability(CXAvailability_Available), Hidden(false),
- QualifierIsInformative(QualifierIsInformative),
- StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
- DeclaringEntity(false), Qualifier(Qualifier) {
+ : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
+ Hidden(false), QualifierIsInformative(QualifierIsInformative),
+ StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
+ DeclaringEntity(false), Qualifier(Qualifier) {
computeCursorKindAndAvailability(Accessible);
}
/// \brief Build a result that refers to a keyword or symbol.
CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword)
- : Declaration(nullptr), Keyword(Keyword), Priority(Priority),
- StartParameter(0), Kind(RK_Keyword), CursorKind(CXCursor_NotImplemented),
- Availability(CXAvailability_Available), Hidden(false),
- QualifierIsInformative(0), StartsNestedNameSpecifier(false),
- AllParametersAreInformative(false), DeclaringEntity(false),
- Qualifier(nullptr) {}
+ : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
+ CursorKind(CXCursor_NotImplemented), Hidden(false),
+ QualifierIsInformative(false), StartsNestedNameSpecifier(false),
+ AllParametersAreInformative(false), DeclaringEntity(false) {}
/// \brief Build a result that refers to a macro.
CodeCompletionResult(const IdentifierInfo *Macro,
unsigned Priority = CCP_Macro)
- : Declaration(nullptr), Macro(Macro), Priority(Priority), StartParameter(0),
- Kind(RK_Macro), CursorKind(CXCursor_MacroDefinition),
- Availability(CXAvailability_Available), Hidden(false),
- QualifierIsInformative(0), StartsNestedNameSpecifier(false),
- AllParametersAreInformative(false), DeclaringEntity(false),
- Qualifier(nullptr) {}
+ : Macro(Macro), Priority(Priority), Kind(RK_Macro),
+ CursorKind(CXCursor_MacroDefinition), Hidden(false),
+ QualifierIsInformative(false), StartsNestedNameSpecifier(false),
+ AllParametersAreInformative(false), DeclaringEntity(false) {}
/// \brief Build a result that refers to a pattern.
CodeCompletionResult(CodeCompletionString *Pattern,
@@ -761,23 +839,19 @@ public:
CXCursorKind CursorKind = CXCursor_NotImplemented,
CXAvailabilityKind Availability = CXAvailability_Available,
const NamedDecl *D = nullptr)
- : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0),
- Kind(RK_Pattern), CursorKind(CursorKind), Availability(Availability),
- Hidden(false), QualifierIsInformative(0),
- StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
- DeclaringEntity(false), Qualifier(nullptr)
- {
- }
+ : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
+ CursorKind(CursorKind), Availability(Availability), Hidden(false),
+ QualifierIsInformative(false), StartsNestedNameSpecifier(false),
+ AllParametersAreInformative(false), DeclaringEntity(false) {}
/// \brief Build a result that refers to a pattern with an associated
/// declaration.
CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D,
unsigned Priority)
- : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0),
- Kind(RK_Pattern), Availability(CXAvailability_Available), Hidden(false),
- QualifierIsInformative(false), StartsNestedNameSpecifier(false),
- AllParametersAreInformative(false), DeclaringEntity(false),
- Qualifier(nullptr) {
+ : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
+ Hidden(false), QualifierIsInformative(false),
+ StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
+ DeclaringEntity(false) {
computeCursorKindAndAvailability();
}
@@ -839,7 +913,6 @@ inline bool operator>=(const CodeCompletionResult &X,
return !(X < Y);
}
-
raw_ostream &operator<<(raw_ostream &OS,
const CodeCompletionString &CCS);
@@ -860,8 +933,10 @@ public:
enum CandidateKind {
/// \brief The candidate is a function declaration.
CK_Function,
+
/// \brief The candidate is a function template.
CK_FunctionTemplate,
+
/// \brief The "candidate" is actually a variable, expression, or block
/// for which we only have a function prototype.
CK_FunctionType
@@ -887,13 +962,13 @@ public:
public:
OverloadCandidate(FunctionDecl *Function)
- : Kind(CK_Function), Function(Function) { }
+ : Kind(CK_Function), Function(Function) {}
OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
- : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) { }
+ : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {}
OverloadCandidate(const FunctionType *Type)
- : Kind(CK_FunctionType), Type(Type) { }
+ : Kind(CK_FunctionType), Type(Type) {}
/// \brief Determine the kind of overload candidate.
CandidateKind getKind() const { return Kind; }
@@ -923,8 +998,7 @@ public:
CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts,
bool OutputIsBinary)
- : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary)
- { }
+ : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) {}
/// \brief Whether the code-completion consumer wants to see macros.
bool includeMacros() const {
@@ -977,7 +1051,7 @@ public:
virtual void ProcessCodeCompleteResults(Sema &S,
CodeCompletionContext Context,
CodeCompletionResult *Results,
- unsigned NumResults) { }
+ unsigned NumResults) {}
/// \param S the semantic-analyzer object for which code-completion is being
/// done.
@@ -989,7 +1063,7 @@ public:
/// \param NumCandidates the number of overload candidates
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
- unsigned NumCandidates) { }
+ unsigned NumCandidates) {}
//@}
/// \brief Retrieve the allocator that will be used to allocate
@@ -1033,6 +1107,6 @@ public:
CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
};
-} // end namespace clang
+} // namespace clang
#endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
diff --git a/include/clang/Sema/Ownership.h b/include/clang/Sema/Ownership.h
index 1e35316fd5..11382c3fb6 100644
--- a/include/clang/Sema/Ownership.h
+++ b/include/clang/Sema/Ownership.h
@@ -1,4 +1,4 @@
-//===--- Ownership.h - Parser ownership helpers -----------------*- C++ -*-===//
+//===- Ownership.h - Parser ownership helpers -------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -17,21 +17,27 @@
#include "clang/AST/Expr.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
+#include "llvm/Support/type_traits.h"
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
//===----------------------------------------------------------------------===//
// OpaquePtr
//===----------------------------------------------------------------------===//
namespace clang {
- class CXXCtorInitializer;
- class CXXBaseSpecifier;
- class Decl;
- class Expr;
- class ParsedTemplateArgument;
- class QualType;
- class Stmt;
- class TemplateName;
- class TemplateParameterList;
+
+class CXXBaseSpecifier;
+class CXXCtorInitializer;
+class Decl;
+class Expr;
+class ParsedTemplateArgument;
+class QualType;
+class Stmt;
+class TemplateName;
+class TemplateParameterList;
/// \brief Wrapper for void* pointer.
/// \tparam PtrTy Either a pointer type like 'T*' or a type that behaves like
@@ -44,9 +50,10 @@ namespace clang {
template <class PtrTy>
class OpaquePtr {
void *Ptr = nullptr;
+
explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
- typedef llvm::PointerLikeTypeTraits<PtrTy> Traits;
+ using Traits = llvm::PointerLikeTypeTraits<PtrTy>;
public:
OpaquePtr(std::nullptr_t = nullptr) {}
@@ -103,26 +110,32 @@ namespace clang {
return *this;
}
};
-}
+
+} // namespace clang
namespace llvm {
+
template <class T>
- struct PointerLikeTypeTraits<clang::OpaquePtr<T> > {
+ struct PointerLikeTypeTraits<clang::OpaquePtr<T>> {
+ enum { NumLowBitsAvailable = 0 };
+
static inline void *getAsVoidPointer(clang::OpaquePtr<T> P) {
// FIXME: Doesn't work? return P.getAs< void >();
return P.getAsOpaquePtr();
}
+
static inline clang::OpaquePtr<T> getFromVoidPointer(void *P) {
return clang::OpaquePtr<T>::getFromOpaquePtr(P);
}
- enum { NumLowBitsAvailable = 0 };
};
template <class T>
- struct isPodLike<clang::OpaquePtr<T> > { static const bool value = true; };
-}
+ struct isPodLike<clang::OpaquePtr<T>> { static const bool value = true; };
+
+} // namespace llvm
namespace clang {
+
// Basic
class DiagnosticBuilder;
@@ -146,8 +159,7 @@ namespace clang {
bool Invalid;
public:
- ActionResult(bool Invalid = false)
- : Val(PtrTy()), Invalid(Invalid) {}
+ ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
ActionResult(PtrTy val) : Val(val), Invalid(false) {}
ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {}
@@ -178,17 +190,20 @@ namespace clang {
// A pointer whose low bit is 1 if this result is invalid, 0
// otherwise.
uintptr_t PtrWithInvalid;
- typedef llvm::PointerLikeTypeTraits<PtrTy> PtrTraits;
+
+ using PtrTraits = llvm::PointerLikeTypeTraits<PtrTy>;
+
public:
ActionResult(bool Invalid = false)
- : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) { }
+ : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
ActionResult(PtrTy V) {
void *VP = PtrTraits::getAsVoidPointer(V);
PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
}
- ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { }
+
+ ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
// These two overloads prevent void* -> bool conversions.
ActionResult(const void *) = delete;
@@ -202,6 +217,7 @@ namespace clang {
void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
return PtrTraits::getFromVoidPointer(VP);
}
+
template <typename T> T *getAs() { return static_cast<T*>(get()); }
void set(PtrTy V) {
@@ -229,8 +245,8 @@ namespace clang {
/// An opaque type for threading parsed type information through the
/// parser.
- typedef OpaquePtr<QualType> ParsedType;
- typedef UnionOpaquePtr<QualType> UnionParsedType;
+ using ParsedType = OpaquePtr<QualType>;
+ using UnionParsedType = UnionOpaquePtr<QualType>;
// We can re-use the low bit of expression, statement, base, and
// member-initializer pointers for the "invalid" flag of
@@ -248,21 +264,21 @@ namespace clang {
static const bool value = true;
};
- typedef ActionResult<Expr*> ExprResult;
- typedef ActionResult<Stmt*> StmtResult;
- typedef ActionResult<ParsedType> TypeResult;
- typedef ActionResult<CXXBaseSpecifier*> BaseResult;
- typedef ActionResult<CXXCtorInitializer*> MemInitResult;
+ using ExprResult = ActionResult<Expr *>;
+ using StmtResult = ActionResult<Stmt *>;
+ using TypeResult = ActionResult<ParsedType>;
+ using BaseResult = ActionResult<CXXBaseSpecifier *>;
+ using MemInitResult = ActionResult<CXXCtorInitializer *>;
- typedef ActionResult<Decl*> DeclResult;
- typedef OpaquePtr<TemplateName> ParsedTemplateTy;
- typedef UnionOpaquePtr<TemplateName> UnionParsedTemplateTy;
+ using DeclResult = ActionResult<Decl *>;
+ using ParsedTemplateTy = OpaquePtr<TemplateName>;
+ using UnionParsedTemplateTy = UnionOpaquePtr<TemplateName>;
- typedef MutableArrayRef<Expr*> MultiExprArg;
- typedef MutableArrayRef<Stmt*> MultiStmtArg;
- typedef MutableArrayRef<ParsedTemplateArgument> ASTTemplateArgsPtr;
- typedef MutableArrayRef<ParsedType> MultiTypeArg;
- typedef MutableArrayRef<TemplateParameterList*> MultiTemplateParamsArg;
+ using MultiExprArg = MutableArrayRef<Expr *>;
+ using MultiStmtArg = MutableArrayRef<Stmt *>;
+ using ASTTemplateArgsPtr = MutableArrayRef<ParsedTemplateArgument>;
+ using MultiTypeArg = MutableArrayRef<ParsedType>;
+ using MultiTemplateParamsArg = MutableArrayRef<TemplateParameterList *>;
inline ExprResult ExprError() { return ExprResult(true); }
inline StmtResult StmtError() { return StmtResult(true); }
@@ -282,6 +298,7 @@ namespace clang {
assert(!R.isInvalid() && "operation was asserted to never fail!");
return R.get();
}
-}
-#endif
+} // namespace clang
+
+#endif // LLVM_CLANG_SEMA_OWNERSHIP_H
diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp
index 14d334746f..bdb91c7e39 100644
--- a/lib/Sema/AttributeList.cpp
+++ b/lib/Sema/AttributeList.cpp
@@ -1,4 +1,4 @@
-//===--- AttributeList.cpp --------------------------------------*- C++ -*-===//
+//===- AttributeList.cpp --------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -13,14 +13,17 @@
#include "clang/Sema/AttributeList.h"
#include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclTemplate.h"
-#include "clang/AST/Expr.h"
#include "clang/Basic/AttrSubjectMatchRules.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include <cassert>
+#include <cstddef>
+#include <utility>
+
using namespace clang;
IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc,
@@ -44,7 +47,7 @@ AttributeFactory::AttributeFactory() {
// Go ahead and configure all the inline capacity. This is just a memset.
FreeLists.resize(InlineFreeListsCapacity);
}
-AttributeFactory::~AttributeFactory() {}
+AttributeFactory::~AttributeFactory() = default;
static size_t getFreeListIndexForSize(size_t size) {
assert(size >= sizeof(AttributeList));
@@ -175,8 +178,10 @@ struct ParsedAttrInfo {
};
namespace {
- #include "clang/Sema/AttrParsedAttrImpl.inc"
-}
+
+#include "clang/Sema/AttrParsedAttrImpl.inc"
+
+} // namespace
static const ParsedAttrInfo &getInfo(const AttributeList &A) {
return AttrInfoMap[A.getKind()];
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp
index 798e7d6a1c..d012e55e3d 100644
--- a/lib/Sema/CodeCompleteConsumer.cpp
+++ b/lib/Sema/CodeCompleteConsumer.cpp
@@ -1,4 +1,4 @@
-//===--- CodeCompleteConsumer.cpp - Code Completion Interface ---*- C++ -*-===//
+//===- CodeCompleteConsumer.cpp - Code Completion Interface ---------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -10,21 +10,30 @@
// This file implements the CodeCompleteConsumer class.
//
//===----------------------------------------------------------------------===//
+
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang-c/Index.h"
-#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
-#include "clang/Sema/Scope.h"
+#include "clang/AST/DeclarationName.h"
+#include "clang/AST/Type.h"
+#include "clang/Basic/IdentifierTable.h"
#include "clang/Sema/Sema.h"
#include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
-#include <cstring>
-#include <functional>
+#include <cassert>
+#include <cstdint>
+#include <string>
using namespace clang;
@@ -154,9 +163,9 @@ StringRef clang::getCompletionKindString(CodeCompletionContext::Kind Kind) {
//===----------------------------------------------------------------------===//
// Code completion string implementation
//===----------------------------------------------------------------------===//
+
CodeCompletionString::Chunk::Chunk(ChunkKind Kind, const char *Text)
- : Kind(Kind), Text("")
-{
+ : Kind(Kind), Text("") {
switch (Kind) {
case CK_TypedText:
case CK_Text:
@@ -270,10 +279,9 @@ CodeCompletionString::CodeCompletionString(const Chunk *Chunks,
unsigned NumAnnotations,
StringRef ParentName,
const char *BriefComment)
- : NumChunks(NumChunks), NumAnnotations(NumAnnotations),
- Priority(Priority), Availability(Availability),
- ParentName(ParentName), BriefComment(BriefComment)
-{
+ : NumChunks(NumChunks), NumAnnotations(NumAnnotations),
+ Priority(Priority), Availability(Availability),
+ ParentName(ParentName), BriefComment(BriefComment) {
assert(NumChunks <= 0xffff);
assert(NumAnnotations <= 0xffff);
@@ -297,7 +305,6 @@ const char *CodeCompletionString::getAnnotation(unsigned AnnotationNr) const {
return nullptr;
}
-
std::string CodeCompletionString::getAsString() const {
std::string Result;
llvm::raw_string_ostream OS(Result);
@@ -342,7 +349,7 @@ const char *CodeCompletionAllocator::CopyString(const Twine &String) {
StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
const NamedDecl *ND = dyn_cast<NamedDecl>(DC);
if (!ND)
- return StringRef();
+ return {};
// Check whether we've already cached the parent name.
StringRef &CachedParentName = ParentNames[DC];
@@ -352,7 +359,7 @@ StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
// If we already processed this DeclContext and assigned empty to it, the
// data pointer will be non-null.
if (CachedParentName.data() != nullptr)
- return StringRef();
+ return {};
// Find the interesting names.
SmallVector<const DeclContext *, 2> Contexts;
@@ -386,7 +393,7 @@ StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
// Assign an empty StringRef but with non-null data to distinguish
// between empty because we didn't process the DeclContext yet.
CachedParentName = StringRef((const char *)(uintptr_t)~0U, 0);
- return StringRef();
+ return {};
}
OS << Interface->getName() << '(' << Cat->getName() << ')';
@@ -450,9 +457,8 @@ void CodeCompletionBuilder::AddChunk(CodeCompletionString::ChunkKind CK,
}
void CodeCompletionBuilder::addParentContext(const DeclContext *DC) {
- if (DC->isTranslationUnit()) {
+ if (DC->isTranslationUnit())
return;
- }
if (DC->isFunctionOrMethod())
return;
@@ -502,25 +508,21 @@ CodeCompleteConsumer::OverloadCandidate::getFunctionType() const {
// Code completion consumer implementation
//===----------------------------------------------------------------------===//
-CodeCompleteConsumer::~CodeCompleteConsumer() { }
+CodeCompleteConsumer::~CodeCompleteConsumer() = default;
bool PrintingCodeCompleteConsumer::isResultFilteredOut(StringRef Filter,
CodeCompletionResult Result) {
switch (Result.Kind) {
- case CodeCompletionResult::RK_Declaration: {
+ case CodeCompletionResult::RK_Declaration:
return !(Result.Declaration->getIdentifier() &&
Result.Declaration->getIdentifier()->getName().startswith(Filter));
- }
- case CodeCompletionResult::RK_Keyword: {
+ case CodeCompletionResult::RK_Keyword:
return !StringRef(Result.Keyword).startswith(Filter);
- }
- case CodeCompletionResult::RK_Macro: {
+ case CodeCompletionResult::RK_Macro:
return !Result.Macro->getName().startswith(Filter);
- }
- case CodeCompletionResult::RK_Pattern: {
+ case CodeCompletionResult::RK_Pattern:
return !StringRef(Result.Pattern->getAsString()).startswith(Filter);
}
- }
llvm_unreachable("Unknown code completion result Kind.");
}
@@ -552,7 +554,6 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
if (const char *BriefComment = CCS->getBriefComment())
OS << " : " << BriefComment;
}
-
OS << '\n';
break;
@@ -560,7 +561,7 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
OS << Results[I].Keyword << '\n';
break;
- case CodeCompletionResult::RK_Macro: {
+ case CodeCompletionResult::RK_Macro:
OS << Results[I].Macro->getName();
if (CodeCompletionString *CCS
= Results[I].CreateCodeCompletionString(SemaRef, Context,
@@ -571,14 +572,12 @@ PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &SemaRef,
}
OS << '\n';
break;
- }
- case CodeCompletionResult::RK_Pattern: {
+ case CodeCompletionResult::RK_Pattern:
OS << "Pattern : "
<< Results[I].Pattern->getAsString() << '\n';
break;
}
- }
}
}