mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Support for global variables is still missing; they're a bit more tricky because they use a pattern to introduce their name. Prior to this change, explorer heavily relied on name comparisons to determine whether two declarations declare the same entity. Some of those instances are fixed in this PR, but more remain to be fixed, and some TODOs are added for some harder-to-fix instances.
351 lines
8.0 KiB
Plaintext
351 lines
8.0 KiB
Plaintext
compilation_unit {
|
|
package_statement {
|
|
package_name: "ExplorerTest"
|
|
}
|
|
is_api: true
|
|
declarations {
|
|
class_declaration {
|
|
name {
|
|
name: "A"
|
|
}
|
|
members {
|
|
variable {
|
|
binding {
|
|
name: "n"
|
|
type {
|
|
expression_pattern {
|
|
expression {
|
|
int_type_literal {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
declarations {
|
|
impl {
|
|
kind: ExternalImpl
|
|
impl_type {
|
|
identifier {
|
|
name: "A"
|
|
}
|
|
}
|
|
interface {
|
|
where {
|
|
base {
|
|
call {
|
|
function {
|
|
identifier {
|
|
name: "DivWith"
|
|
}
|
|
}
|
|
argument {
|
|
tuple_literal {
|
|
fields {
|
|
int_type_literal {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
clauses {
|
|
rewrite {
|
|
member_name: "Result"
|
|
replacement {
|
|
identifier {
|
|
name: "A"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
members {
|
|
function {
|
|
name {
|
|
name: "Op"
|
|
}
|
|
self_pattern {
|
|
binding_pattern {
|
|
name: "self"
|
|
type {
|
|
expression_pattern {
|
|
expression {
|
|
identifier {
|
|
name: "Self"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
param_pattern {
|
|
fields {
|
|
binding_pattern {
|
|
name: "rhs"
|
|
type {
|
|
expression_pattern {
|
|
expression {
|
|
int_type_literal {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return_term {
|
|
kind: Expression
|
|
type {
|
|
identifier {
|
|
name: "A"
|
|
}
|
|
}
|
|
}
|
|
body {
|
|
statements {
|
|
return_expression_statement {
|
|
expression {
|
|
struct_literal {
|
|
fields {
|
|
name: "n"
|
|
expression {
|
|
operator {
|
|
op: Div
|
|
arguments {
|
|
simple_member_access {
|
|
field: "n"
|
|
object {
|
|
identifier {
|
|
name: "self"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
arguments {
|
|
identifier {
|
|
name: "rhs"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
declarations {
|
|
function {
|
|
name {
|
|
name: "Main"
|
|
}
|
|
param_pattern {
|
|
}
|
|
return_term {
|
|
kind: Expression
|
|
type {
|
|
int_type_literal {
|
|
}
|
|
}
|
|
}
|
|
body {
|
|
statements {
|
|
variable_definition {
|
|
pattern {
|
|
binding_pattern {
|
|
name: "a"
|
|
type {
|
|
expression_pattern {
|
|
expression {
|
|
identifier {
|
|
name: "A"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
init {
|
|
struct_literal {
|
|
fields {
|
|
name: "n"
|
|
expression {
|
|
int_literal {
|
|
value: 19
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
is_returned: false
|
|
}
|
|
}
|
|
statements {
|
|
assign {
|
|
lhs {
|
|
identifier {
|
|
name: "a"
|
|
}
|
|
}
|
|
rhs {
|
|
operator {
|
|
op: Div
|
|
arguments {
|
|
identifier {
|
|
name: "a"
|
|
}
|
|
}
|
|
arguments {
|
|
int_literal {
|
|
value: 3
|
|
}
|
|
}
|
|
}
|
|
}
|
|
op: Plain
|
|
}
|
|
}
|
|
statements {
|
|
expression_statement {
|
|
expression {
|
|
call {
|
|
function {
|
|
identifier {
|
|
name: "Print"
|
|
}
|
|
}
|
|
argument {
|
|
tuple_literal {
|
|
fields {
|
|
string_literal {
|
|
value: "{0}"
|
|
}
|
|
}
|
|
fields {
|
|
simple_member_access {
|
|
field: "n"
|
|
object {
|
|
identifier {
|
|
name: "a"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
statements {
|
|
assign {
|
|
lhs {
|
|
identifier {
|
|
name: "a"
|
|
}
|
|
}
|
|
rhs {
|
|
int_literal {
|
|
value: 2
|
|
}
|
|
}
|
|
op: Div
|
|
}
|
|
}
|
|
statements {
|
|
expression_statement {
|
|
expression {
|
|
call {
|
|
function {
|
|
identifier {
|
|
name: "Print"
|
|
}
|
|
}
|
|
argument {
|
|
tuple_literal {
|
|
fields {
|
|
string_literal {
|
|
value: "{0}"
|
|
}
|
|
}
|
|
fields {
|
|
simple_member_access {
|
|
field: "n"
|
|
object {
|
|
identifier {
|
|
name: "a"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
statements {
|
|
expression_statement {
|
|
expression {
|
|
call {
|
|
function {
|
|
identifier {
|
|
name: "Print"
|
|
}
|
|
}
|
|
argument {
|
|
tuple_literal {
|
|
fields {
|
|
string_literal {
|
|
value: "{0}"
|
|
}
|
|
}
|
|
fields {
|
|
simple_member_access {
|
|
field: "n"
|
|
object {
|
|
operator {
|
|
op: Div
|
|
arguments {
|
|
identifier {
|
|
name: "a"
|
|
}
|
|
}
|
|
arguments {
|
|
int_literal {
|
|
value: 2
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
statements {
|
|
return_expression_statement {
|
|
expression {
|
|
int_literal {
|
|
value: 0
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|