A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
resolve.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
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 A11_FLOW_RESOLVE_H_
18#define A11_FLOW_RESOLVE_H_
19
20#include <string>
21#include <string_view>
22#include <vector>
23
24#include "a11/flow/diagnostic.h"
25#include "a11/flow/graph.h"
26#include "a11/flow/parser.h"
27#include "a11/flow/plan.h"
28#include "a11/flow/syntax.h"
29
30namespace a11::flow {
31
33enum class SymbolKind {
41 kHeader,
43 kCall,
45 kNode,
53 kCarry,
58 kValue,
59};
60
67struct Symbol {
69 std::string name;
73 bool implicit = false;
75 bool readable = true;
77 bool writable = false;
80 std::string action;
81 bool tolerant = false;
82 const FlowPlan* absl_nullable target = nullptr;
84 int reads = 0;
85 int writes = 0;
89 int status_reads = 0;
90 // The graph ref this name reads and writes, when a graph was built: a port, a
91 // node, a header, a loop variable.
105 // The `match` pattern this value came out of, where it came out of a literal
106 // one.
116 std::string pattern;
122 bool value_part = false;
123};
124
128 // The executable graph, when [Resolve] was asked for one.
138 std::vector<Symbol> symbols;
142 const syntax::FlowDeclaration* absl_nullable declaration = nullptr;
143};
144
148 std::vector<ResolvedFlow> flows;
149 std::vector<Diagnostic> diagnostics;
150
151 [[nodiscard]] bool HasErrors() const;
152 [[nodiscard]] const Diagnostic* absl_nullable FirstError() const;
153};
154
175ResolveResult Resolve(std::string_view source, const ParseResult& parsed,
176 bool build_graph = false);
177
179std::string_view SymbolKindName(SymbolKind kind);
180
181} // namespace a11::flow
182
183#endif // A11_FLOW_RESOLVE_H_
TokenKind kind
Definition format.cc:913
constexpr size_t kNone
No such thing – the absent id, for the many fields only some kinds use.
Definition graph.h:47
size_t RefId
Everything in a graph is named by index into the graph that owns it.
Definition graph.h:41
size_t StepId
Definition graph.h:42
Definition boundary.cc:32
@ kCall
A bound run/call step.
@ kHeader
A header, under its alias.
@ kNode
A node of the flow's own.
@ kBarrier
A bound wait/drain.
std::string_view SymbolKindName(SymbolKind kind)
The name of a symbol kind, for a message and for the JSON.
Definition resolve.cc:3889
ResolveResult Resolve(std::string_view source, const ParseResult &parsed, bool build_graph)
Resolve a parsed program: names, ports, scopes, node maps and types.
Definition resolve.cc:3915
SymbolKind
What a name means inside a flow.
Definition resolve.h:33
@ kOutputPort
An out port: written, never read... except by this flow, which may read back what it wrote to one onl...
@ kInputPort
An in port: read, never written.
@ kLoopVariable
A for variable, or the index every loop binds.
@ kValue
One value, read from a stream and given a name by let.
@ kCarry
What a repeat carries.
One problem found in a flow.
Definition diagnostic.h:108
One compiled flow: what a caller sees, and what the runtime will do.
Definition plan.h:149
The flows a file declares, and everything wrong with it.
Definition parser.h:32
Every flow and shape one source file declares.
Definition plan.h:185
A whole file, resolved.
Definition resolve.h:146
Program program
Definition resolve.h:147
std::vector< ResolvedFlow > flows
Definition resolve.h:148
std::vector< Diagnostic > diagnostics
Definition resolve.h:149
const Diagnostic *absl_nullable FirstError() const
Definition resolve.cc:3885
bool HasErrors() const
Definition resolve.cc:3881
One flow, resolved: its plan, its names, and what is wrong with it.
Definition resolve.h:126
const syntax::FlowDeclaration *absl_nullable declaration
The declaration this came from, borrowed.
Definition resolve.h:142
graph::FlowGraph graph
The executable graph, when [Resolve] was asked for one.
Definition resolve.h:134
FlowPlan plan
Definition resolve.h:127
std::vector< Symbol > symbols
Every symbol the flow bound, in the order it bound them.
Definition resolve.h:138
One name, what it is, and what became of it.
Definition resolve.h:67
int value_offset
Definition resolve.h:104
syntax::Location location
Definition resolve.h:70
bool tolerant
Definition resolve.h:81
bool writable
Whether a pipe may write it.
Definition resolve.h:77
int status_reads
For a call: whether anything read its status – wait x, status x, or a bound wait.
Definition resolve.h:89
graph::StepId step
The graph step this name is: a call, or a bound wait/drain.
Definition resolve.h:98
bool readable
Whether a pipeline may read it.
Definition resolve.h:75
std::string pattern
The match pattern this value came out of, where it came out of a literal one.
Definition resolve.h:116
const FlowPlan *absl_nullable target
Definition resolve.h:82
graph::RefId ref
The graph ref this name reads and writes, when a graph was built: a port, a node, a header,...
Definition resolve.h:96
bool implicit
Whether the language bound it rather than the author: the index every loop provides.
Definition resolve.h:73
SymbolKind kind
Definition resolve.h:68
std::string action
For a call: the action named, whether it was try, and the sibling flow it resolves to if it is one.
Definition resolve.h:80
std::string name
Definition resolve.h:69
int writes
Definition resolve.h:85
int reads
How many times something read it, wrote it, or waited for it.
Definition resolve.h:84
bool value_part
Whether this name is one part of a value a let took apart.
Definition resolve.h:122
graph::RefId value_source
For a value a let bound: the stream it took a value of, and which value of that stream it is.
Definition resolve.h:103
The executable graph of one flow.
Definition graph.h:390
One flow name { ... } declaration, or the one flow { ... } entry point.
Definition syntax.h:758
Where a piece of syntax starts, reduced to what every reader of it needs.
Definition syntax.h:49