00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "comma/ast/AttribExpr.h"
00010
00011 using namespace comma;
00012 using llvm::dyn_cast;
00013 using llvm::cast;
00014 using llvm::isa;
00015
00016 attrib::AttributeID AttribExpr::correspondingID(AstKind kind)
00017 {
00018 attrib::AttributeID ID;
00019
00020 switch (kind) {
00021
00022 default:
00023 ID = attrib::UNKNOWN_ATTRIBUTE;
00024 break;
00025
00026 case AST_FirstAE:
00027 case AST_FirstArrayAE:
00028 ID = attrib::First;
00029 break;
00030
00031 case AST_LastAE:
00032 case AST_LastArrayAE:
00033 ID = attrib::Last;
00034 break;
00035 };
00036
00037 return ID;
00038 }
00039
00040
00041
00042
00043 ArrayBoundAE::ArrayBoundAE(AstKind kind,
00044 Expr *prefix, Expr *dimension, Location loc)
00045 : AttribExpr(kind, prefix, loc),
00046 dimExpr(dimension)
00047 {
00048 assert(kind == AST_FirstArrayAE || kind == AST_LastArrayAE);
00049 assert(dimension->isStaticDiscreteExpr());
00050
00051 ArrayType *arrTy = cast<ArrayType>(prefix->getType());
00052
00053 llvm::APInt dim;
00054 dimension->staticDiscreteValue(dim);
00055 assert(dim.getMinSignedBits() <= sizeof(unsigned)*8 &&
00056 "Cannot represent dimension!");
00057
00058 dimValue = unsigned(dim.getSExtValue());
00059 assert(dimValue > 0 && "Non-positive dimension!");
00060 assert(dimValue <= arrTy->getRank() && "Dimension too large!");
00061
00062
00063
00064 --dimValue;
00065 setType(arrTy->getIndexType(dimValue));
00066 }
00067
00068 ArrayBoundAE::ArrayBoundAE(AstKind kind, Expr *prefix, Location loc)
00069 : AttribExpr(kind, prefix, loc),
00070 dimExpr(0),
00071 dimValue(0)
00072 {
00073 assert(kind == AST_FirstArrayAE || kind == AST_LastArrayAE);
00074 ArrayType *arrTy = cast<ArrayType>(prefix->getType());
00075 setType(arrTy->getIndexType(0));
00076 }