use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class Function_Reference_Value method generateSingleExpression.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateSingleExpression(final JavaGenData aData) {
final StringBuilder result = new StringBuilder();
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
if (governor == null || referredFunction == null) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
return result;
}
final IType lastGovernor = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final Function_Type functionType = (Function_Type) lastGovernor;
final Type returnType = functionType.getReturnType();
final String moduleName = referredFunction.getMyScope().getModuleScope().getName();
final String functionName = referredFunction.getIdentifier().getName();
result.append(MessageFormat.format("new {0}(new {0}.function_pointer() '{'\n", governor.getGenNameValue(aData, result, myScope)));
result.append("@Override\n");
result.append("public String getModuleName() {\n");
result.append(MessageFormat.format("return \"{0}\";\n", moduleName));
result.append("}\n");
result.append("@Override\n");
result.append("public String getDefinitionName() {\n");
result.append(MessageFormat.format("return \"{0}\";\n", functionName));
result.append("}\n");
result.append("@Override\n");
result.append("public ");
final StringBuilder actualParList = functionType.getFormalParameters().generateCodeActualParlist("");
if (returnType == null) {
result.append("void");
} else {
if (functionType.returnsTemplate()) {
result.append(returnType.getGenNameTemplate(aData, result, myScope));
} else {
result.append(returnType.getGenNameValue(aData, result, myScope));
}
}
result.append(" invoke(");
functionType.getFormalParameters().generateCode(aData, result);
result.append(") {\n");
result.append(MessageFormat.format("{0}{1}.{2}({3});\n", returnType == null ? "" : "return ", moduleName, functionName, actualParList));
result.append("}\n");
if (functionType.isStartable(CompilationTimeStamp.getBaseTimestamp())) {
aData.addBuiltinTypeImport("TitanComponent");
result.append("@Override\n");
result.append("public void start(final TitanComponent component_reference");
if (functionType.getFormalParameters().getNofParameters() > 0) {
result.append(", ");
functionType.getFormalParameters().generateCode(aData, result);
}
result.append(") {\n");
result.append(MessageFormat.format("{0}.start_{1}(component_reference", moduleName, functionName));
if (actualParList != null && actualParList.length() > 0) {
result.append(MessageFormat.format(", {0}", actualParList));
}
result.append(");\n");
result.append("}\n");
}
result.append("})\n");
return result;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class ApplyExpression method getExpressionGovernor.
@Override
public /**
* {@inheritDoc}
*/
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (myGovernor != null) {
return myGovernor;
}
if (value == null) {
return null;
}
IType type = value.getExpressionGovernor(timestamp, expectedValue);
if (type == null) {
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError(VALUEXPECTED1);
}
setIsErroneous(true);
return null;
}
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_FUNCTION:
final Type result = ((Function_Type) type).getReturnType();
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && ((Function_Type) type).returnsTemplate()) {
location.reportSemanticError(MessageFormat.format(VALUEXPECTED2, type.getTypename(), result.getTypename()));
}
return result;
default:
setIsErroneous(true);
return null;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_ModulePar method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
T3Doc.check(this.getCommentLocation(), KIND);
isUsed = false;
NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
if (withAttributesPath != null) {
withAttributesPath.checkGlobalAttributes(timestamp, false);
withAttributesPath.checkAttributes(timestamp);
}
if (type == null) {
return;
}
type.setGenName("_T_", getGenName());
type.check(timestamp);
final IType lastType = type.getTypeRefdLast(timestamp);
switch(lastType.getTypetype()) {
case TYPE_PORT:
location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
break;
case TYPE_SIGNATURE:
location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
break;
case TYPE_FUNCTION:
case TYPE_ALTSTEP:
case TYPE_TESTCASE:
if (((Function_Type) lastType).isRunsOnSelf()) {
location.reportSemanticError(MessageFormat.format(RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
}
break;
default:
break;
}
if (defaultValue != null) {
defaultValue.setMyGovernor(type);
final IValue temporalValue = type.checkThisValueRef(timestamp, defaultValue);
type.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, true, false, true, hasImplicitOmitAttribute(timestamp), false));
defaultValue.setCodeSection(CodeSectionType.CS_PRE_INIT);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class Def_ModulePar_Template method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
T3Doc.check(this.getCommentLocation(), KIND);
isUsed = false;
NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_MODULEPAR, identifier, this);
NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
if (withAttributesPath != null) {
withAttributesPath.checkGlobalAttributes(timestamp, false);
withAttributesPath.checkAttributes(timestamp);
}
if (type == null) {
return;
}
type.setGenName("_T_", getGenName());
type.check(timestamp);
final IType lastType = type.getTypeRefdLast(timestamp);
switch(lastType.getTypetype()) {
case TYPE_PORT:
location.reportSemanticError(MessageFormat.format(Def_ModulePar.PORTNOTALLOWED, lastType.getFullName()));
break;
case TYPE_SIGNATURE:
location.reportSemanticError(MessageFormat.format(Def_ModulePar.SIGNATURENOTALLOWED, lastType.getFullName()));
break;
case TYPE_FUNCTION:
case TYPE_ALTSTEP:
case TYPE_TESTCASE:
if (((Function_Type) lastType).isRunsOnSelf()) {
location.reportSemanticError(MessageFormat.format(Def_ModulePar.RUNSONSELF_NOT_ALLOWED, lastType.getFullName()));
}
break;
default:
break;
}
if (defaultTemplate != null) {
realTemplate = defaultTemplate;
// Needed in case of universal charstring templates
if (defaultTemplate.getTemplatetype() == Template_type.CSTR_PATTERN && lastType.getTypetype() == Type.Type_type.TYPE_UCHARSTRING) {
realTemplate = defaultTemplate.setTemplatetype(timestamp, Template_type.USTR_PATTERN);
// FIXME implement setting the pattern type,
// once universal charstring pattern are
// supported.
}
final ITTCN3Template temporalTemplate = type.checkThisTemplateRef(timestamp, realTemplate);
temporalTemplate.checkThisTemplateGeneric(timestamp, type, false, true, true, true, false, null);
final IReferenceChain tempReferenceChain = ReferenceChain.getInstance(Def_Template.CIRCULAREMBEDDEDRECURSION, true);
tempReferenceChain.add(this);
temporalTemplate.checkRecursions(timestamp, tempReferenceChain);
tempReferenceChain.release();
// defaultTemplate.setGenNamePrefix("modulepar_");//currently does not need the prefix
defaultTemplate.setGenNameRecursive(getGenName());
defaultTemplate.setCodeSection(CodeSectionType.CS_PRE_INIT);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.Function_Type in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method getExpressionGovernor.
@Override
public /**
* {@inheritDoc}
*/
IType getExpressionGovernor(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
if (myGovernor != null) {
return myGovernor;
}
if (value == null) {
setIsErroneous(true);
return null;
}
IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError(VALUEXPECTED1);
}
setIsErroneous(true);
return null;
}
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_FUNCTION:
final Type result = ((Function_Type) type).getReturnType();
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && ((Function_Type) type).returnsTemplate()) {
location.reportSemanticError(MessageFormat.format(VALUEXPECTED2, type.getTypename(), result.getTypename()));
}
return result;
case TYPE_ALTSTEP:
setIsErroneous(true);
return null;
default:
value.getLocation().reportSemanticError(MessageFormat.format(FUNCTIONEXPECTED, type.getTypename()));
}
return null;
}
Aggregations