00001 //===-- ast/DSTDefinition.cpp --------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #include "comma/ast/DSTDefinition.h" 00010 #include "comma/ast/AstResource.h" 00011 #include "comma/ast/RangeAttrib.h" 00012 #include "comma/ast/Type.h" 00013 00014 using namespace comma; 00015 using llvm::dyn_cast; 00016 using llvm::cast; 00017 using llvm::isa; 00018 00019 DSTDefinition::DSTDefinition(Location loc, Ast *base, DSTTag tag) 00020 : Ast(AST_DSTDefinition), 00021 loc(loc), 00022 definition(base) 00023 { 00024 bits = tag; 00025 00026 // Ensure the given tag and AST node are compatible. 00027 // 00028 // FIXME: Wrap in a DEBUG macro or similar. 00029 switch (tag) { 00030 case Attribute_DST: 00031 assert(isa<RangeAttrib>(base) && "Inconsistent ast/tag combo!"); 00032 break; 00033 00034 case Range_DST: 00035 case Type_DST: 00036 case Constrained_DST: 00037 case Unconstrained_DST: 00038 assert(isa<DiscreteType>(base) && "Inconsistent ast/tag combo!"); 00039 break; 00040 } 00041 } 00042 00043 DiscreteType *DSTDefinition::getType() 00044 { 00045 DiscreteType *result = 0; 00046 00047 switch (getTag()) { 00048 case Attribute_DST: 00049 result = cast<RangeAttrib>(definition)->getType(); 00050 break; 00051 case Range_DST: 00052 case Type_DST: 00053 case Constrained_DST: 00054 case Unconstrained_DST: 00055 result = cast<DiscreteType>(definition); 00056 break; 00057 } 00058 return result; 00059 } 00060 00061 const Range *DSTDefinition::getRange() const 00062 { 00063 if (definedUsingRange()) 00064 return cast<DiscreteType>(definition)->getConstraint(); 00065 return 0; 00066 } 00067 00068 Range *DSTDefinition::getRange() 00069 { 00070 if (definedUsingRange()) 00071 return cast<DiscreteType>(definition)->getConstraint(); 00072 return 0; 00073 } 00074 00075 const RangeAttrib *DSTDefinition::getAttrib() const 00076 { 00077 return dyn_cast<RangeAttrib>(definition); 00078 } 00079 00080 RangeAttrib *DSTDefinition::getAttrib() 00081 { 00082 return dyn_cast<RangeAttrib>(definition); 00083 }