libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / rust / expand / rust-macro-builtins-helpers.h
blobf5d018b35f8140c31dbe2785fcd562d2c9801b1a
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 // This file is part of GCC.
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.
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.
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/>.
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-session-manager.h"
33 #include "rust-system.h"
34 #include "rust-token.h"
35 namespace Rust {
37 std::string
38 make_macro_path_str (BuiltinMacro kind);
40 std::vector<std::unique_ptr<AST::MacroInvocation>>
41 check_for_eager_invocations (
42 std::vector<std::unique_ptr<AST::Expr>> &expressions);
44 // Shorthand function for creating unique_ptr tokens
46 std::unique_ptr<AST::Token>
47 make_token (const TokenPtr tok);
49 std::unique_ptr<AST::Expr>
50 make_string (location_t locus, std::string value);
51 // TODO: Is this correct?
52 AST::Fragment
53 make_eager_builtin_invocation (
54 BuiltinMacro kind, location_t locus, AST::DelimTokenTree arguments,
55 std::vector<std::unique_ptr<AST::MacroInvocation>> &&pending_invocations);
56 // Match the end token of a macro given the start delimiter of the macro
57 TokenId
58 macro_end_token (AST::DelimTokenTree &invoc_token_tree,
59 Parser<MacroInvocLexer> &parser);
60 // Expand and then extract a string literal from the macro
61 std::unique_ptr<AST::LiteralExpr>
62 try_extract_string_literal_from_fragment (const location_t &parent_locus,
63 std::unique_ptr<AST::Expr> &node);
65 std::vector<std::unique_ptr<AST::Expr>>
66 try_expand_many_expr (Parser<MacroInvocLexer> &parser,
67 const TokenId last_token_id, MacroExpander *expander,
68 bool &has_error);
70 // Parse a single string literal from the given delimited token tree,
71 // and return the LiteralExpr for it. Allow for an optional trailing comma,
72 // but otherwise enforce that these are the only tokens.
74 std::unique_ptr<AST::Expr>
75 parse_single_string_literal (BuiltinMacro kind,
76 AST::DelimTokenTree &invoc_token_tree,
77 location_t invoc_locus, MacroExpander *expander);
79 // Treat PATH as a path relative to the source file currently being
80 // compiled, and return the absolute path for it.
82 std::string
83 source_relative_path (std::string path, location_t locus);
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