00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "IdentifierResolver.h"
00010 #include "comma/ast/Expr.h"
00011 #include "comma/ast/Stmt.h"
00012 #include "comma/typecheck/TypeCheck.h"
00013 #include "llvm/ADT/BitVector.h"
00014 #include "llvm/Support/Casting.h"
00015
00016 using namespace comma;
00017 using llvm::dyn_cast;
00018 using llvm::cast;
00019 using llvm::isa;
00020
00021
00022 Node TypeCheck::acceptQualifier(Node typeNode, Location loc)
00023 {
00024 Type *type = ensureValueType(typeNode, loc);
00025
00026 if (type) {
00027 typeNode.release();
00028 DeclRegion *region = type->getDeclaration()->asDeclRegion();
00029 assert(region && "Bad type serving as qualifier.");
00030 return getNode(new Qualifier(region, loc));
00031 }
00032 else
00033 return getInvalidNode();
00034 }
00035
00036 Node TypeCheck::acceptNestedQualifier(Node qualifierNode,
00037 Node typeNode,
00038 Location loc)
00039 {
00040 Qualifier *qualifier = cast_node<Qualifier>(qualifierNode);
00041 Type *type = ensureValueType(typeNode, loc);
00042
00043 if (type) {
00044 typeNode.release();
00045 DeclRegion *region = type->getDeclaration()->asDeclRegion();
00046 assert(region && "Bad type serving as qualifier.");
00047 qualifier->addQualifier(region, loc);
00048 return qualifierNode;
00049 }
00050 else
00051 return getInvalidNode();
00052 }
00053
00054
00055
00056 Node TypeCheck::acceptQualifiedName(Node qualNode,
00057 IdentifierInfo *name,
00058 Location loc)
00059 {
00060 Qualifier *qualifier = cast_node<Qualifier>(qualNode);
00061 DeclRegion *region = qualifier->resolve();
00062 llvm::SmallVector<FunctionDecl*, 8> decls;
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 for (DeclRegion::DeclIter iter = region->beginDecls();
00076 iter != region->endDecls(); ++iter) {
00077 Decl *decl = *iter;
00078 if (decl->getIdInfo() == name) {
00079 if (FunctionDecl *fdecl = dyn_cast<FunctionDecl>(decl)) {
00080 if (fdecl->getArity() == 0)
00081 decls.push_back(fdecl);
00082 }
00083 }
00084 else if (EnumerationDecl *edecl = dyn_cast<EnumerationDecl>(decl)) {
00085
00086
00087
00088 if (EnumLiteral *lit = edecl->findLiteral(name))
00089 decls.push_back(lit);
00090 }
00091 }
00092
00093 if (decls.empty()) {
00094 report(loc, diag::NAME_NOT_VISIBLE) << name;
00095 return getInvalidNode();
00096 }
00097
00098
00099
00100 FunctionCallExpr *call
00101 = new FunctionCallExpr(&decls[0], decls.size(), 0, 0, loc);
00102 call->setQualifier(qualifier);
00103 qualNode.release();
00104 return getNode(call);
00105 }
00106
00107 Node TypeCheck::acceptDirectName(IdentifierInfo *name,
00108 Location loc,
00109 Node qualNode)
00110 {
00111 if (!qualNode.isNull())
00112 return acceptQualifiedName(qualNode, name, loc);
00113
00114 IdentifierResolver resolver;
00115
00116 if (!resolver.resolve(name)) {
00117 report(loc, diag::NAME_NOT_VISIBLE) << name;
00118 return getInvalidNode();
00119 }
00120
00121
00122
00123 if (resolver.hasDirectValue()) {
00124 ValueDecl *vdecl = resolver.getDirectValue();
00125 DeclRefExpr *ref = new DeclRefExpr(vdecl, loc);
00126 return getNode(ref);
00127 }
00128
00129 llvm::SmallVector<Decl *, 8> overloads;
00130 resolver.filterOverloadsWRTArity(0);
00131 resolver.filterProcedures();
00132
00133
00134 overloads.append(resolver.beginDirectOverloads(),
00135 resolver.endDirectOverloads());
00136
00137
00138
00139 if (!resolver.hasIndirectValues()) {
00140 overloads.append(resolver.beginIndirectOverloads(),
00141 resolver.endIndirectOverloads());
00142 if (!overloads.empty()) {
00143 llvm::SmallVector<FunctionDecl*, 8> connectives;
00144 unsigned size = overloads.size();
00145
00146 for (unsigned i = 0; i < size; ++i)
00147 connectives.push_back(cast<FunctionDecl>(overloads[i]));
00148
00149 FunctionCallExpr *call =
00150 new FunctionCallExpr(&connectives[0], size, 0, 0, loc);
00151 return getNode(call);
00152 }
00153 report(loc, diag::NAME_NOT_VISIBLE) << name;
00154 return getInvalidNode();
00155 }
00156
00157
00158
00159 if (!overloads.empty()) {
00160 llvm::SmallVector<FunctionDecl*, 8> connectives;
00161 unsigned size = overloads.size();
00162
00163 for (unsigned i = 0; i < size; ++i)
00164 connectives.push_back(cast<FunctionDecl>(overloads[i]));
00165
00166 FunctionCallExpr *call =
00167 new FunctionCallExpr(&connectives[0], size, 0, 0, loc);
00168 return getNode(call);
00169 }
00170
00171
00172
00173 if (resolver.hasIndirectOverloads()) {
00174 report(loc, diag::MULTIPLE_IMPORT_AMBIGUITY);
00175 return getInvalidNode();
00176 }
00177
00178
00179 if (resolver.numIndirectValues() != 1) {
00180 report(loc, diag::MULTIPLE_IMPORT_AMBIGUITY);
00181 return getInvalidNode();
00182 }
00183
00184
00185 return getNode(new DeclRefExpr(resolver.getIndirectValue(0), loc));
00186 }
00187
00188 Node TypeCheck::acceptFunctionName(IdentifierInfo *name,
00189 Location loc,
00190 Node qualNode)
00191 {
00192 if (!qualNode.isNull()) {
00193 Qualifier *qualifier = cast_node<Qualifier>(qualNode);
00194 DeclRegion *region = qualifier->resolve();
00195
00196
00197
00198
00199 typedef DeclRegion::PredRange PredRange;
00200 typedef DeclRegion::PredIter PredIter;
00201 PredRange range = region->findDecls(name);
00202 llvm::SmallVector<SubroutineDecl*, 8> decls;
00203
00204
00205 for (PredIter iter = range.first; iter != range.second; ++iter) {
00206 FunctionDecl *candidate = dyn_cast<FunctionDecl>(*iter);
00207 if (candidate)
00208 decls.push_back(candidate);
00209 }
00210
00211 if (decls.empty()) {
00212 report(loc, diag::NAME_NOT_VISIBLE);
00213 return getInvalidNode();
00214 }
00215
00216 if (decls.size() == 1)
00217 return getNode(decls.front());
00218
00219 return getNode(new OverloadedDeclName(&decls[0], decls.size()));
00220 }
00221
00222 IdentifierResolver resolver;
00223
00224 if (!resolver.resolve(name) || resolver.hasDirectValue()) {
00225 report(loc, diag::NAME_NOT_VISIBLE) << name;
00226 return getInvalidNode();
00227 }
00228
00229 llvm::SmallVector<SubroutineDecl *, 8> overloads;
00230 unsigned numOverloads = 0;
00231 resolver.filterProcedures();
00232 resolver.filterNullaryOverloads();
00233
00234
00235 {
00236 typedef IdentifierResolver::DirectOverloadIter iterator;
00237 iterator E = resolver.endDirectOverloads();
00238 for (iterator I = resolver.beginDirectOverloads(); I != E; ++I)
00239 overloads.push_back(cast<FunctionDecl>(*I));
00240 }
00241
00242
00243
00244 if (!resolver.hasIndirectValues()) {
00245 typedef IdentifierResolver::IndirectOverloadIter iterator;
00246 iterator E = resolver.endIndirectOverloads();
00247 for (iterator I = resolver.beginIndirectOverloads(); I != E; ++I)
00248 overloads.push_back(cast<FunctionDecl>(*I));
00249 numOverloads = overloads.size();
00250 if (numOverloads == 1)
00251 return getNode(overloads.front());
00252 else if (numOverloads > 1)
00253 return getNode(new OverloadedDeclName(&overloads[0], numOverloads));
00254 else {
00255 report(loc, diag::NAME_NOT_VISIBLE) << name;
00256 return getInvalidNode();
00257 }
00258 }
00259
00260
00261
00262 numOverloads = overloads.size();
00263 if (numOverloads == 1)
00264 return getNode(overloads.front());
00265 else if (numOverloads > 1)
00266 return getNode(new OverloadedDeclName(&overloads[0], numOverloads));
00267
00268
00269 report(loc, diag::NAME_NOT_VISIBLE) << name;
00270 return getInvalidNode();
00271 }
00272
00273 Node TypeCheck::acceptFunctionCall(Node connective,
00274 Location loc,
00275 NodeVector &argNodes)
00276 {
00277 std::vector<SubroutineDecl*> decls;
00278 unsigned targetArity = argNodes.size();
00279
00280 assert(targetArity > 0 && "Cannot accept nullary function calls!");
00281
00282 connective.release();
00283
00284 if (FunctionDecl *fdecl = lift_node<FunctionDecl>(connective)) {
00285 if (fdecl->getArity() == targetArity)
00286 decls.push_back(fdecl);
00287 else {
00288 report(loc, diag::WRONG_NUM_ARGS_FOR_SUBROUTINE)
00289 << fdecl->getIdInfo();
00290 return getInvalidNode();
00291 }
00292 }
00293 else {
00294 OverloadedDeclName *odn = cast_node<OverloadedDeclName>(connective);
00295 for (OverloadedDeclName::iterator iter = odn->begin();
00296 iter != odn->end(); ++iter) {
00297 FunctionDecl *fdecl = cast<FunctionDecl>(*iter);
00298 if (fdecl->getArity() == targetArity)
00299 decls.push_back(fdecl);
00300 }
00301
00302 delete odn;
00303
00304
00305
00306 if (decls.empty()) {
00307 report(loc, diag::NAME_NOT_VISIBLE) << odn->getIdInfo();
00308 return getInvalidNode();
00309 }
00310 }
00311
00312 return acceptSubroutineCall(decls, loc, argNodes);
00313 }
00314
00315 Node TypeCheck::acceptSubroutineCall(std::vector<SubroutineDecl*> &decls,
00316 Location loc,
00317 NodeVector &argNodes)
00318 {
00319 llvm::SmallVector<Expr*, 8> args;
00320 unsigned numArgs = argNodes.size();
00321 IdentifierInfo *name = decls[0]->getIdInfo();
00322
00323
00324 for (unsigned i = 0; i < numArgs; ++i)
00325 args.push_back(cast_node<Expr>(argNodes[i]));
00326
00327 if (decls.size() == 1) {
00328 Node call = checkSubroutineCall(decls[0], loc, &args[0], numArgs);
00329 if (call.isValid()) argNodes.release();
00330 return call;
00331 }
00332
00333
00334
00335
00336 llvm::BitVector declFilter(decls.size(), true);
00337
00338
00339
00340 for (unsigned i = 0; i < decls.size(); ++i) {
00341 SubroutineDecl *decl = decls[i];
00342 for (unsigned j = 0; j < numArgs; ++j) {
00343 Expr *arg = args[j];
00344 if (KeywordSelector *selector = dyn_cast<KeywordSelector>(arg)) {
00345 IdentifierInfo *key = selector->getKeyword();
00346 Location keyLoc = selector->getLocation();
00347 int keyIndex = decl->getKeywordIndex(key);
00348
00349 if (keyIndex < 0) {
00350 declFilter[i] = false;
00351 if (declFilter.none()) {
00352 report(keyLoc, diag::SUBROUTINE_HAS_NO_SUCH_KEYWORD)
00353 << key << name;
00354 return getInvalidNode();
00355 }
00356 break;
00357 }
00358 }
00359 }
00360 }
00361
00362
00363
00364 for (unsigned i = 0; i < decls.size(); ++i) {
00365 SubroutineDecl *decl = decls[i];
00366 for (unsigned j = 0; j < numArgs && declFilter[i]; ++j) {
00367 Expr *arg = args[j];
00368 unsigned targetIndex = j;
00369
00370 if (KeywordSelector *selector = dyn_cast<KeywordSelector>(args[j])) {
00371 arg = selector->getExpression();
00372 targetIndex = decl->getKeywordIndex(selector->getKeyword());
00373 }
00374
00375 Type *targetType = decl->getArgType(targetIndex);
00376
00377
00378
00379 if (arg->hasType()) {
00380 if (!targetType->equals(arg->getType())) {
00381 declFilter[i] = false;
00382
00383
00384 if (declFilter.none())
00385 report(loc, diag::AMBIGUOUS_EXPRESSION);
00386 }
00387 continue;
00388 }
00389
00390
00391
00392
00393 if (IntegerLiteral *intLit = dyn_cast<IntegerLiteral>(arg)) {
00394 if (!targetType->isIntegerType()) {
00395 declFilter[i] = false;
00396
00397
00398 if (declFilter.none())
00399 report(loc, diag::AMBIGUOUS_EXPRESSION);
00400 }
00401 else {
00402
00403
00404 intLit->setType(targetType);
00405 }
00406 continue;
00407 }
00408
00409 typedef FunctionCallExpr::ConnectiveIterator ConnectiveIter;
00410 bool applicableArgument = false;
00411 FunctionCallExpr *argCall = cast<FunctionCallExpr>(arg);
00412
00413
00414
00415 for (ConnectiveIter iter = argCall->beginConnectives();
00416 iter != argCall->endConnectives(); ++iter) {
00417 FunctionDecl *connective = cast<FunctionDecl>(*iter);
00418 Type *returnType = connective->getReturnType();
00419 if (targetType->equals(returnType)) {
00420 applicableArgument = true;
00421 break;
00422 }
00423 }
00424
00425
00426
00427
00428
00429 if (!applicableArgument) {
00430 declFilter[i] = false;
00431 if (declFilter.none())
00432 report(arg->getLocation(), diag::AMBIGUOUS_EXPRESSION);
00433 }
00434 }
00435 }
00436
00437
00438
00439 if (declFilter.none())
00440 return getInvalidNode();
00441
00442
00443 if (declFilter.count() == 1) {
00444 argNodes.release();
00445 SubroutineDecl *decl = decls[declFilter.find_first()];
00446 Node result = checkSubroutineCall(decl, loc, &args[0], numArgs);
00447 if (result.isValid()) argNodes.release();
00448 return result;
00449 }
00450
00451
00452
00453
00454 if (isa<FunctionDecl>(decls[0])) {
00455 llvm::SmallVector<FunctionDecl*, 4> connectives;
00456 for (unsigned i = 0; i < decls.size(); ++i)
00457 if (declFilter[i])
00458 connectives.push_back(cast<FunctionDecl>(decls[i]));
00459 FunctionCallExpr *call =
00460 new FunctionCallExpr(&connectives[0], connectives.size(),
00461 &args[0], numArgs, loc);
00462 argNodes.release();
00463 return getNode(call);
00464 }
00465 else {
00466 report(loc, diag::AMBIGUOUS_EXPRESSION);
00467 return getInvalidNode();
00468 }
00469 }
00470
00471 Node TypeCheck::checkSubroutineCall(SubroutineDecl *decl, Location loc,
00472 Expr **args, unsigned numArgs)
00473 {
00474 if (decl->getArity() != numArgs) {
00475 report(loc, diag::WRONG_NUM_ARGS_FOR_SUBROUTINE) << decl->getIdInfo();
00476 return getInvalidNode();
00477 }
00478
00479 llvm::SmallVector<Expr*, 4> sortedArgs(numArgs);
00480 unsigned numPositional = 0;
00481
00482
00483 for (unsigned i = 0; i < numArgs; ++i) {
00484 Expr *arg = args[i];
00485
00486 if (KeywordSelector *selector = dyn_cast<KeywordSelector>(arg)) {
00487 IdentifierInfo *key = selector->getKeyword();
00488 Location keyLoc = selector->getLocation();
00489 int keyIdx = decl->getKeywordIndex(key);
00490
00491
00492 if (keyIdx < 0) {
00493 report(keyLoc, diag::SUBROUTINE_HAS_NO_SUCH_KEYWORD)
00494 << key << decl->getIdInfo();
00495 return getInvalidNode();
00496 }
00497
00498
00499
00500
00501 if ((unsigned)keyIdx < numPositional) {
00502 report(keyLoc, diag::PARAM_PROVIDED_POSITIONALLY) << key;
00503 return getInvalidNode();
00504 }
00505
00506
00507
00508 for (unsigned j = numPositional; j < i; ++j) {
00509 KeywordSelector *prevSelector;
00510 prevSelector = cast<KeywordSelector>(args[j]);
00511
00512 if (prevSelector->getKeyword() == key) {
00513 report(keyLoc, diag::DUPLICATE_KEYWORD) << key;
00514 return getInvalidNode();
00515 }
00516 }
00517
00518
00519 sortedArgs[keyIdx] = arg;
00520 }
00521 else {
00522 numPositional++;
00523 sortedArgs[i] = arg;
00524 }
00525 }
00526
00527 if (!checkSubroutineArguments(decl, &sortedArgs[0], numArgs))
00528 return getInvalidNode();
00529
00530 if (FunctionDecl *fdecl = dyn_cast<FunctionDecl>(decl)) {
00531 FunctionCallExpr *call =
00532 new FunctionCallExpr(fdecl, &sortedArgs[0], numArgs, loc);
00533 return getNode(call);
00534 }
00535 else {
00536 ProcedureDecl *pdecl = cast<ProcedureDecl>(decl);
00537 ProcedureCallStmt *call =
00538 new ProcedureCallStmt(pdecl, &sortedArgs[0], numArgs, loc);
00539 return getNode(call);
00540 }
00541 }
00542
00550 bool TypeCheck::checkSubroutineArguments(SubroutineDecl *decl,
00551 Expr **args,
00552 unsigned numArgs)
00553 {
00554
00555 for (unsigned i = 0; i < numArgs; ++i) {
00556 Type *targetType = decl->getArgType(i);
00557 Expr *arg = args[i];
00558 Location argLoc = arg->getLocation();
00559 PM::ParameterMode targetMode = decl->getParamMode(i);
00560
00561 if (KeywordSelector *selector = dyn_cast<KeywordSelector>(arg))
00562 arg = selector->getExpression();
00563
00564 if (!checkExprInContext(arg, targetType))
00565 return false;
00566
00567
00568
00569 if (targetMode == PM::MODE_OUT or targetMode == PM::MODE_IN_OUT) {
00570 if (DeclRefExpr *declRef = dyn_cast<DeclRefExpr>(arg)) {
00571 ValueDecl *vdecl = declRef->getDeclaration();
00572 if (ParamValueDecl *param = dyn_cast<ParamValueDecl>(vdecl)) {
00573
00574
00575 if (param->getParameterMode() == PM::MODE_IN) {
00576 report(argLoc, diag::IN_PARAMETER_NOT_MODE_COMPATABLE)
00577 << param->getString() << targetMode;
00578 return false;
00579 }
00580 }
00581 else {
00582
00583
00584 assert(isa<ObjectDecl>(vdecl) && "Cannot typecheck decl!");
00585 }
00586 continue;
00587 }
00588
00589
00590 report(argLoc, diag::EXPRESSION_NOT_MODE_COMPATABLE) << targetMode;
00591 return false;
00592 }
00593 }
00594 return true;
00595 }
00596
00597
00598
00599
00600
00601
00602 bool TypeCheck::checkExprInContext(Expr *expr, Type *context)
00603 {
00604
00605
00606
00607 if (IntegerLiteral *intLit = dyn_cast<IntegerLiteral>(expr))
00608 return resolveIntegerLiteral(intLit, context);
00609 if (FunctionCallExpr *fcall = dyn_cast<FunctionCallExpr>(expr))
00610 return resolveFunctionCall(fcall, context);
00611
00612
00613
00614 Type *exprTy = expr->getType();
00615 assert(exprTy && "Expression does not have a resolved type!");
00616 if (exprTy->equals(context))
00617 return true;
00618 else {
00619
00620 report(expr->getLocation(), diag::INCOMPATIBLE_TYPES);
00621 return false;
00622 }
00623 }
00624
00625
00626
00627
00628
00629 bool TypeCheck::resolveIntegerLiteral(IntegerLiteral *intLit, Type *context)
00630 {
00631 if (intLit->hasType()) {
00632 assert(intLit->getType()->equals(context) &&
00633 "Cannot resolve literal to different type!");
00634 return true;
00635 }
00636
00637 if (!context->isIntegerType()) {
00638
00639 report(intLit->getLocation(), diag::INCOMPATIBLE_TYPES);
00640 return false;
00641 }
00642
00643
00644
00645 intLit->setType(context);
00646 return true;
00647 }
00648
00649
00650
00651
00652
00653 bool TypeCheck::resolveNullaryFunctionCall(FunctionCallExpr *call,
00654 Type *targetType)
00655 {
00656 assert(call->getNumArgs() == 0 &&
00657 "Call expression has too many arguments!");
00658
00659 typedef FunctionCallExpr::ConnectiveIterator ConnectiveIter;
00660 ConnectiveIter iter = call->beginConnectives();
00661 ConnectiveIter endIter = call->endConnectives();
00662 FunctionDecl *connective = 0;
00663
00664 for ( ; iter != endIter; ++iter) {
00665 FunctionDecl *candidate = *iter;
00666 Type *returnType = candidate->getReturnType();
00667
00668 if (targetType->equals(returnType)) {
00669 if (connective) {
00670 report(call->getLocation(), diag::AMBIGUOUS_EXPRESSION);
00671 return false;
00672 }
00673 else
00674 connective = candidate;
00675 }
00676 }
00677 call->resolveConnective(connective);
00678 return true;
00679 }
00680
00681
00682
00683
00684 bool TypeCheck::resolveFunctionCall(FunctionCallExpr *call, Type *targetType)
00685 {
00686 if (!call->isAmbiguous()) {
00687
00688
00689
00690
00691 if (!call->getType()->equals(targetType)) {
00692 report(call->getLocation(), diag::INCOMPATIBLE_TYPES);
00693 return false;
00694 }
00695 return true;
00696 }
00697
00698 if (call->getNumArgs() == 0)
00699 return resolveNullaryFunctionCall(call, targetType);
00700
00701 typedef FunctionCallExpr::ConnectiveIterator ConnectiveIter;
00702 ConnectiveIter iter = call->beginConnectives();
00703 ConnectiveIter endIter = call->endConnectives();
00704 FunctionDecl *fdecl = 0;
00705
00706 for ( ; iter != endIter; ++iter) {
00707 FunctionDecl *candidate = cast<FunctionDecl>(*iter);
00708 Type *returnType = candidate->getReturnType();
00709 if (targetType->equals(returnType)) {
00710 if (fdecl) {
00711 report(call->getLocation(), diag::AMBIGUOUS_EXPRESSION);
00712 return false;
00713 }
00714 else
00715 fdecl = candidate;
00716 }
00717 }
00718
00719
00720
00721 if (!fdecl) {
00722 report(call->getLocation(), diag::AMBIGUOUS_EXPRESSION);
00723 return false;
00724 }
00725 else {
00726
00727 call->resolveConnective(fdecl);
00728 }
00729
00730
00731
00732
00733
00734 bool status = true;
00735 unsigned numArgs = call->getNumArgs();
00736 llvm::SmallVector<Expr*, 8> sortedArgs(numArgs);
00737
00738 for (unsigned i = 0; i < call->getNumArgs(); ++i) {
00739 unsigned argIndex = i;
00740 Expr *arg = call->getArg(i);
00741
00742
00743
00744 if (KeywordSelector *select = dyn_cast<KeywordSelector>(arg)) {
00745 arg = select->getExpression();
00746 argIndex = fdecl->getKeywordIndex(select->getKeyword());
00747 sortedArgs[argIndex] = select;
00748 }
00749 else
00750 sortedArgs[argIndex] = arg;
00751
00752 status = status and
00753 checkExprInContext(arg, fdecl->getArgType(argIndex));
00754 }
00755
00756 return status;
00757 }
00758
00759 Node TypeCheck::acceptInj(Location loc, Node exprNode)
00760 {
00761 Expr *expr = cast_node<Expr>(exprNode);
00762 Domoid *domoid = getCurrentDomoid();
00763
00764 if (!domoid) {
00765 report(loc, diag::INVALID_INJ_CONTEXT);
00766 return getInvalidNode();
00767 }
00768
00769
00770 DomainType *domTy = domoid->getPercent();
00771 Type *exprTy = expr->getType();
00772 if (!domTy->equals(exprTy)) {
00773 report(loc, diag::INCOMPATIBLE_TYPES);
00774 return getInvalidNode();
00775 }
00776
00777
00778 CarrierDecl *carrier = domoid->getImplementation()->getCarrier();
00779 if (!carrier) {
00780 report(loc, diag::CARRIER_TYPE_UNDEFINED);
00781 return getInvalidNode();
00782 }
00783
00784 exprNode.release();
00785 return getNode(new InjExpr(expr, carrier->getType(), loc));
00786 }
00787
00788 Node TypeCheck::acceptPrj(Location loc, Node exprNode)
00789 {
00790 Expr *expr = cast_node<Expr>(exprNode);
00791 Domoid *domoid = getCurrentDomoid();
00792
00793 if (!domoid) {
00794 report(loc, diag::INVALID_PRJ_CONTEXT);
00795 return getInvalidNode();
00796 }
00797
00798
00799 CarrierDecl *carrier = domoid->getImplementation()->getCarrier();
00800 if (!carrier) {
00801 report(loc, diag::CARRIER_TYPE_UNDEFINED);
00802 return getInvalidNode();
00803 }
00804
00805
00806 Type *carrierTy = carrier->getType();
00807 Type *exprTy = expr->getType();
00808 if (!carrierTy->equals(exprTy)) {
00809 report(loc, diag::INCOMPATIBLE_TYPES);
00810 return getInvalidNode();
00811 }
00812
00813 exprNode.release();
00814 return getNode(new PrjExpr(expr, domoid->getPercent(), loc));
00815 }
00816
00817 Node TypeCheck::acceptIntegerLiteral(llvm::APInt &value, Location loc)
00818 {
00819
00820
00821
00822
00823
00824
00825
00826 assert((value == 0 || value.countLeadingZeros() == 0) &&
00827 "Unexpected literal representation!");
00828
00829 if (value != 0)
00830 value.zext(value.getBitWidth() + 1);
00831
00832 return getNode(new IntegerLiteral(value, loc));
00833 }