int EventTransition::compareTo(EventTransition* object) { EventTransition* otherEntry; if (object->instanceOf("EventTransition")) { otherEntry = (EventTransition*)object; if (otherEntry->time < 0 && time >= 0) { return -1; } else if (time < 0 && otherEntry->time >= 0) { return 1; } else if (time < 0 && otherEntry->time < 0) { return compareType(otherEntry); } else if (time < otherEntry->time) { return -1; } else if (time > otherEntry->time) { return 1; } else { return compareType(otherEntry); } } else { return -1; } return -1; }
static int compareExt(const void* arg1, const void* arg2) { const WIN32_FIND_DATA* fd1 = &(*(ShellEntry**)arg1)->_data; const WIN32_FIND_DATA* fd2 = &(*(ShellEntry**)arg2)->_data; const TCHAR *name1, *name2, *ext1, *ext2; int cmp = compareType(fd1, fd2); if (cmp) return cmp; name1 = fd1->cFileName; name2 = fd2->cFileName; ext1 = _tcsrchr(name1, TEXT('.')); ext2 = _tcsrchr(name2, TEXT('.')); if (ext1) ++ext1; else ext1 = TEXT(""); if (ext2) ++ext2; else ext2 = TEXT(""); cmp = lstrcmpi(ext1, ext2); if (cmp) return cmp; return lstrcmpi(name1, name2); }
static int compareExt(const void* arg1, const void* arg2) { const Entry* entry1 = *(const Entry**)arg1; const Entry* entry2 = *(const Entry**)arg2; const TCHAR *name1, *name2, *ext1, *ext2; int cmp = compareType(entry1, entry2); if (cmp) return cmp; name1 = entry1->_data.cFileName; name2 = entry2->_data.cFileName; ext1 = _tcsrchr(name1, TEXT('.')); ext2 = _tcsrchr(name2, TEXT('.')); if (ext1) ++ext1; else ext1 = TEXT(""); if (ext2) ++ext2; else ext2 = TEXT(""); cmp = lstrcmpi(ext1, ext2); if (cmp) return cmp; return lstrcmpi(name1, name2); }
void checkTypeEquality(Type* type1, Type* type2) { if(type1->typeClass == TP_FLOAT && type2->typeClass == TP_INT){ return; } if (compareType(type1, type2) == 0){ error(ERR_TYPE_INCONSISTENCY, currentToken->lineNo, currentToken->colNo); } }
int compareType(Type* type1, Type* type2) { if (type1->typeClass == type2->typeClass) { if (type1->typeClass == TP_ARRAY) { if (type1->arraySize == type2->arraySize) return compareType(type1->elementType, type2->elementType); else return 0; } else return 1; } else return 0; }
static int compareName(const void* arg1, const void* arg2) { const WIN32_FIND_DATA* fd1 = &(*(ShellEntry**)arg1)->_data; const WIN32_FIND_DATA* fd2 = &(*(ShellEntry**)arg2)->_data; int cmp = compareType(fd1, fd2); if (cmp) return cmp; return lstrcmpi(fd1->cFileName, fd2->cFileName); }
static int compareDate(const void* arg1, const void* arg2) { const Entry* entry1 = *(const Entry**)arg1; const Entry* entry2 = *(const Entry**)arg2; int cmp = compareType(entry1, entry2); if (cmp) return cmp; return CompareFileTime(&entry2->_data.ftLastWriteTime, &entry1->_data.ftLastWriteTime); }
static int compareName(const void* arg1, const void* arg2) { const Entry* entry1 = *(const Entry**)arg1; const Entry* entry2 = *(const Entry**)arg2; int cmp = compareType(entry1, entry2); if (cmp) return cmp; return lstrcmpi(entry1->_data.cFileName, entry2->_data.cFileName); }
static int compareDate(const void* arg1, const void* arg2) { WIN32_FIND_DATA* fd1 = &(*(ShellEntry**)arg1)->_data; WIN32_FIND_DATA* fd2 = &(*(ShellEntry**)arg2)->_data; int cmp = compareType(fd1, fd2); if (cmp) return cmp; return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime); }
int compareType(Type* type1, Type* type2) { if (type1->typeClass == type2->typeClass) { if (type1->typeClass == TP_ARRAY) { if (!(type1->arraySize == type2->arraySize && compareType(type1->elementType, type2->elementType))) return 0; } return 1; } return 0; }
DataType typeCheckFactor(SyntaxNode *parent) { //test if the left is null indicating that there is no math if(parent->nodeField.factor.leftFactor == NULL) { return typeCheckSubFactor(parent->nodeField.factor.rightSubFactor); } else { DataType factorType = typeCheckFactor(parent->nodeField.factor.leftFactor); DataType subFactorType = typeCheckSubFactor(parent->nodeField.factor.rightSubFactor); if(compareType(subFactorType, factorType) == 0) { return factorType; } else { fprintf(stderr, "Error: defined as incorrect type at factor level.\n"); exit(1); return -1; } } }
static int compareSize(const void* arg1, const void* arg2) { const Entry* entry1 = *(const Entry**)arg1; const Entry* entry2 = *(const Entry**)arg2; int cmp = compareType(entry1, entry2); if (cmp) return cmp; cmp = entry2->_data.nFileSizeHigh - entry1->_data.nFileSizeHigh; if (cmp < 0) return -1; else if (cmp > 0) return 1; cmp = entry2->_data.nFileSizeLow - entry1->_data.nFileSizeLow; return cmp<0? -1: cmp>0? 1: 0; }
static int compareSize(const void* arg1, const void* arg2) { WIN32_FIND_DATA* fd1 = &(*(ShellEntry**)arg1)->_data; WIN32_FIND_DATA* fd2 = &(*(ShellEntry**)arg2)->_data; int cmp = compareType(fd1, fd2); if (cmp) return cmp; cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh; if (cmp < 0) return -1; else if (cmp > 0) return 1; cmp = fd2->nFileSizeLow - fd1->nFileSizeLow; return cmp<0? -1: cmp>0? 1: 0; }
Symbol* Parser::resolveOverload(Symbol* firstCandidate, List<ExpressionAST*>* actuals) { auto bestCandidate = firstCandidate; auto functionName = firstCandidate->unqualifiedName(); size_t argc = 0; for (auto it = actuals; it; it = it->next) // ### TODO remove this loop ++argc; std::vector<Symbol*> candidates; candidates.push_back(bestCandidate); for (Symbol* candidate = firstCandidate->next(); candidate; candidate = candidate->next()) { if (candidate->unqualifiedName() != functionName) continue; auto funTy = candidate->type()->asFunctionType(); if (! funTy) continue; auto&& funArgumentTypes = funTy->argumentTypes(); if (funArgumentTypes.size() != argc) // ### TODO variadic continue; auto bestFunTy = bestCandidate->type()->asFunctionType(); auto&& bestArgumentTypes = bestFunTy->argumentTypes(); assert(funArgumentTypes.size() == bestArgumentTypes.size()); // ### TODO variadic int bestScore = 0, funScore = 0; auto it = actuals; for (size_t index = 0, end = funArgumentTypes.size(); index != end; ++index, it = it->next) { assert(it->value); auto delta = compareType(it->value, bestArgumentTypes[index], funArgumentTypes[index]); if (delta < 0) ++bestScore; else if (delta > 0) ++funScore; } if (funScore < bestScore) continue; if (funScore > bestScore) { candidates.clear(); bestCandidate = candidate; } candidates.push_back(candidate); } if (candidates.size() == 1) return candidates.front(); return nullptr; }
DataType typeCheckExp(SyntaxNode *parent) { //test if left is null indicating that it is not arithametic if(parent->nodeField.exp.leftExp == NULL) { return typeCheckFactor(parent->nodeField.exp.rightFactor); } else { DataType expType = typeCheckExp(parent->nodeField.exp.leftExp); DataType factorType = typeCheckFactor(parent->nodeField.exp.rightFactor); if(compareType(expType, factorType) == 0) { return expType; } else { fprintf(stderr, "Error: defined as incorrect type at exp level.\n"); printTypeError(parent->nodeField.exp.leftExp, parent->nodeField.exp.rightFactor); exit(1); return -1; } } }
DataType typeCheckAssig(SyntaxNode *parent) { SyntaxNode *assigned = parent->nodeField.assignment.assigned; SyntaxNode *expression = parent->nodeField.assignment.exp; DataType assignedType = assigned->dataType; DataType expType = typeCheckExp(expression); if(assignedType == -1 || expType == -1) { fprintf(stderr, "Error: defined as incorrect type at assignment level.\n"); exit(1); return -1; } else if(compareType(assignedType, expType) == 0) { return assignedType; } else { fprintf(stderr, "Error: defined as incorrect type at assignment level.\n"); printTypeError(assigned, expression); exit(1); return -1; } }
void checkTypeEquality(Type* type1, Type* type2) { if (compareType(type1, type2) == 0){ error(ERR_TYPE_INCONSISTENCY, currentToken->lineNo, currentToken->colNo); } }
static void forward_lospre_assignment(G_t &G, typename boost::graph_traits<G_t>::vertex_descriptor i, const iCode *ic, const assignment_lospre& a) { typedef typename boost::graph_traits<G_t>::adjacency_iterator adjacency_iter_t; adjacency_iter_t c, c_end; operand *tmpop = IC_RIGHT(ic); const std::pair<int, int> forward(IC_RESULT(ic)->key, IC_RIGHT(ic)->key); for(;;) { if (G[i].forward == forward) break; // Was here before. iCode *nic = G[i].ic; if (isOperandEqual(IC_RESULT(ic), IC_LEFT(nic)) && nic->op != ADDRESS_OF && (!POINTER_GET(nic) || !IS_PTR(operandType(IC_RESULT(nic))) || !IS_BITFIELD(operandType(IC_LEFT(nic))->next) || compareType(operandType(IC_LEFT(nic)), operandType(tmpop)) == 1)) { bool isaddr = IC_LEFT (nic)->isaddr; #ifdef DEBUG_LOSPRE std::cout << "Forward substituted left operand " << OP_SYMBOL_CONST(IC_LEFT(nic))->name << " at " << nic->key << "\n"; #endif //bitVectUnSetBit (OP_SYMBOL (IC_LEFT (nic))->uses, nic->key); IC_LEFT(nic) = operandFromOperand (tmpop); //bitVectSetBit (OP_SYMBOL (IC_LEFT (nic))->uses, nic->key); IC_LEFT (nic)->isaddr = isaddr; } if (isOperandEqual(IC_RESULT(ic), IC_RIGHT(nic))) { #ifdef DEBUG_LOSPRE std::cout << "Forward substituted right operand " << OP_SYMBOL_CONST(IC_RIGHT(nic))->name << " at " << nic->key << "\n"; #endif //bitVectUnSetBit (OP_SYMBOL (IC_RIGHT (nic))->uses, nic->key); IC_RIGHT(nic) = operandFromOperand (tmpop); //bitVectSetBit (OP_SYMBOL (IC_RIGHT (nic))->uses, nic->key); } if (POINTER_SET(nic) && isOperandEqual(IC_RESULT(ic), IC_RESULT(nic)) && (!IS_PTR(operandType(IC_RESULT(nic))) || !IS_BITFIELD(operandType(IC_RESULT(nic))->next) || compareType(operandType(IC_RESULT(nic)), operandType(tmpop)) == 1)) { #ifdef DEBUG_LOSPRE std::cout << "Forward substituted result operand " << OP_SYMBOL_CONST(IC_RESULT(nic))->name << " at " << nic->key << "\n"; #endif //bitVectUnSetBit (OP_SYMBOL (IC_RESULT (nic))->uses, nic->key); IC_RESULT(nic) = operandFromOperand (tmpop); IC_RESULT(nic)->isaddr = true; //bitVectSetBit (OP_SYMBOL (IC_RESULT (nic))->uses, nic->key); } if (nic->op == LABEL) // Reached label. Continue only if all edges goining here are safe. { typedef typename boost::graph_traits<G_t>::in_edge_iterator in_edge_iter_t; in_edge_iter_t e, e_end; for (boost::tie(e, e_end) = boost::in_edges(i, G); e != e_end; ++e) if (G[boost::source(*e, G)].forward != forward) break; if(e != e_end) break; } if (isOperandEqual(IC_RESULT (ic), IC_RESULT(nic)) && !POINTER_SET(nic) /*|| G[i].uses*/) break; if ((nic->op == CALL || nic->op == PCALL || POINTER_SET(nic)) && IS_TRUE_SYMOP(IC_RESULT(ic))) break; G[i].forward = forward; if (nic->op == GOTO || nic->op == IFX || nic->op == JUMPTABLE) { adjacency_iter_t c, c_end; for(boost::tie(c, c_end) = boost::adjacent_vertices(i, G); c != c_end; ++c) { if(!((a.global[i] & true) && !G[i].invalidates) && (a.global[*c] & true)) // Calculation edge continue; forward_lospre_assignment(G, *c, ic, a); } break; } boost::tie(c, c_end) = adjacent_vertices(i, G); if(c == c_end) break; if(!((a.global[i] & true) && !G[i].invalidates) && (a.global[*c] & true)) // Calculation edge break; i = *c; } }
/*-----------------------------------------------------------------*/ static void convilong (iCode * ic, eBBlock * ebp, sym_link * type, int op) { symbol *func = NULL; iCode *ip = ic->next; iCode *newic; int lineno = ic->lineno; int bwd; int su; int bytesPushed=0; remiCodeFromeBBlock (ebp, ic); /* depending on the type */ for (bwd = 0; bwd < 3; bwd++) { for (su = 0; su < 2; su++) { if (compareType (type, __multypes[bwd][su]) == 1) { if (op == '*') func = __muldiv[0][bwd][su]; else if (op == '/') func = __muldiv[1][bwd][su]; else if (op == '%') func = __muldiv[2][bwd][su]; else if (op == RRC) func = __rlrr[1][bwd][su]; else if (op == RLC) func = __rlrr[0][bwd][su]; else if (op == RIGHT_OP) func = __rlrr[1][bwd][su]; else if (op == LEFT_OP) func = __rlrr[0][bwd][su]; else assert (0); goto found; } } } assert (0); found: /* if int & long support routines NOT compiled as reentrant */ if (!options.intlong_rent) { /* first one */ if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_LEFT (ic), NULL); else { newic = newiCode ('=', NULL, IC_LEFT (ic)); IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* second one */ if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { newic = newiCode ('=', NULL, IC_RIGHT (ic)); IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; } else { /* compiled as reentrant then push */ /* push right */ if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) { newic = newiCode (SEND, IC_RIGHT (ic), NULL); } else { newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); newic->parmPush = 1; bytesPushed += getSize(operandType(IC_RIGHT(ic))); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* insert push left */ if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { newic = newiCode (SEND, IC_LEFT (ic), NULL); } else { newic = newiCode (IPUSH, IC_LEFT (ic), NULL); newic->parmPush = 1; bytesPushed += getSize(operandType(IC_LEFT(ic))); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; } /* for the result */ newic = newiCode (CALL, operandFromSymbol (func), NULL); IC_RESULT (newic) = IC_RESULT (ic); newic->lineno = lineno; newic->parmBytes+=bytesPushed; // to clear the stack after the call addiCodeToeBBlock (ebp, newic, ip); }
/*-----------------------------------------------------------------*/ static void cnvFromFloatCast (iCode * ic, eBBlock * ebp) { iCode *ip, *newic; symbol *func; sym_link *type = operandType (IC_LEFT (ic)); int lineno = ic->lineno; int bwd, su; ip = ic->next; /* remove it from the iCode */ remiCodeFromeBBlock (ebp, ic); /* depending on the type */ for (bwd = 0; bwd < 3; bwd++) { for (su = 0; su < 2; su++) { if (compareType (type, __multypes[bwd][su]) == 1) { func = __conv[1][bwd][su]; goto found; } } } assert (0); found: /* if float support routines NOT compiled as reentrant */ if (!options.float_rent) { /* first one */ if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { newic = newiCode ('=', NULL, IC_RIGHT (ic)); IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; } else { /* push the left */ if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) newic = newiCode (SEND, IC_RIGHT (ic), NULL); else { newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); newic->parmPush = 1; } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; } /* make the call */ newic = newiCode (CALL, operandFromSymbol (func), NULL); IC_RESULT (newic) = IC_RESULT (ic); addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; }