This repository was archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.h
More file actions
89 lines (78 loc) · 3.01 KB
/
Copy pathnode.h
File metadata and controls
89 lines (78 loc) · 3.01 KB
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
89
/* $Id: node.h,v 1.4 2012/09/12 17:24:33 prs Exp $ */
#ifndef __NODE_H__
#define __NODE_H__
#include <stdio.h> /* for FILE argument to printNode and scanNode */
#ifdef _64bits_
typedef long long regint;
#define PRTREG "%lld"
#define strtol strtoll
#else
typedef int regint;
#define PRTREG "%d"
#endif
typedef enum { nodeNil, nodeInt, nodeStr, nodeReal, nodeData, nodeOpr } NodeType;
typedef enum { nodeUser = 1, nodeLine = 2, nodeState = 4, nodeInfo = 8, nodePlace = 16 } NodeTag;
typedef struct typeNode Node;
struct typeNode {
NodeType type; /* type of node */
void *user; /* pointer to any user data */
int attrib; /* user defined attributes */
int line; /* input file parse line */
void *state; /* for the instruction selector (burg) */
int info; /* specific info such as type or register used */
void (*listen)(Node*); /* listener */
long place; /* location information */
union {
regint i; /* value of literal integer */
double r; /* value of literal real number */
char *s; /* value of literal string (null terminated) */
struct {
int size; /* size of data */
void *data; /* pointer to data */
} d; /* value of any opaque data (untyped) */
struct {
unsigned num; /* number of subnodes in this node */
Node *n[1]; /* subnodes (expandable) */
} sub;
} value;
};
/* prototypes */
Node *uniNode(int attrib, Node *n1);
Node *binNode(int attrib, Node *n1, Node *n2);
Node *triNode(int attrib, Node *n1, Node *n2, Node *n3);
Node *quadNode(int attrib, Node *n1, Node *n2, Node *n3, Node *n4);
Node *pentNode(int attrib, Node *n1, Node *n2, Node *n3, Node *n4, Node *n5);
Node *subNode(int attrib, unsigned nops, ...);
Node *seqNode(int oper, unsigned nops, ...);
Node *revNode(int oper, unsigned nops, ...);
Node *nilNode(int attrib);
Node *intNode(int attrib, regint i);
Node *realNode(int attrib, double d);
Node *dataNode(int attrib, int size, void *user);
Node *strNode(int attrib, char *s);
Node *addNode(Node *base, Node *node, unsigned pos);
Node *removeNode(Node *base, unsigned pos);
void *userNode(Node *p, void *user);
Node *compareNode(Node *p, Node *n, int full);
Node *copyNode(Node *p);
void freeNode(Node *p);
void printNode(Node *p, FILE *fp, char *tab[]);
Node *newNode(NodeType t, int attrib, unsigned nops);
void visitNode(Node *p, int mode, void (*func[])(Node*));
void listenNode(Node *p, int mode);
void listenerNode(Node *p, void (*func)(Node*));
void pathNode(Node *p, FILE *fp, char *tab[], char *base);
extern int debugNode;
#define CHILD(x) value.sub.n[x]
#define POS 0
#define PRE 1
/* defines for pburg */
#define STATE_TYPE void*
#define NODEPTR_TYPE Node*
#define OP_LABEL(p) ((p)->attrib)
#define LEFT_CHILD(p) ((p)->type == nodeOpr && (p)->value.sub.num > 0 ? (p)->value.sub.n[0] : 0)
#define RIGHT_CHILD(p) ((p)->type == nodeOpr && (p)->value.sub.num > 1 ? (p)->value.sub.n[1] : 0)
#define STATE_LABEL(p) ((p)->state)
#define PLACE(p) ((p)->info)
#define SUB(x) value.sub.n[x]
#endif /* __NODE_H__ */