use of org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.TestportType 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);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.TestportType in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method checkAttributes.
/**
* Does the semantic checking of the attributes assigned to the port type having this body.
*
* @param timestamp the time stamp of the actual semantic check cycle.
* @param withAttributesPath the withAttributesPath assigned to the port type.
*/
public void checkAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
if (lastTimeAttributesChecked != null && !lastTimeAttributesChecked.isLess(timestamp)) {
return;
}
lastTimeAttributesChecked = lastTimeChecked;
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0; i < realAttributes.size(); i++) {
attribute = realAttributes.get(i);
if (Attribute_Type.Extension_Attribute.equals(attribute.getAttributeType())) {
final Qualifiers qualifiers = attribute.getQualifiers();
if (qualifiers == null || qualifiers.getNofQualifiers() == 0) {
if (specifications == null) {
specifications = new ArrayList<AttributeSpecification>();
}
final AttributeSpecification specification = attribute.getAttributeSpecification();
if (specification.getSpecification() != null) {
// there is nothing to parse if specification string is null,
// anyway it would cause NPE in ExtensionAttributeAnalyzer.parse()
specifications.add(specification);
}
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
AttributeSpecification specification;
for (int i = 0; i < specifications.size(); i++) {
specification = specifications.get(i);
final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
analyzer.parse(specification);
final List<ExtensionAttribute> temp = analyzer.getAttributes();
if (temp != null) {
attributes.addAll(temp);
}
}
if (attributes.isEmpty()) {
return;
}
// clear the old attributes
testportType = TestPortAPI_type.TP_REGULAR;
portType = PortType_type.PT_REGULAR;
// check the new attributes
for (int i = 0; i < attributes.size(); i++) {
final ExtensionAttribute extensionAttribute = attributes.get(i);
if (ExtensionAttribute_type.PORTTYPE.equals(extensionAttribute.getAttributeType())) {
final PortTypeAttribute portAttribute = (PortTypeAttribute) extensionAttribute;
switch(portAttribute.getPortTypeType()) {
case INTERNAL:
switch(testportType) {
case TP_REGULAR:
break;
case TP_INTERNAL:
extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `internal'");
break;
case TP_ADDRESS:
extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
break;
default:
break;
}
testportType = TestPortAPI_type.TP_INTERNAL;
break;
case ADDRESS:
switch(testportType) {
case TP_REGULAR:
break;
case TP_INTERNAL:
extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
break;
case TP_ADDRESS:
extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `address'");
break;
default:
break;
}
testportType = TestPortAPI_type.TP_ADDRESS;
break;
case PROVIDER:
switch(portType) {
case PT_REGULAR:
break;
case PT_PROVIDER:
extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `provider'");
break;
case PT_USER:
extensionAttribute.getLocation().reportSemanticError("Attributes `user' and `provider' cannot be used at the same time");
break;
default:
break;
}
addProviderAttribute();
break;
case USER:
switch(portType) {
case PT_REGULAR:
break;
case PT_PROVIDER:
extensionAttribute.getLocation().reportSemanticError("Attributes `provider' and `user' cannot be used at the same time");
break;
case PT_USER:
extensionAttribute.getLocation().reportSemanticError("Duplicate attribute `user'");
break;
default:
break;
}
final UserPortTypeAttribute user = (UserPortTypeAttribute) portAttribute;
addUserAttribute(user.getReference(), user.getInMappings(), user.getOutMappings());
break;
default:
break;
}
}
}
if (PortType_type.PT_USER.equals(portType)) {
checkUserAttribute(timestamp);
} else if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
final TTCN3Module module = (TTCN3Module) myType.getMyScope().getModuleScope();
if (module.getAddressType(timestamp) == null) {
location.reportSemanticError(MessageFormat.format("Type `address'' is not defined in module `{0}''", module.getIdentifier().getDisplayName()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.PortGenerator.TestportType in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method checkUserAttribute.
/**
* Checks the attributes for the specific case when the port is of user type.
*
* @param timestamp the time stamp of the actual semantic check cycle.
*/
private void checkUserAttribute(final CompilationTimeStamp timestamp) {
if (providerReference == null) {
return;
}
providerType = null;
PortTypeBody providerBody = null;
final Assignment assignment = providerReference.getRefdAssignment(timestamp, true);
if (assignment != null) {
if (Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
final IType type = assignment.getType(timestamp).getTypeRefdLast(timestamp);
if (Type_type.TYPE_PORT.equals(type.getTypetype())) {
providerType = type;
providerBody = ((Port_Type) type).getPortBody();
} else {
providerReference.getLocation().reportSemanticError(MessageFormat.format("Type reference `{0}'' does not refer to a port type", providerReference.getDisplayName()));
}
} else {
providerReference.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' does not refer to a type", providerReference.getDisplayName()));
}
}
// checking the consistency of attributes in this and provider_body
if (providerBody != null && !TestPortAPI_type.TP_INTERNAL.equals(testportType)) {
if (!PortType_type.PT_PROVIDER.equals(providerBody.portType)) {
providerReference.getLocation().reportSemanticError(MessageFormat.format("The referenced port type `{0}'' must have the `provider'' attribute", providerType.getTypename()));
}
switch(providerBody.testportType) {
case TP_REGULAR:
if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
providerReference.getLocation().reportSemanticError(MessageFormat.format("Attribute `address'' cannot be used because the provider port type `{0}''" + " does not have attribute `address''", providerType.getTypename()));
}
break;
case TP_INTERNAL:
providerReference.getLocation().reportSemanticError(MessageFormat.format("Missing attribute `internal''. Provider port type `{0}'' has attribute `internal''," + " which must be also present here", providerType.getTypename()));
break;
case TP_ADDRESS:
break;
default:
break;
}
// inherit the test port API type from the provider
testportType = providerBody.testportType;
}
// check the incoming mappings
if (inMappings != null && inMappings.getNofMappings() != 0) {
inMappings.check(timestamp);
if (providerBody != null) {
if (providerBody.inMessages != null) {
// check if all source types are present on the `in' list of the provider
for (int i = 0, size = inMappings.getNofMappings(); i < size; i++) {
final Type sourceType = inMappings.getMappingByIndex(i).getSourceType();
// }
if (sourceType != null && !providerBody.inMessages.hasType(timestamp, sourceType)) {
sourceType.getLocation().reportSemanticError(MessageFormat.format("Source type `{0}'' of the `in'' mapping is not present " + "on the list of incoming messages in provider port type `{1}''", sourceType.getTypename(), providerType.getTypename()));
}
}
// check if all types of the `in' list of the provider are handled by the mappings
for (int i = 0, size = providerBody.inMessages.getNofTypes(); i < size; i++) {
final IType messageType = providerBody.inMessages.getTypeByIndex(i);
if (!inMappings.hasMappingForType(timestamp, messageType)) {
inMappings.getLocation().reportSemanticError(MessageFormat.format("Incoming message type `{0}'' of provider port type `{1}'' is not handled by the incoming mappings", messageType.getTypename(), providerType.getTypename()));
inMappings.hasMappingForType(timestamp, messageType);
}
}
} else {
inMappings.getLocation().reportSemanticError(MessageFormat.format("Invalid incoming mappings. Provider port type `{0}' does not have incoming message types'", providerType.getTypename()));
}
}
// checking target types
for (int i = 0, size = inMappings.getNofMappings(); i < size; i++) {
final TypeMapping mapping = inMappings.getMappingByIndex(i);
for (int j = 0, nofTargets = mapping.getNofTargets(); j < nofTargets; j++) {
final Type targetType = mapping.getTargetByIndex(j).getTargetType();
if (targetType != null && (inMessages == null || !inMessages.hasType(timestamp, targetType))) {
targetType.getLocation().reportSemanticError(MessageFormat.format("Target type `{0}'' of the `in'' mapping is not present on the list of incoming messages in user port type `{1}''", targetType.getTypename(), myType.getTypename()));
}
}
}
} else if (providerBody != null && providerBody.inMessages != null) {
location.reportSemanticError(MessageFormat.format("Missing `in'' mappings to handle the incoming message types of provider port type `{0}''", providerType.getTypename()));
}
if (outMappings != null && outMappings.getNofMappings() != 0) {
outMappings.check(timestamp);
if (outMessages != null) {
// check if all source types are present on the `in' list of the provider
for (int i = 0, size = outMappings.getNofMappings(); i < size; i++) {
final Type sourceType = outMappings.getMappingByIndex(i).getSourceType();
if (sourceType != null && !outMessages.hasType(timestamp, sourceType)) {
sourceType.getLocation().reportSemanticError(MessageFormat.format("Source type `{0}'' of the `out'' mapping is not present on the list of outgoing messages in user port type `{1}''", sourceType.getTypename(), myType.getTypename()));
}
}
// check if all types of the `in' list of the provider are handled by the mappings
for (int i = 0, size = outMessages.getNofTypes(); i < size; i++) {
final IType messageType = outMessages.getTypeByIndex(i);
if (!outMappings.hasMappingForType(timestamp, messageType)) {
outMappings.getLocation().reportSemanticError(MessageFormat.format("Outgoing message type `{0}'' of user port type `{1}'' is not handled by the outgoing mappings", messageType.getTypename(), myType.getTypename()));
}
}
} else {
outMappings.getLocation().reportSemanticError(MessageFormat.format("Invalid outgoing mappings. User port type `{0}'' does not have outgoing message types", myType.getTypename()));
}
// checking target types
if (providerBody != null) {
for (int i = 0, size = outMappings.getNofMappings(); i < size; i++) {
final TypeMapping mapping = outMappings.getMappingByIndex(i);
for (int j = 0, nofTargets = mapping.getNofTargets(); j < nofTargets; j++) {
final Type targetType = mapping.getTargetByIndex(j).getTargetType();
if (targetType != null && (providerBody.outMessages == null || !providerBody.outMessages.hasType(timestamp, targetType))) {
targetType.getLocation().reportSemanticError(MessageFormat.format("Target type `{0}'' of the `out'' mapping is not present " + "on the list of outgoing messages in provider port type `{1}''", targetType.getTypename(), providerType.getTypename()));
}
}
}
}
} else if (outMessages != null) {
location.reportSemanticError(MessageFormat.format("Missing `out'' mapping to handle the outgoing message types of user port type `{0}''", myType.getTypename()));
}
// checking the compatibility of signature lists
if (providerBody == null) {
return;
}
if (inSignatures != null) {
for (int i = 0, size = inSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = inSignatures.getTypeByIndex(i);
if (providerBody.inSignatures == null || !providerBody.inSignatures.hasType(timestamp, signatureType)) {
final IType last = signatureType.getTypeRefdLast(timestamp);
if (!last.getIsErroneous(timestamp) && Type_type.TYPE_SIGNATURE.equals(last.getTypetype())) {
final Signature_Type lastSignature = (Signature_Type) last;
if (!lastSignature.isNonblocking() || lastSignature.getSignatureExceptions() != null) {
signatureType.getLocation().reportSemanticError(MessageFormat.format("Incoming signature `{0}'' of user port type `{1}'' is not present on the list " + "of incoming signatures in provider port type `{2}''", signatureType.getTypename(), myType.getTypename(), providerType.getTypename()));
}
}
}
}
}
if (providerBody.inSignatures != null) {
for (int i = 0, size = providerBody.inSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = providerBody.inSignatures.getTypeByIndex(i);
if (inSignatures == null || !inSignatures.hasType(timestamp, signatureType)) {
location.reportSemanticError(MessageFormat.format("Incoming signature `{0}'' of provider port type `{1}'' " + "is not present on the list of incoming signatures in user port type `{2}''", signatureType.getTypename(), providerType.getTypename(), myType.getTypename()));
}
}
}
if (outSignatures != null) {
for (int i = 0, size = outSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = outSignatures.getTypeByIndex(i);
if (providerBody.outSignatures == null || !providerBody.outSignatures.hasType(timestamp, signatureType)) {
signatureType.getLocation().reportSemanticError(MessageFormat.format("Outgoing signature `{0}'' of user port type `{1}'' is not present " + "on the list of outgoing signatures in provider port type `{2}''", signatureType.getTypename(), myType.getTypename(), providerType.getTypename()));
}
}
}
if (providerBody.outSignatures != null) {
for (int i = 0, size = providerBody.outSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = providerBody.outSignatures.getTypeByIndex(i);
if (outSignatures == null || !outSignatures.hasType(timestamp, signatureType)) {
final IType last = signatureType.getTypeRefdLast(timestamp);
if (!last.getIsErroneous(timestamp) && Type_type.TYPE_SIGNATURE.equals(last.getTypetype())) {
final Signature_Type lastSignature = (Signature_Type) last;
if (!lastSignature.isNonblocking() || lastSignature.getSignatureExceptions() != null) {
location.reportSemanticError(MessageFormat.format("Outgoing signature `{0}'' of provider port type `{1}'' is not present " + "on the list of outgoing signatures in user port type `{2}''", signatureType.getTypename(), providerType.getTypename(), myType.getTypename()));
}
}
}
}
}
}
Aggregations