blob: 7834a2bdd9c1451b08998ab1ab7370b42858c60e [file] [log] [blame]
The Android Open Source Project23580ca2008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AMEND_AST_H_
18#define AMEND_AST_H_
19
20#include "commands.h"
21
22typedef struct AmStringValue AmStringValue;
23
24typedef struct {
25 int argc;
26 AmStringValue *argv;
27} AmFunctionArguments;
28
29/* An internal structure used only by the parser;
30 * will not appear in the output AST.
31xxx try to move this into parser.h
32 */
33typedef struct AmFunctionArgumentBuilder AmFunctionArgumentBuilder;
34struct AmFunctionArgumentBuilder {
35 AmFunctionArgumentBuilder *next;
36 AmStringValue *arg;
37 int argCount;
38};
39
40typedef struct AmWordListBuilder AmWordListBuilder;
41struct AmWordListBuilder {
42 AmWordListBuilder *next;
43 const char *word;
44 int wordCount;
45};
46
47typedef struct {
48 const char *name;
49 Function *fn;
50 AmFunctionArguments *args;
51} AmFunctionCall;
52
53
54/* <string-value> ::=
55 * <literal-string> |
56 * <function-call>
57 */
58struct AmStringValue {
59 unsigned int line;
60
61 enum {
62 AM_SVAL_LITERAL,
63 AM_SVAL_FUNCTION,
64 } type;
65 union {
66 const char *literal;
67//xxx inline instead of using pointers
68 AmFunctionCall *function;
69 } u;
70};
71
72
73/* <string-comparison-expression> ::=
74 * <string-value> <string-comparison-operator> <string-value>
75 */
76typedef struct {
77 unsigned int line;
78
79 enum {
80 AM_SOP_LT,
81 AM_SOP_LE,
82 AM_SOP_GT,
83 AM_SOP_GE,
84 AM_SOP_EQ,
85 AM_SOP_NE,
86 } op;
87 AmStringValue *arg1;
88 AmStringValue *arg2;
89} AmStringComparisonExpression;
90
91
92/* <boolean-expression> ::=
93 * ! <boolean-value> |
94 * <boolean-value> <binary-boolean-operator> <boolean-value>
95 */
96typedef struct AmBooleanValue AmBooleanValue;
97typedef struct {
98 unsigned int line;
99
100 enum {
101 AM_BOP_NOT,
102
103 AM_BOP_EQ,
104 AM_BOP_NE,
105
106 AM_BOP_AND,
107
108 AM_BOP_OR,
109 } op;
110 AmBooleanValue *arg1;
111 AmBooleanValue *arg2;
112} AmBooleanExpression;
113
114
115/* <boolean-value> ::=
116 * <boolean-expression> |
117 * <string-comparison-expression>
118 */
119struct AmBooleanValue {
120 unsigned int line;
121
122 enum {
123 AM_BVAL_EXPRESSION,
124 AM_BVAL_STRING_COMPARISON,
125 } type;
126 union {
127 AmBooleanExpression expression;
128 AmStringComparisonExpression stringComparison;
129 } u;
130};
131
132
133typedef struct {
134 unsigned int line;
135
136 int argc;
137 const char **argv;
138} AmWordList;
139
140
141typedef struct {
142 bool booleanArgs;
143 union {
144 AmWordList *w;
145 AmBooleanValue *b;
146 } u;
147} AmCommandArguments;
148
149typedef struct {
150 unsigned int line;
151
152 const char *name;
153 Command *cmd;
154 AmCommandArguments *args;
155} AmCommand;
156
157typedef struct {
158 AmCommand **commands;
159 int commandCount;
160 int arraySize;
161} AmCommandList;
162
163void dumpCommandList(const AmCommandList *commandList);
164
165#endif // AMEND_AST_H_