aboutsummaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/AST/ASTContext.h24
-rw-r--r--include/clang/AST/PrettyPrinter.h18
-rw-r--r--include/clang/AST/Type.h119
-rw-r--r--include/clang/AST/TypeNodes.def2
-rw-r--r--include/clang/Frontend/PCHBitCodes.h6
-rw-r--r--include/clang/Parse/DeclSpec.h7
6 files changed, 156 insertions, 20 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 041a0f33ad..e85eac59a7 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -274,7 +274,8 @@ public:
/// variable array of the specified element type.
QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals);
+ unsigned EltTypeQuals,
+ SourceRange Brackets);
/// getDependentSizedArrayType - Returns a non-unique reference to
/// the type for a dependently-sized array of the specified element
@@ -282,7 +283,8 @@ public:
/// comparable, at some point.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals);
+ unsigned EltTypeQuals,
+ SourceRange Brackets);
/// getIncompleteArrayType - Returns a unique reference to the type for a
/// incomplete array of the specified element type.
@@ -295,7 +297,23 @@ public:
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
ArrayType::ArraySizeModifier ASM,
unsigned EltTypeQuals);
-
+
+ /// getConstantArrayWithExprType - Return a reference to the type for a
+ /// constant array of the specified element type.
+ QualType getConstantArrayWithExprType(QualType EltTy,
+ const llvm::APInt &ArySize,
+ Expr *ArySizeExpr,
+ ArrayType::ArraySizeModifier ASM,
+ unsigned EltTypeQuals,
+ SourceRange Brackets);
+
+ /// getConstantArrayWithoutExprType - Return a reference to the type
+ /// for a constant array of the specified element type.
+ QualType getConstantArrayWithoutExprType(QualType EltTy,
+ const llvm::APInt &ArySize,
+ ArrayType::ArraySizeModifier ASM,
+ unsigned EltTypeQuals);
+
/// getVectorType - Return the unique reference to a vector type of
/// the specified element type and size. VectorType must be a built-in type.
QualType getVectorType(QualType VectorType, unsigned NumElts);
diff --git a/include/clang/AST/PrettyPrinter.h b/include/clang/AST/PrettyPrinter.h
index 6ad3a6bcc2..a054522423 100644
--- a/include/clang/AST/PrettyPrinter.h
+++ b/include/clang/AST/PrettyPrinter.h
@@ -79,6 +79,24 @@ struct PrintingPolicy {
/// and pretty-printing involves printing something similar to
/// source code.
bool Dump : 1;
+
+ /// \brief Whether we should print the sizes of constant array expressions
+ /// as written in the sources.
+ ///
+ /// This flag is determines whether arrays types declared as
+ ///
+ /// \code
+ /// int a[4+10*10];
+ /// char a[] = "A string";
+ /// \endcode
+ ///
+ /// will be printed as written or as follows:
+ ///
+ /// \code
+ /// int a[104];
+ /// char a[9] = "A string";
+ /// \endcode
+ bool ConstantArraySizeAsWritten : 1;
};
} // end namespace clang
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h
index a00c0c4ff1..ffba78a3c8 100644
--- a/include/clang/AST/Type.h
+++ b/include/clang/AST/Type.h
@@ -291,7 +291,7 @@ private:
/// TypeClass bitfield - Enum that specifies what subclass this belongs to.
/// Note that this should stay at the end of the ivars for Type so that
/// subclasses can pack their bitfields into the same word.
- unsigned TC : 5;
+ unsigned TC : 6;
Type(const Type&); // DO NOT IMPLEMENT.
void operator=(const Type&); // DO NOT IMPLEMENT.
@@ -839,6 +839,8 @@ public:
static bool classof(const Type *T) {
return T->getTypeClass() == ConstantArray ||
+ T->getTypeClass() == ConstantArrayWithExpr ||
+ T->getTypeClass() == ConstantArrayWithoutExpr ||
T->getTypeClass() == VariableArray ||
T->getTypeClass() == IncompleteArray ||
T->getTypeClass() == DependentSizedArray;
@@ -846,15 +848,21 @@ public:
static bool classof(const ArrayType *) { return true; }
};
-/// ConstantArrayType - This class represents C arrays with a specified constant
-/// size. For example 'int A[100]' has ConstantArrayType where the element type
-/// is 'int' and the size is 100.
+/// ConstantArrayType - This class represents the canonical version of
+/// C arrays with a specified constant size. For example, the canonical
+/// type for 'int A[4 + 4*100]' is a ConstantArrayType where the element
+/// type is 'int' and the size is 404.
class ConstantArrayType : public ArrayType {
llvm::APInt Size; // Allows us to unique the type.
ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
ArraySizeModifier sm, unsigned tq)
- : ArrayType(ConstantArray, et, can, sm, tq), Size(size) {}
+ : ArrayType(ConstantArray, et, can, sm, tq),
+ Size(size) {}
+protected:
+ ConstantArrayType(TypeClass tc, QualType et, QualType can,
+ const llvm::APInt &size, ArraySizeModifier sm, unsigned tq)
+ : ArrayType(tc, et, can, sm, tq), Size(size) {}
friend class ASTContext; // ASTContext creates these.
public:
const llvm::APInt &getSize() const { return Size; }
@@ -872,22 +880,91 @@ public:
ID.AddInteger(SizeMod);
ID.AddInteger(TypeQuals);
}
- static bool classof(const Type *T) {
- return T->getTypeClass() == ConstantArray;
+ static bool classof(const Type *T) {
+ return T->getTypeClass() == ConstantArray ||
+ T->getTypeClass() == ConstantArrayWithExpr ||
+ T->getTypeClass() == ConstantArrayWithoutExpr;
}
static bool classof(const ConstantArrayType *) { return true; }
};
+/// ConstantArrayWithExprType - This class represents C arrays with a
+/// constant size specified by means of an integer constant expression.
+/// For example 'int A[sizeof(int)]' has ConstantArrayWithExprType where
+/// the element type is 'int' and the size expression is 'sizeof(int)'.
+/// These types are non-canonical.
+class ConstantArrayWithExprType : public ConstantArrayType {
+ /// SizeExpr - The ICE occurring in the concrete syntax.
+ Expr *SizeExpr;
+ /// Brackets - The left and right array brackets.
+ SourceRange Brackets;
+
+ ConstantArrayWithExprType(QualType et, QualType can,
+ const llvm::APInt &size, Expr *e,
+ ArraySizeModifier sm, unsigned tq,
+ SourceRange brackets)
+ : ConstantArrayType(ConstantArrayWithExpr, et, can, size, sm, tq),
+ SizeExpr(e), Brackets(brackets) {}
+ friend class ASTContext; // ASTContext creates these.
+ virtual void Destroy(ASTContext& C);
+
+public:
+ Expr *getSizeExpr() const { return SizeExpr; }
+ SourceRange getBracketsRange() const { return Brackets; }
+ SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
+ SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
+
+ virtual void getAsStringInternal(std::string &InnerString,
+ const PrintingPolicy &Policy) const;
+
+ static bool classof(const Type *T) {
+ return T->getTypeClass() == ConstantArrayWithExpr;
+ }
+ static bool classof(const ConstantArrayWithExprType *) { return true; }
+
+ void Profile(llvm::FoldingSetNodeID &ID) {
+ assert(0 && "Cannot unique ConstantArrayWithExprTypes.");
+ }
+};
+
+/// ConstantArrayWithoutExprType - This class represents C arrays with a
+/// constant size that was not specified by an integer constant expression,
+/// but inferred by static semantics.
+/// For example 'int A[] = { 0, 1, 2 }' has ConstantArrayWithoutExprType.
+/// These types are non-canonical: the corresponding canonical type,
+/// having the size specified in an APInt object, is a ConstantArrayType.
+class ConstantArrayWithoutExprType : public ConstantArrayType {
+
+ ConstantArrayWithoutExprType(QualType et, QualType can,
+ const llvm::APInt &size,
+ ArraySizeModifier sm, unsigned tq)
+ : ConstantArrayType(ConstantArrayWithoutExpr, et, can, size, sm, tq) {}
+ friend class ASTContext; // ASTContext creates these.
+
+public:
+ virtual void getAsStringInternal(std::string &InnerString,
+ const PrintingPolicy &Policy) const;
+
+ static bool classof(const Type *T) {
+ return T->getTypeClass() == ConstantArrayWithoutExpr;
+ }
+ static bool classof(const ConstantArrayWithoutExprType *) { return true; }
+
+ void Profile(llvm::FoldingSetNodeID &ID) {
+ assert(0 && "Cannot unique ConstantArrayWithoutExprTypes.");
+ }
+};
+
/// IncompleteArrayType - This class represents C arrays with an unspecified
/// size. For example 'int A[]' has an IncompleteArrayType where the element
/// type is 'int' and the size is unspecified.
class IncompleteArrayType : public ArrayType {
+
IncompleteArrayType(QualType et, QualType can,
- ArraySizeModifier sm, unsigned tq)
+ ArraySizeModifier sm, unsigned tq)
: ArrayType(IncompleteArray, et, can, sm, tq) {}
friend class ASTContext; // ASTContext creates these.
public:
-
virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const;
static bool classof(const Type *T) {
@@ -928,10 +1005,14 @@ class VariableArrayType : public ArrayType {
/// SizeExpr - An assignment expression. VLA's are only permitted within
/// a function block.
Stmt *SizeExpr;
-
+ /// Brackets - The left and right array brackets.
+ SourceRange Brackets;
+
VariableArrayType(QualType et, QualType can, Expr *e,
- ArraySizeModifier sm, unsigned tq)
- : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
+ ArraySizeModifier sm, unsigned tq,
+ SourceRange brackets)
+ : ArrayType(VariableArray, et, can, sm, tq),
+ SizeExpr((Stmt*) e), Brackets(brackets) {}
friend class ASTContext; // ASTContext creates these.
virtual void Destroy(ASTContext& C);
@@ -941,6 +1022,9 @@ public:
// to have a dependency of Type.h on Stmt.h/Expr.h.
return (Expr*) SizeExpr;
}
+ SourceRange getBracketsRange() const { return Brackets; }
+ SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
+ SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const;
@@ -971,10 +1055,14 @@ class DependentSizedArrayType : public ArrayType {
/// SizeExpr - An assignment expression that will instantiate to the
/// size of the array.
Stmt *SizeExpr;
+ /// Brackets - The left and right array brackets.
+ SourceRange Brackets;
DependentSizedArrayType(QualType et, QualType can, Expr *e,
- ArraySizeModifier sm, unsigned tq)
- : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {}
+ ArraySizeModifier sm, unsigned tq,
+ SourceRange brackets)
+ : ArrayType(DependentSizedArray, et, can, sm, tq),
+ SizeExpr((Stmt*) e), Brackets(brackets) {}
friend class ASTContext; // ASTContext creates these.
virtual void Destroy(ASTContext& C);
@@ -984,6 +1072,9 @@ public:
// to have a dependency of Type.h on Stmt.h/Expr.h.
return (Expr*) SizeExpr;
}
+ SourceRange getBracketsRange() const { return Brackets; }
+ SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
+ SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const;
diff --git a/include/clang/AST/TypeNodes.def b/include/clang/AST/TypeNodes.def
index 64a09d8002..36bc64b87b 100644
--- a/include/clang/AST/TypeNodes.def
+++ b/include/clang/AST/TypeNodes.def
@@ -57,6 +57,8 @@ TYPE(RValueReference, ReferenceType)
TYPE(MemberPointer, Type)
ABSTRACT_TYPE(Array, Type)
TYPE(ConstantArray, ArrayType)
+NON_CANONICAL_TYPE(ConstantArrayWithExpr, ConstantArrayType)
+NON_CANONICAL_TYPE(ConstantArrayWithoutExpr, ConstantArrayType)
TYPE(IncompleteArray, ArrayType)
TYPE(VariableArray, ArrayType)
DEPENDENT_TYPE(DependentSizedArray, ArrayType)
diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h
index 80aa248a78..8efaf26cc8 100644
--- a/include/clang/Frontend/PCHBitCodes.h
+++ b/include/clang/Frontend/PCHBitCodes.h
@@ -393,7 +393,11 @@ namespace clang {
/// \brief An ObjCObjectPointerType record.
TYPE_OBJC_OBJECT_POINTER = 23,
/// \brief a DecltypeType record.
- TYPE_DECLTYPE = 24
+ TYPE_DECLTYPE = 24,
+ /// \brief A ConstantArrayWithExprType record.
+ TYPE_CONSTANT_ARRAY_WITH_EXPR = 25,
+ /// \brief A ConstantArrayWithoutExprType record.
+ TYPE_CONSTANT_ARRAY_WITHOUT_EXPR = 26
};
/// \brief The type IDs for special types constructed by semantic
diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h
index 300602e514..0c57915298 100644
--- a/include/clang/Parse/DeclSpec.h
+++ b/include/clang/Parse/DeclSpec.h
@@ -457,6 +457,8 @@ struct DeclaratorChunk {
/// Loc - The place where this type was defined.
SourceLocation Loc;
+ /// EndLoc - If valid, the place where this chunck ends.
+ SourceLocation EndLoc;
struct PointerTypeInfo {
/// The type qualifiers: const/volatile/restrict.
@@ -696,10 +698,11 @@ struct DeclaratorChunk {
///
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic,
bool isStar, void *NumElts,
- SourceLocation Loc) {
+ SourceLocation LBLoc, SourceLocation RBLoc) {
DeclaratorChunk I;
I.Kind = Array;
- I.Loc = Loc;
+ I.Loc = LBLoc;
+ I.EndLoc = RBLoc;
I.Arr.TypeQuals = TypeQuals;
I.Arr.hasStatic = isStatic;
I.Arr.isStar = isStar;