use of org.eclipse.titan.designer.AST.TTCN3.definitions.Group in project titan.EclipsePlug-ins by eclipse.
the class Type method checkVariants.
/**
* Checks the type's variant attributes (when using the new codec handling).
*/
public void checkVariants(final CompilationTimeStamp timestamp) {
if (isAsn() || ownerType != TypeOwner_type.OT_TYPE_DEF) {
return;
}
WithAttributesPath globalAttributesPath;
final Def_Type def = (Def_Type) owner;
final Group nearest_group = def.getParentGroup();
if (nearest_group == null) {
// no group, use the module
Module myModule = myScope.getModuleScope();
globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
} else {
globalAttributesPath = nearest_group.getAttributePath();
}
if (globalAttributesPath != null) {
// process all global variants, not just the closest group
final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
checkThisVariant(timestamp, singleWithAttribute, true);
}
}
}
// check local variant attributes second, so they overwrite global ones if they
// conflict with each other
final WithAttributesPath attributePath = getAttributePath();
if (attributePath != null) {
final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
if (multipleWithAttributes != null) {
for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Variant_Attribute) {
final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
}
final Reference reference = new Reference(null, fieldsOrArrays);
final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
if (type != null) {
if (type.getMyScope() != myScope) {
qualifier.getLocation().reportSemanticWarning("Variant attribute is ignored, because it refers to a type from a different type definition");
} else {
type.checkThisVariant(timestamp, singleWithAttribute, false);
}
}
}
} else {
checkThisVariant(timestamp, singleWithAttribute, false);
}
}
}
}
}
// check the coding attributes set by the variants
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
checkCodingAttributes(timestamp, chain);
chain.release();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Group in project titan.EclipsePlug-ins by eclipse.
the class RecordSetCodeGenerator method genRawDecodeRecordField.
/**
* This function generates the code for decoding a record field.
*
* @param aData only used to update imports if needed.
* @param source where the source code is to be generated.
* @param fieldInfos the list of field informations.
* @param i the index of the field to generate for.
* @param raw the raw attribute of the record/set.
* @param raw_options the pre-calculated raw options.
* @param delayed_decode true to generated for delayed decoding.
* @param prev_ext_group the index of the previous extension group.
*/
private static void genRawDecodeRecordField(final JavaGenData aData, final StringBuilder source, final List<FieldInfo> fieldInfos, final int i, final RawASTStruct raw, final ArrayList<raw_option_struct> raw_options, final boolean delayed_decode, final AtomicInteger prev_ext_group) {
final raw_option_struct tempRawOption = raw_options.get(i);
if (tempRawOption.ptrbase) {
source.append(MessageFormat.format("start_pos_of_field{0} = buff.get_pos_bit();\n", i));
}
if (prev_ext_group.get() != tempRawOption.extbitgroup) {
prev_ext_group.set(tempRawOption.extbitgroup);
if (prev_ext_group.get() > 0 && raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit != RawAST.XDEFNO) {
if (tempRawOption.pointerof > 0) {
final FieldInfo pointedField = fieldInfos.get(tempRawOption.pointerof - 1);
source.append("{\n");
source.append("int old_pos = buff.get_pos_bit();\n");
source.append(MessageFormat.format("if (start_of_field{0} != -1 && start_pos_of_field{1} != -1) '{'\n", i, pointedField.raw.pointerbase));
source.append(MessageFormat.format("start_of_field{0} = start_pos_of_field{1} + get{2}(){3}.getInt() * {4} + {5};\n", i, pointedField.raw.pointerbase, pointedField.mVarName, pointedField.isOptional ? ".get()" : "", pointedField.raw.unit, pointedField.raw.ptroffset));
source.append(MessageFormat.format("buff.set_pos_bit(start_of_field{0});\n", i));
source.append(MessageFormat.format("limit = end_of_available_data - start_of_field{0};\n", i));
}
source.append("{\n");
source.append("char[] data = buff.get_read_data();\n");
source.append("int count = 1;\n");
source.append("int rot = local_top_order == raw_order_t.ORDER_LSB ? 0: 7;\n");
source.append(MessageFormat.format("while (((data[count - 1] >> rot) & 0x01) == {0} && count * 8 < limit) '{'\n", raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit == RawAST.XDEFYES ? 0 : 1));
source.append("count++;\n");
source.append("}\n");
source.append(" if (limit > 0) {\n");
source.append("group_limit = count * 8;\n");
source.append("}\n");
source.append("}\n");
if (tempRawOption.pointerof > 0) {
source.append(" } else {\n");
source.append("group_limit = 0;\n");
source.append("}\n");
source.append("buff.set_pos_bit(old_pos);\n");
source.append("limit = end_of_available_data - old_pos;\n");
source.append("}\n");
}
}
}
final FieldInfo fieldInfo = fieldInfos.get(i);
final int crosstagsize = fieldInfo.raw == null || fieldInfo.raw.crosstaglist == null || fieldInfo.raw.crosstaglist.list == null ? 0 : fieldInfo.raw.crosstaglist.list.size();
if (crosstagsize > 0) {
int other = -1;
boolean first_value = true;
for (int j = 0; j < crosstagsize; j++) {
final rawAST_coding_taglist cur_choice = fieldInfo.raw.crosstaglist.list.get(j);
if (cur_choice.fields != null && cur_choice.fields.size() > 0) {
if (first_value) {
source.append("if (");
first_value = false;
} else {
source.append(" else if (");
}
genRawFieldChecker(source, cur_choice, true);
source.append(") {\n");
source.append(MessageFormat.format("selected_field = {0};\n", cur_choice.fieldnum));
source.append("}");
} else {
other = cur_choice.fieldnum;
}
}
source.append(" else {\n");
source.append(MessageFormat.format("selected_field = {0};\n", other));
source.append("}\n");
}
/* check the presence of optional field*/
if (fieldInfo.isOptional) {
/* check if enough bits to decode the field*/
source.append("if ( limit > 0");
for (int a = 0; a < tempRawOption.lengthof; a++) {
final int field_index = tempRawOption.lengthofField.get(a);
if (i > field_index) {
source.append(MessageFormat.format(" && value_of_length_field{0} > 0", field_index));
}
}
if (tempRawOption.extbitgroup > 0 && raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit != RawAST.XDEFNO) {
source.append(" && group_limit > 0");
}
if (tempRawOption.pointerof > 0) {
source.append(MessageFormat.format(" && start_of_field{0} != -1 && start_pos_of_field{1} != -1", i, fieldInfos.get(tempRawOption.pointerof - 1).raw.pointerbase));
}
final int presenceSize = fieldInfo.raw == null || fieldInfo.raw.presence == null || fieldInfo.raw.presence.fields == null ? 0 : fieldInfo.raw.presence.fields.size();
if (presenceSize > 0) {
source.append(" && ");
if (presenceSize > 1) {
source.append('(');
}
genRawFieldChecker(source, fieldInfo.raw.presence, true);
if (presenceSize > 1) {
source.append(')');
}
}
if (crosstagsize > 0) {
source.append("&& selected_field != -1");
}
source.append(") {\n");
}
if (tempRawOption.pointerof > 0) {
final FieldInfo tempPointed = fieldInfos.get(tempRawOption.pointerof - 1);
source.append(MessageFormat.format("start_of_field{0} = start_pos_of_field{1} + get{2}(){3}.getInt() * {4} + {5};\n", i, tempPointed.raw.pointerbase, tempPointed.mJavaVarName, tempPointed.isOptional ? ".get()" : "", tempPointed.raw.unit, tempPointed.raw.ptroffset));
source.append(MessageFormat.format("buff.set_pos_bit(start_of_field{0});\n", i));
source.append(MessageFormat.format("limit = end_of_available_data - start_of_field{0};\n", i));
}
if (fieldInfo.isOptional) {
source.append("int fl_start_pos = buff.get_pos_bit();\n");
}
final ExpressionStruct expression = new ExpressionStruct();
if (delayed_decode) {
/* the fixed field length is used as limit in case of delayed decoding */
expression.expression.append(fieldInfo.raw.length);
} else {
genRawFieldDecodeLimit(aData, expression, fieldInfos, i, raw, raw_options);
}
if (expression.preamble.length() > 0) {
source.append(expression.preamble);
}
source.append(MessageFormat.format("decoded_field_length = get{0}(){1}.RAW_decode({2}_descr_, buff, ", fieldInfo.mJavaVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.mTypeDescriptorName));
source.append(expression.expression);
source.append(MessageFormat.format(", local_top_order, {0}", fieldInfo.isOptional ? "true" : "no_err"));
if (crosstagsize > 0) {
source.append(", selected_field");
} else {
source.append(", -1");
}
boolean found = false;
for (int a = 0; a < tempRawOption.lengthof && !found; a++) {
final int field_index = tempRawOption.lengthofField.get(a);
if (fieldInfos.get(field_index).raw.unit == -1) {
source.append(MessageFormat.format(", value_of_length_field{0}", field_index));
found = true;
}
}
if (!found) {
source.append(", true");
}
source.append(");\n");
if (delayed_decode) {
source.append(MessageFormat.format("if ( decoded_field_length != {0}) '{'\n", fieldInfo.raw.length));
source.append("return -1;\n");
source.append("}\n");
} else if (fieldInfo.isOptional) {
source.append("if (decoded_field_length < 1) {\n");
source.append(MessageFormat.format("{0}.assign(template_sel.OMIT_VALUE);\n", fieldInfo.mVarName));
source.append("buff.set_pos_bit(fl_start_pos);\n");
source.append(" } else {\n");
} else {
source.append("if (decoded_field_length < 0) {\n");
source.append("return decoded_field_length;\n");
source.append("}\n");
}
if (tempRawOption.tag_type > 0 && raw.taglist.list.get(tempRawOption.tag_type - 1).fields.size() > 0) {
final rawAST_coding_taglist cur_choice = raw.taglist.list.get(tempRawOption.tag_type - 1);
source.append("if (");
genRawFieldChecker(source, cur_choice, false);
source.append(") {\n");
if (fieldInfo.isOptional) {
source.append(MessageFormat.format("{0}.assign(template_sel.OMIT_VALUE);\n", fieldInfo.mVarName));
source.append("buff.set_pos_bit(fl_start_pos);\n");
source.append(" } else {");
} else {
source.append("return -1;\n");
source.append("}\n");
}
}
if (!delayed_decode) {
source.append("decoded_length += decoded_field_length;\n");
source.append("limit -= decoded_field_length;\n");
source.append("last_decoded_pos = Math.max(last_decoded_pos, buff.get_pos_bit());\n");
}
if (tempRawOption.extbitgroup > 0 && raw.ext_bit_groups.get(tempRawOption.extbitgroup - 1).ext_bit != RawAST.XDEFNO) {
source.append("group_limit -= decoded_field_length;\n");
}
if (tempRawOption.lengthto) {
if (fieldInfo.raw.lengthindex != null) {
if (fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD) {
source.append(MessageFormat.format("if ({0}{1}.get{2}().isPresent()) '{'\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthindex.nthfieldname));
}
if (fieldInfo.raw.lengthto_offset != 0) {
source.append(MessageFormat.format("{0}{1}.get{2}(){3}.assign({0}{1}.get{2}(){3} - {4});\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthindex.nthfieldname, fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD ? ".get()" : "", fieldInfo.raw.lengthto_offset));
}
source.append(MessageFormat.format("value_of_length_field{0} += {1}{2}.get{3}(){4}.getInt() * {5};\n", i, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthindex.nthfieldname, fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD ? ".get()" : "", fieldInfo.raw.unit == -1 ? 1 : fieldInfo.raw.unit));
if (fieldInfo.raw.lengthindex.fieldtype == rawAST_coding_field_type.OPTIONAL_FIELD) {
source.append("}\n");
}
} else if (fieldInfo.raw.union_member_num > 0) {
source.append(MessageFormat.format("switch ({0}{1}.get_selection()) '{'\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : ""));
for (int m = 0; m < fieldInfo.raw.member_name.size(); m++) {
source.append(MessageFormat.format("case {0}.{1}", fieldInfo.raw.member_name.get(0), fieldInfo.raw.member_name.get(m)));
if (fieldInfo.raw.lengthto_offset != 0) {
source.append(MessageFormat.format("{0}{1}.get{2}().assign({0}{1}.get{2}() - {3});\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.member_name.get(m), fieldInfo.raw.lengthto_offset));
}
source.append(MessageFormat.format("value_of_length_field{0} += {1}{2}.get{3}().getInt() * {4};\n", i, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.member_name.get(m), fieldInfo.raw.unit == -1 ? 1 : fieldInfo.raw.unit));
source.append("break;\n");
}
source.append("default:\n");
source.append(MessageFormat.format("value_of_length_field{0} = 0;\n", i));
source.append("}\n");
} else {
if (fieldInfo.raw.lengthto_offset != 0) {
source.append(MessageFormat.format("{0}{1}.assign({0}{1}.getInt() - {2});\n", fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.lengthto_offset));
}
source.append(MessageFormat.format("value_of_length_field{0} += {1}{2}.getInt() * {3};\n", i, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.unit == -1 ? 1 : fieldInfo.raw.unit));
}
}
if (tempRawOption.pointerto) {
source.append(MessageFormat.format("start_of_field{0} = {1}{2}.getInt() {3};\n ", fieldInfo.raw.pointerto, fieldInfo.mVarName, fieldInfo.isOptional ? ".get()" : "", fieldInfo.raw.ptroffset > 0 ? " + 1" : "- 1"));
}
if (!delayed_decode) {
/* mark the used bits in length area*/
for (int a = 0; a < tempRawOption.lengthof; a++) {
final int field_index = tempRawOption.lengthofField.get(a);
source.append(MessageFormat.format("value_of_length_field{0} -= decoded_field_length;\n", field_index));
if (i == field_index) {
source.append(MessageFormat.format("if (value_of_length_field{0} < 0) '{'\n", field_index));
source.append("return -1;\n");
source.append("}\n");
}
}
}
if (fieldInfo.isOptional) {
source.append("}\n");
source.append("}");
if (tempRawOption.tag_type > 0) {
source.append("\n}");
}
source.append(" else {\n");
source.append(MessageFormat.format("{0}.assign(template_sel.OMIT_VALUE);\n", fieldInfo.mVarName));
source.append("}\n");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Group in project titan.EclipsePlug-ins by eclipse.
the class Visibility method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (node instanceof FormalParameter) {
return;
} else if (node instanceof Definition) {
final Definition s = (Definition) node;
final Identifier identifier = s.getIdentifier();
check(identifier, s.getDescription(), problems);
} else if (node instanceof Group) {
final Group s = (Group) node;
final Identifier identifier = s.getIdentifier();
check(identifier, "group", problems);
} else {
return;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Group in project titan.EclipsePlug-ins by eclipse.
the class Definitions method updateSyntax.
/**
* Handles the incremental parsing of this list of definitions.
*
* @param reparser
* the parser doing the incremental parsing.
* @param importedModules
* the list of module importations found in the same
* module.
* @param friendModules
* the list of friend module declaration in the same
* module.
* @param controlpart
* the control part found in the same module.
* @throws ReParseException
* if there was an error while refreshing the location
* information and it could not be solved internally.
*/
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> importedModules, final List<FriendModule> friendModules, final ControlPart controlpart) throws ReParseException {
// calculate damaged region
int result = 0;
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = location.getOffset();
int rightBoundary = location.getEndOffset();
final int damageOffset = reparser.getDamageStart();
final int damageEndOffset = reparser.getDamageEnd();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
boolean isControlPossible = controlpart == null;
if (controlpart != null) {
final Location tempLocation = controlpart.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
} else if (!reparser.isDamaged(tempLocation)) {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = controlpart;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = controlpart;
}
}
}
for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
final Group tempGroup = groups.get(i);
final Location tempLocation = tempGroup.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = tempGroup;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = tempGroup;
}
}
}
if (!groups.isEmpty()) {
isControlPossible &= groups.get(groups.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
final ImportModule tempImport = importedModules.get(i);
if (tempImport.getParentGroup() == null) {
final Location tempLocation = tempImport.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = tempImport;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = tempImport;
}
}
}
}
if (!importedModules.isEmpty()) {
isControlPossible &= importedModules.get(importedModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
final FriendModule tempFriend = friendModules.get(i);
if (tempFriend.getParentGroup() == null) {
final Location tempLocation = tempFriend.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = tempFriend;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = tempFriend;
}
}
}
}
if (!friendModules.isEmpty()) {
isControlPossible &= friendModules.get(friendModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
final Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
} else {
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (cumulativeLocation.getOffset() > damageEndOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
final Location tempCommentLocation = temp.getCommentLocation();
if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
nofDamaged++;
rightBoundary = tempLocation.getEndOffset();
}
}
}
if (!definitions.isEmpty()) {
isControlPossible &= definitions.get(definitions.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
// was not enveloped
if (!enveloped && reparser.isDamaged(location)) {
// the extension might be correct
if (lastAppendableBeforeChange != null) {
final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
if (isBeingExtended) {
leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (lastPrependableBeforeChange != null) {
final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
if (temp != null && reparser.endsWithToken(temp)) {
rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (nofDamaged != 0) {
// remove damaged stuff
removeStuffInRange(reparser, importedModules, friendModules);
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
lastCompilationTimeStamp = null;
}
// extend damaged region till the neighbor definitions just here to avoid calculating something damaged or extended:
// Perhaps it should be moved even farther:
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
// update what is left
for (int i = 0; i < groups.size(); i++) {
final Group temp = groups.get(i);
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, importedModules, definitions, friendModules);
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
groups.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
for (int i = 0; i < importedModules.size(); i++) {
final ImportModule temp = importedModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
if (isDamaged) {
((TTCN3Module) parentScope).checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
importedModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
}
for (int i = 0; i < friendModules.size(); i++) {
final FriendModule temp = friendModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
if (isDamaged) {
((TTCN3Module) parentScope).checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
friendModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(cumulativeLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, isDamaged);
if (reparser.getNameChanged()) {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
// to recheck the whole module
lastCompilationTimeStamp = null;
reparser.setNameChanged(false);
// This could also spread
}
if (isDamaged) {
// TODO lets move this into the definitions
temp.checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(cumulativeLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
}
if (result == 1) {
removeStuffInRange(reparser, importedModules, friendModules);
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
lastCompilationTimeStamp = null;
}
for (int i = 0, size = groups.size(); i < size; i++) {
final Group temp = groups.get(i);
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (int i = 0, size = importedModules.size(); i < size; i++) {
final ImportModule temp = importedModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
}
for (int i = 0, size = friendModules.size(); i < size; i++) {
final FriendModule temp = friendModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(tempLocation)) {
if (tempLocation != cumulativeLocation) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(tempLocation);
}
}
}
final boolean tempIsControlPossible = isControlPossible;
if (!enveloped) {
if (reparser.envelopsDamage(location)) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
result = reparse(reparser, tempIsControlPossible);
result = Math.max(result - 1, 0);
lastCompilationTimeStamp = null;
} else {
result = Math.max(result, 1);
}
}
if (result == 0) {
lastUniquenessCheckTimeStamp = null;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
throw new ReParseException(result);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Group in project titan.EclipsePlug-ins by eclipse.
the class Group method updateSyntax.
/**
* Handles the incremental parsing of this list of definitions.
*
* @param reparser
* the parser doing the incremental parsing.
* @param allImportedModules
* the list of module importations found in the same
* module.
* @param allDefinitions
* the list of definitions found in the same module.
* @param allFriends
* the list of friend module declarations found in the
* same module.
* @return in case of processing error the minimum amount of semantic
* levels that must be destroyed to handle the syntactic
* changes, otherwise 0.
*/
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> allImportedModules, final List<Definition> allDefinitions, final List<FriendModule> allFriends) throws ReParseException {
int result = 0;
Location tempLocation = identifier.getLocation();
if (reparser.isDamaged(tempLocation)) {
if (reparser.envelopsDamage(tempLocation) || reparser.isExtending(tempLocation)) {
reparser.extendDamagedRegion(tempLocation);
result = reparseIdentifier(reparser);
if (result != 0) {
throw new ReParseException(result);
}
} else {
throw new ReParseException();
}
} else {
reparser.updateLocation(tempLocation);
}
if (reparser.isDamaged(innerLocation) && !reparser.envelopsDamage(innerLocation)) {
throw new ReParseException();
}
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = innerLocation.getOffset();
int rightBoundary = innerLocation.getEndOffset();
final int damageOffset = reparser.getDamageStart();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
final Group temp = groups.get(i);
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
final ImportModule temp = importedModules.get(i);
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
final FriendModule temp = friendModules.get(i);
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
final Definition temp = iterator.next();
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
// reparser.extendDamagedRegion(temp_location);
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
final Location tempCommentLocation = temp.getCommentLocation();
if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
rightBoundary = tempCommentLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
// was not enveloped
if (!enveloped && reparser.envelopsDamage(location)) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
// correct
if (lastAppendableBeforeChange != null) {
final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
if (isBeingExtended) {
leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (lastPrependableBeforeChange != null) {
final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
if (temp != null && reparser.endsWithToken(temp)) {
rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (nofDamaged != 0) {
// remove damaged stuff
removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
}
// update what is left
for (int i = 0; i < groups.size(); i++) {
final Group temp = groups.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, allImportedModules, allDefinitions, friendModules);
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
groups.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
for (int i = 0; i < importedModules.size(); i++) {
final ImportModule temp = importedModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
importedModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
for (int i = 0; i < friendModules.size(); i++) {
final FriendModule temp = friendModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
friendModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, isDamaged);
if (reparser.getNameChanged()) {
lastUniquenessCheckTimeStamp = null;
reparser.setNameChanged(false);
}
if (isDamaged) {
temp.checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
if (result == 1) {
removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
}
for (int i = 0, size = groups.size(); i < size; i++) {
final Group temp = groups.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (int i = 0, size = importedModules.size(); i < size; i++) {
final ImportModule temp = importedModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (int i = 0, size = friendModules.size(); i < size; i++) {
final FriendModule temp = friendModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
if (withAttributesPath != null && reparser.isAffected(withAttributesPath.getLocation())) {
if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
reparser.extendDamagedRegion(withAttributesPath.getLocation());
result = reparseOptionalWithStatement(reparser);
if (result != 0) {
throw new ReParseException(result);
}
return;
}
withAttributesPath.updateSyntax(reparser, reparser.envelopsDamage(withAttributesPath.getLocation()));
reparser.updateLocation(withAttributesPath.getLocation());
}
if (!enveloped && reparser.envelopsDamage(innerLocation)) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
result = reparseModuleDefinitionsList(reparser);
}
reparser.updateLocation(innerLocation);
if (result > 1) {
throw new ReParseException(result - 1);
}
return;
}
Aggregations