Debian Codegraph @

gcc/rust/expand/rust-macro-builtins-helpers.h

raw
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2
3 // This file is part of GCC.
4
5 // GCC is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 3, or (at your option) any later
8 // version.
9
10 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 // for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with GCC; see the file COPYING3. If not see
17 // <http://www.gnu.org/licenses/>.
18
19 #ifndef GCCRS_RUST_MACRO_BUILTINS_HELPERS_H
20 #define GCCRS_RUST_MACRO_BUILTINS_HELPERS_H
21 #include "rust-ast-fragment.h"
22 #include "rust-ast.h"
23 #include "rust-cfg-strip.h"
24 #include "rust-diagnostics.h"
25 #include "rust-early-name-resolver.h"
26 #include "rust-expr.h"
27 #include "rust-lex.h"
28 #include "rust-macro-builtins.h"
29 #include "rust-macro-invoc-lexer.h"
30 #include "rust-macro.h"
31 #include "rust-parse.h"
32 #include "rust-system.h"
33 #include "rust-token.h"
34 namespace Rust {
35
36 std::string
37 make_macro_path_str (BuiltinMacro kind);
38
39 std::vector<std::unique_ptr<AST::MacroInvocation>>
40 check_for_eager_invocations (
41 std::vector<std::unique_ptr<AST::Expr>> &expressions);
42
43 // Shorthand function for creating unique_ptr tokens
44
45 std::unique_ptr<AST::Token>
46 make_token (const TokenPtr tok);
47
48 std::unique_ptr<AST::Expr>
49 make_string (location_t locus, std::string value);
50 // TODO: Is this correct?
51 AST::Fragment
52 make_eager_builtin_invocation (
53 BuiltinMacro kind, location_t locus, AST::DelimTokenTree arguments,
54 std::vector<std::unique_ptr<AST::MacroInvocation>> &&pending_invocations);
55 // Match the end token of a macro given the start delimiter of the macro
56 TokenId
57 macro_end_token (AST::DelimTokenTree &invoc_token_tree,
58 Parser<MacroInvocLexer> &parser);
59 // Expand and then extract a string literal from the macro
60 std::unique_ptr<AST::LiteralExpr>
61 try_extract_string_literal_from_fragment (const location_t &parent_locus,
62 std::unique_ptr<AST::Expr> &node);
63
64 std::vector<std::unique_ptr<AST::Expr>>
65 try_expand_many_expr (Parser<MacroInvocLexer> &parser,
66 const TokenId last_token_id, MacroExpander *expander,
67 bool &has_error);
68
69 // Parse a single string literal from the given delimited token tree,
70 // and return the LiteralExpr for it. Allow for an optional trailing comma,
71 // but otherwise enforce that these are the only tokens.
72
73 std::unique_ptr<AST::Expr>
74 parse_single_string_literal (BuiltinMacro kind,
75 AST::DelimTokenTree &invoc_token_tree,
76 location_t invoc_locus, MacroExpander *expander,
77 bool is_semicoloned = false);
78
79 // Treat PATH as a path relative to the source file currently being
80 // compiled, and return the absolute path for it.
81
82 std::string
83 source_relative_path (std::string path, location_t locus);
84
85 // Read the full contents of the file FILENAME and return them in a vector.
86 // FIXME: platform specific.
87 tl::optional<std::vector<uint8_t>>
88 load_file_bytes (location_t invoc_locus, const char *filename);
89 } // namespace Rust
90 #endif // GCCRS_RUST_MACRO_BUILTINS_HELPERS_H