use of org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification in project titan.EclipsePlug-ins by eclipse.
the class Def_Extfunction method analyzeExtensionAttributes.
/**
* Convert and check the encoding attributes applied to this external
* function.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
public void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0, size = realAttributes.size(); i < 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>();
}
specifications.add(attribute.getAttributeSpecification());
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
AttributeSpecification specification;
for (int i = 0, size = specifications.size(); i < 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);
}
}
ExtensionAttribute extensionAttribute;
for (int i = 0, size = attributes.size(); i < size; i++) {
extensionAttribute = attributes.get(i);
switch(extensionAttribute.getAttributeType()) {
case PROTOTYPE:
if (EncodingPrototype_type.NONE.equals(prototype)) {
prototype = ((PrototypeAttribute) extensionAttribute).getPrototypeType();
} else {
location.reportSemanticError("duplicate attribute `prototype'.");
}
break;
case ENCODE:
switch(functionEncodingType) {
case MANUAL:
break;
case ENCODE:
location.reportSemanticError("duplicate attribute `encode'.");
break;
case DECODE:
location.reportSemanticError("`decode' and `encode' attributes cannot be used at the same time.");
break;
default:
break;
}
encodingType = ((EncodeAttribute) extensionAttribute).getEncodingType();
encodingOptions = ((EncodeAttribute) extensionAttribute).getOptions();
functionEncodingType = ExternalFunctionEncodingType_type.ENCODE;
break;
case DECODE:
switch(functionEncodingType) {
case MANUAL:
break;
case ENCODE:
location.reportSemanticError("`decode' and `encode' attributes cannot be used at the same time.");
break;
case DECODE:
location.reportSemanticError("duplicate attribute `decode'.");
break;
default:
break;
}
encodingType = ((DecodeAttribute) extensionAttribute).getEncodingType();
encodingOptions = ((DecodeAttribute) extensionAttribute).getOptions();
functionEncodingType = ExternalFunctionEncodingType_type.DECODE;
break;
case ERRORBEHAVIOR:
if (errorBehaviorList == null) {
errorBehaviorList = ((ErrorBehaviorAttribute) extensionAttribute).getErrrorBehaviorList();
} else {
errorBehaviorList.addAllBehaviors(((ErrorBehaviorAttribute) extensionAttribute).getErrrorBehaviorList());
}
break;
case PRINTING:
if (printingType == null) {
printingType = ((PrintingAttribute) extensionAttribute).getPrintingType();
} else {
location.reportSemanticError("duplicate attribute `printing'.");
}
break;
default:
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification in project titan.EclipsePlug-ins by eclipse.
the class Def_Function method analyzeExtensionAttributes.
/**
* Convert and check the encoding attributes applied to this function.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
public void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0, size = realAttributes.size(); i < 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>();
}
specifications.add(attribute.getAttributeSpecification());
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
for (int i = 0, size = specifications.size(); i < size; i++) {
final AttributeSpecification specification = specifications.get(i);
final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
analyzer.parse(specification);
final List<ExtensionAttribute> temp = analyzer.getAttributes();
if (temp != null) {
attributes.addAll(temp);
}
}
for (int i = 0, size = attributes.size(); i < size; i++) {
final ExtensionAttribute extensionAttribute = attributes.get(i);
if (ExtensionAttribute_type.PROTOTYPE.equals(extensionAttribute.getAttributeType())) {
final PrototypeAttribute realAttribute = (PrototypeAttribute) extensionAttribute;
if (EncodingPrototype_type.NONE.equals(prototype)) {
prototype = realAttribute.getPrototypeType();
} else {
realAttribute.getLocation().reportSingularSemanticError("Duplicate attribute `prototype'");
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification in project titan.EclipsePlug-ins by eclipse.
the class Anytype_Type method analyzeExtensionAttributes.
/**
* Convert and check the anytype attributes applied to the module of this type.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
clear();
final TTCN3Module myModule = (TTCN3Module) getMyScope().getModuleScope();
final WithAttributesPath moduleAttributePath = myModule.getAttributePath();
if (moduleAttributePath == null) {
return;
}
final List<SingleWithAttribute> realAttributes = moduleAttributePath.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>();
}
specifications.add(attribute.getAttributeSpecification());
}
}
}
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);
}
}
final Scope definitionsScope = myModule.getDefinitions();
ExtensionAttribute extensionAttribute;
for (int i = 0; i < attributes.size(); i++) {
extensionAttribute = attributes.get(i);
if (ExtensionAttribute_type.ANYTYPE.equals(extensionAttribute.getAttributeType())) {
final AnytypeAttribute anytypeAttribute = (AnytypeAttribute) extensionAttribute;
for (int j = 0; j < anytypeAttribute.getNofTypes(); j++) {
final Type tempType = anytypeAttribute.getType(j);
String fieldName;
Identifier identifier = null;
if (Type_type.TYPE_REFERENCED.equals(tempType.getTypetype())) {
final Reference reference = ((Referenced_Type) tempType).getReference();
identifier = reference.getId();
fieldName = identifier.getTtcnName();
} else {
fieldName = tempType.getTypename();
identifier = new Identifier(Identifier_type.ID_TTCN, fieldName);
}
tempType.setMyScope(definitionsScope);
addComp(new CompField(identifier, tempType, false, null));
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification in project titan.EclipsePlug-ins by eclipse.
the class Definition method parseErrAttrSpecString.
private static ErroneousAttributeSpecification parseErrAttrSpecString(final AttributeSpecification aAttrSpec) {
String code = aAttrSpec.getSpecification();
if (code == null) {
return null;
}
final Location location = aAttrSpec.getLocation();
// code must be transformed, according to
// compiler2/ttcn3/charstring_la.l
// TODO
code = Ttcn3CharstringLexer.parseCharstringValue(code, location);
final Reader reader = new StringReader(code);
final CharStream charStream = new UnbufferedCharStream(reader);
final Ttcn3Lexer lexer = new Ttcn3Lexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
// needs to be shifted by one because of the \" of the string
lexer.setCharPositionInLine(0);
// lexer and parser listener
final TitanListener parserListener = new TitanListener();
// remove ConsoleErrorListener
lexer.removeErrorListeners();
lexer.addErrorListener(parserListener);
// 1. Previously it was UnbufferedTokenStream(lexer), but it was changed to BufferedTokenStream, because UnbufferedTokenStream seems to be unusable. It is an ANTLR 4 bug.
// Read this: https://groups.google.com/forum/#!topic/antlr-discussion/gsAu-6d3pKU
// pr_PatternChunk[StringBuilder builder, boolean[] uni]:
// $builder.append($v.text); <-- exception is thrown here: java.lang.UnsupportedOperationException: interval 85..85 not in token buffer window: 86..341
// 2. Changed from BufferedTokenStream to CommonTokenStream, otherwise tokens with "-> channel(HIDDEN)" are not filtered out in lexer.
final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
final Ttcn3Reparser parser = new Ttcn3Reparser(tokenStream);
ParserUtilities.setBuildParseTree(parser);
final IFile file = (IFile) location.getFile();
parser.setActualFile(file);
parser.setOffset(location.getOffset());
parser.setLine(location.getLine());
// remove ConsoleErrorListener
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
MarkerHandler.markMarkersForRemoval(GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER, location.getFile(), location.getOffset(), location.getEndOffset());
final Pr_ErroneousAttributeSpecContext root = parser.pr_ErroneousAttributeSpec();
ParserUtilities.logParseTree(root, parser);
final ErroneousAttributeSpecification returnValue = root.errAttrSpec;
final List<SyntacticErrorStorage> errors = parser.getErrors();
final List<TITANMarker> warnings = parser.getWarnings();
final List<TITANMarker> unsupportedConstructs = parser.getUnsupportedConstructs();
// add markers
if (errors != null) {
for (int i = 0; i < errors.size(); i++) {
final Location temp = new Location(location);
temp.setOffset(temp.getOffset());
ParserMarkerSupport.createOnTheFlySyntacticMarker(file, errors.get(i), IMarker.SEVERITY_ERROR, temp);
}
}
if (warnings != null) {
for (final TITANMarker marker : warnings) {
if (file.isAccessible()) {
final Location loc = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
loc.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
}
}
}
if (unsupportedConstructs != null) {
for (final TITANMarker marker : unsupportedConstructs) {
if (file.isAccessible()) {
final Location loc = new Location(file, marker.getLine(), marker.getOffset(), marker.getEndOffset());
loc.reportExternalProblem(marker.getMessage(), marker.getSeverity(), GeneralConstants.ONTHEFLY_SYNTACTIC_MARKER);
}
}
}
return returnValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification in project titan.EclipsePlug-ins by eclipse.
the class Def_Type method analyzeExtensionAttributes.
/**
* Convert and check the encoding attributes applied to this function.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
public void analyzeExtensionAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0, size = realAttributes.size(); i < 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>();
}
specifications.add(attribute.getAttributeSpecification());
} else {
for (int j = 0, size2 = qualifiers.getNofQualifiers(); j < size2; j++) {
final Qualifier tempQualifier = qualifiers.getQualifierByIndex(i);
final ISubReference tempSubReference = tempQualifier.getSubReferenceByIndex(0);
if (tempSubReference.getReferenceType() == Subreference_type.arraySubReference) {
tempQualifier.getLocation().reportSemanticError(Qualifier.INVALID_INDEX_QUALIFIER);
} else {
tempQualifier.getLocation().reportSemanticError(MessageFormat.format(Qualifier.INVALID_FIELD_QUALIFIER, tempSubReference.getId().getDisplayName()));
}
}
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
for (int i = 0; i < specifications.size(); i++) {
final AttributeSpecification specification = specifications.get(i);
final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
analyzer.parse(specification);
final List<ExtensionAttribute> temp = analyzer.getAttributes();
if (temp != null) {
attributes.addAll(temp);
}
}
for (int i = 0; i < attributes.size(); i++) {
final ExtensionAttribute extensionAttribute = attributes.get(i);
switch(extensionAttribute.getAttributeType()) {
case ANYTYPE:
case VERSION:
case REQUIRES:
case TITANVERSION:
break;
default:
// only extension attributes are allowed ... and
// only because they can not be stopped earlier.
extensionAttribute.getLocation().reportSemanticError("Extension attributes are not supported for types");
}
}
}
Aggregations