AST Support for arrays.

Swift SVN r206
This commit is contained in:
Chris Lattner
2010-10-17 12:56:04 +00:00
parent fd54c7f5a0
commit ff38a2db1b
4 changed files with 65 additions and 3 deletions

View File

@@ -17,6 +17,8 @@
#ifndef SWIFT_AST_ASTCONTEXT_H
#define SWIFT_AST_ASTCONTEXT_H
#include "llvm/Support/DataTypes.h"
namespace llvm {
class BumpPtrAllocator;
class SourceMgr;
@@ -26,10 +28,10 @@ namespace llvm {
namespace swift {
class Type;
class AliasType;
class DataType;
class TupleType;
class FunctionType;
class ArrayType;
class Identifier;
class TupleTypeElt;
class DataDecl;
@@ -44,7 +46,8 @@ class ASTContext {
void *AliasTypes; // llvm::DenseMap<Identifier, AliasType*>
void *DataTypes; // llvm::DenseMap<Identifier, DataType*>
void *TupleTypes; // llvm::FoldingSet<TupleType>
void *FunctionTypes; // DenseMap<std::pair<Type*,Type*>, FunctionType*>
void *FunctionTypes; // DenseMap<std::pair<Type*, Type*>, FunctionType*>
void *ArrayTypes; // DenseMap<std::pair<Type*, uint64_t>, ArrayType*>
public:
ASTContext(llvm::SourceMgr &SourceMgr);
~ASTContext();
@@ -96,6 +99,10 @@ public:
/// getFunctionType - Return a uniqued function type with the specified
/// input and result.
FunctionType *getFunctionType(Type *Input, Type *Result);
/// getArrayType - Return a uniqued array type with the specified base type
/// and the specified size. Size=0 indicates an unspecified size array.
ArrayType *getArrayType(Type *BaseType, uint64_t Size);
};
} // end namespace swift

View File

@@ -37,6 +37,7 @@ namespace swift {
DataTypeKind,
TupleTypeKind,
FunctionTypeKind,
ArrayTypeKind,
Builtin_First = BuiltinInt32Kind,
Builtin_Last = BuiltinInt32Kind
@@ -225,10 +226,33 @@ public:
private:
FunctionType(Type *input, Type *result)
: Type(FunctionTypeKind), Input(input), Result(result) {}
: Type(FunctionTypeKind), Input(input), Result(result) {}
friend class ASTContext;
};
/// ArrayType - An array type has a base type and either an unspecified or a
/// constant size. For example "int[]" and "int[4]". Array types cannot have
/// size = 0.
class ArrayType : public Type {
public:
Type *const Base;
/// Size - When this is zero it indicates an unsized array like "int[]".
uint64_t Size;
void print(llvm::raw_ostream &OS) const;
// Implement isa/cast/dyncast/etc.
static bool classof(const ArrayType *) { return true; }
static bool classof(const Type *T) { return T->Kind == ArrayTypeKind; }
private:
ArrayType(Type *base, uint64_t size)
: Type(ArrayTypeKind), Base(base), Size(size) {}
friend class ASTContext;
};
} // end namespace swift
namespace llvm {