Search in sources :

Example 21 with Reference

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

the class Template_ActualParameter method generateCodeDefaultValue.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeDefaultValue(final JavaGenData aData, final StringBuilder source) {
    if (template == null) {
        return;
    }
    final TTCN3Template temp = template.getTemplateBody();
    final Reference baseReference = template.getDerivedReference();
    if (baseReference != null) {
        final ExpressionStruct expression = new ExpressionStruct();
        expression.expression.append(MessageFormat.format("{0}.assign(", temp.get_lhs_name()));
        baseReference.generateCode(aData, expression);
        expression.expression.append(')');
    }
// FIXME handle the needs conversion case
// temp.generateCodeInit(aData, source, temp.get_lhs_name());
// FIXME generate restriction check code if needed
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) ExpressionStruct(org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)

Example 22 with Reference

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

the class Call_Statement method checkCallBody.

/**
 * Checks the response and exception handling part of a call operation.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 * @param portType
 *                the port type of the actual call statement.
 * @param signature
 *                the signature type of the actual call statement.
 */
private void checkCallBody(final CompilationTimeStamp timestamp, final Port_Type portType, final IType signature) {
    boolean hasCatchTimeout = false;
    for (int i = 0; i < altGuards.getNofAltguards(); i++) {
        final AltGuard altGuard = altGuards.getAltguardByIndex(i);
        if (!altguard_type.AG_OP.equals(altGuard.getType())) {
            continue;
        }
        final Statement statement = ((Operation_Altguard) altGuard).getGuardStatement();
        if (Statement_type.S_CATCH.equals(statement.getType())) {
            ((Catch_Statement) statement).setCallSettings(true, timerValue != null);
            hasCatchTimeout |= ((Catch_Statement) statement).hasTimeout();
        }
    }
    altGuards.setMyLaicStmt(altGuards, null);
    altGuards.setMyAltguards(altGuards);
    altGuards.check(timestamp);
    if (portType != null) {
        // operation.
        for (int i = 0; i < altGuards.getNofAltguards(); i++) {
            final AltGuard altguard = altGuards.getAltguardByIndex(i);
            if (!altguard_type.AG_OP.equals(altguard.getType())) {
                continue;
            }
            final Statement statement = ((Operation_Altguard) altguard).getGuardStatement();
            if (statement.getIsErroneous()) {
                continue;
            }
            switch(statement.getType()) {
                case S_GETREPLY:
                    {
                        final Reference tempPortReference = ((Getreply_Statement) statement).getPortReference();
                        if (tempPortReference == null) {
                            final String message = MessageFormat.format("The `{0}'' operation must refer to the same port as the previous `call'' statement: `{1}'' was expected instead of `any port''", statement.getStatementName(), portReference.getId().getDisplayName());
                            statement.getLocation().reportSemanticError(message);
                        } else if (!portReference.getId().equals(tempPortReference.getId())) {
                            final String message = MessageFormat.format("The `{0}'' operation refers to a different port than the previous `call'' statement: `{1}'' was expected instead of `{2}''", statement.getStatementName(), portReference.getId().getDisplayName(), tempPortReference.getId().getDisplayName());
                            tempPortReference.getLocation().reportSemanticError(message);
                        }
                        final TemplateInstance instance = ((Getreply_Statement) statement).getReceiveParameter();
                        if (instance != null) {
                            final IType tempSignature = instance.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
                            if (tempSignature != null && signature != null && !signature.isCompatible(timestamp, tempSignature, null, null, null)) {
                                final String message = MessageFormat.format(GETRPELYTOWRONGSIGNATURE, signature.getTypename(), tempSignature.getTypename());
                                instance.getLocation().reportSemanticError(message);
                            }
                        }
                        break;
                    }
                case S_CATCH:
                    final Reference tempPortReference = ((Catch_Statement) statement).getPortReference();
                    if (tempPortReference == null) {
                        final String message = MessageFormat.format("The `{0}'' operation must refer to the same port as the previous `call'' statement: `{1}'' was expected instead of `any port''", statement.getStatementName(), portReference.getId().getDisplayName());
                        statement.getLocation().reportSemanticError(message);
                    } else if (!portReference.getId().equals(tempPortReference.getId())) {
                        final String message = MessageFormat.format("The `{0}'' operation refers to a different port than the previous `call'' statement: `{1}'' was expected instead of `{2}''", statement.getStatementName(), portReference.getId().getDisplayName(), tempPortReference.getId().getDisplayName());
                        tempPortReference.getLocation().reportSemanticError(message);
                    }
                    final Signature_Type tempSignature = ((Catch_Statement) statement).getSignatureType();
                    if (tempSignature != null && signature != null && !signature.isCompatible(timestamp, tempSignature, null, null, null)) {
                        final String message = MessageFormat.format("The `catch'' operation refers to a different signature than the previous `call'' statement: `{0}'' was expected instead of `{1}''", signature.getTypename(), tempSignature.getTypename());
                        statement.getLocation().reportSemanticError(message);
                    }
                    break;
                default:
                    break;
            }
        }
    }
    if (timerValue != null && !hasCatchTimeout) {
        location.reportSemanticWarning("The call operation has a timer, but the timeout expection is not cought");
    }
}
Also used : Reference(org.eclipse.titan.designer.AST.Reference) Signature_Type(org.eclipse.titan.designer.AST.TTCN3.types.Signature_Type) TemplateInstance(org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance) IType(org.eclipse.titan.designer.AST.IType)

Example 23 with Reference

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

the class Qualifier method findReferences.

@Override
public /**
 * {@inheritDoc}
 */
void findReferences(final ReferenceFinder referenceFinder, final List<Hit> foundIdentifiers) {
    if (definition != null && subReferences != null) {
        // qualifiers were not semantically analyzed
        for (ISubReference sr : subReferences) {
            sr.findReferences(referenceFinder, foundIdentifiers);
        }
        if (referenceFinder.fieldId != null) {
            // we are searching for a field of a type
            final IType t = definition.getType(CompilationTimeStamp.getBaseTimestamp());
            if (t == null) {
                return;
            }
            final List<IType> typeArray = new ArrayList<IType>();
            final Reference reference = new Reference(null);
            reference.addSubReference(new FieldSubReference(definition.getIdentifier()));
            for (ISubReference sr : subReferences) {
                reference.addSubReference(sr);
            }
            reference.setLocation(location);
            reference.setMyScope(definition.getMyScope());
            final boolean success = t.getFieldTypesAsArray(reference, 1, typeArray);
            if (!success) {
                // TODO: maybe a partially erroneous reference could be searched too
                return;
            }
            if (subReferences.size() != typeArray.size()) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            for (int i = 0; i < subReferences.size(); i++) {
                if (typeArray.get(i) == referenceFinder.type && !(subReferences.get(i) instanceof ArraySubReference) && subReferences.get(i).getId().equals(referenceFinder.fieldId)) {
                    foundIdentifiers.add(new Hit(subReferences.get(i).getId()));
                }
            }
        }
    }
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) Hit(org.eclipse.titan.designer.AST.ReferenceFinder.Hit) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArrayList(java.util.ArrayList) IType(org.eclipse.titan.designer.AST.IType) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference)

Example 24 with Reference

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

the class ASN1_Enumerated_Type method checkThisValueRef.

@Override
public final /**
 * {@inheritDoc}
 */
IValue checkThisValueRef(final CompilationTimeStamp timestamp, final IValue value) {
    IValue temp = value;
    if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
        // we are not able to parse lower identifier values as default values
        // so the parsed reference needs to be converted.
        final Reference reference = ((Referenced_Value) value).getReference();
        if (reference.getModuleIdentifier() == null && reference.getSubreferences().size() == 1) {
            final Identifier identifier = reference.getId();
            temp = new Enumerated_Value(identifier);
            temp.setMyGovernor(this);
            temp.setFullNameParent(this);
            temp.setMyScope(value.getMyScope());
            return temp;
        }
    }
    if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(temp.getValuetype())) {
        if (nameMap != null && nameMap.containsKey(((Undefined_LowerIdentifier_Value) temp).getIdentifier().getName())) {
            temp = temp.setValuetype(timestamp, Value_type.ENUMERATED_VALUE);
            temp.setMyGovernor(this);
            temp.setFullNameParent(this);
            temp.setMyScope(value.getMyScope());
            return temp;
        }
    }
    return super.checkThisValueRef(timestamp, value);
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Identifier(org.eclipse.titan.designer.AST.Identifier) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) Reference(org.eclipse.titan.designer.AST.Reference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) Referenced_Value(org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)

Example 25 with Reference

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

the class TableConstraint method getOpenTypeAlternativeName.

// Original titan.core version: t_type->get_otaltname(is_strange);
private Identifier getOpenTypeAlternativeName(final CompilationTimeStamp timestamp, final Type type, final AtomicBoolean isStrange) {
    StringBuffer sb = new StringBuffer();
    // TODO:  if (is_tagged() || is_constrained() || hasRawAttrs()) {
    if (!type.getIsErroneous(timestamp) && type.isConstrained()) {
        sb.append(type.getGenNameOwn());
        isStrange.set(true);
    } else if (!type.getIsErroneous(timestamp) && type instanceof Referenced_Type) {
        Reference t_ref = ((Referenced_Type) type).getReference();
        if (t_ref != null) {
            final Identifier id = t_ref.getId();
            final String dn = id.getDisplayName();
            int i = dn.indexOf('.');
            if (i >= 0 && i < dn.length()) {
                // id is not regular because t_ref is a parameterized reference
                sb.append(id.getName());
                isStrange.set(true);
            } else {
                Assignment as = t_ref.getRefdAssignment(timestamp, true);
                if (as == null) {
                    return null;
                }
                Scope assScope = as.getMyScope();
                if (assScope.getParentScope() == assScope.getModuleScope()) {
                    sb.append(id.getName());
                    isStrange.set(false);
                } else {
                    // t_ref is a dummy reference in a parameterized assignment
                    // (i.e. it points to a parameter assignment of an instantiation)
                    // perform the same examination recursively on the referenced type
                    // (which is the actual parameter)
                    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
                    IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
                    chain.release();
                    return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
                }
            }
        } else {
            // the type comes from an information object [class]
            // examine the referenced type recursively
            IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
            IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
            chain.release();
            return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
        }
    } else {
        Identifier tmpId1 = new Identifier(Identifier_type.ID_NAME, type.getFullName());
        String s = tmpId1.getDisplayName();
        // module name will be cut off:
        if (s.startsWith("@") && s.indexOf('.') > 0) {
            s = s.substring(s.indexOf('.') + 1);
        }
        Identifier tmpId2 = new Identifier(Identifier_type.ID_ASN, s);
        sb.append(tmpId2.getTtcnName());
    }
    // conversion to lower case initial:
    sb.replace(0, 1, sb.substring(0, 1).toLowerCase());
    // trick:
    Identifier tmpId = new Identifier(Identifier_type.ID_NAME, sb.toString());
    return new Identifier(Identifier_type.ID_ASN, tmpId.getAsnName());
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IReferencingType(org.eclipse.titan.designer.AST.IReferencingType) TTCN3_Set_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Type) ASN1_Sequence_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Sequence_Type) TTCN3_Choice_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Choice_Type) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) ASN1_Set_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Type) FieldSetting_Type(org.eclipse.titan.designer.AST.ASN1.Object.FieldSetting_Type) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) ObjectClassField_Type(org.eclipse.titan.designer.AST.ASN1.types.ObjectClassField_Type) TTCN3_Sequence_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Sequence_Type) Type(org.eclipse.titan.designer.AST.Type) ASN1_Choice_Type(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Choice_Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type) IType(org.eclipse.titan.designer.AST.IType)

Aggregations

Reference (org.eclipse.titan.designer.AST.Reference)88 Assignment (org.eclipse.titan.designer.AST.Assignment)48 ISubReference (org.eclipse.titan.designer.AST.ISubReference)37 IValue (org.eclipse.titan.designer.AST.IValue)26 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)23 IType (org.eclipse.titan.designer.AST.IType)23 Identifier (org.eclipse.titan.designer.AST.Identifier)22 ArrayList (java.util.ArrayList)19 Module (org.eclipse.titan.designer.AST.Module)16 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)15 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)13 IFile (org.eclipse.core.resources.IFile)11 Location (org.eclipse.titan.designer.AST.Location)10 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)10 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)9 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)8 Type (org.eclipse.titan.designer.AST.Type)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7