X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Fvalues%2FTreeValue.java;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2Fvalues%2FTreeValue.java;h=84d36149145c216e0609adc6f354d3e1251b0e11;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/values/TreeValue.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/values/TreeValue.java new file mode 100644 index 000000000..84d361491 --- /dev/null +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/values/TreeValue.java @@ -0,0 +1,78 @@ +package org.simantics.graph.compiler.internal.values; + +import java.util.Collection; + +import org.antlr.runtime.tree.Tree; +import org.simantics.databoard.binding.Binding; +import org.simantics.graph.compiler.internal.parsing.GraphParser; +import org.simantics.graph.compiler.internal.store.IPreValue; +import org.simantics.graph.compiler.internal.translation.DataValueTranslator; +import org.simantics.graph.query.Path; +import org.simantics.graph.query.Paths; +import org.simantics.ltk.ISource; +import org.simantics.ltk.Location; +import org.simantics.ltk.Problem; +import org.simantics.ltk.antlr.ANTLRUtils; + +public class TreeValue implements IPreValue { + + ISource source; + Tree tree; + + public TreeValue(ISource source, Tree tree) { + this.source = source; + this.tree = tree; + } + + @Override + public Object toValue(Binding binding, Collection problems) { + return new DataValueTranslator(source, problems).translate(tree, binding); + } + + public Tree getTree() { + return tree; + } + + @Override + public Path getDefaultType(Paths paths) { + Tree b = this.tree; + while(b.getType() == GraphParser.TUPLE && b.getChildCount() == 1) + b = b.getChild(0); + + switch(b.getType()) { + case GraphParser.INT: return paths.Integer; + case GraphParser.FLOAT: return paths.Double; + case GraphParser.STRING: return paths.String; + case GraphParser.TRUE: + case GraphParser.FALSE: return paths.Boolean; + case GraphParser.VARIANT: return paths.Variant; + case GraphParser.ARRAY: + if(b.getChildCount() > 0) { + switch(b.getChild(0).getType()) { + case GraphParser.INT: + case GraphParser.FLOAT: + for(int i=0;i