summaryrefslogtreecommitdiff
path: root/parse/node.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-10-15 13:49:45 -0400
committerOri Bernstein <ori@eigenstate.org>2014-10-15 13:49:45 -0400
commite92ebbba27581d60d697ce774387fb86a33c55f7 (patch)
tree23beacd24b73b553e76912ad0c2805b577958d8e /parse/node.c
parent050c29b20810d6519702f6ee4928c835203caea3 (diff)
downloadmc-e92ebbba27581d60d697ce774387fb86a33c55f7.tar.gz
Add support for literal nodes in dtree.
Diffstat (limited to 'parse/node.c')
-rw-r--r--parse/node.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/parse/node.c b/parse/node.c
index ec98858..8d9a173 100644
--- a/parse/node.c
+++ b/parse/node.c
@@ -351,6 +351,33 @@ Type *nodetype(Node *n)
return NULL;
}
+int liteq(Node *a, Node *b)
+{
+ assert(a->type == Nlit && b->type == Nlit);
+ if (a->lit.littype != b->lit.littype)
+ return 0;
+ if (!tyeq(a->lit.type, b->lit.type))
+ return 0;
+ switch (a->lit.littype) {
+ case Lchr:
+ return a->lit.chrval == b->lit.chrval;
+ case Lbool:
+ return a->lit.boolval == b->lit.boolval;
+ case Lint:
+ return a->lit.intval == b->lit.intval;
+ case Lflt:
+ return a->lit.fltval == b->lit.fltval;
+ case Lstr:
+ return !strcmp(a->lit.strval, b->lit.strval);
+ case Lfunc:
+ return a->lit.fnval == b->lit.fnval;
+ case Llbl:
+ return !strcmp(a->lit.lblval, b->lit.lblval);
+ break;
+ }
+ return 0;
+}
+
/* name hashing */
ulong namehash(void *p)
{