| 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 |
| 16 |
extern "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 |
|
| 32 |
typedef 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 */ |
| 44 |
} Exinput_t; |
| 45 |
|
| 46 |
typedef 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 */ |
| 52 |
} Print_t; |
| 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 |
|
| 130 |
typedef 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; ///< switch test type |
| 141 |
} Switch_t; |
| 142 |
|
| 143 |
typedef 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 |
|
| 151 |
typedef struct // ex global state |
| 152 |
{ |
| 153 |
Exid_t* id; /* current declaration id */ |
| 154 |
long declare; ///< current declaration type |
| 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 |
|
| 165 |
extern Exid_t exbuiltin[]; |
| 166 |
extern const char* exversion; |
| 167 |
extern Exstate_t expr; |
| 168 |
|
| 169 |
extern int ex_parse(void); /* yacc should do this */ |
| 170 |
|
| 171 |
#ifdef __cplusplus |
| 172 |
} |
| 173 |
#endif |