Changeset: 397186310dc6 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=397186310dc6
Modified Files:
monetdb5/extras/jaql/jaql.c
monetdb5/extras/jaql/jaql.h
monetdb5/extras/jaql/jaqlgencode.c
monetdb5/extras/jaql/parser/jaql.y
Branch: jacqueline
Log Message:
variables: promote array indices to real variable indirections
This way we can support constructs like x[1][2], which is necessary.
Incidentially, it improves the code cleanliness.
diffs (truncated from 522 to 300 lines):
diff --git a/monetdb5/extras/jaql/jaql.c b/monetdb5/extras/jaql/jaql.c
--- a/monetdb5/extras/jaql/jaql.c
+++ b/monetdb5/extras/jaql/jaql.c
@@ -593,26 +593,6 @@ make_jaql_top(long long int num)
return res;
}
-tree *
-make_array_index(long long int idx, char isstar)
-{
- tree *res = GDKzalloc(sizeof(tree));
-
- if (idx < 0) {
- res->type = j_error;
- res->sval = GDKstrdup("variable: array index must be a "
- "positive integer value");
- return res;
- }
-
- res->type = j_arr_idx;
- res->nval = idx;
- if (isstar)
- res->nval = -1;
-
- return res;
-}
-
/* create predicate between left and right which can be predicates on
* their own, or variables and values */
tree *
@@ -694,22 +674,21 @@ append_sort_arg(tree *osarg, tree *nsarg
return osarg;
}
-/* create a variable name from ident, with optional array indirection */
+/* create a variable name from ident */
tree *
-make_varname(char *ident, tree *arridx)
+make_varname(char *ident)
{
tree *res = GDKzalloc(sizeof(tree));
res->type = j_var;
res->sval = ident;
- res->tval2 = arridx;
return res;
}
/* append an object indirection to the variable in var with the name
- * from ident, with optional array indirection */
+ * from ident */
tree *
-append_varname(tree *var, char *ident, tree *arridx)
+append_varname(tree *var, char *ident)
{
tree *t = var;
@@ -719,7 +698,32 @@ append_varname(tree *var, char *ident, t
t = t->tval1 = GDKzalloc(sizeof(tree));
t->type = j_var;
t->sval = ident;
- t->tval2 = arridx;
+
+ return var;
+}
+
+tree *
+append_vararray(tree *var, long long int idx, char isstar)
+{
+ tree *t = var;
+
+ if (idx < 0) {
+ freetree(var);
+ t = GDKzalloc(sizeof(tree));
+ t->type = j_error;
+ t->sval = GDKstrdup("variable: array index must be a "
+ "positive integer value");
+ return t;
+ }
+
+ /* find last in chain to append to */
+ while (t->tval1 != NULL)
+ t = t->tval1;
+ t = t->tval1 = GDKzalloc(sizeof(tree));
+ t->type = j_arr_idx;
+ t->nval = idx;
+ if (isstar)
+ t->nval = -1;
return var;
}
@@ -884,7 +888,7 @@ make_join_input(char preserve, tree *var
res->nval = preserve;
res->tval2 = var;
if (invar == NULL) {
- res->tval1 = make_varname(GDKstrdup(var->sval), NULL);
+ res->tval1 = make_varname(GDKstrdup(var->sval));
} else {
res->tval1 = invar;
}
@@ -1494,17 +1498,21 @@ printtree(tree *t, int level, char op)
break;
case j_var:
if (op) {
- printf("j_var( %s%s ",
- t->sval == NULL ? "*" :
t->sval,
- t->tval1 != NULL ? "."
: "");
- if (t->tval1 != NULL)
+ printf("j_var( %s ", t->sval == NULL ?
"*" : t->sval);
+ if (t->tval1 != NULL) {
+ printf(", ");
printtree(t->tval1, level +
step, op);
+ }
printf(") ");
} else {
printf("%s", t->sval == NULL ? "*" :
t->sval);
- printtree(t->tval2, level + step, op);
- printf("%c", t->tval1 != NULL ? '.' : '
');
- printtree(t->tval1, level + step, op);
+ if (t->tval1 != NULL) {
+ if (t->tval1->type == j_var)
+ printf(".");
+ printtree(t->tval1, level +
step, op);
+ } else {
+ printf(" ");
+ }
}
break;
case j_arr_idx:
@@ -1515,6 +1523,10 @@ printtree(tree *t, int level, char op)
} else {
printf("%lld ", t->nval);
}
+ if (t->tval1 != NULL) {
+ printf(", ");
+ printtree(t->tval1, level +
step, op);
+ }
printf(") ");
} else {
if (t->nval == -1) {
@@ -1522,6 +1534,13 @@ printtree(tree *t, int level, char op)
} else {
printf("[%lld]", t->nval);
}
+ if (t->tval1 != NULL) {
+ if (t->tval1->type == j_var)
+ printf(".");
+ printtree(t->tval1, level +
step, op);
+ } else {
+ printf(" ");
+ }
}
break;
case j_num:
diff --git a/monetdb5/extras/jaql/jaql.h b/monetdb5/extras/jaql/jaql.h
--- a/monetdb5/extras/jaql/jaql.h
+++ b/monetdb5/extras/jaql/jaql.h
@@ -136,8 +136,9 @@ tree *make_array_index(long long int idx
tree *make_pred(tree *var, tree *comp, tree *value);
tree *make_sort_arg(tree *var, char asc);
tree *append_sort_arg(tree *osarg, tree *nsarg);
-tree *make_varname(char *ident, tree *arridx);
-tree *append_varname(tree *var, char *ident, tree *arridx);
+tree *make_varname(char *ident);
+tree *append_varname(tree *var, char *ident);
+tree *append_vararray(tree *var, long long int idx, char isstar);
tree *make_pair(char *name, tree *val);
tree *append_pair(tree *opair, tree *npair);
tree *append_elem(tree *oelem, tree *nelem);
diff --git a/monetdb5/extras/jaql/jaqlgencode.c
b/monetdb5/extras/jaql/jaqlgencode.c
--- a/monetdb5/extras/jaql/jaqlgencode.c
+++ b/monetdb5/extras/jaql/jaqlgencode.c
@@ -117,7 +117,7 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
a = getArg(q, 0);
pushInstruction(mb, q);
- if (t->tval2->nval == -1 && t->tval1 == NULL) {
+ if (t->nval == -1 && t->tval1 == NULL) {
/* all array members (return as a single array) */
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, batRef);
@@ -126,7 +126,7 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
q = pushArgument(mb, q, a);
b = getArg(q, 0);
pushInstruction(mb, q);
- } else if (t->tval2->nval == -1 && t->tval1 != NULL) {
+ } else if (t->nval == -1 && t->tval1 != NULL) {
/* all array members of which objects will be dereferenced */
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, algebraRef);
@@ -200,8 +200,8 @@ dumparrrefvar(MalBlkPtr mb, tree *t, int
setFunctionId(q, selectRef);
q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
q = pushArgument(mb, q, b);
- q = pushOid(mb, q, (oid)t->tval2->nval);
- q = pushOid(mb, q, (oid)t->tval2->nval);
+ q = pushOid(mb, q, (oid)t->nval);
+ q = pushOid(mb, q, (oid)t->nval);
b = getArg(q, 0);
pushInstruction(mb, q);
q = newInstruction(mb, ASSIGNsymbol);
@@ -252,22 +252,6 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
assert(t && t->type == j_var);
- if (t->tval1 == NULL) {
- if (t->tval2 != NULL) {
- b = dumparrrefvar(mb, t, elems, *j5);
- } else {
- /* just var, has no derefs or anything, so all */
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, batRef);
- setFunctionId(q, mirrorRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, elems);
- b = getArg(q, 0);
- pushInstruction(mb, q);
- }
- return b;
- }
-
q = newInstruction(mb, ASSIGNsymbol);
setModuleId(q, batRef);
setFunctionId(q, mirrorRef);
@@ -276,97 +260,13 @@ dumprefvar(MalBlkPtr mb, tree *t, int el
b = getArg(q, 0);
pushInstruction(mb, q);
+ /* just var, has no derefs or anything, so all */
+ if (t->tval1 == NULL)
+ return b;
+
a = elems;
- if (t->tval2 != 0) {
- c = dumparrrefvar(mb, t, a, *j5);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, joinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, c);
- q = pushArgument(mb, q, b);
- b = getArg(q, 0);
- pushInstruction(mb, q);
- /* re-retrieve kinds now we've updated again */
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, semijoinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, *j1);
- q = pushArgument(mb, q, b);
- a = getArg(q, 0);
- pushInstruction(mb, q);
- if (t->tval2->nval == -1)
- encapsulate = 1;
- }
for (t = t->tval1; t != NULL; t = t->tval1) {
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, uselectRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, a);
- q = pushBte(mb, q, 'o'); /* deref requires object */
- a = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, semijoinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, *j6);
- q = pushArgument(mb, q, a);
- a = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, batRef);
- setFunctionId(q, reverseRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, a);
- a = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, joinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, a);
- q = pushArgument(mb, q, b);
- b = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, semijoinRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, *j7);
- q = pushArgument(mb, q, a);
- a = getArg(q, 0);
- pushInstruction(mb, q);
- q = newInstruction(mb, ASSIGNsymbol);
- setModuleId(q, algebraRef);
- setFunctionId(q, uselectRef);
- q = pushReturn(mb, q, newTmpVariable(mb, TYPE_any));
- q = pushArgument(mb, q, a);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list