-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexptree.h
64 lines (53 loc) · 2.3 KB
/
exptree.h
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
/* exptree.h: Copyright (C) 2011 by Brian Raiter <breadbox@muppetlabs.com>
* License GPLv2+: GNU GPL version 2 or later.
* This is free software; you are free to change and redistribute it.
* There is NO WARRANTY, to the extent permitted by law.
*/
#ifndef _exptree_h_
#define _exptree_h_
/*
* An expression tree parses and, where possible, evaluates C
* preprocessor expressions. A parsed expression can then be evaluated
* and to a limited degree edited.
*/
#include "types.h"
/* Allocates an expression tree.
*/
extern exptree *initexptree(void);
/* Deallocates the expression tree.
*/
extern void freeexptree(exptree *t);
/* Resets an exptree back to its initial state.
*/
extern void clearexptree(exptree *t);
/* Returns the length of the expression inside the string.
*/
extern int getexplength(exptree const *t);
/* Parses a C expression into an expression tree. exp points to the
* expression to parse, potentially embedded inside of a larger
* string, and cl provides a lexer initialized to exp's position. The
* return value points to the bytes following the parsed expression.
*/
extern char const *parseexptree(exptree *t, clexer *cl, char const *input);
/* Runs through the parsed expression and marks all of the identifiers
* that appear in set as having a specific definition state, either
* defined or undefined according to the third argument.
* (Sub-expressions consisting entirely of definite symbols are
* themselves considered definite.) The return value is true if any
* identifiers in set were found in the expression tree.
*/
extern int markdefined(exptree *t, symset const *set, int defined);
/* Attempts to evaluate the parsed expression's value. If the
* expression has a definite value, it is returned and defined
* receives a true value. If some or all of the expression lacks a
* definition state, defined receives a false value.
*/
extern long evaltree(exptree *t, int *defined);
/* Copy into buffer the part of the parsed expression that lacks a
* definition state. Any sub-expressions that have a definite value
* are applied and do not form part of the output. The return value is
* the length of the string written to buffer. This string is
* guaranteed not to be longer than the original parsed expression.
*/
extern int unparseevaluated(exptree const *t, char *buffer);
#endif