- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_parse.c
More file actions
Latest commit
99 lines (76 loc) · 1.95 KB
/
Copy pathjs_parse.c
File metadata and controls
99 lines (76 loc) · 1.95 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
90
91
92
93
94
95
96
97
98
99
#include"js.h"
// find node's root node
firstNode*findFirstNode(Node*table, uint32_tslot) {
uint32_tstart=0;
while(start<slot) {
firstNode*fn= (firstNode*)(table+start);
start+=fn->moduleSize;
if( start>slot )
returnfn;
}
return (firstNode*)table;
}
uint32_tnewNode (parseData*pd, nodeTypetype, uint32_tsize, boolzero) {
uint32_tblks= (size+sizeof(Node) -1)/sizeof(Node);
uint32_taddr=pd->tableNext, newSize[1];
Node*node;
if( blks+pd->tableNext >= pd->tableSize ) {
if( pd->tableSize )
pd->tableSize *= 2;
else
pd->tableSize=4090;
*newSize=pd->tableSize*sizeof(Node);
if (pd->table)
pd->table=js_realloc (pd->table, newSize, false);
else
pd->table=js_alloc (*newSize, false);
pd->tableSize=*newSize / sizeof(Node);
}
node=pd->table+pd->tableNext;
if (zero)
memset (node, 0, size);
node->bits=type;
node->lineNo=pd->lineNo;
pd->tableNext+=blks;
returnaddr;
}
charconvLit(charquoted) {
switch(quoted) {
case0x0a: return0;
case0x0d: return0;
case'f': return0x0c;
case'r': return0x0d;
case'n': return0x0a;
case't': return0x09;
case'b': return0x08;
}
returnquoted;
}
uint32_tnewStrNode (parseData*pd, char*text, uint32_tsize) {
uint32_tlen=0, addr, off=0, max, idx;
stringNode*sn;
charc;
for(max=1; max<size; max++)
switch(text[max]) {
case'\\': continue;
case0x0a: pd->lineNo++; continue;
case0x0d: continue;
default: len++; continue;
}
max--; // discard trailing quote mark
len--; // discard trailing quote mark
addr=newNode(pd, node_string, sizeof(stringNode) +len+1, false);
sn= (stringNode*)(pd->table+addr);
sn->str.len=len;
for(idx=1; idx<max&&off<len; idx++)
switch((c=text[idx])) {
case'\\':
if ((sn->str.val[off] =convLit(text[++idx])))
off++;
continue;
case0x0a: continue;
case0x0d: continue;
default: sn->str.val[off++] =c;
}
returnaddr;
}