mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 11:31:04 +01:00
In parse, form a list of methods that are defined inline, tracking where they start, where they end, and which other inline methods are nested within them. In check, when we reach an inline method body, skip it and add it to a worklist to be processed later. We also track when we reach the start and end of a context in which inline method bodies are deferred, so that we know when to replay the bodies. When suspending a function definition to be processed later, the `DeclNameStack` entry is moved to separate storage, including popping the corresponding scopes from the scope stack and removing the corresponding lexical names from lexical lookup. Later, when we return to the function and parse its definition, the `DeclNameStack` entry is restored. The same is done when we reach the end of a nested context that can have inline methods, so that we can reenter the nested scope before processing its members. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
85 lines
3.5 KiB
Plaintext
85 lines
3.5 KiB
Plaintext
// 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
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
interface DefaultConstructible {
|
|
fn Make() -> Self;
|
|
}
|
|
|
|
class A {
|
|
impl i32 as DefaultConstructible {
|
|
// `Self` here refers to `i32`, not `A`.
|
|
// TODO: Revisit this once #3714 is resolved.
|
|
fn Make() -> Self { return 0; }
|
|
}
|
|
}
|
|
|
|
// CHECK:STDOUT: --- self_in_class.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %.1: type = interface_type @DefaultConstructible [template]
|
|
// CHECK:STDOUT: %.2: type = assoc_entity_type @DefaultConstructible, <function> [template]
|
|
// CHECK:STDOUT: %.3: <associated <function> in DefaultConstructible> = assoc_entity element0, @DefaultConstructible.%Make [template]
|
|
// CHECK:STDOUT: %A: type = class_type @A [template]
|
|
// CHECK:STDOUT: %.4: <witness> = interface_witness (@impl.%Make) [template]
|
|
// CHECK:STDOUT: %.5: type = struct_type {} [template]
|
|
// CHECK:STDOUT: %.6: i32 = int_literal 0 [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .DefaultConstructible = %DefaultConstructible.decl
|
|
// CHECK:STDOUT: .A = %A.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %DefaultConstructible.decl: type = interface_decl @DefaultConstructible [template = constants.%.1] {}
|
|
// CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: interface @DefaultConstructible {
|
|
// CHECK:STDOUT: %Self: DefaultConstructible = bind_symbolic_name Self [symbolic]
|
|
// CHECK:STDOUT: %Make: <function> = fn_decl @Make.1 [template] {
|
|
// CHECK:STDOUT: %Self.ref: DefaultConstructible = name_ref Self, %Self [symbolic = %Self]
|
|
// CHECK:STDOUT: %.loc8_16.1: type = facet_type_access %Self.ref [symbolic = %Self]
|
|
// CHECK:STDOUT: %.loc8_16.2: type = converted %Self.ref, %.loc8_16.1 [symbolic = %Self]
|
|
// CHECK:STDOUT: %return.var: ref Self = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %.loc8_20: <associated <function> in DefaultConstructible> = assoc_entity element0, %Make [template = constants.%.3]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = %Self
|
|
// CHECK:STDOUT: .Make = %.loc8_20
|
|
// CHECK:STDOUT: witness = (%Make)
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: impl @impl: i32 as DefaultConstructible {
|
|
// CHECK:STDOUT: %Make: <function> = fn_decl @Make.2 [template] {
|
|
// CHECK:STDOUT: %Self.ref: type = name_ref Self, i32 [template = i32]
|
|
// CHECK:STDOUT: %return.var: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %.1: <witness> = interface_witness (%Make) [template = constants.%.4]
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Make = %Make
|
|
// CHECK:STDOUT: witness = %.1
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @A {
|
|
// CHECK:STDOUT: impl_decl @impl {
|
|
// CHECK:STDOUT: %DefaultConstructible.ref: type = name_ref DefaultConstructible, file.%DefaultConstructible.decl [template = constants.%.1]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%A
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Make.1() -> Self;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Make.2() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc15: i32 = int_literal 0 [template = constants.%.6]
|
|
// CHECK:STDOUT: return %.loc15
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|