Search in sources :

Example 21 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class PortTypeBody method generateCode.

/**
 * Add generated java code on this level.
 * @param aData only used to update imports if needed
 * @param source the source code generated
 *
 * FIXME the implementation only serves as a minimal testing setup
 */
public void generateCode(final JavaGenData aData, final StringBuilder source) {
    final String genName = myType.getGenNameOwn();
    final Scope myScope = myType.getMyScope();
    final PortDefinition portDefinition = new PortDefinition(genName, getFullName());
    if (inMessages != null) {
        for (int i = 0; i < inMessages.getNofTypes(); i++) {
            final IType inType = inMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(inType.getGenNameValue(aData, source, myScope), inType.getGenNameTemplate(aData, source, myScope), inType.getTypename());
            portDefinition.inMessages.add(info);
        }
    }
    if (outMessages != null) {
        for (int i = 0; i < outMessages.getNofTypes(); i++) {
            final IType outType = outMessages.getTypeByIndex(i);
            final messageTypeInfo info = new messageTypeInfo(outType.getGenNameValue(aData, source, myScope), outType.getGenNameTemplate(aData, source, myScope), outType.getTypename());
            portDefinition.outMessages.add(info);
        }
    }
    if (inSignatures != null) {
        for (int i = 0; i < inSignatures.getNofTypes(); i++) {
            final IType outType = inSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, false);
            portDefinition.inProcedures.add(info);
        }
    }
    if (outSignatures != null) {
        for (int i = 0; i < outSignatures.getNofTypes(); i++) {
            final IType outType = outSignatures.getTypeByIndex(i);
            final Signature_Type signature = (Signature_Type) outType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
            final procedureSignatureInfo info = new procedureSignatureInfo(outType.getGenNameValue(aData, source, myScope), outType.getTypename(), signature.isNonblocking(), signature.getSignatureExceptions() != null, signature.getSignatureReturnType() != null);
            portDefinition.outProcedures.add(info);
        }
    }
    switch(testportType) {
        case TP_REGULAR:
            portDefinition.testportType = TestportType.NORMAL;
            break;
        case TP_INTERNAL:
            portDefinition.testportType = TestportType.INTERNAL;
            break;
        case TP_ADDRESS:
            portDefinition.testportType = TestportType.ADDRESS;
            portDefinition.addressName = "TitanAddress";
            break;
        default:
            portDefinition.testportType = TestportType.NORMAL;
    }
    if (vardefs != null) {
        portDefinition.varDefs = new StringBuilder();
        portDefinition.varInit = new StringBuilder();
        for (int i = 0; i < vardefs.getNofAssignments(); i++) {
            final Definition def = vardefs.getAssignmentByIndex(i);
            String type = "";
            switch(def.getAssignmentType()) {
                case A_VAR:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    if (((Def_Var) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                case A_CONST:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameValue(aData, source, myScope);
                    def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    break;
                case A_VAR_TEMPLATE:
                    type = def.getType(CompilationTimeStamp.getBaseTimestamp()).getGenNameTemplate(aData, source, myScope);
                    if (((Def_Var_Template) def).getInitialValue() == null) {
                        portDefinition.varInit.append(MessageFormat.format("{0}.cleanUp();\n", def.getGenName()));
                    } else {
                        def.generateCodeInitComp(aData, portDefinition.varInit, def);
                    }
                    break;
                default:
                    // FATAL ERROR
                    break;
            }
            portDefinition.varDefs.append(MessageFormat.format("private {0} {1} = new {0}();\n", type, def.getGenName()));
        }
    }
    PortGenerator.generateClass(aData, source, portDefinition);
}
Also used : PortGenerator.messageTypeInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.messageTypeInfo) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) Scope(org.eclipse.titan.designer.AST.Scope) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) PortDefinition(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.PortDefinition) IType(org.eclipse.titan.designer.AST.IType) PortGenerator.procedureSignatureInfo(org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.procedureSignatureInfo)

Example 22 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method getAssBySRef.

@Override
public /**
 * {@inheritDoc}
 */
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
    if (reference.getModuleIdentifier() != null) {
        return getParentScope().getAssBySRef(timestamp, reference);
    }
    if (lastUniquenessCheck == null) {
        checkUniqueness(timestamp);
    }
    final String name = reference.getId().getName();
    Definition definition = definitions.getDefinition(name);
    if (definition != null) {
        return definition;
    }
    definition = extendsGainedDefinitions.get(name);
    if (definition != null) {
        if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
            return definition;
        }
        reference.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, reference.getId().getDisplayName(), identifier.getDisplayName()));
        return null;
    }
    definition = attributeGainedDefinitions.get(name);
    if (definition != null) {
        if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
            return definition;
        }
        reference.getLocation().reportSemanticError(MessageFormat.format(MEMBERNOTVISIBLE, reference.getId().getDisplayName(), identifier.getDisplayName()));
        return null;
    }
    return getParentScope().getAssBySRef(timestamp, reference);
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 23 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method addDeclaration.

public void addDeclaration(final DeclarationCollector declarationCollector, final int i) {
    final Identifier identifier = declarationCollector.getReference().getId();
    Definition definition = definitions.getDefinition(identifier.getName());
    if (definition != null) {
        definition.addDeclaration(declarationCollector, i);
    }
    definition = extendsGainedDefinitions.get(identifier.getName());
    if (definition != null) {
        definition.addDeclaration(declarationCollector, i);
    }
    definition = attributeGainedDefinitions.get(identifier.getName());
    if (definition != null) {
        definition.addDeclaration(declarationCollector, i);
    }
    if (i == 0) {
        super.addDeclaration(declarationCollector);
    }
}
Also used : Identifier(org.eclipse.titan.designer.AST.Identifier) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 24 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method hasLocalAssignmentWithId.

/**
 * Detects if an assignment with the provided identifier exists inside this
 * component.
 *
 * @param identifier the identifier to be use to search for the assignment.
 * @return true if an assignment with the same identifier exists, or false
 *         otherwise.
 */
public boolean hasLocalAssignmentWithId(final Identifier identifier) {
    if (lastUniquenessCheck == null) {
        checkUniqueness(CompilationTimeStamp.getBaseTimestamp());
    }
    final String name = identifier.getName();
    Definition definition = definitions.getDefinition(name);
    if (definition != null) {
        return true;
    }
    definition = extendsGainedDefinitions.get(name);
    if (definition != null) {
        return true;
    }
    return attributeGainedDefinitions.containsKey(name);
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Example 25 with Definition

use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.

the class ComponentTypeBody method hasAssignmentWithId.

@Override
public /**
 * {@inheritDoc}
 */
boolean hasAssignmentWithId(final CompilationTimeStamp timestamp, final Identifier identifier) {
    final String name = identifier.getName();
    Definition definition = definitions.getDefinition(name);
    if (definition != null) {
        return true;
    }
    definition = extendsGainedDefinitions.get(name);
    if (definition != null) {
        if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
            return true;
        }
    }
    definition = attributeGainedDefinitions.get(name);
    if (definition != null) {
        if (VisibilityModifier.Public.equals(definition.getVisibilityModifier())) {
            return true;
        }
    }
    return super.hasAssignmentWithId(timestamp, identifier);
}
Also used : Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)

Aggregations

Definition (org.eclipse.titan.designer.AST.TTCN3.definitions.Definition)52 Assignment (org.eclipse.titan.designer.AST.Assignment)16 IValue (org.eclipse.titan.designer.AST.IValue)12 Location (org.eclipse.titan.designer.AST.Location)11 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)10 IType (org.eclipse.titan.designer.AST.IType)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 Module (org.eclipse.titan.designer.AST.Module)10 ArrayList (java.util.ArrayList)9 Reference (org.eclipse.titan.designer.AST.Reference)9 StatementBlock (org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)8 ISubReference (org.eclipse.titan.designer.AST.ISubReference)6 Def_Function (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function)6 ExpressionStruct (org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct)6 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)6 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)5 RunsOnScope (org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope)5 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)5 IFile (org.eclipse.core.resources.IFile)4 Restriction_type (org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type)4