mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 15:40:11 +01:00
Semantic handling for use of `T*` and `const T` as types.
There's no way to form values of these types yet, and no conversions for
them are supported.
Factor out the common code to canonicalize types using a folding set,
and switch to using the same folding set for all kinds of type by adding
the kind as part of the folding set key.
Improve type printing to not include the `as type` portion when the type
is printed in a context within another type where a conversion to `type`
is implied, as in `{}*` and pre-existing cases like `({}, {}) as type`
(which we used to print as `({} as type, {} as type}) as type`.
69 lines
2.1 KiB
Plaintext
69 lines
2.1 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
|
|
// CHECK:STDOUT: cross_reference_irs_size: 1
|
|
// CHECK:STDOUT: functions: [
|
|
// CHECK:STDOUT: {name: str0, param_refs: block0, return_type: type0, body: {block2}}},
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: integer_literals: [
|
|
// CHECK:STDOUT: 0,
|
|
// CHECK:STDOUT: 0,
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: real_literals: [
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: strings: [
|
|
// CHECK:STDOUT: F,
|
|
// CHECK:STDOUT: n,
|
|
// CHECK:STDOUT: p,
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: types: [
|
|
// CHECK:STDOUT: nodeIntegerType,
|
|
// CHECK:STDOUT: node+5,
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: type_blocks: [
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: nodes: [
|
|
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
|
|
// CHECK:STDOUT: {kind: VarStorage, type: type0},
|
|
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+1, type: type0},
|
|
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type0},
|
|
// CHECK:STDOUT: {kind: Assign, arg0: node+1, arg1: node+3},
|
|
// CHECK:STDOUT: {kind: PointerType, arg0: type0, type: typeTypeType},
|
|
// CHECK:STDOUT: {kind: VarStorage, type: type1},
|
|
// CHECK:STDOUT: {kind: BindName, arg0: str2, arg1: node+6, type: type1},
|
|
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type0},
|
|
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+8},
|
|
// CHECK:STDOUT: ]
|
|
// CHECK:STDOUT: node_blocks: [
|
|
// CHECK:STDOUT: [
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: [
|
|
// CHECK:STDOUT: node+0,
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: [
|
|
// CHECK:STDOUT: node+1,
|
|
// CHECK:STDOUT: node+2,
|
|
// CHECK:STDOUT: node+3,
|
|
// CHECK:STDOUT: node+4,
|
|
// CHECK:STDOUT: node+5,
|
|
// CHECK:STDOUT: node+6,
|
|
// CHECK:STDOUT: node+7,
|
|
// CHECK:STDOUT: node+8,
|
|
// CHECK:STDOUT: node+9,
|
|
// CHECK:STDOUT: ],
|
|
// CHECK:STDOUT: ]
|
|
|
|
fn F() -> i32 {
|
|
var n: i32 = 0;
|
|
var p: i32*;
|
|
|
|
// TODO: Test taking address and dereference.
|
|
// p = &n;
|
|
// *p = 1;
|
|
// return *p;
|
|
|
|
return 0;
|
|
}
|