use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Type method checkThisValueSet.
/**
* Checks the Set_Value kind value against this type.
* <p>
* Please note, that this function can only be called once we know for sure
* that the value is of set type.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param value the value to be checked
* @param expectedValue the kind of value we expect to find.
* @param incompleteAllowed wheather incomplete value is allowed or not.
* @param impliciOmit true if the implicit omit optional attribute was set
* for the value, false otherwise
*/
private boolean checkThisValueSet(final CompilationTimeStamp timestamp, final Set_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean impliciOmit, final boolean strElem) {
value.removeGeneratedValues();
boolean selfReference = false;
final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
final boolean isAsn = value.isAsn();
final int nofValueComponents = value.getNofComponents();
for (int i = 0; i < nofValueComponents; i++) {
final NamedValue namedValue = value.getSequenceValueByIndex(i);
final Identifier valueId = namedValue.getName();
if (!realComponents.containsKey(valueId.getName())) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDASN1 : NONEXISTENTFIELDTTCN3, namedValue.getName().getDisplayName(), getTypename()));
} else {
if (componentMap.containsKey(valueId.getName())) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDAGAINASN1 : DUPLICATEFIELDAGAINTTCN3, valueId.getDisplayName()));
componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(MessageFormat.format(isAsn ? DUPLICATEFIELDFIRSTASN1 : DUPLICATEFIELDFIRSTTTCN3, valueId.getDisplayName()));
} else {
componentMap.put(valueId.getName(), namedValue);
}
final CompField componentField = realComponents.get(valueId.getName());
final Type type = componentField.getType();
final IValue componentValue = namedValue.getValue();
if (componentValue != null) {
componentValue.setMyGovernor(type);
if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
if (!incompleteAllowed) {
componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
}
} else {
final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, impliciOmit, strElem));
}
}
}
}
if (!incompleteAllowed || strictConstantCheckingSeverity) {
final int nofTypeComponents = realComponents.size();
CompField field;
for (int i = 0; i < nofTypeComponents; i++) {
field = compFieldMap.fields.get(i);
final Identifier id = field.getIdentifier();
if (!componentMap.containsKey(id.getName())) {
if (field.isOptional() && impliciOmit) {
value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
} else {
value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
}
}
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class ExtractToFunctionRefactoring method createFunction.
public WorkspaceJob createFunction() {
final WorkspaceJob job = new WorkspaceJob("ExtractToFunction: creating new function text") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
final StatementList selectedStatements = selectionFinder.getSelectedStatements();
final Module selectedModule = getSelectedModule();
final IFile selectedFile = getSelectedFile();
final Reference runsOnRef = selectionFinder.getRunsOnRef();
final Type returnType = selectionFinder.getReturnType();
final ReturnCertainty retCertainty = selectionFinder.getReturnCertainty();
parentFunc = selectionFinder.getParentFunc();
if (parentFunc == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not find the enclosing function of the selection! ");
return Status.CANCEL_STATUS;
}
if (selectionFinder.getInsertLoc() < 0) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Could not calculate the insert location! ");
return Status.CANCEL_STATUS;
}
if (selectedStatements == null || selectedStatements.isEmpty() || selectedModule == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): No or invalid selection! ");
return Status.CANCEL_STATUS;
}
// collect params and find runs on clause
paramCollector = new ParamCollector(project, selectedStatements, selectedModule);
paramCollector.perform();
List<Param> params = paramCollector.getParams();
//
if (params == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to collect params! ");
return Status.CANCEL_STATUS;
}
// create new function text
functionCreator = new FunctionCreator(selectedStatements, selectedFile, newFuncName, params, runsOnRef, returnType, retCertainty);
functionCreator.perform();
functionText = functionCreator.getFunctionText();
if (functionText == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function text! ");
return Status.CANCEL_STATUS;
}
functionCallText = functionCreator.getFunctionCallText();
if (functionCallText == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.createFunction(): Unable to create function call text! ");
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method createModuleParListForSaving.
public String createModuleParListForSaving() {
if (modulePars == null || modulePars.isEmpty()) {
return "<empty>";
}
final List<ModuleParListRecord> records = new ArrayList<ModuleParListRecord>();
for (Def_ModulePar def : modulePars) {
final IResource f = def.getLocation().getFile();
if (!(f instanceof IFile)) {
ErrorReporter.logError("ExtractModulePar/SelectionFinder: IResource `" + f.getName() + "' is not an IFile.");
continue;
}
final Identifier id = def.getIdentifier();
final Type t = def.getType(CompilationTimeStamp.getBaseTimestamp());
records.add(new ModuleParListRecord(def.getMyScope().getModuleScope().getIdentifier().getDisplayName(), id.getDisplayName(), t.getTypename()));
}
//
Collections.sort(records);
final StringBuilder sb = new StringBuilder();
for (ModuleParListRecord rec : records) {
sb.append(rec.toString()).append('\n');
}
return sb.toString();
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class TemplateParser method process.
@Override
public Scope process(IVisitableNode node) {
if (node instanceof Identifier) {
name = node.toString();
// TODO : find a more sophisticated way of storing symbols (e.g. SymbolTable)
myASTVisitor.nodeNameNodeTypeHashMap.put(name, "template");
}
if (node instanceof Type) {
type = Util.getTypeName((Type) node);
template = new Template(name, type);
return Action.skip(Type.class, this);
}
if (node instanceof FormalParameterList) {
return new FormalParameterParser(this, template);
}
// is a modification
if (node instanceof Reference) {
Reference reference = (Reference) node;
String basename = reference.getId().toString();
Template base = registry.find(basename);
// TODO : templates need a base value as a fallback
// TODO : this base value should be used as a reference, to diff against
// TODO : this was a hotfix for the union types to work
String type = base.getValue().getType();
template.setValue(new Value(type, (code, indent) -> code.append("(", type, ") ").append(basename, "()")));
isModification = true;
return Action.skip(Reference.class, this);
}
if (node instanceof TTCN3Template) {
if (isModification) {
return ModificationParser.getScope(this, template, "", type, node);
}
return TemplateValueParser.getScope(this, template, type, node);
}
return this;
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterParser method process.
@Override
public Scope process(IVisitableNode node) {
if (node instanceof FormalParameter) {
FormalParameter parameter = (FormalParameter) node;
name = parameter.getIdentifier().toString();
}
if (node instanceof Type) {
type = Util.getTypeName((Type) node);
}
return this;
}
Aggregations