forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle arrow operator (carbon-language#3768)
This change implements the check behavior for the arrow operator. `ptr->Foo()` is rewritten as `(*ptr).Foo()` and `ptr->(X.y)` is rewritten as `(*ptr).(X.y)`
- Loading branch information
1 parent
4421a75
commit d0e8afc
Showing
17 changed files
with
365 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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 | ||
|
||
#include "llvm/ADT/STLFunctionalExtras.h" | ||
#include "toolchain/check/context.h" | ||
#include "toolchain/check/convert.h" | ||
#include "toolchain/parse/node_ids.h" | ||
#include "toolchain/sem_ir/ids.h" | ||
|
||
namespace Carbon::Check { | ||
|
||
auto PerformPointerDereference( | ||
Context& context, Parse::AnyPointerDeferenceExprId node_id, | ||
SemIR::InstId base_id, | ||
llvm::function_ref<auto(SemIR::TypeId not_pointer_type_id)->void> | ||
diagnose_not_pointer) -> SemIR::InstId { | ||
base_id = ConvertToValueExpr(context, base_id); | ||
auto type_id = | ||
context.GetUnqualifiedType(context.insts().Get(base_id).type_id()); | ||
auto result_type_id = SemIR::TypeId::Error; | ||
if (auto pointer_type = | ||
context.types().TryGetAs<SemIR::PointerType>(type_id)) { | ||
result_type_id = pointer_type->pointee_id; | ||
} else if (type_id != SemIR::TypeId::Error) { | ||
diagnose_not_pointer(type_id); | ||
} | ||
return context.AddInst({node_id, SemIR::Deref{result_type_id, base_id}}); | ||
} | ||
|
||
} // namespace Carbon::Check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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 | ||
|
||
#ifndef CARBON_TOOLCHAIN_CHECK_POINTER_DEREFERENCE_H_ | ||
#define CARBON_TOOLCHAIN_CHECK_POINTER_DEREFERENCE_H_ | ||
|
||
#include "llvm/ADT/STLFunctionalExtras.h" | ||
#include "toolchain/check/context.h" | ||
#include "toolchain/parse/node_ids.h" | ||
#include "toolchain/sem_ir/ids.h" | ||
|
||
namespace Carbon::Check { | ||
|
||
// Creates SemIR to perform a pointer dereference with base expression | ||
// `base_id`. Returns the result of the access. | ||
auto PerformPointerDereference( | ||
Context& context, Parse::AnyPointerDeferenceExprId node_id, | ||
SemIR::InstId base_i, | ||
llvm::function_ref<auto(SemIR::TypeId not_pointer_type_id)->void> | ||
diagnose_not_pointer) -> SemIR::InstId; | ||
|
||
} // namespace Carbon::Check | ||
|
||
#endif // CARBON_TOOLCHAIN_CHECK_POINTER_DEREFERENCE_H_ |
Oops, something went wrong.