mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 18:44:59 +01:00
Support is added for all overloaded operator interfaces in the current design apart from `Assign`, which is going to require some more work to properly handle, given that primitive assignment currently has a special implementation for quite a few builtin types. As we don't have support for generics yet -- in particular, generic interfaces -- there is no support for `*With` interfaces, but homogenous interfaces such as `Add` are supported instead. Factor out building of call expressions so that overloaded operators can generate calls. Switch a few places from using specific kinds of NodeId to a general NodeId. Because overloaded operators and other things like implicit conversions can result in member access and function calls, those operations can't require a specific kind of NodeId. Add import support for associated entities, and fix import support for interfaces and symbolic bindings. We now import interfaces in two steps, first importing a forward declaration then a definition, just like we do for classes. For symbolic bindings, we ensure that each BindSymbolicName is imported only once, because its ID is used as its symbolic identity. This is necessary because we (only) support operator interfaces that are defined in an imported Carbon package for now. The entire contents of `check/operator.cpp` should probably be rethought. In particular, doing a lot of name lookups on each operator is likely to be bad for performance. But this gets us to the point where overloaded operators are basically working, which seems like a good place to iterate from. For now, the tests that the individual operators map to the right interfaces are mostly generated by a script, but that's just because I'm expecting a fair bit of churn in how we define the prelude and the `impl`s -- in particular, when we add support for `AddWith`, we'll need to update all the tests. The plan is to remove the script once things settle down. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
44 lines
1.4 KiB
Bash
Executable File
44 lines
1.4 KiB
Bash
Executable File
#! /bin/bash
|
|
# 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
|
|
|
|
# TODO: This is a short-term script to regenerate the test files for operators
|
|
# while we're in a period where we expect the tests to have substantial churn.
|
|
# Once the implementation of overloaded operators has stabilized, this script
|
|
# and its template files should be removed.
|
|
|
|
make_test() {
|
|
HEADER="// This file was generated from $4. Run make_tests.sh to regenerate."
|
|
sed "s,INTERFACE,$1,g; s,OP,$2,g; s,HEADER,$HEADER," "$4" > "$3.carbon"
|
|
}
|
|
|
|
make_unary_op_test() {
|
|
make_test "$1" "$2" "$3" unary_op.carbon.tmpl
|
|
}
|
|
|
|
make_unary_stmt_test() {
|
|
make_test "$1" "$2" "$3" unary_stmt.carbon.tmpl
|
|
}
|
|
|
|
make_binary_op_test() {
|
|
make_test "$1" "$2" "$3" binary_op.carbon.tmpl
|
|
}
|
|
|
|
make_unary_op_test BitComplement '^' bit_complement
|
|
make_unary_op_test Negate '-' negate
|
|
|
|
make_unary_stmt_test Dec '--' dec
|
|
make_unary_stmt_test Inc '++' inc
|
|
|
|
make_binary_op_test Add '+' add
|
|
make_binary_op_test BitAnd '\&' bit_and
|
|
make_binary_op_test BitOr '|' bit_or
|
|
make_binary_op_test BitXor '^' bit_xor
|
|
make_binary_op_test Div '/' div
|
|
make_binary_op_test LeftShift '<<' left_shift
|
|
make_binary_op_test Mod '%' mod
|
|
make_binary_op_test Mul '*' mul
|
|
make_binary_op_test RightShift '>>' right_shift
|
|
make_binary_op_test Sub '-' sub
|