00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "comma/ast/Expr.h"
00010 #include "llvm/Support/Casting.h"
00011
00012 using namespace comma;
00013 using llvm::dyn_cast;
00014 using llvm::cast;
00015 using llvm::isa;
00016
00017
00018
00019
00020 KeywordSelector::KeywordSelector(IdentifierInfo *key, Location loc, Expr *expr)
00021 : Expr(AST_KeywordSelector, loc),
00022 keyword(key),
00023 expression(expr)
00024 {
00025 if (expression->hasType())
00026 this->setType(expression->getType());
00027 }
00028
00029
00030
00031
00032 FunctionCallExpr::FunctionCallExpr(FunctionDecl *connective,
00033 Expr **args,
00034 unsigned numArgs,
00035 Location loc)
00036 : Expr(AST_FunctionCallExpr, loc),
00037 connective(connective),
00038 numArgs(numArgs),
00039 qualifier(0)
00040 {
00041 arguments = new Expr*[numArgs];
00042 std::copy(args, args + numArgs, arguments);
00043 setTypeForConnective();
00044 }
00045
00046 FunctionCallExpr::FunctionCallExpr(FunctionDecl **connectives,
00047 unsigned numConnectives,
00048 Expr **args,
00049 unsigned numArgs,
00050 Location loc)
00051 : Expr(AST_FunctionCallExpr, loc),
00052 numArgs(numArgs),
00053 qualifier(0)
00054 {
00055 if (numConnectives > 1)
00056 connective = new OverloadedDeclName(connectives,
00057 connectives + numConnectives);
00058 else {
00059 connective = connectives[0];
00060 setTypeForConnective();
00061 }
00062
00063 arguments = new Expr*[numArgs];
00064 std::copy(args, args + numArgs, arguments);
00065 }
00066
00067 void FunctionCallExpr::setTypeForConnective()
00068 {
00069 FunctionDecl *fdecl = cast<FunctionDecl>(connective);
00070 setType(fdecl->getReturnType());
00071 }
00072
00073 FunctionCallExpr::~FunctionCallExpr()
00074 {
00075 delete[] arguments;
00076
00077 if (OverloadedDeclName *odn = dyn_cast<OverloadedDeclName>(connective))
00078 delete odn;
00079 }
00080
00081 unsigned FunctionCallExpr::numConnectives() const
00082 {
00083 if (OverloadedDeclName *odn = dyn_cast<OverloadedDeclName>(connective))
00084 return odn->numOverloads();
00085 else
00086 return 1;
00087 }
00088
00089 FunctionDecl *FunctionCallExpr::getConnective(unsigned i) const
00090 {
00091 assert(i < numConnectives() && "Connective index out of range!");
00092
00093 if (OverloadedDeclName *odn = dyn_cast<OverloadedDeclName>(connective))
00094 return cast<FunctionDecl>(odn->getOverload(i));
00095 else
00096 return cast<FunctionDecl>(connective);
00097 }
00098
00099 void FunctionCallExpr::resolveConnective(FunctionDecl *decl)
00100 {
00101 OverloadedDeclName *odn = cast<OverloadedDeclName>(connective);
00102
00103 connective = decl;
00104 setType(decl->getReturnType());
00105 delete odn;
00106 }
00107
00108 bool FunctionCallExpr::containsConnective(FunctionType *ftype) const
00109 {
00110 for (unsigned i = 0; i < numConnectives(); ++i) {
00111 FunctionDecl *connective = dyn_cast<FunctionDecl>(getConnective(i));
00112 if (connective) {
00113 FunctionType *connectiveType = connective->getType();
00114 if (connectiveType->equals(ftype))
00115 return true;
00116 }
00117 }
00118 return false;
00119 }