Commit aae06b63 authored by Fred Eisele's avatar Fred Eisele
Browse files

checkpoint on providing interfaces for expressions

parent b6967f9a
......@@ -232,11 +232,7 @@ public class TypeSide<Ty, Sym> implements Semantics {
return pre + eq.first + ". " + eq.second + " = " + eq.third;
}
public static TypeSide<Void,Void> terminal() {
return terminalEx();
}
public static <Ty,Sym> TypeSide<Ty,Sym> terminalEx() {
public static <Ty,Sym> TypeSide<Ty,Sym> terminal() {
final Set<Ty> tys = new HashSet<>();
final Map<Sym, Pair<List<Ty>, Ty>> syms = new HashMap<>();
......
......@@ -171,26 +171,26 @@ public class AqlLoaderListener extends AqlParserBaseListener {
this.mapped_terms_2 = new ParseTreeProperty<>();
this.aopts = new ParseTreeProperty<>();
}
public final List<Triple<String, Integer, Exp<?>>> decls;
public final List<Triple<String, Integer, ExpI>> decls;
public final List<Pair<String, String>> global_options;
public Function<Exp<?>, String> kind;
private final ParseTreeProperty<String> str;
private final ParseTreeProperty<TyExp<Ty,Sym>> exp_ty = new ParseTreeProperty<>();
private final ParseTreeProperty<GraphExp<String,String>> exp_graph = new ParseTreeProperty<>();
private final ParseTreeProperty<SchExp<Ty,En,Sym,Fk,Att>> exp_sch = new ParseTreeProperty<>();
private final ParseTreeProperty<InstExp<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y>> exp_inst = new ParseTreeProperty<>();
private final ParseTreeProperty<MapExp<Ty,En,Sym,Fk,Att,En,Fk,Att>> exp_map = new ParseTreeProperty<>();
private final ParseTreeProperty<QueryExp<Ty,En,Sym,Fk,Att,En,Fk,Att>> exp_query = new ParseTreeProperty<>();
private final ParseTreeProperty<ColimSchExp<String>> exp_scolim = new ParseTreeProperty<>();
private final ParseTreeProperty<EdsExp<Ty,En,Sym,Fk,Att>> exp_rule = new ParseTreeProperty<>();
private final ParseTreeProperty<PragmaExp> exp_cmd = new ParseTreeProperty<>();
private final ParseTreeProperty<TransExp<Ty,En,Sym,Fk,Att,Gen,Sk,Gen,Sk,X,Y,X,Y>> exp_trans = new ParseTreeProperty<>();
private final ParseTreeProperty<TyExpI> exp_ty = new ParseTreeProperty<>();
private final ParseTreeProperty<GraphExpI> exp_graph = new ParseTreeProperty<>();
private final ParseTreeProperty<SchExpI> exp_sch = new ParseTreeProperty<>();
private final ParseTreeProperty<InstExpI> exp_inst = new ParseTreeProperty<>();
private final ParseTreeProperty<MapExpI> exp_map = new ParseTreeProperty<>();
private final ParseTreeProperty<QueryExpI> exp_query = new ParseTreeProperty<>();
private final ParseTreeProperty<ColimSchExpI> exp_scolim = new ParseTreeProperty<>();
private final ParseTreeProperty<EdsExpI> exp_rule = new ParseTreeProperty<>();
private final ParseTreeProperty<PragmaExpI> exp_cmd = new ParseTreeProperty<>();
private final ParseTreeProperty<TransExpI> exp_trans = new ParseTreeProperty<>();
private final ParseTreeProperty<RawTerm> terms;
public final Map<String, Exp<?>> ns = new HashMap<>();
public final Map<String, ExpI> ns = new HashMap<>();
/******
* Utility functions
......@@ -208,7 +208,6 @@ public class AqlLoaderListener extends AqlParserBaseListener {
* @param quoted
* @return
*/
private String unquote(final String quoted) {
return StringUtils.removeEnd(StringUtils.removeStart(quoted, "\""), "\"");
}
......@@ -220,7 +219,6 @@ public class AqlLoaderListener extends AqlParserBaseListener {
this.str.put(ctx, unquote(ctx.getText()));
}
/**
* Process all options rule
* @param sect TODO
......@@ -307,7 +305,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
@Override public void exitGraphAssignment(AqlParser.GraphAssignmentContext ctx) {
final String name = ctx.graphId().getText();
final Integer id = getLoc(ctx);
final Exp<?> exp = this.exp_graph.get(ctx.graphExp());
final ExpI exp = (ExpI) this.exp_graph.get(ctx.graphExp());
if (exp == null) {
log.warning("null graph exp " + name);
return;
......@@ -378,7 +376,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
@Override public void exitTypesideAssignment(AqlParser.TypesideAssignmentContext ctx) {
final String name = ctx.typesideId().getText();
final Integer id = getLoc(ctx);
final Exp<?> exp = this.exp_ty.get(ctx.typesideExp());
final ExpI exp = (ExpI) this.exp_ty.get(ctx.typesideExp());
if (exp == null) {
log.warning("null typeside exp " + name);
return;
......@@ -416,10 +414,10 @@ public class AqlLoaderListener extends AqlParserBaseListener {
@Override
public void exitTypesideExp_Of(AqlParser.TypesideExp_OfContext ctx) {
final SchExp<Ty, En, Sym, Fk, Att>
final SchExpI
schema = this.exp_sch.get(ctx.schemaKind());
final TyExp<Ty,Sym>
final TyExp.TyExpSch<Ty,Sym>
exp = new TyExp.TyExpSch<>(schema);
this.exp_ty.put(ctx, exp);
......@@ -432,10 +430,10 @@ public class AqlLoaderListener extends AqlParserBaseListener {
final TypesideLiteralSectionContext
sect = ctx.typesideLiteralSection();
final List<Pair<Integer,TyExp<?,?>>>
final List<Pair<Integer,TyExpI>>
imports = sect.typesideImport().stream()
.map(elt ->
new Pair<Integer,TyExp<?,?>>(
new Pair<Integer,TyExpI>(
getLoc(elt),
this.exp_ty.get(elt)))
.collect(Collectors.toList());
......@@ -2126,7 +2124,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
instSrcExp = this.exp_inst.get(instSrcRef),
instTgtExp = this.exp_inst.get(instTgtRef);
List<Pair<LocStr, String>>
final List<Pair<LocStr, String>>
transFiles = sect.transformFileExpr().stream()
.map(x -> new Pair<>(
makeLocStr(x.schemaEntityId()),
......@@ -2493,7 +2491,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
final TransformRefContext transRef = ctx.transformRef();
final CommandExportCsvSectionContext sect = ctx.commandExportCsvSection();
final TransExp<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, X, Y, X, Y>
final TransExp<Ty,En,Sym,Fk,Att,Gen,Sk,Gen,Sk,X,Y,X,Y>
transExp = this.exp_trans.get(transRef);
final String cmdFile = cmdFileNode.getText();
......
package catdata.aql.exp;
public interface ColimSchExpI {
}
package catdata.aql.exp;
public interface EdsExpI {
}
......@@ -7,17 +7,11 @@ import catdata.Pair;
import catdata.aql.AqlOptions.AqlOption;
import catdata.aql.Kind;
public abstract class Exp<X> {
public abstract class Exp<X> implements ExpI<X> {
public Object getOrDefault(AqlEnv env, AqlOption option) {
return env.defaults.getOrDefault(options(), option);
return env.defaults.getOrDefault(this.options(), option);
}
protected abstract Map<String, String> options();
public abstract Kind kind();
public abstract X eval(AqlEnv env);
@Override
public abstract String toString();
......
package catdata.aql.exp;
import java.util.Collection;
import java.util.Map;
import catdata.Pair;
import catdata.aql.Kind;
import catdata.aql.AqlOptions.AqlOption;
public interface ExpI<X> {
public Object getOrDefault(AqlEnv env, AqlOption option);
public Map<String, String> options();
public Kind kind();
public X eval(AqlEnv env);
@Override
public String toString();
@Override
public int hashCode();
@Override
public boolean equals(Object o);
/**
* This will not capture global order constraints;
* for example, that pragmas form barriers.
*/
public abstract Collection<Pair<String, Kind>> deps();
}
......@@ -16,7 +16,7 @@ import catdata.aql.Graph;
import catdata.aql.Kind;
import catdata.graph.DMG;
public abstract class GraphExp<N,E> extends Exp<Graph<N,E>> {
public abstract class GraphExp<N,E> extends Exp<Graph<N,E>> implements GraphExpI {
@Override
public Kind kind() {
......
package catdata.aql.exp;
public interface GraphExpI {
}
package catdata.aql.exp;
public interface InstExpI {
}
package catdata.aql.exp;
public interface MapExpI {
}
package catdata.aql.exp;
public interface PragmaExpI {
}
package catdata.aql.exp;
public interface QueryExpI {
}
......@@ -15,10 +15,8 @@ import catdata.aql.exp.SchExpRaw.Fk;
import catdata.aql.exp.TyExpRaw.Sym;
import catdata.aql.exp.TyExpRaw.Ty;
public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,Att>> {
public abstract SchExp<Ty,En,Sym,Fk,Att> resolve(AqlTyping G, Program<Exp<?>> prog);
public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,Att>> implements SchExpI<Ty,Sym> {
@Override
public Kind kind() {
return Kind.SCHEMA;
......@@ -36,8 +34,7 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
}
//TODO aql schema equality too weak
@Override
public SchExp<Ty,En2,Sym,Fk2,Att2> resolve(AqlTyping G, Program<Exp<?>> prog) {
public SchExpI<Ty,Sym> resolve(AqlTyping G, Program<Exp<?>> prog) {
return this;
}
......@@ -86,9 +83,7 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
public Collection<Pair<String, Kind>> deps() {
return exp.deps();
}
}
......@@ -98,8 +93,8 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
public final InstExp<Ty,En,Sym,Fk,Att,?,?,?,?> inst;
@Override
public SchExp<Ty,En,Sym,Fk,Att> resolve(AqlTyping G, Program<Exp<?>> prog) {
return (SchExp<Ty,En,Sym,Fk,Att>) inst.type(G);
public SchExpI<Ty,Sym> resolve(AqlTyping G, Program<Exp<?>> prog) {
return inst.type(G);
}
@Override
......@@ -147,25 +142,18 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
public Schema<Ty, En, Sym, Fk, Att> eval(AqlEnv env) {
return inst.eval(env).schema();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public static final class SchExpEmpty<Ty,Sym> extends SchExpEmptyEx<Ty,Void,Sym,Void,Void> {
public SchExpEmpty(TyExp<Ty, Sym> typeSide) {
super(typeSide);
}
}
public static class SchExpEmptyEx<Ty,En,Sym,Fk,Att> extends SchExp<Ty,En,Sym,Fk,Att> {
public static final class SchExpEmpty<Ty,Sym> extends SchExp<Ty,Void,Sym,Void,Void> {
public final TyExp<Ty,Sym> typeSide;
public final TyExpI<Ty,Sym> typeSide;
public SchExp<Ty,En,Sym,Fk,Att> resolve(AqlTyping G, Program<Exp<?>> prog) {
return new SchExpEmptyEx<>(typeSide.resolve(prog));
public SchExpI<Ty,Sym> resolve(AqlTyping G, Program<Exp<?>> prog) {
return new SchExpEmpty<Ty,Sym>(typeSide.resolve(prog));
}
......@@ -178,7 +166,7 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
return typeSide.deps();
}
public SchExpEmptyEx(TyExp<Ty, Sym> typeSide) {
public SchExpEmpty(TyExpI<Ty,Sym> typeSide) {
if (typeSide == null) {
throw new RuntimeException("Attempt to use null typeSide in SchExpEmpty");
}
......@@ -211,7 +199,7 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
}
@Override
public Schema<Ty,En,Sym,Fk,Att> eval(AqlEnv env) {
public Schema<Ty,Void,Sym,Void,Void> eval(AqlEnv env) {
return Schema.terminalEx(typeSide.eval(env));
}
......@@ -223,7 +211,7 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
public static final class SchExpVar<Ty,En,Sym,Fk,Att> extends SchExp<Ty,En,Sym,Fk,Att> {
@Override
public SchExp<Ty, En, Sym, Fk, Att> resolve(AqlTyping G, Program<Exp<?>> prog) {
public SchExpI<Ty, Sym> resolve(AqlTyping G, Program<Exp<?>> prog) {
if (!prog.exps.containsKey(var)) {
throw new RuntimeException("Unbound typeside variable: " + var);
}
......@@ -284,8 +272,6 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
public String toString() {
return var;
}
}
......@@ -345,6 +331,11 @@ public abstract class SchExp<Ty,En,Sym,Fk,Att> extends Exp<Schema<Ty,En,Sym,Fk,A
public SchExp<Ty, Sym, En, Fk, Att> resolve(AqlTyping G, Program<Exp<?>> prog) {
return this;
}
@Override
public SchExpI resolve(AqlTyping G, Program prog) {
// TODO Auto-generated method stub
return null;
}
}
......
package catdata.aql.exp;
import java.util.Collection;
import catdata.Pair;
import catdata.Program;
import catdata.aql.Kind;
public interface SchExpI<Ty,Sym> {
public SchExpI<Ty,Sym> resolve(AqlTyping G, Program<Exp<?>> prog);
public Kind kind();
Object eval(AqlEnv env);
Collection<Pair<String, Kind>> deps();
}
package catdata.aql.exp;
public interface TransExpI {
}
......@@ -10,9 +10,9 @@ import catdata.Util;
import catdata.aql.Kind;
import catdata.aql.TypeSide;
public abstract class TyExp<Ty, Sym> extends Exp<TypeSide<Ty, Sym>> {
public abstract class TyExp<Ty, Sym> extends Exp<TypeSide<Ty, Sym>> implements TyExpI<Ty,Sym> {
public TyExp<Ty, Sym> resolve(Program<Exp<?>> prog) {
public TyExpI resolve(Program<Exp<?>> prog) {
return this;
}
......@@ -31,9 +31,9 @@ public abstract class TyExp<Ty, Sym> extends Exp<TypeSide<Ty, Sym>> {
return Collections.emptyMap();
}
public final SchExp<Ty, ?, Sym, ?, ?> schema;
public final SchExpI schema;
public TyExpSch(SchExp<Ty, ?, Sym, ?, ?> schema) {
public TyExpSch(SchExpI schema) {
this.schema = schema;
}
......@@ -77,10 +77,8 @@ public abstract class TyExp<Ty, Sym> extends Exp<TypeSide<Ty, Sym>> {
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public static final class TyExpEmpty extends TyExpEmptyEx<Void,Void> {
}
public static class TyExpEmptyEx<Ty,Sym> extends TyExp<Ty,Sym> {
public static class TyExpEmpty<Ty,Sym> extends TyExp<Ty,Sym> {
@Override
public Collection<Pair<String, Kind>> deps() {
......
package catdata.aql.exp;
import java.util.Collection;
import catdata.Pair;
import catdata.Program;
import catdata.aql.Kind;
import catdata.aql.TypeSide;
public interface TyExpI<Ty,Sym> extends ExpI<TypeSide<Ty,Sym>> {
public TyExpI<Ty,Sym> resolve(Program<Exp<?>> prog);
public Kind kind();
Collection<Pair<String, Kind>> deps();
}
......@@ -139,7 +139,7 @@ public final class TyExpRaw extends TyExp<Ty, Sym> implements Raw {
@SuppressWarnings("unchecked")
public TyExpRaw(
List<Pair<Integer,TyExp<?,?>>> imports,
List<Pair<Integer, TyExpI>> imports2,
List<LocStr> types,
List<Pair<LocStr, Pair<List<String>, String>>> functions,
List<Pair<Integer, Triple<List<Pair<String, String>>, RawTerm, RawTerm>>> eqsX,
......@@ -147,7 +147,7 @@ public final class TyExpRaw extends TyExp<Ty, Sym> implements Raw {
List<Pair<LocStr, String>> java_parser_string,
List<Pair<LocStr, Triple<List<String>, String, String>>> java_fns_string,
List<Pair<String, String>> options) {
this.imports = Util.toSetSafely((List<Pair<Integer,TyExp<Ty,Sym>>>)((Object)imports));
this.imports = Util.toSetSafely((List<Pair<Integer,TyExp<Ty,Sym>>>)((Object)imports2));
this.types = LocStr.set1(types);
this.functions = LocStr.functions1(functions);
this.eqs = LocStr.eqs1(eqsX);
......@@ -171,7 +171,7 @@ public final class TyExpRaw extends TyExp<Ty, Sym> implements Raw {
//do above because find() requires the index
doGuiIndex(imports, types, functions, eqsX, java_tys_string, java_parser_string, java_fns_string);
doGuiIndex(imports2, types, functions, eqsX, java_tys_string, java_parser_string, java_fns_string);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment