File: node.c

package info (click to toggle)
minc 2.1.10-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,160 kB
  • sloc: ansic: 82,507; sh: 10,666; yacc: 1,187; perl: 612; makefile: 586; lex: 319
file content (88 lines) | stat: -rw-r--r-- 2,637 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Copyright David Leonard and Andrew Janke, 2000. All rights reserved. */

#include <stdlib.h>
#include "node.h"

struct nodename { enum nodetype type; const char *name; } 
nodenames[] = {
        { NODETYPE_ADD,      "add" },
        { NODETYPE_SUB,      "sub" },
        { NODETYPE_MUL,      "mul" },
        { NODETYPE_DIV,      "div" },
        { NODETYPE_POW,      "pow" },
        { NODETYPE_INDEX,    "index" },
        { NODETYPE_SUM,      "sum" },
        { NODETYPE_PROD,     "prod" },
        { NODETYPE_AVG,      "avg" },
        { NODETYPE_LEN,      "len" },
        { NODETYPE_MAX,      "max" },
        { NODETYPE_MIN,      "min" },
        { NODETYPE_IMAX,     "imax" },
        { NODETYPE_IMIN,     "imin" },
        { NODETYPE_IDENT,    "ident" },
        { NODETYPE_REAL,     "real" },
        { NODETYPE_LET,      "let" },
        { NODETYPE_VEC1,     "vec1" },
        { NODETYPE_VEC2,     "vec2" },
        { NODETYPE_GEN,      "gen" },
        { NODETYPE_RANGE,    "range" },
        { NODETYPE_LT,       "lt" },
        { NODETYPE_LE,       "le" },
        { NODETYPE_GT,       "gt" },
        { NODETYPE_GE,       "ge" },
        { NODETYPE_EQ,       "eq" },
        { NODETYPE_NE,       "ne" },
        { NODETYPE_NOT,      "not" },
        { NODETYPE_AND,      "and" },
        { NODETYPE_OR,       "or" },
        { NODETYPE_ISNAN,    "isnan" },
        { NODETYPE_SQRT,     "sqrt" },
        { NODETYPE_ABS,      "abs" },
        { NODETYPE_EXP,      "exp" },
        { NODETYPE_LOG,      "log" },
        { NODETYPE_SIN,      "sin" },
        { NODETYPE_COS,      "cos" },
        { NODETYPE_TAN,      "tan" },
        { NODETYPE_ASIN,     "asin" },
        { NODETYPE_ACOS,     "acos" },
        { NODETYPE_ATAN,     "atan" },
        { NODETYPE_CLAMP,    "clamp" },
        { NODETYPE_SEGMENT,  "segment" },
        { NODETYPE_EXPRLIST, "exprlist" },
        { NODETYPE_ASSIGN,   "assign" },
        { NODETYPE_IFELSE,   "ifelse" },
        { NODETYPE_FOR,      "for" },
        { (enum nodetype) 0, NULL }
};

node_t new_node(int numargs, int is_scalar) {
   node_t n;
   n = malloc(sizeof *n);
   n->numargs = numargs;
   n->flags = 0;
   if (is_scalar) {
      n->flags |= NODE_IS_SCALAR;
   }
   return n;
}

node_t new_scalar_node(int numargs) {
   return new_node(numargs, 1);
}

node_t new_vector_node(int numargs) {
   return new_node(numargs, 0);
}

const char *node_name(node_t n){
   struct nodename *p;

   for (p = nodenames; p->name; p++)
      if (p->type == n->type)
         return p->name;
   return "unknown";
}

int node_is_scalar(node_t n) {
   return (n->flags & NODE_IS_SCALAR);
}