use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class CompFieldMap method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
lastCompilationTimeStamp = null;
if (doubleComponents != null) {
fields.addAll(doubleComponents);
doubleComponents = null;
lastUniquenessCheck = null;
}
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = location.getOffset();
int rightBoundary = location.getEndOffset();
final int damageOffset = reparser.getDamageStart();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
for (int i = 0, size = fields.size(); i < size && !enveloped; i++) {
final CompField field = fields.get(i);
final Location tempLocation = field.getLocation();
// move offset to commentLocation
if (field.getCommentLocation() != null) {
tempLocation.setOffset(field.getCommentLocation().getOffset());
}
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
lastAppendableBeforeChange = field;
} else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
lastPrependableBeforeChange = field;
}
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = field;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = field;
}
}
}
// extend the reparser to the calculated values if the damage was not enveloped
if (!enveloped) {
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) {
removeStuffInRange(reparser);
}
for (int i = 0; i < fields.size(); i++) {
final CompField field = fields.get(i);
final Location tempLocation = field.getLocation();
if (reparser.isAffectedAppended(tempLocation)) {
try {
field.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
reparser.updateLocation(field.getLocation());
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
fields.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
} else {
e.decreaseDepth();
throw e;
}
}
}
}
if (!enveloped) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
int result = reparse(reparser);
if (result == 0) {
return;
}
throw new ReParseException(Math.max(--result, 0));
}
return;
}
for (int i = 0, size = fields.size(); i < size; i++) {
final CompField field = fields.get(i);
field.updateSyntax(reparser, false);
reparser.updateLocation(field.getLocation());
}
if (doubleComponents != null) {
for (int i = 0, size = doubleComponents.size(); i < size; i++) {
final CompField field = doubleComponents.get(i);
field.updateSyntax(reparser, false);
reparser.updateLocation(field.getLocation());
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class UStringValueConstraint method except.
/**
* return (first - second) set
*/
@Override
public UStringValueConstraint except(final SubtypeConstraint other) {
final UStringValueConstraint o = (UStringValueConstraint) other;
final Set<UniversalCharstring> returnValue = new TreeSet<UniversalCharstring>();
for (UniversalCharstring str : values) {
if (!o.values.contains(str)) {
returnValue.add(str);
}
}
return new UStringValueConstraint(returnValue);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class Reference method getRefdAssignment.
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList, final IReferenceChain referenceChain) {
if (myScope == null || getId() == null) {
return null;
}
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp) && !checkParameterList) {
return referredAssignment;
}
lastTimeChecked = timestamp;
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
isErroneous = false;
detectedModuleId = false;
detectModid();
referredAssignment = myScope.getAssBySRef(timestamp, this, referenceChain);
if (referredAssignment == null) {
isErroneous = true;
return referredAssignment;
}
referredAssignment.check(timestamp, tempReferenceChain);
referredAssignment.setUsed();
if (referredAssignment instanceof Definition) {
final String referingModuleName = getMyScope().getModuleScope().getName();
if (!((Definition) referredAssignment).referingHere.contains(referingModuleName)) {
((Definition) referredAssignment).referingHere.add(referingModuleName);
}
}
if (checkParameterList) {
FormalParameterList formalParameterList = null;
if (referredAssignment instanceof IParameterisedAssignment) {
formalParameterList = ((IParameterisedAssignment) referredAssignment).getFormalParameterList();
}
if (formalParameterList == null) {
if (!subReferences.isEmpty() && subReferences.get(0) instanceof ParameterisedSubReference) {
final String message = MessageFormat.format("The referenced {0} cannot have actual parameters", referredAssignment.getDescription());
getLocation().reportSemanticError(message);
setIsErroneous(true);
}
} else if (!subReferences.isEmpty()) {
final ISubReference firstSubReference = subReferences.get(0);
if (firstSubReference instanceof ParameterisedSubReference) {
formalParameterList.check(timestamp, referredAssignment.getAssignmentType());
isErroneous = ((ParameterisedSubReference) firstSubReference).checkParameters(timestamp, formalParameterList);
} else {
// default values
if (!Assignment.Assignment_type.A_TEMPLATE.semanticallyEquals(referredAssignment.getAssignmentType()) || !formalParameterList.hasOnlyDefaultValues()) {
final String message = MessageFormat.format("Reference to parameterized definition `{0}'' without actual parameter list", referredAssignment.getIdentifier().getDisplayName());
getLocation().reportSemanticError(message);
setIsErroneous(true);
}
}
}
}
return referredAssignment;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last == this) {
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(name);
expression.expression.append(".assign(");
reference.generateConstRef(aData, expression);
expression.expression.append(")");
expression.mergeExpression(source);
return source;
}
// the code generation is based on the referred value
if (last.canGenerateSingleExpression() && myScope.getModuleScope() == last.getMyScope().getModuleScope()) {
// simple substitution for in-line values within the same module
source.append(MessageFormat.format("{0}.assign({1});\n", name, last.generateSingleExpression(aData)));
} else {
// TODO might need initialization see needs_init_precede
// TODO Value.cc:generate_code_init_refd
source.append(MessageFormat.format("{0}.assign({1});\n", name, last.getGenNameOwn(myScope)));
}
return source;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Values in project titan.EclipsePlug-ins by eclipse.
the class Sequence_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
* generate_code_init_se in the compiler
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (convertedValue != null) {
return convertedValue.generateCodeInit(aData, source, name);
}
IType governor = myGovernor;
if (governor == null) {
governor = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
}
if (governor == null) {
governor = myLastSetGovernor;
}
final IType type = governor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
int nofComps = 0;
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
nofComps = ((TTCN3_Sequence_Type) type).getNofComponents();
break;
case TYPE_ASN1_SEQUENCE:
nofComps = ((ASN1_Sequence_Type) type).getNofComponents(CompilationTimeStamp.getBaseTimestamp());
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
if (nofComps == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
return source;
}
CompField compField = null;
for (int i = 0; i < nofComps; i++) {
switch(type.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
compField = ((TTCN3_Sequence_Type) type).getComponentByIndex(i);
break;
case TYPE_ASN1_SEQUENCE:
compField = ((ASN1_Sequence_Type) type).getComponentByIndex(i);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for value `" + getFullName() + "''");
}
final Identifier fieldName = compField.getIdentifier();
IValue fieldValue;
if (hasComponentWithName(fieldName)) {
fieldValue = getComponentByName(fieldName).getValue();
if (Value_type.NOTUSED_VALUE.equals(fieldValue.getValuetype())) {
continue;
} else if (Value_type.OMIT_VALUE.equals(fieldValue.getValuetype())) {
fieldValue = null;
}
} else // TODO add support for asn default values when needed
{
continue;
}
final String javaGetterName = FieldSubReference.getJavaGetterName(fieldName.getName());
if (fieldValue != null) {
// TODO handle the case when temporary reference is needed
final StringBuilder embeddedName = new StringBuilder();
embeddedName.append(name);
embeddedName.append(".get");
embeddedName.append(javaGetterName);
embeddedName.append("()");
if (compField.isOptional()) /*&& fieldValue.isCompound() */
{
embeddedName.append(".get()");
}
// TODO add extra handling for optional fields
fieldValue.generateCodeInit(aData, source, embeddedName.toString());
} else {
aData.addBuiltinTypeImport("Base_Template.template_sel");
source.append(MessageFormat.format("{0}.get{1}().assign(template_sel.OMIT_VALUE);\n", name, javaGetterName));
}
}
return source;
}
Aggregations