00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 #ifndef COMMA_AST_ASTRESOURCE_HDR_GUARD
00017 #define COMMA_AST_ASTRESOURCE_HDR_GUARD
00018 
00019 #include "comma/ast/AstBase.h"
00020 #include "comma/basic/IdentifierPool.h"
00021 #include "comma/basic/PrimitiveOps.h"
00022 
00023 #include "llvm/ADT/FoldingSet.h"
00024 
00025 #include <vector>
00026 
00027 namespace llvm {
00028 
00029 class APInt;
00030 
00031 } 
00032 
00033 namespace comma {
00034 
00035 class IndexConstraint;
00036 class RangeConstraint;
00037 class TextProvider;
00038 
00039 class AstResource {
00040 
00041 public:
00042     
00043     
00044     
00045     AstResource(TextProvider &txtProvider, IdentifierPool &idPool);
00046 
00047     
00048     
00049     TextProvider &getTextProvider() { return txtProvider; }
00050 
00051     IdentifierPool &getIdentifierPool() { return idPool; }
00052 
00053     
00054     
00055     IdentifierInfo *getIdentifierInfo(const char *name) const {
00056         return &idPool.getIdentifierInfo(name);
00057     }
00058     IdentifierInfo *getIdentifierInfo(const char *name, unsigned len) const {
00059         return &idPool.getIdentifierInfo(name, len);
00060     }
00061     IdentifierInfo *getIdentifierInfo(const std::string &name) const {
00062         return &idPool.getIdentifierInfo(name);
00063     }
00064 
00066     FunctionType *getFunctionType(Type **argTypes, unsigned numArgs,
00067                                   Type *returnType);
00068 
00070     ProcedureType *getProcedureType(Type **argTypes, unsigned numArgs);
00071 
00073 
00074 
00079     DomainType *createDomainType(DomainTypeDecl *decl);
00080 
00082     DomainType *createDomainSubtype(DomainType *rootTy, IdentifierInfo *name);
00084 
00086 
00087 
00088     EnumerationDecl *createEnumDecl(IdentifierInfo *name, Location loc,
00089                                     std::pair<IdentifierInfo*, Location> *elems,
00090                                     unsigned numElems, DeclRegion *parent);
00091 
00093     EnumerationDecl *createEnumSubtypeDecl(IdentifierInfo *name, Location loc,
00094                                            EnumerationType *subtype,
00095                                            Expr *low, Expr *high,
00096                                            DeclRegion *parent);
00097 
00099     EnumerationDecl *createEnumSubtypeDecl(IdentifierInfo *name, Location loc,
00100                                            EnumerationType *subtype,
00101                                            DeclRegion *parent);
00102 
00104     EnumerationType *createEnumType(EnumerationDecl *decl);
00105 
00107     EnumerationType *createEnumSubtype(EnumerationType *base,
00108                                        EnumerationDecl *decl = 0);
00109 
00111     EnumerationType *createEnumSubtype(EnumerationType *base,
00112                                        Expr *low, Expr *high,
00113                                        EnumerationDecl *decl = 0);
00115 
00117 
00118 
00119     IntegerDecl *createIntegerDecl(IdentifierInfo *name, Location loc,
00120                                    Expr *lowRange, Expr *highRange,
00121                                    DeclRegion *parent);
00122 
00124     IntegerDecl *createIntegerSubtypeDecl(IdentifierInfo *name, Location loc,
00125                                           IntegerType *subtype,
00126                                           Expr *lower, Expr *upper,
00127                                           DeclRegion *parent);
00128 
00130     IntegerDecl *createIntegerSubtypeDecl(IdentifierInfo *name, Location loc,
00131                                           IntegerType *subtype,
00132                                           DeclRegion *parent);
00133 
00135     IntegerType *createIntegerType(IntegerDecl *decl,
00136                                    const llvm::APInt &low,
00137                                    const llvm::APInt &high);
00138 
00143     IntegerType *createIntegerSubtype(IntegerType *base, Expr *low, Expr *high,
00144                                       IntegerDecl *decl = 0);
00145 
00154     IntegerType *createIntegerSubtype(IntegerType *base,
00155                                       const llvm::APInt &low,
00156                                       const llvm::APInt &high,
00157                                       IntegerDecl *decl = 0);
00158 
00160     IntegerType *createIntegerSubtype(IntegerType *base,
00161                                       IntegerDecl *decl = 0);
00163 
00167     DiscreteType *createDiscreteSubtype(DiscreteType *base,
00168                                         Expr *low, Expr *high,
00169                                         TypeDecl *decl = 0);
00170 
00172 
00173 
00174     ArrayDecl *createArrayDecl(IdentifierInfo *name, Location loc,
00175                                unsigned rank, DSTDefinition **indices,
00176                                Type *component, bool isConstrained,
00177                                DeclRegion *parent);
00178 
00181     ArrayType *createArrayType(ArrayDecl *decl,
00182                                unsigned rank, DiscreteType **indices,
00183                                Type *component, bool isConstrained);
00184 
00186     ArrayType *createArraySubtype(IdentifierInfo *name, ArrayType *base,
00187                                   DiscreteType **indices);
00188 
00190     ArrayType *createArraySubtype(IdentifierInfo *name, ArrayType *base);
00192 
00194 
00195 
00196     RecordDecl *createRecordDecl(IdentifierInfo *name, Location loc,
00197                                  DeclRegion *parent);
00198 
00200     RecordType *createRecordType(RecordDecl *decl);
00201 
00203     RecordType *createRecordSubtype(IdentifierInfo *name, RecordType *base);
00205 
00207 
00208 
00209     AccessDecl *createAccessDecl(IdentifierInfo *name, Location loc,
00210                                  Type *targetType, DeclRegion *parent);
00211 
00214     AccessType *createAccessType(AccessDecl *decl, Type *targetType);
00215 
00217     AccessType *createAccessSubtype(IdentifierInfo *name, AccessType *baseType);
00219 
00221 
00222 
00223     IncompleteTypeDecl *createIncompleteTypeDecl(IdentifierInfo *name,
00224                                                  Location loc,
00225                                                  DeclRegion *parent);
00226 
00228     IncompleteType *createIncompleteType(IncompleteTypeDecl *decl);
00229 
00231     IncompleteType *createIncompleteSubtype(IdentifierInfo *name,
00232                                             IncompleteType *base);
00234 
00242     ExceptionDecl *createExceptionDecl(IdentifierInfo *name, Location loc,
00243                                        DeclRegion *region);
00244 
00260     FunctionDecl *createPrimitiveDecl(PO::PrimitiveID ID,
00261                                       Location loc, Type *type,
00262                                       DeclRegion *region);
00263 
00270 
00271     EnumerationDecl *getTheBooleanDecl() const { return theBooleanDecl; }
00272     EnumerationType *getTheBooleanType() const;
00273 
00274     EnumerationDecl *getTheCharacterDecl() const { return theCharacterDecl; }
00275     EnumerationType *getTheCharacterType() const;
00276 
00277     IntegerDecl *getTheRootIntegerDecl() const { return theRootIntegerDecl; }
00278     IntegerType *getTheRootIntegerType() const;
00279 
00280     IntegerDecl *getTheIntegerDecl() const { return theIntegerDecl; }
00281     IntegerType *getTheIntegerType() const;
00282 
00283     IntegerDecl *getTheNaturalDecl() const { return theNaturalDecl; }
00284     IntegerType *getTheNaturalType() const;
00285 
00286     IntegerDecl *getThePositiveDecl() const { return thePositiveDecl; }
00287     IntegerType *getThePositiveType() const;
00288 
00289     ArrayDecl *getTheStringDecl() const { return theStringDecl; }
00290     ArrayType *getTheStringType() const;
00291 
00292     ExceptionDecl *getTheProgramError() const { return theProgramError; }
00293     ExceptionDecl *getTheConstraintError() const { return theConstraintError; }
00294     ExceptionDecl *getTheAssertionError() const { return theAssertionError; }
00296 
00297 private:
00298     TextProvider &txtProvider;
00299     IdentifierPool &idPool;
00300 
00301     
00302     std::vector<Decl*> decls;
00303     std::vector<Type*> types;
00304 
00305     
00306     llvm::FoldingSet<FunctionType> functionTypes;
00307     llvm::FoldingSet<ProcedureType> procedureTypes;
00308 
00310 
00313     EnumerationDecl *theBooleanDecl;
00314     EnumerationDecl *theCharacterDecl;
00315     IntegerDecl *theRootIntegerDecl;
00316     IntegerDecl *theIntegerDecl;
00317     IntegerDecl *theNaturalDecl;
00318     IntegerDecl *thePositiveDecl;
00319     ArrayDecl *theStringDecl;
00320     ExceptionDecl *theProgramError;
00321     ExceptionDecl *theConstraintError;
00322     ExceptionDecl *theAssertionError;
00323 
00331 
00332     void initializeLanguageDefinedNodes();
00333     void initializeBoolean();
00334     void initializeCharacter();
00335     void initializeRootInteger();
00336     void initializeInteger();
00337     void initializeNatural();
00338     void initializePositive();
00339     void initializeString();
00340     void initializeExceptions();
00342 };
00343 
00344 } 
00345 
00346 #endif