8 #include <hilti/rt/3rdparty/ArticleEnumClass-v2/EnumClass.h>
10 #include <hilti/ast/ctor.h>
11 #include <hilti/ast/expression.h>
12 #include <hilti/ast/operator.h>
13 #include <hilti/ast/type.h>
14 #include <hilti/base/util.h>
19 enum class CoercionStyle {
24 Assignment = (1U << 0U),
30 FunctionCall = (1U << 2U),
36 TryExactMatch = (1U << 3U),
42 TryConstPromotion = (1U << 4U),
49 TryCoercion = (1U << 5U),
57 TryCoercionWithinSameType = (1U << 6U),
60 DisallowTypeChanges = (1U << 7U),
68 ContextualConversion = (1U << 8U),
71 TryDeref = (1U << 9U),
77 TryAllForAssignment = Assignment | TryExactMatch | TryConstPromotion | TryCoercion | TryDeref,
83 TryDirectForMatching = TryExactMatch | TryConstPromotion,
89 TryAllForMatching = TryDirectForMatching | TryCoercion,
95 TryDirectMatchForFunctionCall = FunctionCall | TryExactMatch | TryConstPromotion,
101 TryAllForFunctionCall = TryDirectMatchForFunctionCall | TryCoercion | TryDeref,
108 extern std::string to_string(bitmask<CoercionStyle> style);
112 enableEnumClassBitmask(hilti::CoercionStyle);
119 operator bool()
const {
return coerced.hasValue(); }
197 CoercedExpression coerceExpression(Builder* builder, Expression* e, QualifiedType* dst,
198 bitmask<CoercionStyle> style = CoercionStyle::TryAllForAssignment,
bool lhs =
false);
221 CoercedExpression coerceExpression(Builder* builder, Expression* e, QualifiedType* src_, QualifiedType* dst_,
222 bitmask<CoercionStyle> style = CoercionStyle::TryAllForAssignment,
bool lhs =
false);
243 Result<std::pair<bool, Expressions>> coerceOperands(Builder* builder, operator_::Kind kind,
const Expressions& exprs,
244 const operator_::Operands& operands, bitmask<CoercionStyle> style);
257 Result<Ctor*> coerceCtor(Builder* builder, Ctor* c, QualifiedType* dst,
258 bitmask<CoercionStyle> style = CoercionStyle::TryAllForAssignment);
271 Result<QualifiedType*> coerceType(Builder* builder, QualifiedType* src_, QualifiedType* dst_,
272 bitmask<CoercionStyle> style = CoercionStyle::TryAllForAssignment);
275 namespace coercer::detail {
278 Ctor* coerceCtor(Builder* builder, Ctor* c, QualifiedType* dst, bitmask<CoercionStyle> style);
281 QualifiedType* coerceType(Builder* builder, QualifiedType* t, QualifiedType* dst, bitmask<CoercionStyle> style);
Definition: expression.h:15
Definition: coercer.h:117
CoercedExpression(QualifiedType *src, Expression *coerced)
Definition: coercer.h:163
Result< Expression * > coerced
Definition: coercer.h:126
CoercedExpression(const result::Error &error)
Definition: coercer.h:175
bool consider_type_changed
Definition: coercer.h:139
CoercedExpression(Expression *src)
Definition: coercer.h:154
Expression * nexpr
Definition: coercer.h:132
CoercedExpression()=default