00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00014 
00015 
00016 #ifndef COMMA_AST_KEYWORDSELECTOR_HDR_GUARD
00017 #define COMMA_AST_KEYWORDSELECTOR_HDR_GUARD
00018 
00019 #include "comma/ast/Expr.h"
00020 #include "comma/ast/TypeRef.h"
00021 
00022 namespace comma {
00023 
00038 class KeywordSelector : public Ast {
00039 
00040 public:
00048     KeywordSelector(IdentifierInfo *key, Location loc, Expr *expr)
00049         : Ast(AST_KeywordSelector),
00050           keyword(key), loc(loc), rhs(expr) { }
00051 
00059     KeywordSelector(IdentifierInfo *key, Location loc, TypeRef *tyRef)
00060         : Ast(AST_KeywordSelector),
00061           keyword(key), loc(loc), rhs(tyRef) { }
00062 
00064     IdentifierInfo *getKeyword() const { return keyword; }
00065 
00067     Location getLocation()  const { return loc; }
00068 
00070     bool isTypeSelector() const { return llvm::isa<TypeRef>(rhs); }
00071 
00073     bool isExprSelector() const { return llvm::isa<Expr>(rhs); }
00074 
00076 
00077 
00078     void setRHS(Expr *expr) { rhs = expr; }
00079     void setRHS(TypeRef *ref) { rhs = ref; }
00081 
00083 
00084 
00085     Expr *getExpression() { return llvm::dyn_cast<Expr>(rhs); }
00086     const Expr *getExpression() const { return llvm::dyn_cast<Expr>(rhs); }
00088 
00092     Type *getType() const {
00093         if (const Expr *expr = getExpression()) {
00094             if (expr->hasType())
00095                 return expr->getType();
00096         }
00097         return 0;
00098     }
00099 
00101 
00102 
00103     TypeRef *getTypeRef() { return llvm::dyn_cast<TypeRef>(rhs); }
00104     const TypeRef *getTypeRef() const { return llvm::dyn_cast<TypeRef>(rhs); }
00106 
00107     
00108     static bool classof(const KeywordSelector *node) { return true; }
00109     static bool classof(const Ast *node) {
00110         return node->getKind() == AST_KeywordSelector;
00111     }
00112 
00113 private:
00114     IdentifierInfo *keyword;
00115     Location loc;
00116     Ast *rhs;
00117 };
00118 
00119 } 
00120 
00121 #endif