Files
carbon-lang/toolchain/check/cpp/macros.h
T
Ivana Ivanovska b68b6ae1e7 Add support for more complex object-like macros (#6338)
Uses `clang::Parser::ParseConstantExpression()` to parse the macro
replacement tokens, added as a token stream to the preprocessor. This
extends the support from simple object-like macros with a single
replacement token, to multiple tokens like unary operators, binary
operators, casting, nested macros etc.
The support is still limited to macros that are evaluated to an integer
constant. More types to be added as a follow-up.

Part of #6303
2025-11-12 17:06:39 +00:00

23 lines
896 B
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TOOLCHAIN_CHECK_CPP_MACROS_H_
#define CARBON_TOOLCHAIN_CHECK_CPP_MACROS_H_
#include "toolchain/check/context.h"
namespace Carbon::Check {
// Tries to evaluate the given macro to a constant expression. Returns the
// evaluated expression on success or nullptr otherwise. Currently supports only
// object-like macros that evaluate to an integer constant.
// TODO: Add support for other literal types.
auto TryEvaluateMacroToConstant(Context& context, SemIR::LocId loc_id,
SemIR::NameId name_id,
clang::MacroInfo* macro_info) -> clang::Expr*;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_CPP_MACROS_H_