Graphviz 13.1.3~dev.20250815.1023
Loading...
Searching...
No Matches
exlib.h
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#pragma once
12
13#include <stddef.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/*
20 * Glenn Fowler
21 * AT&T Research
22 *
23 * expression library private definitions
24 */
25
26#include <ast/ast.h>
27#include <sfio/sfio.h>
28#include <stdio.h>
29#include <util/agxbuf.h>
30#include <util/arena.h>
31
32typedef struct Exinput_s /* input stack */
33{
34 struct Exinput_s*next; /* next in stack */
35 int close; /* close fp on pop */
36 char* file; /* previous file */
37 FILE* fp; /* expression file pointer */
38 int line; /* previous line */
39 int nesting; /* expression nesting level */
40 int peek; /* 1 char peek */
41 int unit; /* first frame in parse unit */
42 char* pushback; /* pushback buffer */
43 char* pp; /* pushback pointer */
45
46typedef struct Print_s /* compiled printf arg node */
47{
48 struct Print_s* next; /* next arg */
49 char* format; /* printf format for arg */
50 struct Exnode_s*param[3]; /* 0:width 1:precision 2:base */
51 struct Exnode_s*arg; /* arg to format */
53
54#define _EX_DATA_PRIVATE_ \
55 Exnode_t* next; /* free list link */ \
56 Extype_t value; /* dynamic variable value */ \
57 struct \
58 { \
59 Exid_t* procedure; /* called procedure */ \
60 Exnode_t* args; /* actual argument list */ \
61 } call; /* procedure call */ \
62 struct \
63 { \
64 Exnode_t* array; /* array name */ \
65 Exid_t* index; /* array index */ \
66 Exnode_t* statement; /* statement to apply */ \
67 } generate; /* associative array generator */ \
68 struct \
69 { \
70 Exid_t* array; /* array */ \
71 Exnode_t* string; /* string */ \
72 Exnode_t* seps; /* optional separators */ \
73 } split; /* string split */ \
74 struct \
75 { \
76 Exnode_t* descriptor; /* Expr_t.file index */ \
77 Print_t* args; /* compiler printf args */ \
78 } print; /* printf */ \
79 struct \
80 { \
81 Exnode_t* base; /* base string */ \
82 Exnode_t* pat; /* pattern or start index */ \
83 Exnode_t* repl; /* optional replacement or end index */ \
84 } string; /* string builtins */ \
85 struct \
86 { \
87 Exnode_t* args; /* formal arg list */ \
88 Exnode_t* body; /* body */ \
89 Dt_t* frame; /* local symbol frame */ \
90 int arity; /* # formal args */ \
91 } procedure; /* procedure args and body */ \
92 struct \
93 { \
94 Exnode_t* descriptor; /* Expr_t.file index */ \
95 Exnode_t* format; /* format arg */ \
96 Exnode_t* args; /* actual args */ \
97 } scan; /* printf */
98
99#define _EX_NODE_PRIVATE_ \
100 int subop; /* operator qualifier */
101
102#define _EX_PROG_PRIVATE_ \
103 arena_t ve; /* eval tmp region */ \
104 Dt_t* frame; /* frame symbol table */ \
105 Exdisc_t* disc; /* user discipline */ \
106 Exinput_t* input; /* input stack */ \
107 Expr_t* program; /* previous program on stack */ \
108 agxbuf tmp; /* tmp string buffer */ \
109 Extype_t loopret; /* return value */ \
110 Exid_t main; /* main procedure */ \
111 char line[512]; /* last few input tokens */ \
112 char* linep; /* line[] pointer */ \
113 int eof; /* lex hit eof */ \
114 int errors; /* fatal error count */ \
115 int linewrap; /* linep wrapped around line[] */ \
116 long long loopcount; /* break|continue|return count */ \
117 long loopop; /* break|continue|return op */ \
118 int nesting; /* exstatement() nesting */
119
120#include <expr/expr.h>
121#include <ctype.h>
122#include <ast/error.h>
123
124#define id_string (&exbuiltin[0])
125
126#define exunlex(p,c) ((p)->linep--,(p)->input->peek=(c))
127#define putcontext(p,c) (((p)->linep>=&(p)->line[sizeof((p)->line)]?(p)->linep=(p)->line,(p)->linewrap=1:0),*(p)->linep++=(c))
128#define setcontext(p) ((p)->linep=(p)->line,(p)->linewrap=0)
129
130typedef struct Switch_s /* switch parse state */
131{
132 struct Switch_s*prev; /* previous switch state */
133 Exnode_t* firstcase; /* first case block */
134 Exnode_t* lastcase; /* last case block */
135 Exnode_t* defcase; /* default case block */
136 Extype_t** base; /* label base pointer */
137 size_t cur; /* current label offset */
138 size_t cap; /* total labels allocated */
139 int def; /* default label hit */
140 long type;
142
143typedef struct // associative array bucket
144{
145 Dtlink_t link; /* table link */
146 Extype_t key; /* key */
147 Extype_t value; /* value */
148 char name[1]; /* index name */
149} Exassoc_t;
150
151typedef struct // ex global state
152{
153 Exid_t* id; /* current declaration id */
154 long declare;
155 int nolabel; /* <id>':' not a label */
156 Exinput_t null; /* null input */
157 Expr_t* program; /* current program */
158 Exnode_t* procedure; /* current procedure */
159 Exref_t* refs; /* . reference list */
160 int assigned; /* declaration assignment */
161 Switch_t* swstate; /* switch parse state */
162 char nullstring[1]; /* "" */
163} Exstate_t;
164
165extern Exid_t exbuiltin[];
166extern const char* exversion;
167extern Exstate_t expr;
168
169extern int ex_parse(void); /* yacc should do this */
170
171#ifdef __cplusplus
172}
173#endif
Region-based memory allocator.
struct Switch_s Switch_t
Exid_t exbuiltin[]
Definition exdata.c:24
struct Exinput_s Exinput_t
struct Print_s Print_t
Exstate_t expr
int ex_parse(void)
const char * exversion
Definition exdata.c:22
Extype_t key
Definition exlib.h:146
Extype_t value
Definition exlib.h:147
Dtlink_t link
Definition exlib.h:145
Definition expr.h:91
int nesting
Definition exlib.h:39
char * pp
Definition exlib.h:43
char * file
Definition exlib.h:36
int line
Definition exlib.h:38
char * pushback
Definition exlib.h:42
int unit
Definition exlib.h:41
struct Exinput_s * next
Definition exlib.h:34
int close
Definition exlib.h:35
FILE * fp
Definition exlib.h:37
int peek
Definition exlib.h:40
Definition expr.h:218
int assigned
Definition exlib.h:160
Expr_t * program
Definition exlib.h:157
Switch_t * swstate
Definition exlib.h:161
Exinput_t null
Definition exlib.h:156
Exid_t * id
Definition exlib.h:153
Exref_t * refs
Definition exlib.h:159
long declare
current declaration type
Definition exlib.h:154
int nolabel
Definition exlib.h:155
Exnode_t * procedure
Definition exlib.h:158
struct Exnode_s * param[3]
Definition exlib.h:50
char * format
Definition exlib.h:49
struct Exnode_s * arg
Definition exlib.h:51
struct Print_s * next
Definition exlib.h:48
size_t cap
Definition exlib.h:138
int def
Definition exlib.h:139
Exnode_t * defcase
Definition exlib.h:135
struct Switch_s * prev
Definition exlib.h:132
long type
switch test type
Definition exlib.h:140
Exnode_t * lastcase
Definition exlib.h:134
size_t cur
Definition exlib.h:137
Extype_t ** base
Definition exlib.h:136
Exnode_t * firstcase
Definition exlib.h:133