Graphviz 13.0.0~dev.20250210.0415
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
31typedef struct Exinput_s /* input stack */
32{
33 struct Exinput_s*next; /* next in stack */
34 int close; /* close fp on pop */
35 char* file; /* previous file */
36 FILE* fp; /* expression file pointer */
37 int line; /* previous line */
38 int nesting; /* expression nesting level */
39 int peek; /* 1 char peek */
40 int unit; /* first frame in parse unit */
41 char* pushback; /* pushback buffer */
42 char* pp; /* pushback pointer */
44
45typedef struct Print_s /* compiled printf arg node */
46{
47 struct Print_s* next; /* next arg */
48 char* format; /* printf format for arg */
49 struct Exnode_s*param[3]; /* 0:width 1:precision 2:base */
50 struct Exnode_s*arg; /* arg to format */
52
53#define _EX_DATA_PRIVATE_ \
54 Exnode_t* next; /* free list link */ \
55 Extype_t value; /* dynamic variable value */ \
56 struct \
57 { \
58 Exid_t* procedure; /* called procedure */ \
59 Exnode_t* args; /* actual argument list */ \
60 } call; /* procedure call */ \
61 struct \
62 { \
63 Exnode_t* array; /* array name */ \
64 Exid_t* index; /* array index */ \
65 Exnode_t* statement; /* statement to apply */ \
66 } generate; /* associative array generator */ \
67 struct \
68 { \
69 Exid_t* array; /* array */ \
70 Exnode_t* string; /* string */ \
71 Exnode_t* seps; /* optional separators */ \
72 } split; /* string split */ \
73 struct \
74 { \
75 Exnode_t* descriptor; /* Expr_t.file index */ \
76 Print_t* args; /* compiler printf args */ \
77 } print; /* printf */ \
78 struct \
79 { \
80 Exnode_t* base; /* base string */ \
81 Exnode_t* pat; /* pattern or start index */ \
82 Exnode_t* repl; /* optional replacement or end index */ \
83 } string; /* string builtins */ \
84 struct \
85 { \
86 Exnode_t* args; /* formal arg list */ \
87 Exnode_t* body; /* body */ \
88 Dt_t* frame; /* local symbol frame */ \
89 int arity; /* # formal args */ \
90 } procedure; /* procedure args and body */ \
91 struct \
92 { \
93 Exnode_t* descriptor; /* Expr_t.file index */ \
94 Exnode_t* format; /* format arg */ \
95 Exnode_t* args; /* actual args */ \
96 } scan; /* printf */
97
98#define _EX_NODE_PRIVATE_ \
99 int subop; /* operator qualifier */
100
101#define _EX_PROG_PRIVATE_ \
102 Vmalloc_t* ve; /* eval tmp region */ \
103 Dt_t* frame; /* frame symbol table */ \
104 Exdisc_t* disc; /* user discipline */ \
105 Exinput_t* input; /* input stack */ \
106 Expr_t* program; /* previous program on stack */ \
107 agxbuf tmp; /* tmp string buffer */ \
108 Extype_t loopret; /* return value */ \
109 Exid_t main; /* main procedure */ \
110 char line[512]; /* last few input tokens */ \
111 char* linep; /* line[] pointer */ \
112 int eof; /* lex hit eof */ \
113 int errors; /* fatal error count */ \
114 int linewrap; /* linep wrapped around line[] */ \
115 long long loopcount; /* break|continue|return count */ \
116 long loopop; /* break|continue|return op */ \
117 int nesting; /* exstatement() nesting */
118
119#include <expr/expr.h>
120#include <ctype.h>
121#include <ast/error.h>
122
123#define id_string (&exbuiltin[0])
124
125#define exunlex(p,c) ((p)->linep--,(p)->input->peek=(c))
126#define putcontext(p,c) (((p)->linep>=&(p)->line[sizeof((p)->line)]?(p)->linep=(p)->line,(p)->linewrap=1:0),*(p)->linep++=(c))
127#define setcontext(p) ((p)->linep=(p)->line,(p)->linewrap=0)
128
129typedef struct Switch_s /* switch parse state */
130{
131 struct Switch_s*prev; /* previous switch state */
132 Exnode_t* firstcase; /* first case block */
133 Exnode_t* lastcase; /* last case block */
134 Exnode_t* defcase; /* default case block */
135 Extype_t** base; /* label base pointer */
136 size_t cur; /* current label offset */
137 size_t cap; /* total labels allocated */
138 int def; /* default label hit */
139 long type;
141
142typedef struct // associative array bucket
143{
144 Dtlink_t link; /* table link */
145 Extype_t key; /* key */
146 Extype_t value; /* value */
147 char name[1]; /* index name */
148} Exassoc_t;
149
150typedef struct // ex global state
151{
152 Exid_t* id; /* current declaration id */
153 long declare;
154 int nolabel; /* <id>':' not a label */
155 Exinput_t null; /* null input */
156 Expr_t* program; /* current program */
157 Exnode_t* procedure; /* current procedure */
158 Exref_t* refs; /* . reference list */
159 int assigned; /* declaration assignment */
160 Switch_t* swstate; /* switch parse state */
161 char nullstring[1]; /* "" */
162} Exstate_t;
163
164extern Exid_t exbuiltin[];
165extern const char* exversion;
166extern Exstate_t expr;
167
168extern int ex_parse(void); /* yacc should do this */
169
170#ifdef __cplusplus
171}
172#endif
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:145
Extype_t value
Definition exlib.h:146
Dtlink_t link
Definition exlib.h:144
Definition expr.h:93
int nesting
Definition exlib.h:38
char * pp
Definition exlib.h:42
char * file
Definition exlib.h:35
int line
Definition exlib.h:37
char * pushback
Definition exlib.h:41
int unit
Definition exlib.h:40
struct Exinput_s * next
Definition exlib.h:33
int close
Definition exlib.h:34
FILE * fp
Definition exlib.h:36
int peek
Definition exlib.h:39
Definition expr.h:198
int assigned
Definition exlib.h:159
Expr_t * program
Definition exlib.h:156
Switch_t * swstate
Definition exlib.h:160
Exinput_t null
Definition exlib.h:155
Exid_t * id
Definition exlib.h:152
Exref_t * refs
Definition exlib.h:158
long declare
current declaration type
Definition exlib.h:153
int nolabel
Definition exlib.h:154
Exnode_t * procedure
Definition exlib.h:157
struct Exnode_s * param[3]
Definition exlib.h:49
char * format
Definition exlib.h:48
struct Exnode_s * arg
Definition exlib.h:50
struct Print_s * next
Definition exlib.h:47
size_t cap
Definition exlib.h:137
int def
Definition exlib.h:138
Exnode_t * defcase
Definition exlib.h:134
struct Switch_s * prev
Definition exlib.h:131
long type
switch test type
Definition exlib.h:139
Exnode_t * lastcase
Definition exlib.h:133
size_t cur
Definition exlib.h:136
Extype_t ** base
Definition exlib.h:135
Exnode_t * firstcase
Definition exlib.h:132