UNPKG

6.55 kBTypeScriptView Raw
1/**
2 * Internal representation: the parsed syntax for C0/C1
3 *
4 * This file describes exactly the syntax that gets parsed by the parser. It is therefore very sensitive to changes in the parser, and so should not be relied upon.
5 *
6 * The only producer of these types is parse-util.ts. The only consumer of these types is restrictsyntax.ts. The structure of this file should match ast.ts as much as practical.
7 */
8import * as ast from "./ast";
9export declare type Expression = ast.Identifier | IntLiteral | StringLiteral | CharLiteral | ast.BoolLiteral | ast.NullLiteral | ArrayMemberExpression | StructMemberExpression | CallExpression | IndirectCallExpression | CastExpression | UnaryExpression | BinaryExpression | LogicalExpression | ConditionalExpression | AllocExpression | AllocArrayExpression | ResultExpression | LengthExpression | HasTagExpression | AssignmentExpression | UpdateExpression | AssertExpression | ErrorExpression;
10export interface IntLiteral extends ast.Syn {
11 readonly tag: "IntLiteral";
12 readonly raw: string;
13}
14export interface StringLiteral extends ast.Syn {
15 readonly tag: "StringLiteral";
16 readonly raw: string[];
17}
18export interface CharLiteral extends ast.Syn {
19 readonly tag: "CharLiteral";
20 readonly raw: string;
21}
22export interface ArrayMemberExpression extends ast.Syn {
23 readonly tag: "ArrayMemberExpression";
24 readonly object: Expression;
25 readonly index: Expression;
26}
27export interface StructMemberExpression extends ast.Syn {
28 readonly tag: "StructMemberExpression";
29 readonly deref: boolean;
30 readonly object: Expression;
31 readonly field: ast.Identifier;
32}
33export interface CallExpression extends ast.Syn {
34 readonly tag: "CallExpression";
35 readonly callee: ast.Identifier;
36 readonly arguments: Expression[];
37}
38export interface IndirectCallExpression extends ast.Syn {
39 readonly tag: "IndirectCallExpression";
40 readonly callee: Expression;
41 readonly arguments: Expression[];
42}
43export interface CastExpression extends ast.Syn {
44 readonly tag: "CastExpression";
45 readonly kind: ast.Type;
46 readonly argument: Expression;
47}
48export interface UnaryExpression extends ast.Syn {
49 readonly tag: "UnaryExpression";
50 readonly operator: "&" | "!" | "~" | "-" | "*";
51 readonly argument: Expression;
52}
53/**
54 * Eager binary operations `e+e` and friends
55 */
56export interface BinaryExpression extends ast.Syn {
57 readonly tag: "BinaryExpression";
58 readonly operator: "*" | "/" | "%" | "+" | "-" | "<<" | ">>" | "<" | "<=" | ">=" | ">" | "==" | "!=" | "&" | "^" | "|";
59 readonly left: Expression;
60 readonly right: Expression;
61}
62export interface LogicalExpression extends ast.Syn {
63 readonly tag: "LogicalExpression";
64 readonly operator: "||" | "&&";
65 readonly left: Expression;
66 readonly right: Expression;
67}
68export interface ConditionalExpression extends ast.Syn {
69 readonly tag: "ConditionalExpression";
70 readonly test: Expression;
71 readonly consequent: Expression;
72 readonly alternate: Expression;
73}
74export interface AllocExpression extends ast.Syn {
75 readonly tag: "AllocExpression";
76 readonly kind: ast.Type;
77}
78export interface AllocArrayExpression extends ast.Syn {
79 readonly tag: "AllocArrayExpression";
80 readonly kind: ast.Type;
81 readonly size: Expression;
82}
83export interface ResultExpression extends ast.Syn {
84 readonly tag: "ResultExpression";
85}
86export interface LengthExpression extends ast.Syn {
87 readonly tag: "LengthExpression";
88 readonly argument: Expression;
89}
90export interface HasTagExpression extends ast.Syn {
91 readonly tag: "HasTagExpression";
92 readonly kind: ast.Type;
93 readonly argument: Expression;
94}
95export interface AssignmentExpression extends ast.Syn {
96 readonly tag: "AssignmentExpression";
97 readonly operator: "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | "&=" | "^=" | "|=";
98 readonly left: Expression;
99 readonly right: Expression;
100}
101export interface UpdateExpression extends ast.Syn {
102 readonly tag: "UpdateExpression";
103 readonly operator: "++" | "--";
104 readonly argument: Expression;
105}
106export interface AssertExpression extends ast.Syn {
107 readonly tag: "AssertExpression";
108 readonly test: Expression;
109}
110export interface ErrorExpression extends ast.Syn {
111 readonly tag: "ErrorExpression";
112 readonly argument: Expression;
113}
114export declare type Statement = AnnoStatement | ExpressionStatement | VariableDeclaration | IfStatement | WhileStatement | ForStatement | ReturnStatement | BlockStatement | ast.BreakStatement | ast.ContinueStatement;
115export interface Anno {
116 readonly tag: "requires" | "ensures" | "loop_invariant" | "assert";
117 readonly test: Expression;
118}
119export interface AnnoStatement extends ast.Syn {
120 readonly tag: "AnnoStatement";
121 readonly anno: Anno;
122}
123export interface ExpressionStatement extends ast.Syn {
124 readonly tag: "ExpressionStatement";
125 readonly expression: Expression;
126}
127export interface VariableDeclaration extends ast.Syn {
128 readonly tag: "VariableDeclaration";
129 readonly kind: ast.Type;
130 readonly id: ast.Identifier;
131 readonly init: Expression | null;
132}
133export interface IfStatement extends ast.Syn {
134 readonly tag: "IfStatement";
135 readonly test: Expression;
136 readonly consequent: [Anno[], Statement];
137 readonly alternate?: [Anno[], Statement];
138}
139export interface WhileStatement extends ast.Syn {
140 readonly tag: "WhileStatement";
141 readonly test: Expression;
142 readonly annos: Anno[];
143 readonly body: Statement;
144}
145export interface ForStatement extends ast.Syn {
146 readonly tag: "ForStatement";
147 readonly init: VariableDeclaration | ExpressionStatement | null;
148 readonly test: Expression;
149 readonly update: Expression | null;
150 readonly annos: Anno[];
151 readonly body: Statement;
152}
153export interface ReturnStatement extends ast.Syn {
154 readonly tag: "ReturnStatement";
155 readonly argument: Expression | null;
156}
157export interface BlockStatement extends ast.Syn {
158 readonly tag: "BlockStatement";
159 readonly body: Statement[];
160}
161export declare type Declaration = FunctionDeclaration | BlockStatement;
162export interface VariableDeclarationOnly extends ast.Syn {
163 readonly kind: ast.Type;
164 readonly id: ast.Identifier;
165}
166export interface FunctionDeclaration extends ast.Syn {
167 readonly tag: "FunctionDeclaration";
168 readonly returns: ast.Type;
169 readonly id: ast.Identifier;
170 readonly params: ast.VariableDeclarationOnly[];
171 readonly annos: Anno[];
172 readonly body: null | BlockStatement;
173}