Example #1
0
	insieme::core::TypePtr autoReturnType(NodeManager& nodeMan, const CompoundStmtPtr& body) {
		auto debug = false;
		if(debug) { std::cout << "{{{{{{ autoReturnType ----\n"; }

		// find all returns
		TypePtr newReturnType = nodeMan.getLangBasic().getUnit();
		auto returns = analysis::getFreeNodes(body, NT_ReturnStmt, toVector(NT_LambdaExpr, NT_JobExpr, NT_ReturnStmt));
		if(debug) { std::cout << "{{{{{{{{{{{{{ Returns: " << returns << "\n"; }

		// if no returns, unit is fine
		if(!returns.empty()) {
			auto typeList = ::transform(returns, [](const NodePtr& ret) { return ret.as<ReturnStmtPtr>()->getReturnExpr()->getType(); });
			if(debug) { std::cout << "{{{{{{{{{{{{{ typeList: " << typeList << "\n"; }

			newReturnType = types::getSmallestCommonSuperType(typeList);
			if(debug) { std::cout << "{{{{{{{{{{{{{ returnType: " << newReturnType << "\n"; }

			assert_true(newReturnType) << "Return type deduction, multiple return types have no common supertype.";
		}

		return newReturnType;
	}
Example #2
0
	std::map<NodePtr,precedence_container> create_precedence_map(NodeManager& nm)
	{

		auto& lang = nm.getLangBasic();
		auto& refs = nm.getLangExtension<lang::ReferenceExtension>();

		std::map<NodePtr, precedence_container> m;

		m[refs.getGenPostInc()] = {2,0};
		m[refs.getGenPostDec()] = {2,0};
		m[lang.getBoolLNot()] = {3,1};
		m[lang.getSignedIntNot()] = {3,1};
		m[lang.getUnsignedIntNot()] = {3,1};
		m[refs.getGenPreInc()] = {3,1};
		m[refs.getGenPreDec()] = {3,1};
		m[lang.getSignedIntMul()] = {5,0};
		m[lang.getGenMul()] = {5,0};
		m[lang.getUnsignedIntMul()] = {5,0};
		m[lang.getRealMul()] = {5,0};
		m[lang.getCharMul()] = {5,0};
		m[lang.getSignedIntMod()] = {5,0};
		m[lang.getGenMod()] = {5,0};
		m[lang.getUnsignedIntMod()] = {5,0};
		m[lang.getCharMod()] = {5,0};
		m[lang.getSignedIntDiv()] = {5,0};
		m[lang.getGenDiv()] = {5,0};
		m[lang.getUnsignedIntDiv()] = {5,0};
		m[lang.getRealDiv()] = {5,0};
		m[lang.getCharDiv()] = {5,0};
		m[lang.getSignedIntAdd()] = {6,0};
		m[lang.getGenAdd()] = {6,0};
		m[lang.getUnsignedIntAdd()] = {6,0};
		m[lang.getRealAdd()] = {6,0};
		m[lang.getCharAdd()] = {6,0};
		m[lang.getSignedIntSub()] = {6,0};
		m[lang.getGenSub()] = {6,0};
		m[lang.getUnsignedIntSub()] = {6,0};
		m[lang.getRealSub()] = {6,0};
		m[lang.getCharSub()] = {6,0};
		m[lang.getSignedIntLShift()] = {7,0};
		m[lang.getGenLShift()] = {7,0};
		m[lang.getSignedIntRShift()] = {7,0};
		m[lang.getGenRShift()] = {7,0};
		m[lang.getUnsignedIntLShift()] = {7,0};
		m[lang.getUnsignedIntRShift()] = {7,0};
		m[lang.getSignedIntLt()] = {8,0};
		m[lang.getGenLt()] = {8,0};
		m[lang.getRealLt()] = {8,0};
		m[lang.getUnsignedIntLt()] = {8,0};
		m[lang.getCharLt()] = {8,0};
		m[lang.getSignedIntLe()] = {8,0};
		m[lang.getGenLe()] = {8,0};
		m[lang.getRealLe()] = {8,0};
		m[lang.getUnsignedIntLe()] = {8,0};
		m[lang.getCharLe()] = {8,0};
		m[lang.getSignedIntGt()] = {8,0};
		m[lang.getGenGt()] = {8,0};
		m[lang.getRealGt()] = {8,0};
		m[lang.getUnsignedIntGt()] = {8,0};
		m[lang.getCharGt()] = {8,0};
		m[lang.getSignedIntGe()] = {8,0};
		m[lang.getGenGe()] = {8,0};
		m[lang.getRealGe()] = {8,0};
		m[lang.getUnsignedIntGe()] = {8,0};
		m[lang.getCharGe()] = {8,0};
		m[lang.getSignedIntEq()] = {9,0};
		m[lang.getGenEq()] = {9,0};
		m[lang.getRealEq()] = {9,0};
		m[lang.getUnsignedIntEq()] = {9,0};
		m[lang.getCharEq()] = {9,0};
		m[lang.getBoolEq()] = {9,0};
		m[lang.getTypeEq()] = {9,0};
		m[lang.getSignedIntNe()] = {9,0};
		m[lang.getGenNe()] = {9,0};
		m[lang.getUnsignedIntNe()] = {9,0};
		m[lang.getCharNe()] = {9,0};
		m[lang.getBoolNe()] = {9,0};
		m[lang.getRealNe()] = {9,0};
		m[lang.getSignedIntAnd()] = {10,0};
		m[lang.getGenAnd()] = {10,0};
		m[lang.getUnsignedIntAnd()] = {10,0};
		m[lang.getBoolAnd()] = {10,0};
		m[lang.getSignedIntXor()] = {11,0};
		m[lang.getGenXor()] = {11,0};
		m[lang.getUnsignedIntXor()] = {11,0};
		m[lang.getBoolXor()] = {11,0};
		m[lang.getSignedIntOr()] = {12,0};
		m[lang.getGenOr()] = {12,0};
		m[lang.getUnsignedIntOr()] = {12,0};
		m[lang.getBoolOr()] = {12,0};
		m[lang.getBoolLAnd()] = {13,0};
		m[lang.getBoolLOr()] = {14,0};

		return m;
	}
Example #3
0
	ExpressionPtr buildArrayCreate(NodeManager& mgr, size_t size, const ExpressionList& list) {
		auto& basic = mgr.getLangBasic();
		IRBuilder builder(mgr);
		auto sizeType = builder.numericType(Literal::get(mgr, basic.getUIntInf(), toString(size)));
		return buildArrayCreate(sizeType, list);
	}