Spicy
visitors.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <iostream>
6 #include <set>
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
11 #include <hilti/ast/ctor.h>
12 #include <hilti/ast/expression.h>
13 #include <hilti/ast/function.h>
14 #include <hilti/ast/node.h>
15 #include <hilti/ast/operator.h>
16 #include <hilti/base/logger.h>
17 #include <hilti/compiler/context.h>
18 
19 namespace hilti {
20 
21 class Unit;
22 
23 namespace printer {
24 class Stream;
25 } // namespace printer
26 
27 namespace detail {
28 
30 std::set<context::ModuleIndex> importModules(const Node& root, Unit* unit);
31 
36 void printAST(const Node& root, std::ostream& out, bool compact = false);
37 
42 void printAST(const Node& root, printer::Stream& stream); // NOLINT
43 
45 std::string renderOperatorPrototype(const expression::UnresolvedOperator& o);
46 
48 std::string renderOperatorPrototype(const expression::ResolvedOperator& o);
49 
51 std::string renderOperatorInstance(const expression::UnresolvedOperator& o);
52 
54 std::string renderOperatorInstance(const expression::ResolvedOperator& o);
55 
57 void renderNode(const Node& n, std::ostream& out, bool include_scopes = false);
58 void renderNode(const Node& n, logging::DebugStream stream, bool include_scopes = false);
59 
63 void clearErrors(Node* root);
64 
66 void buildScopes(const std::vector<std::pair<ID, NodeRef>>& modules, Unit* unit);
68 bool resolveIDs(Node* root, Unit* unit);
70 bool resolveOperators(Node* root, Unit* unit);
72 std::optional<Ctor> coerceCtor(Ctor c, const Type& dst, bitmask<CoercionStyle> style);
74 std::optional<Type> coerceType(Type t, const Type& dst, bitmask<CoercionStyle> style);
76 bool applyCoercions(Node* root, Unit* unit);
78 void validateAST(Node* root);
79 
80 
81 } // namespace detail
82 } // namespace hilti