Search in sources :

Example 1 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class ConstantParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof Identifier) {
        name = node.toString();
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
        value = new Value(type, Writable.NULL);
        return Action.skip(Type.class, this);
    }
    if (node instanceof org.eclipse.titan.designer.AST.Value) {
        ValueHolder holder = v -> value = v;
        return dispatch(this, type, holder, node);
    }
    return this;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Writable(org.eclipse.titan.codegenerator.Writable) Iterator(java.util.Iterator) ValueHolder(org.eclipse.titan.codegenerator.template.ValueHolder) Identifier(org.eclipse.titan.designer.AST.Identifier) Util(org.eclipse.titan.codegenerator.template.Util) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) HashMap(java.util.HashMap) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) ArrayList(java.util.ArrayList) SourceCode(org.eclipse.titan.codegenerator.SourceCode) List(java.util.List) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Action(org.eclipse.titan.codegenerator.template.Action) Value(org.eclipse.titan.codegenerator.template.Value) Type(org.eclipse.titan.designer.AST.Type) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) Value(org.eclipse.titan.codegenerator.template.Value) ValueHolder(org.eclipse.titan.codegenerator.template.ValueHolder)

Example 2 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Type_Visit_Handler method visitDefTypeChildrenNodes.

public void visitDefTypeChildrenNodes(IVisitableNode node) {
    if (node instanceof Def_Port) {
        Def_Port port = (Def_Port) node;
        componentPortNames.add(port.getIdentifier().toString());
    }
    if (node instanceof Def_Var) {
        Def_Var var = (Def_Var) node;
        componentVarNames.add(var.getIdentifier().toString());
        if (var.getType(compilationCounter) instanceof Integer_Type) {
            componentVarTypes.add("INTEGER");
        }
    }
    if (waitForCompReference && (node instanceof Reference)) {
        componentPortTypes.add(((Reference) node).getId().toString());
    }
    if (waitForSetOfFieldType) {
        if (node instanceof Reference) {
            setOfFieldType = node.toString();
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SetOf_Type)) {
            Type type = (Type) node;
            setOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameSetOfTypesHashMap.put(parentName, setOfFieldType);
            waitForSetOfFieldType = false;
        }
    }
    if (waitForRecordOfFieldType) {
        if (node instanceof Reference) {
            recordOfFieldType = node.toString();
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        } else if (node instanceof Type && !(node instanceof Referenced_Type) && !(node instanceof SequenceOf_Type)) {
            Type type = (Type) node;
            recordOfFieldType = TypeMapper.map(type.getTypename());
            myASTVisitor.nodeNameRecordOfTypesHashMap.put(parentName, recordOfFieldType);
            waitForRecordOfFieldType = false;
        }
    }
    if (node instanceof CompField) {
        // component
        CompField compFieldNode = (CompField) node;
        if (compFieldNode.getType() instanceof Referenced_Type) {
            compFieldTypes.add(((Referenced_Type) compFieldNode.getType()).getReference().getId().toString());
        } else {
            compFieldTypes.add(myASTVisitor.cutModuleNameFromBeginning(compFieldNode.getType().getTypename()));
        }
        compFieldNames.add(compFieldNode.getIdentifier().toString());
    }
    if (node instanceof Charstring_Value) {
        // charstring
        Charstring_Value singleValuedNode = (Charstring_Value) node;
        charstringValue = singleValuedNode.getValue();
    }
    if (node instanceof Integer_Value) {
        String value = ((Integer_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add("new INTEGER(\"" + value + "\")");
    }
    if (node instanceof Real_Value) {
        String value = ((Real_Value) node).toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        if (value.equals("-Infinity") || value.equals("Infinity")) {
            value = "null";
        }
        expressionValue.add(value);
    }
    if (node instanceof Undefined_LowerIdentifier_Value) {
        String value = ((Undefined_LowerIdentifier_Value) node).getIdentifier().toString();
        if (myASTVisitor.isNextIntegerNegative) {
            value = "-" + value;
        }
        expressionValue.add(value);
    }
    if (node instanceof EnumerationItems) {
        for (int i = 0; i < ((EnumerationItems) node).getItems().size(); i++) {
            enumItems.add(((EnumerationItems) node).getItems().get(i).getId().toString());
            if (((EnumerationItems) node).getItems().get(i).getValue() != null) {
                enumItemValues.add(((EnumerationItems) node).getItems().get(i).getValue().toString());
            } else {
                enumItemValues.add(null);
            }
        }
    }
    if (waitingForPortAttriburtes && (node instanceof Referenced_Type)) {
        isPortTypeAReferencedType = true;
    }
    if (waitingForPortAttriburtes && (node instanceof PortTypeBody)) {
        PortTypeBody body = (PortTypeBody) node;
        int inCount = body.getInMessages().getNofTypes();
        int outCount = body.getOutMessage().getNofTypes();
        for (int i = 0; i < inCount; i++) {
            inMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getInMessages().getTypeByIndex(i).getTypename()));
        }
        for (int i = 0; i < outCount; i++) {
            outMessageName.add(myASTVisitor.cutModuleNameFromBeginning(body.getOutMessage().getTypeByIndex(i).getTypename()));
        }
        int shorterListSize = inMessageName.size() <= outMessageName.size() ? inMessageName.size() : outMessageName.size();
        // if inout delete from both lists and add to inout
        for (int i = 0; i < inMessageName.size(); i++) {
            for (int j = 0; j < outMessageName.size(); j++) {
                if (inMessageName.get(i).equals(outMessageName.get(j))) {
                    inOutMessageName.add(inMessageName.get(i));
                    inMessageName.remove(i);
                    if (j == (outMessageName.size() - 1)) {
                        i--;
                    }
                    outMessageName.remove(j);
                    j--;
                }
            }
        }
        myASTVisitor.portNamePortTypeHashMap.put(currentPortName, body.getTestportType().toString());
        portTypeList.add(body.getTestportType().toString());
    }
}
Also used : Def_Var(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var) Reference(org.eclipse.titan.designer.AST.Reference) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Def_Port(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) CompField(org.eclipse.titan.designer.AST.TTCN3.types.CompField) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) EnumerationItems(org.eclipse.titan.designer.AST.TTCN3.types.EnumerationItems) PortTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Undefined_LowerIdentifier_Value(org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)

Example 3 with Type

use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.

the class Def_Type_Visit_Handler method visitDefTypeNodes.

public void visitDefTypeNodes(IVisitableNode node) {
    Def_Type typeNode = (Def_Type) node;
    String nodeName = typeNode.getIdentifier().toString();
    myASTVisitor.currentFileName = nodeName;
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    Type type = typeNode.getType(compilationCounter);
    if (type.getTypetype().equals(TYPE_TTCN3_SEQUENCE)) {
        // record
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "record");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_TTCN3_SET)) {
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "set");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_TTCN3_CHOICE)) {
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "union");
        parentName = nodeName;
    } else if (type instanceof Integer_Type) {
        Def_Type_Integer_Writer.getInstance(typeNode);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "INTEGER");
        parentName = nodeName;
        isInteger = true;
    } else if (type instanceof CharString_Type) {
        Def_Type_Charstring_Writer.getInstance(typeNode);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "CHARSTRING");
        parentName = nodeName;
    } else if (type instanceof TTCN3_Enumerated_Type) {
        Def_Type_Enum_Writer.getInstance(typeNode);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "enum");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_SET_OF)) {
        waitForSetOfFieldType = true;
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "setof");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_SEQUENCE_OF)) {
        waitForRecordOfFieldType = true;
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "recordof");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_PORT)) {
        Def_Type_Port_Writer.getInstance(typeNode);
        waitingForPortAttriburtes = true;
        currentPortName = nodeName;
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "port");
        parentName = nodeName;
    } else if (type.getTypetype().equals(TYPE_COMPONENT)) {
        Def_Type_Component_Writer.getInstance(typeNode);
        waitForCompReference = true;
        AstWalkerJava.componentList.add(nodeName);
        myASTVisitor.nodeNameNodeTypeHashMap.put(nodeName, "component");
        parentName = nodeName;
    }
}
Also used : Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) Range_ParsedSubType(org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType) SequenceOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) SetOf_Type(org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) Type(org.eclipse.titan.designer.AST.Type) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) CharString_Type(org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type)

Example 4 with Type

use of org.eclipse.titan.designer.AST.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;
}
Also used : Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) IType(org.eclipse.titan.designer.AST.IType)

Example 5 with Type

use of org.eclipse.titan.designer.AST.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;
    }
}
Also used : Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Function_Type(org.eclipse.titan.designer.AST.TTCN3.types.Function_Type) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Type (org.eclipse.titan.designer.AST.Type)69 IType (org.eclipse.titan.designer.AST.IType)56 Identifier (org.eclipse.titan.designer.AST.Identifier)35 IValue (org.eclipse.titan.designer.AST.IValue)13 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)13 CompField (org.eclipse.titan.designer.AST.TTCN3.types.CompField)12 HashMap (java.util.HashMap)11 IASN1Type (org.eclipse.titan.designer.AST.ASN1.IASN1Type)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 ASN1_Choice_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type)9 NamedTemplate (org.eclipse.titan.designer.AST.TTCN3.templates.NamedTemplate)9 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)8 Reference (org.eclipse.titan.designer.AST.Reference)8 SubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType)8 Attribute_Type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type)7 ASN1_Sequence_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type)6 ASN1_Set_Type (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type)6 TTCN3_Choice_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type)6 TTCN3_Sequence_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type)6 NamedValue (org.eclipse.titan.designer.AST.TTCN3.values.NamedValue)6