mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:10:12 +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>
99 lines
3.3 KiB
Plaintext
99 lines
3.3 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
|
|
|
|
class Class {
|
|
fn F() -> i32 {
|
|
return 1;
|
|
}
|
|
|
|
fn G() -> i32 {
|
|
return F();
|
|
}
|
|
}
|
|
|
|
fn F() -> i32 {
|
|
return 2;
|
|
}
|
|
|
|
fn Run() {
|
|
var a: i32 = F();
|
|
var b: i32 = Class.F();
|
|
}
|
|
|
|
// CHECK:STDOUT: --- scope.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Class: type = class_type @Class [template]
|
|
// CHECK:STDOUT: %.1: type = struct_type {} [template]
|
|
// CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
|
|
// CHECK:STDOUT: %.3: i32 = int_literal 2 [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .Class = %Class.decl
|
|
// CHECK:STDOUT: .F = %F
|
|
// CHECK:STDOUT: .Run = %Run
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
|
|
// CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
|
|
// CHECK:STDOUT: %return.var: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Run: <function> = fn_decl @Run [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @Class {
|
|
// CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {
|
|
// CHECK:STDOUT: %return.var.loc8: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %G: <function> = fn_decl @G [template] {
|
|
// CHECK:STDOUT: %return.var.loc12: ref i32 = var <return slot>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%Class
|
|
// CHECK:STDOUT: .F = %F
|
|
// CHECK:STDOUT: .G = %G
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F.1() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc9: i32 = int_literal 1 [template = constants.%.2]
|
|
// CHECK:STDOUT: return %.loc9
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @G() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %F.ref: <function> = name_ref F, @Class.%F [template = @Class.%F]
|
|
// CHECK:STDOUT: %.loc13_13.1: init i32 = call %F.ref()
|
|
// CHECK:STDOUT: %.loc13_15: i32 = value_of_initializer %.loc13_13.1
|
|
// CHECK:STDOUT: %.loc13_13.2: i32 = converted %.loc13_13.1, %.loc13_15
|
|
// CHECK:STDOUT: return %.loc13_13.2
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @F.2() -> i32 {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc18: i32 = int_literal 2 [template = constants.%.3]
|
|
// CHECK:STDOUT: return %.loc18
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Run() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %a.var: ref i32 = var a
|
|
// CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
|
|
// CHECK:STDOUT: %F.ref.loc22: <function> = name_ref F, file.%F [template = file.%F]
|
|
// CHECK:STDOUT: %.loc22: init i32 = call %F.ref.loc22()
|
|
// CHECK:STDOUT: assign %a.var, %.loc22
|
|
// CHECK:STDOUT: %b.var: ref i32 = var b
|
|
// CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
|
|
// CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
|
|
// CHECK:STDOUT: %F.ref.loc23: <function> = name_ref F, @Class.%F [template = @Class.%F]
|
|
// CHECK:STDOUT: %.loc23: init i32 = call %F.ref.loc23()
|
|
// CHECK:STDOUT: assign %b.var, %.loc23
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|