Search in sources :

Example 1 with Scope

use of org.eclipse.titan.codegenerator.Scope in project titan.EclipsePlug-ins by eclipse.

the class ConstantParser method process.

@Override
public Scope process(IVisitableNode node) {
    if (node instanceof Identifier) {
        name = node.toString();
    }
    if (node instanceof Type) {
        type = Util.getTypeName((Type) node);
        value = new Value(type, Writable.NULL);
        return Action.skip(Type.class, this);
    }
    if (node instanceof org.eclipse.titan.designer.AST.Value) {
        ValueHolder holder = v -> value = v;
        return dispatch(this, type, holder, node);
    }
    return this;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Writable(org.eclipse.titan.codegenerator.Writable) Iterator(java.util.Iterator) ValueHolder(org.eclipse.titan.codegenerator.template.ValueHolder) Identifier(org.eclipse.titan.designer.AST.Identifier) Util(org.eclipse.titan.codegenerator.template.Util) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) HashMap(java.util.HashMap) Def_Const(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const) ArrayList(java.util.ArrayList) SourceCode(org.eclipse.titan.codegenerator.SourceCode) List(java.util.List) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Action(org.eclipse.titan.codegenerator.template.Action) Value(org.eclipse.titan.codegenerator.template.Value) Type(org.eclipse.titan.designer.AST.Type) Identifier(org.eclipse.titan.designer.AST.Identifier) NamedValue(org.eclipse.titan.designer.AST.TTCN3.values.NamedValue) SequenceOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SequenceOf_Value) Sequence_Value(org.eclipse.titan.designer.AST.TTCN3.values.Sequence_Value) Value(org.eclipse.titan.codegenerator.template.Value) ValueHolder(org.eclipse.titan.codegenerator.template.ValueHolder)

Example 2 with Scope

use of org.eclipse.titan.codegenerator.Scope 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;
}
Also used : IVisitableNode(org.eclipse.titan.designer.AST.IVisitableNode) Reference(org.eclipse.titan.designer.AST.Reference) Type(org.eclipse.titan.designer.AST.Type) Scope(org.eclipse.titan.codegenerator.Scope) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) org.eclipse.titan.codegenerator.myASTVisitor(org.eclipse.titan.codegenerator.myASTVisitor) Identifier(org.eclipse.titan.designer.AST.Identifier) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Type(org.eclipse.titan.designer.AST.Type) FormalParameterList(org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList) Identifier(org.eclipse.titan.designer.AST.Identifier) Reference(org.eclipse.titan.designer.AST.Reference) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template) Def_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Aggregations

Scope (org.eclipse.titan.codegenerator.Scope)2 org.eclipse.titan.codegenerator.myASTVisitor (org.eclipse.titan.codegenerator.myASTVisitor)2 IVisitableNode (org.eclipse.titan.designer.AST.IVisitableNode)2 Identifier (org.eclipse.titan.designer.AST.Identifier)2 Type (org.eclipse.titan.designer.AST.Type)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 SourceCode (org.eclipse.titan.codegenerator.SourceCode)1 Writable (org.eclipse.titan.codegenerator.Writable)1 Action (org.eclipse.titan.codegenerator.template.Action)1 Util (org.eclipse.titan.codegenerator.template.Util)1 Value (org.eclipse.titan.codegenerator.template.Value)1 ValueHolder (org.eclipse.titan.codegenerator.template.ValueHolder)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Def_Const (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const)1 Def_Template (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template)1 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)1 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)1