예제 #1
0
void CallbacksForGeneratingExpressionCode::OnStaticFunction(string functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo)
{
    codeGenerator.AddIncludeFile(expressionInfo.codeExtraInformation.optionalIncludeFile);

    //Launch custom code generator if needed
    if ( expressionInfo.codeExtraInformation.optionalCustomCodeGenerator != std::shared_ptr<gd::ExpressionCodeGenerationInformation::CustomCodeGenerator>() )
    { plainExpression += expressionInfo.codeExtraInformation.optionalCustomCodeGenerator->GenerateCode(parameters, codeGenerator, context); return; }

    //Special case: For strings expressions, function without name is a string.
    if ( GetReturnType() == "string" && functionName.empty() )
    {
        if ( parameters.empty() ) return;
        plainExpression += codeGenerator.ConvertToStringExplicit(parameters[0].GetPlainString());

        return;
    }

    //Prepare parameters
    vector<string> parametersCode = codeGenerator.GenerateParametersCodes(parameters, expressionInfo.parameters, context);
    string parametersStr;
    for (unsigned int i = 0;i<parametersCode.size();++i)
    {
        if ( i != 0 ) parametersStr += ", ";
        parametersStr += parametersCode[i];
    }

    plainExpression += expressionInfo.codeExtraInformation.functionCallName+"("+parametersStr+")";
};
예제 #2
0
void edbPackageFunction::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Argument count"), GetArgCount());
		properties->AppendItem(_("Arguments"), GetArgListWithNames());
		properties->AppendItem(_("Signature arguments"), GetArgSigList());
		if (!GetIsProcedure())
			properties->AppendItem(_("Return type"), GetReturnType());
		properties->AppendItem(_("Visibility"), GetVisibility());
		properties->AppendItem(_("Source"), firstLineOnly(GetSource()));
	}
}
예제 #3
0
void CallbacksForGeneratingExpressionCode::OnObjectAutomatismFunction(string functionName, const std::vector<gd::Expression> & parameters, const gd::ExpressionMetadata & expressionInfo)
{
    const gd::Project & project = codeGenerator.GetProject();
    const gd::Layout & scene = codeGenerator.GetLayout();

    codeGenerator.AddIncludeFile(expressionInfo.codeExtraInformation.optionalIncludeFile);
    if ( parameters.size() < 2 ) return;

    //Launch custom code generator if needed
    if ( expressionInfo.codeExtraInformation.optionalCustomCodeGenerator != std::shared_ptr<gd::ExpressionCodeGenerationInformation::CustomCodeGenerator>() )
    { plainExpression += expressionInfo.codeExtraInformation.optionalCustomCodeGenerator->GenerateCode(parameters, codeGenerator, context); return; }

    //Prepare parameters
    vector<string> parametersCode = codeGenerator.GenerateParametersCodes(parameters, expressionInfo.parameters, context);
    string parametersStr;
    for (unsigned int i = 2;i<parametersCode.size();++i)
    {
        if ( i != 2 ) parametersStr += ", ";
        parametersStr += parametersCode[i];
    }

    //Get object(s) concerned by function call
    std::vector<std::string> realObjects = codeGenerator. ExpandObjectsName(parameters[0].GetPlainString(), context);

    std::string output = GetReturnType() == "string" ? "\"\"" : "0";
    for (unsigned int i = 0;i<realObjects.size();++i)
    {
        context.ObjectsListNeeded(realObjects[i]);

        //Cast the object if needed
        string automatismType = gd::GetTypeOfAutomatism(project, scene, parameters[1].GetPlainString());
        const AutomatismMetadata & autoInfo = MetadataProvider::GetAutomatismMetadata(codeGenerator.GetPlatform(), automatismType);

        //Build string to access the automatism
        codeGenerator.AddIncludeFiles(autoInfo.includeFiles);
        output = codeGenerator.GenerateObjectAutomatismFunctionCall(realObjects[i], parameters[1].GetPlainString(), autoInfo, expressionInfo.codeExtraInformation, parametersStr, output, context);
    }

    plainExpression += output;
};
예제 #4
0
void pgFunction::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("Argument count"), GetArgCount());
		properties->AppendItem(_("Arguments"), GetArgListWithNames());
		properties->AppendItem(_("Signature arguments"), GetArgSigList());
		if (!GetIsProcedure())
			properties->AppendItem(_("Return type"), GetReturnType());
		properties->AppendItem(_("Language"), GetLanguage());
		properties->AppendYesNoItem(_("Returns a set?"), GetReturnAsSet());
		if (GetLanguage().IsSameAs(wxT("C"), false))
		{
			properties->AppendItem(_("Object file"), GetBin());
			properties->AppendItem(_("Link symbol"), GetSource());
		}
		else
			properties->AppendItem(_("Source"), firstLineOnly(GetSource()));

		if (GetConnection()->BackendMinimumVersion(8, 3))
		{
			properties->AppendItem(_("Estimated cost"), GetCost());
			if (GetReturnAsSet())
				properties->AppendItem(_("Estimated rows"), GetRows());
		}

		properties->AppendItem(_("Volatility"), GetVolatility());
		if (GetConnection()->BackendMinimumVersion(9, 2))
			properties->AppendYesNoItem(_("Leak proof?"), GetIsLeakProof());
		properties->AppendYesNoItem(_("Security of definer?"), GetSecureDefiner());
		properties->AppendYesNoItem(_("Strict?"), GetIsStrict());
		if (GetConnection()->BackendMinimumVersion(8, 4))
			properties->AppendYesNoItem(_("Window?"), GetIsWindow());

		size_t i;
		for (i = 0 ; i < configList.GetCount() ; i++)
		{
			wxString item = configList.Item(i);
			properties->AppendItem(item.BeforeFirst('='), item.AfterFirst('='));
		}

		properties->AppendItem(_("ACL"), GetAcl());
		properties->AppendYesNoItem(_("System function?"), GetSystemObject());
		properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));

		if (!GetLabels().IsEmpty())
		{
			wxArrayString seclabels = GetProviderLabelArray();
			if (seclabels.GetCount() > 0)
			{
				for (unsigned int index = 0 ; index < seclabels.GetCount() - 1 ; index += 2)
				{
					properties->AppendItem(seclabels.Item(index), seclabels.Item(index + 1));
				}
			}
		}
	}
}
예제 #5
0
wxString pgFunction::GetSql(ctlTree *browser)
{
	if (sql.IsNull())
	{
		wxString qtName = GetQuotedFullIdentifier()  + wxT("(") + GetArgListWithNames() + wxT(")");
		wxString qtSig = GetQuotedFullIdentifier()  + wxT("(") + GetArgSigList() + wxT(")");

		sql = wxT("-- Function: ") + qtSig + wxT("\n\n")
		      + wxT("-- DROP FUNCTION ") + qtSig + wxT(";")
		      + wxT("\n\nCREATE OR REPLACE FUNCTION ") + qtName;

		// Use Oracle style syntax for edb-spl functions
		if (GetLanguage() == wxT("edbspl") && GetProcType() == 2)
		{
			sql += wxT("\nRETURN ");
			sql += GetReturnType();

			sql += wxT(" AS");
			if (GetSource().StartsWith(wxT("\n")))
				sql += GetSource();
			else
				sql += wxT("\n") + GetSource();
		}
		else
		{
			sql += wxT("\n  RETURNS ");
			if (GetReturnAsSet() && !GetReturnType().StartsWith(wxT("TABLE")))
				sql += wxT("SETOF ");
			sql += GetReturnType();

			sql += wxT(" AS\n");

			if (GetLanguage().IsSameAs(wxT("C"), false))
			{
				sql += qtDbString(GetBin()) + wxT(", ") + qtDbString(GetSource());
			}
			else
			{
				if (GetConnection()->BackendMinimumVersion(7, 5))
					sql += qtDbStringDollar(GetSource());
				else
					sql += qtDbString(GetSource());
			}
			sql += wxT("\n  LANGUAGE ") + GetLanguage() + wxT(" ");
			if (GetConnection()->BackendMinimumVersion(8, 4) && GetIsWindow())
				sql += wxT("WINDOW ");
			sql += GetVolatility();

			if (GetConnection()->BackendMinimumVersion(9, 2) && GetIsLeakProof())
				sql += wxT(" LEAKPROOF");
			if (GetIsStrict())
				sql += wxT(" STRICT");
			if (GetSecureDefiner())
				sql += wxT(" SECURITY DEFINER");

			// PostgreSQL 8.3+ cost/row estimations
			if (GetConnection()->BackendMinimumVersion(8, 3))
			{
				sql += wxT("\n  COST ") + NumToStr(GetCost());

				if (GetReturnAsSet())
					sql += wxT("\n  ROWS ") + NumToStr(GetRows());
			}
		}

		if (!sql.Strip(wxString::both).EndsWith(wxT(";")))
			sql += wxT(";");

		size_t i;
		for (i = 0 ; i < configList.GetCount() ; i++)
		{
			if (configList.Item(i).BeforeFirst('=') != wxT("search_path") &&
			        configList.Item(i).BeforeFirst('=') != wxT("temp_tablespaces"))
				sql += wxT("\nALTER FUNCTION ") + qtSig
				       + wxT(" SET ") + configList.Item(i).BeforeFirst('=') + wxT("='") + configList.Item(i).AfterFirst('=') + wxT("';\n");
			else
				sql += wxT("\nALTER FUNCTION ") + qtSig
				       + wxT(" SET ") + configList.Item(i).BeforeFirst('=') + wxT("=") + configList.Item(i).AfterFirst('=') + wxT(";\n");
		}

		sql += wxT("\n")
		       +  GetOwnerSql(8, 0, wxT("FUNCTION ") + qtSig)
		       +  GetGrant(wxT("X"), wxT("FUNCTION ") + qtSig);

		if (!GetComment().IsNull())
		{
			sql += wxT("COMMENT ON FUNCTION ") + qtSig
			       + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n");
		}

		if (GetConnection()->BackendMinimumVersion(9, 1))
			sql += GetSeqLabelsSql();
	}

	return sql;
}
예제 #6
0
void CSyntTree::Imprimir(int n)
{
	int i;

	for (i = 0; i < n; i++)
		printf("    ");

	int hijo = 0;

	switch(GetType())
	{
		case SYNT_INSTRUCCION:
			printf("Instrucción: \n");
			break;

		case SYNT_RETURN:
			printf("Return: \n");
			break;

		case SYNT_FOR:
			printf("Instrucción For:\n");
			
			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Inicialización:\n");
			GetChild(hijo++)->Imprimir(n + 2);

			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Condicion:\n");
			GetChild(hijo++)->Imprimir(n + 2);

			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Incremento:\n");
			GetChild(hijo++)->Imprimir(n + 2);

			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Ciclo:\n");
			GetChild(hijo++)->Imprimir(n + 2);
			break;

		case SYNT_WHILE:
			printf("Instrucción While:\n");
			
			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Condición:\n");
			GetChild(hijo++)->Imprimir(n + 2);

			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Ciclo:\n");
			GetChild(hijo++)->Imprimir(n + 2);
			break;

		case SYNT_IF:
			printf("Instrucción If:\n");
			
			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Condición:\n");
			GetChild(hijo++)->Imprimir(n + 2);

			for (i = 0; i < n + 1; i++)
				printf("    ");
			printf("Si es verdad:\n");
			GetChild(hijo++)->Imprimir(n + 2);

			if (GetChilds() == 3)
			{
				for (i = 0; i < n + 1; i++)
					printf("    ");
				printf("Si es falso:\n");
				GetChild(hijo++)->Imprimir(n + 2);
			}
			break;

		case SYNT_INSTRUCCION_NULA:
			printf("Instrucción nula\n");
			break;

		case SYNT_LISTA_FUNCIONES:
			printf("Lista de funciones:\n");
			break;

		case SYNT_LISTA_INSTRUCCIONES:
			printf("Lista de instrucciones:\n");
			break;

		case SYNT_IDENTIFICADOR:
			printf("Identificador: %s\n", GetString());
			break;

		case SYNT_VARIABLE:
			printf("Variable: %s\n", GetString());
			break;
		
		case SYNT_CONSTANTE:
			printf("Valor constante ");

			if (strcmp(GetReturnType()->GetNombre(), SIMBOLO_INT) == 0)
				printf("(entero) %ld\n", GetInteger());
			else
				if (strcmp(GetReturnType()->GetNombre(), SIMBOLO_FLOAT) == 0)
					printf("(float) %f\n", GetFloat());
				else
					if (strcmp(GetReturnType()->GetNombre(), SIMBOLO_STRING) == 0)
						printf("(cadena) %s\n", GetString());
			break;

		case SYNT_OP_ASIGNACION:
			printf ("Operador =\n");
			break;

		case SYNT_OP_MAS:
			printf ("Operador +\n");
			break;

		case SYNT_OP_MENOS:
			printf ("Operador -\n");
			break;

		case SYNT_OP_POR:
			printf ("Operador *\n");
			break;

		case SYNT_OP_DIV:
			printf ("Operador /\n");
			break;

		case SYNT_LLAMADO_FUNCION:
			printf("LLamado a función: %s\n", GetString());
			break;

		case SYNT_DECLARACION_VARIABLE:
			printf("Declaración de variables del tipo %s\n", GetString());
			break;

		case SYNT_DECLARACION_FUNCION:
			printf("Declaración de la función: %s\n", GetString());
			break;
		
		case SYNT_CONVERSION:
			printf("Conversion desde %s a %s\n", GetChild(0)->GetReturnType()->GetNombre(), GetReturnType()->GetNombre());
			break;

		case SYNT_TABLA_SIMBOLOS:
			printf("Tabla de simbolos\n");
			m_pTablaSimbolos->Imprimir(n + 1);
			break;
	}

	n++;

	for (; hijo < GetChilds(); hijo++)
		GetChild(hijo)->Imprimir(n);
}