Ejemplo n.º 1
0
bool ReturnNode::checkReturn(DataType returnType, SemanticDebugger *semanticDebugger)
{
    if(returnType != DATA_TYPE_UNDEFINED && returnType != DATA_TYPE_VOID)
    {
        DataType expressionType = this->expression_->typeCheck(semanticDebugger);
        this->returnType_ = expressionType;

        if(expressionType != returnType && expressionType != DATA_TYPE_ERROR)
        {
            const char *returnTypeName = getDataTypeName(returnType);
            const char *expressionTypeName = getDataTypeName(expressionType);

            semanticDebugger->debugTypeMismatchError("return",
                    returnTypeName,
                    expressionTypeName,
                    this->expression_->getFirstLine());
        }
        else if(expressionType == returnType && this->expression_->isConstant())
        {
            this->expression_ = this->expression_->getConstantExpression();
        }
    }
    else if(returnType ==DATA_TYPE_VOID)
    {
        semanticDebugger->debugReturnInProcedureError(this->getFirstLine());
    }
    else
    {
        semanticDebugger->debugReturnOutOfFunctionError(this->getFirstLine());
    }

    return true;
}
Ejemplo n.º 2
0
void Db::createTable(const Table& table) {
    table.assertNonMutable();
    std::string sql;
    if (!table.check()) {
        throw std::invalid_argument("The Table definition is invalid");
    }
    sql.append("CREATE ");
    if(table.isTemporary()) {
        sql.append("TEMPORARY ");
    }
    sql.append(" TABLE ").append(table.getName()).append("( ");
    if (table.isAutoPK()) {
        sql.append("id INTEGER PRIMARY KEY ASC, ");
    }
    const std::vector<std::string>& column_name(table.getColumnName());
    const std::vector<DataType>& column_type(table.getColumnType());
    for(size_t i; i < column_name.size(); i++) {
        sql.append(column_name[i]). append(" ").append(getDataTypeName(column_type[i])).append(" ");
        if (i == table.getPK() & !table.isAutoPK()) {
            sql.append("PRIMARY KEY, ");
        }
        else {
            sql.append(", ");
        }
    }
    sql.resize(sql.size() - 2);
    sql.append(");");
    this->exec(sql);
}
Ejemplo n.º 3
0
void interpreteByteCode(char *buf, int length)
{
	char *progBuf = buf;
	char *stop = progBuf + length;
	struct instruction instruct;
	long offset;
	long count;
	long l;
	double d;
	enum data_type type;

	while (progBuf < stop) {
		/*get instruction info*/
		printf("Offset: %ld\n", progBuf - buf);
		instruct = GetInstructionAndAdvance(progBuf);
		printf("OP[%X]: %s\n", instruct.opType, getName(instruct.opType));
		switch (instruct.opType) {
			case iJMP:
			case iJMPF:
			case iJMPT:
			case iLVPUSH:
			case iGVPUSH:
				offset = GetTypeAndAdvance(progBuf, long);
				printf("\toffset: %ld\n", offset);
				break;
			case iIPUSH:
				l = GetTypeAndAdvance(progBuf, long);
				printf("\tValue: %ld\n", l);
				break;
			case iFPUSH:
				d = GetTypeAndAdvance(progBuf, double);
				printf("\tValue: %lf\n", d);
				break;

			case iVALLOC:
			case iVDALLOC:
				count = GetTypeAndAdvance(progBuf, long);
				printf("\tCount: %ld\n", count);
				break;


			case iVSETTYPE:
				offset = GetTypeAndAdvance(progBuf, long);
				type = GetTypeAndAdvance(progBuf, enum datasource);
				printf("\tOffset: %ld\n", offset);
				printf("\tType: %s\n", getDataTypeName(type));
				break;
			default:
				break;
		}

	}
}
Ejemplo n.º 4
0
PropertyHelper<UBox>::return_type
PropertyHelper<UBox>::fromString(const String& str)
{
    UBox ret(UDim(0.0f, 0.0f), UDim(0.0f, 0.0f), UDim(0.0f, 0.0f), UDim(0.0f, 0.0f));

    if (str.empty())
        return ret;

    std::stringstream& sstream = SharedStringstream::GetPreparedStream(str);
    sstream >> ret;
    if (sstream.fail())
        throwParsingException(getDataTypeName(), str);

    return ret;
}
Ejemplo n.º 5
0
PropertyHelper<URect>::return_type
PropertyHelper<URect>::fromString(const String& str)
{
    URect ur(UVector2(UDim(0.0f, 0.0f), UDim(0.0f, 0.0f)), UVector2(UDim(0.0f, 0.0f), UDim(0.0f, 0.0f)));

    if (str.empty())
        return ur;

    std::stringstream& sstream = SharedStringstream::GetPreparedStream(str);
    sstream >> ur;
    if (sstream.fail())
        throwParsingException(getDataTypeName(), str);

    return ur;
}
Ejemplo n.º 6
0
PropertyHelper<UDim>::return_type
PropertyHelper<UDim>::fromString(const String& str)
{
    UDim ud(0.0f, 0.0f);

    if (str.empty())
        return ud;

    std::stringstream& sstream = SharedStringstream::GetPreparedStream(str);
    sstream >> ud;
    if (sstream.fail())
        throwParsingException(getDataTypeName(), str);

    return ud;
}
Ejemplo n.º 7
0
PropertyHelper<float>::return_type
PropertyHelper<float>::fromString(const String& str)
{
    float val = 0.0f;

    if (str.empty())
        return val;

    std::stringstream& sstream = SharedStringstream::GetPreparedStream(str);
    sstream >> val;
    if (sstream.fail())
        throwParsingException(getDataTypeName(), str);

    return val;
}
void FormalParameterInformation::debug(SymbolTableDebugger *symbolTableDebugger)
{
    const char *categoryTypeName = getIdentifierCategoryTypeName( this->getCategoryType() );
    const char *typeName = getDataTypeName( this->getType() );

    stringstream scopeLevelStr;
    scopeLevelStr << this->getScopeLevel();

    symbolTableDebugger->debugIdentifierInfo(categoryTypeName);
    symbolTableDebugger->debugIdentifierInfoAttribute("Identifier", this->getIdentifier());
    symbolTableDebugger->debugIdentifierInfoAttribute("Type", typeName);
    symbolTableDebugger->debugIdentifierInfoAttribute("Scope Level", scopeLevelStr.str().c_str());

    symbolTableDebugger->newLine();

}
Ejemplo n.º 9
0
void FunctionNode::debug(ASTDebugger * astDebugger, int nodeLevel)
{
    astDebugger->openParentNode("Function/Procedure", nodeLevel);

    string functionIdentifier = "Identifier: ";
    functionIdentifier += getIdentifier();

    string functionReturnType = "Return Type: ";
    functionReturnType += getDataTypeName( getReturnType() );

    astDebugger->insertLeafNode(functionIdentifier.c_str(), nodeLevel + 1);
    astDebugger->insertLeafNode(functionReturnType.c_str(), nodeLevel + 1);

    this->declarations_->debug(astDebugger, nodeLevel + 1);
    this->statements_->debug(astDebugger, nodeLevel + 1);

    astDebugger->closeParentNode("Function/Procedure", nodeLevel);
}
Ejemplo n.º 10
0
/// override the default display just so we can overlay a bit more text
void TerrainDemo::renderme(void)
{
	// give base class a shot
	DemoApplication::renderme();

	// overlay any debug information
	if (m_dynamicsWorld)
		m_dynamicsWorld->debugDrawWorld();

	// switch to orthographic
	setOrthographicProjection();

	// we'll draw on the right top of the screen
	const int lineWidth = 200;
	const int lineHeight = 16;
	char buffer[256];

	int xStart = m_glutScreenWidth - lineWidth;
	int yStart = lineHeight;

	sprintf(buffer, "Terrain Type: %s", getTerrainTypeName(m_model));
	doPrint(xStart, yStart, lineHeight, buffer);
	doPrint(xStart, yStart, lineHeight, "Press ',' to cycle terrain types");
	doPrint(xStart, yStart, lineHeight, "");

	sprintf(buffer, "Data Type: %s", getDataTypeName(m_type));
	doPrint(xStart, yStart, lineHeight, buffer);
	doPrint(xStart, yStart, lineHeight, "Press '/' to cycle data types");
	doPrint(xStart, yStart, lineHeight, "");

	sprintf(buffer, "'up' axis: %s", getUpAxisName(m_upAxis));
	doPrint(xStart, yStart, lineHeight, buffer);
	doPrint(xStart, yStart, lineHeight, "Press '\\' to cycle 'up' axes");
	doPrint(xStart, yStart, lineHeight, "");

	if (eRadial == m_model) {
		sprintf(buffer, "Dynamic: %s", m_isDynamic ? "yes" : "no");
		doPrint(xStart, yStart, lineHeight, buffer);
		doPrint(xStart, yStart, lineHeight, "Press '[' to toggle dynamics");
	}
}
Ejemplo n.º 11
0
PropertyHelper<Font*>::return_type
PropertyHelper<Font*>::fromString(const String& str)
{
    // handle empty string case
    if (str.empty())
        return 0;

    PropertyHelper<Font*>::return_type image;

    try
    {
        image = &FontManager::getSingleton().get(str);
    }
    catch (UnknownObjectException&)
    {
        image = 0;
        throwParsingException(getDataTypeName(), str);
    }

    return image;
}
Ejemplo n.º 12
0
void FunctionNode::typeCheck(SemanticDebugger *semanticDebugger)
{
    DataType returnType = this->getReturnType();
    bool inRepetition = false;

    this->declarations_->typeCheck(semanticDebugger);

    this->statements_->typeCheck(semanticDebugger);
    this->statements_->checkRepetition(inRepetition, semanticDebugger);

    if(!this->statements_->checkReturn(returnType, semanticDebugger))
    {
        if(returnType != DATA_TYPE_VOID)
        {
            semanticDebugger->debugMissingReturnError(this->getIdentifier(),
                    getDataTypeName(returnType),
                    this->getFirstLine());
        }

    }
}
Ejemplo n.º 13
0
PropertyHelper<ColourRect>::return_type
PropertyHelper<ColourRect>::fromString(const String& str)
{
    ColourRect val(Colour(0xFF000000));

    if (str.empty())
         return val;

    std::stringstream& sstream = SharedStringstream::GetPreparedStream(str);

    if (str.length() == 8)
    {
        CEGUI::Colour colourForEntireRect(0xFF000000);

        sstream >> colourForEntireRect;
        if (sstream.fail())
            throwParsingException(getDataTypeName(), str);

        val = ColourRect(colourForEntireRect);

        return val;
    }
Ejemplo n.º 14
0
DataType FunctionCallNode::typeCheck(SemanticDebugger *semanticDebugger)
{
    list<ExpressionNode *> &expList = this->actualParameterList_->getActualParameterList();
    list<FormalParameterInformation *> &parList = this->functionInfo_->getFormalParameterList();

    if(expList.size() != parList.size())
    {
        string paramListStr = "";
        size_t paramIndex = 0;

        list<FormalParameterInformation *>::iterator formalIt = parList.begin();

        while(paramIndex < parList.size() - 1)
        {
            paramListStr += getDataTypeName( (*formalIt)->getType() );
            paramListStr += ", ";

            formalIt++;
            paramIndex++;
        }

        paramListStr += getDataTypeName( (*formalIt)->getType() );

        const char *returnTypeName = getDataTypeName(this->getReturnType());

        //Incorrect number of arguments calling the function 'data_type name(arg_list)'
        semanticDebugger->debugIncorrectArgumentNumberError(this->getIdentifier(), paramListStr.c_str(),returnTypeName, this->getFirstLine());

        setDataType(DATA_TYPE_ERROR);
        return DATA_TYPE_ERROR;
    }
    else
    {
        list<ExpressionNode *>::iterator actualIt = expList.begin();
        list<FormalParameterInformation *>::iterator formalIt = parList.begin();

        size_t paramNum = 1;

        while(actualIt != expList.end())
        {
            DataType actualType = (*actualIt)->typeCheck(semanticDebugger);
            DataType expectedType = (*formalIt)->getType();


            if(actualType != expectedType)
            {

                if(actualType != DATA_TYPE_ERROR)
                {

                    //Type mismatch while calling the function 'F' in the parameter
                    // of number #. Expected XXX instead of YY.
                    const char *expectedTypeName = getDataTypeName(expectedType);
                    const char *actualTypeName = getDataTypeName(actualType);
                    const char *returnTypeName = getDataTypeName(this->getReturnType());

                    semanticDebugger->debugFunctionArgumentMismatchError(
                        this->getIdentifier(),
                        paramNum,
                        expectedTypeName,
                        actualTypeName,
                        returnTypeName,
                        this->getFirstLine());
                }

                setDataType(DATA_TYPE_ERROR);
                return DATA_TYPE_ERROR;
            }
            else
            {
                if((*actualIt)->isConstant())
                {
                    *actualIt = (*actualIt)->getConstantExpression();
                }
            }

            formalIt++;
            actualIt++;
            paramNum++;
        }

        setDataType(this->getReturnType());
        return this->getReturnType();
    }
}
static ShaderLoopCase* createGenericLoopCase (Context& context, const char* caseName, const char* description, bool isVertexCase, LoopType loopType, LoopCountType loopCountType, Precision loopCountPrecision, DataType loopCountDataType)
{
	std::ostringstream vtx;
	std::ostringstream frag;
	std::ostringstream& op = isVertexCase ? vtx : frag;

	vtx << "#version 300 es\n";
	frag << "#version 300 es\n";

	vtx << "in highp vec4 a_position;\n";
	vtx << "in highp vec4 a_coords;\n";
	frag << "layout(location = 0) out mediump vec4 o_color;\n";

	if (loopCountType == LOOPCOUNT_DYNAMIC)
		vtx << "in mediump float a_one;\n";

	if (isVertexCase)
	{
		vtx << "out mediump vec3 v_color;\n";
		frag << "in mediump vec3 v_color;\n";
	}
	else
	{
		vtx << "out mediump vec4 v_coords;\n";
		frag << "in mediump vec4 v_coords;\n";

		if (loopCountType == LOOPCOUNT_DYNAMIC)
		{
			vtx << "out mediump float v_one;\n";
			frag << "in mediump float v_one;\n";
		}
	}

	// \todo [petri] Pass numLoopIters from outside?
	int		numLoopIters = 3;
	bool	isIntCounter = isDataTypeIntOrIVec(loopCountDataType);

	if (isIntCounter)
	{
		if (loopCountType == LOOPCOUNT_UNIFORM || loopCountType == LOOPCOUNT_DYNAMIC)
			op << "uniform ${COUNTER_PRECISION} int " << getIntUniformName(numLoopIters) << ";\n";
	}
	else
	{
		if (loopCountType == LOOPCOUNT_UNIFORM || loopCountType == LOOPCOUNT_DYNAMIC)
			op << "uniform ${COUNTER_PRECISION} float " << getFloatFractionUniformName(numLoopIters) << ";\n";

		if (numLoopIters != 1)
			op << "uniform ${COUNTER_PRECISION} float uf_one;\n";
	}

	vtx << "\n";
	vtx << "void main()\n";
	vtx << "{\n";
	vtx << "	gl_Position = a_position;\n";

	frag << "\n";
	frag << "void main()\n";
	frag << "{\n";

	if (isVertexCase)
		vtx << "	${PRECISION} vec4 coords = a_coords;\n";
	else
		frag << "	${PRECISION} vec4 coords = v_coords;\n";

	if (loopCountType == LOOPCOUNT_DYNAMIC)
	{
		if (isIntCounter)
		{
			if (isVertexCase)
				vtx << "	${COUNTER_PRECISION} int one = int(a_one + 0.5);\n";
			else
				frag << "	${COUNTER_PRECISION} int one = int(v_one + 0.5);\n";
		}
		else
		{
			if (isVertexCase)
				vtx << "	${COUNTER_PRECISION} float one = a_one;\n";
			else
				frag << "	${COUNTER_PRECISION} float one = v_one;\n";
		}
	}

	// Read array.
	op << "	${PRECISION} vec4 res = coords;\n";

	// Loop iteration count.
	string	iterMaxStr;

	if (isIntCounter)
	{
		if (loopCountType == LOOPCOUNT_CONSTANT)
			iterMaxStr = de::toString(numLoopIters);
		else if (loopCountType == LOOPCOUNT_UNIFORM)
			iterMaxStr = getIntUniformName(numLoopIters);
		else if (loopCountType == LOOPCOUNT_DYNAMIC)
			iterMaxStr = string(getIntUniformName(numLoopIters)) + "*one";
		else
			DE_ASSERT(false);
	}
	else
	{
		if (loopCountType == LOOPCOUNT_CONSTANT)
			iterMaxStr = "1.0";
		else if (loopCountType == LOOPCOUNT_UNIFORM)
			iterMaxStr = "uf_one";
		else if (loopCountType == LOOPCOUNT_DYNAMIC)
			iterMaxStr = "uf_one*one";
		else
			DE_ASSERT(false);
	}

	// Loop operations.
	string initValue		= isIntCounter ? "0" : "0.05";
	string loopCountDeclStr	= "${COUNTER_PRECISION} ${LOOP_VAR_TYPE} ndx = " + initValue;
	string loopCmpStr		= ("ndx < " + iterMaxStr);
	string incrementStr;
	if (isIntCounter)
		incrementStr = "ndx++";
	else
	{
		if (loopCountType == LOOPCOUNT_CONSTANT)
			incrementStr = string("ndx += ") + de::toString(1.0f / numLoopIters);
		else if (loopCountType == LOOPCOUNT_UNIFORM)
			incrementStr = string("ndx += ") + getFloatFractionUniformName(numLoopIters);
		else if (loopCountType == LOOPCOUNT_DYNAMIC)
			incrementStr = string("ndx += ") + getFloatFractionUniformName(numLoopIters) + "*one";
		else
			DE_ASSERT(false);
	}

	// Loop body.
	string loopBody;

	loopBody = "		res = res.yzwx;\n";

	if (loopType == LOOPTYPE_FOR)
	{
		op << "	for (" + loopCountDeclStr + "; " + loopCmpStr + "; " + incrementStr + ")\n";
		op << "	{\n";
		op << loopBody;
		op << "	}\n";
	}
	else if (loopType == LOOPTYPE_WHILE)
	{
		op << "\t" << loopCountDeclStr + ";\n";
		op << "	while (" + loopCmpStr + ")\n";
		op << "	{\n";
		op << loopBody;
		op << "\t\t" + incrementStr + ";\n";
		op << "	}\n";
	}
	else if (loopType == LOOPTYPE_DO_WHILE)
	{
		op << "\t" << loopCountDeclStr + ";\n";
		op << "	do\n";
		op << "	{\n";
		op << loopBody;
		op << "\t\t" + incrementStr + ";\n";
		op << "	} while (" + loopCmpStr + ");\n";
	}
	else
		DE_ASSERT(false);

	if (isVertexCase)
	{
		vtx << "	v_color = res.rgb;\n";
		frag << "	o_color = vec4(v_color.rgb, 1.0);\n";
	}
	else
	{
		vtx << "	v_coords = a_coords;\n";
		frag << "	o_color = vec4(res.rgb, 1.0);\n";

		if (loopCountType == LOOPCOUNT_DYNAMIC)
			vtx << "	v_one = a_one;\n";
	}

	vtx << "}\n";
	frag << "}\n";

	// Fill in shader templates.
	map<string, string> params;
	params.insert(pair<string, string>("LOOP_VAR_TYPE", getDataTypeName(loopCountDataType)));
	params.insert(pair<string, string>("PRECISION", "mediump"));
	params.insert(pair<string, string>("COUNTER_PRECISION", getPrecisionName(loopCountPrecision)));

	StringTemplate vertTemplate(vtx.str().c_str());
	StringTemplate fragTemplate(frag.str().c_str());
	string vertexShaderSource = vertTemplate.specialize(params);
	string fragmentShaderSource = fragTemplate.specialize(params);

	// Create the case.
	ShaderEvalFunc evalFunc = getLoopEvalFunc(numLoopIters);
	return new ShaderLoopCase(context, caseName, description, isVertexCase, evalFunc, vertexShaderSource.c_str(), fragmentShaderSource.c_str());
}
void ShaderLoopTests::init (void)
{
	// Loop cases.

	static const ShaderType s_shaderTypes[] =
	{
		SHADERTYPE_VERTEX,
		SHADERTYPE_FRAGMENT
	};

	static const DataType s_countDataType[] =
	{
		TYPE_INT,
		TYPE_FLOAT
	};

	for (int loopType = 0; loopType < LOOPTYPE_LAST; loopType++)
	{
		const char* loopTypeName = getLoopTypeName((LoopType)loopType);

		for (int loopCountType = 0; loopCountType < LOOPCOUNT_LAST; loopCountType++)
		{
			const char* loopCountName = getLoopCountTypeName((LoopCountType)loopCountType);

			string groupName = string(loopTypeName) + "_" + string(loopCountName) + "_iterations";
			string groupDesc = string("Loop tests with ") + loopCountName + " loop counter.";
			TestCaseGroup* group = new TestCaseGroup(m_context, groupName.c_str(), groupDesc.c_str());
			addChild(group);

			// Generic cases.

			for (int precision = 0; precision < PRECISION_LAST; precision++)
			{
				const char* precisionName = getPrecisionName((Precision)precision);

				for (int dataTypeNdx = 0; dataTypeNdx < DE_LENGTH_OF_ARRAY(s_countDataType); dataTypeNdx++)
				{
					DataType loopDataType = s_countDataType[dataTypeNdx];
					const char* dataTypeName = getDataTypeName(loopDataType);

					for (int shaderTypeNdx = 0; shaderTypeNdx < DE_LENGTH_OF_ARRAY(s_shaderTypes); shaderTypeNdx++)
					{
						ShaderType	shaderType		= s_shaderTypes[shaderTypeNdx];
						const char*	shaderTypeName	= getShaderTypeName(shaderType);
						bool		isVertexCase	= (shaderType == SHADERTYPE_VERTEX);

						string name = string("basic_") + precisionName + "_" + dataTypeName + "_" + shaderTypeName;
						string desc = string(loopTypeName) + " loop with " + precisionName + dataTypeName + " " + loopCountName + " iteration count in " + shaderTypeName + " shader.";
						group->addChild(createGenericLoopCase(m_context, name.c_str(), desc.c_str(), isVertexCase, (LoopType)loopType, (LoopCountType)loopCountType, (Precision)precision, loopDataType));
					}
				}
			}

			// Special cases.

			for (int loopCase = 0; loopCase < LOOPCASE_LAST; loopCase++)
			{
				const char* loopCaseName = getLoopCaseName((LoopCase)loopCase);

				// no-iterations not possible with do-while.
				if ((loopCase == LOOPCASE_NO_ITERATIONS) && (loopType == LOOPTYPE_DO_WHILE))
					continue;

				for (int shaderTypeNdx = 0; shaderTypeNdx < DE_LENGTH_OF_ARRAY(s_shaderTypes); shaderTypeNdx++)
				{
					ShaderType	shaderType		= s_shaderTypes[shaderTypeNdx];
					const char*	shaderTypeName	= getShaderTypeName(shaderType);
					bool		isVertexCase	= (shaderType == SHADERTYPE_VERTEX);

					string name = string(loopCaseName) + "_" + shaderTypeName;
					string desc = string(loopCaseName) + " loop with " + loopTypeName + " iteration count in " + shaderTypeName + " shader.";
					group->addChild(createSpecialLoopCase(m_context, name.c_str(), desc.c_str(), isVertexCase, (LoopCase)loopCase, (LoopType)loopType, (LoopCountType)loopCountType));
				}
			}
		}
	}
}