//===--- ASTContext.h - AST Context Object ----------------------*- C++ -*-===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See http://swift.org/LICENSE.txt for license information // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // // This file defines the ASTContext interface. // //===----------------------------------------------------------------------===// #ifndef SWIFT_AST_ASTCONTEXT_H #define SWIFT_AST_ASTCONTEXT_H #include "llvm/Support/DataTypes.h" #include "swift/AST/Type.h" #include namespace llvm { class SourceMgr; } namespace swift { class SourceLoc; class Type; class OneOfType; class TupleType; class FunctionType; class ArrayType; class Identifier; class Module; class TupleTypeElt; class OneOfElementDecl; class DiagnosticEngine; /// ASTContext - This object creates and owns the AST objects. class ASTContext { ASTContext(const ASTContext&) = delete; void operator=(const ASTContext&) = delete; public: // Members that should only be used by ASTContext.cpp. struct Implementation; Implementation &Impl; public: ASTContext(llvm::SourceMgr &SourceMgr, DiagnosticEngine &Diags); ~ASTContext(); /// SourceMgr - The source manager object. llvm::SourceMgr &SourceMgr; /// \Diags - The diagnostics engine. DiagnosticEngine &Diags; /// TheBuiltinModule - The builtin module. Module * const TheBuiltinModule; /// ImportSearchPaths - The paths to search for imports in. std::vector ImportSearchPaths; /// Allocate - Allocate memory from the ASTContext bump pointer. void *Allocate(unsigned long Bytes, unsigned Alignment); template T *Allocate(unsigned NElts) { T *Res = (T*)Allocate(sizeof(T)*NElts, __alignof__(T)); for (unsigned i = 0; i != NElts; ++i) new (Res+i) T(); return Res; } template T *AllocateCopy(It Start, It End) { T *Res = (T*)Allocate(sizeof(T)*(End-Start), __alignof__(T)); for (unsigned i = 0; Start != End; ++Start, ++i) new (Res+i) T(*Start); return Res; } template ArrayRef AllocateCopy(ArrayRef Arr) { return ArrayRef(AllocateCopy(Arr.begin(), Arr.end()), Arr.size()); } template MutableArrayRef AllocateCopy(MutableArrayRef Arr) { return MutableArrayRef(AllocateCopy(Arr.begin(), Arr.end()), Arr.size()); } template ArrayRef AllocateCopy(const SmallVectorImpl &Vec) { return AllocateCopy(ArrayRef(Vec)); } template MutableArrayRef AllocateCopy(SmallVectorImpl &Vec) { return AllocateCopy(MutableArrayRef(Vec)); } /// getIdentifier - Return the uniqued and AST-Context-owned version of the /// specified string. Identifier getIdentifier(StringRef Str); //===--------------------------------------------------------------------===// // Diagnostics Helper functions //===--------------------------------------------------------------------===// bool hadError() const; //===--------------------------------------------------------------------===// // Type manipulation routines. //===--------------------------------------------------------------------===// // Builtin type and simple types that are used frequently. const Type TheErrorType; /// TheErrorType - This is the error singleton. const Type TheEmptyTupleType; /// TheEmptyTupleType - This is "()" const Type TheObjectPointerType; /// Builtin.ObjectPointer const Type TheRawPointerType; /// Builtin.RawPointer /// TheUnstructuredDependentType - Dependent on context. This is given to an /// anonymous closure argument (e.g. $4) and to UnresolvedMemberExprs /// (e.g. .foo) during type checking until they are resolved to something with /// concrete type. const Type TheUnstructuredDependentType; const Type TheIEEE32Type; /// TheIEEE32Type - 32-bit IEEE floating point const Type TheIEEE64Type; /// TheIEEE64Type - 64-bit IEEE floating point // Target specific types. const Type TheIEEE16Type; /// TheIEEE16Type - 16-bit IEEE floating point const Type TheIEEE80Type; /// TheIEEE80Type - 80-bit IEEE floating point const Type TheIEEE128Type; /// TheIEEE128Type - 128-bit IEEE floating point const Type ThePPC128Type; /// ThePPC128Type - 128-bit PowerPC 2xDouble }; } // end namespace swift #endif