mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 06:41:04 +01:00
Add Ptr and RawNew for migration (#751)
Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
committed by
GitHub
co-authored by
Geoff Romer
parent
1eeaa208f2
commit
c6ebe0db67
@@ -30,7 +30,7 @@ auto ExpressionFromParenContents(
|
||||
auto TupleExpressionFromParenContents(
|
||||
int line_num, const ParenContents<Expression>& paren_contents)
|
||||
-> const Expression* {
|
||||
return global_arena->New<TupleLiteral>(
|
||||
return global_arena->RawNew<TupleLiteral>(
|
||||
line_num, paren_contents.TupleElements<FieldInitializer>(line_num));
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,8 @@ TEST(ExpressionTest, UnaryNoCommaAsExpression) {
|
||||
// ```
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
const Expression* expression =
|
||||
@@ -67,7 +68,8 @@ TEST(ExpressionTest, UnaryNoCommaAsExpression) {
|
||||
TEST(ExpressionTest, UnaryNoCommaAsTuple) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
const Expression* tuple =
|
||||
@@ -81,7 +83,8 @@ TEST(ExpressionTest, UnaryNoCommaAsTuple) {
|
||||
TEST(ExpressionTest, UnaryWithCommaAsExpression) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const Expression* expression =
|
||||
@@ -95,7 +98,8 @@ TEST(ExpressionTest, UnaryWithCommaAsExpression) {
|
||||
TEST(ExpressionTest, UnaryWithCommaAsTuple) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/2, 42)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const Expression* tuple =
|
||||
@@ -109,9 +113,11 @@ TEST(ExpressionTest, UnaryWithCommaAsTuple) {
|
||||
TEST(ExpressionTest, BinaryAsExpression) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/2, 42)},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/2, 42)},
|
||||
{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/3, 42)}},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/3, 42)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const Expression* expression =
|
||||
@@ -125,9 +131,11 @@ TEST(ExpressionTest, BinaryAsExpression) {
|
||||
TEST(ExpressionTest, BinaryAsTuple) {
|
||||
ParenContents<Expression> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/2, 42)},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/2, 42)},
|
||||
{.name = std::nullopt,
|
||||
.term = global_arena->New<IntLiteral>(/*line_num=*/3, 42)}},
|
||||
.term =
|
||||
global_arena->RawNew<IntLiteral>(/*line_num=*/3, 42)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const Expression* tuple =
|
||||
|
||||
@@ -59,7 +59,7 @@ TuplePattern::TuplePattern(const Expression* tuple_literal)
|
||||
const auto& tuple = cast<TupleLiteral>(*tuple_literal);
|
||||
for (const FieldInitializer& init : tuple.Fields()) {
|
||||
fields.push_back(Field(
|
||||
init.name, global_arena->New<ExpressionPattern>(init.expression)));
|
||||
init.name, global_arena->RawNew<ExpressionPattern>(init.expression)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ auto PatternFromParenContents(int line_num,
|
||||
auto TuplePatternFromParenContents(int line_num,
|
||||
const ParenContents<Pattern>& paren_contents)
|
||||
-> const TuplePattern* {
|
||||
return global_arena->New<TuplePattern>(
|
||||
return global_arena->RawNew<TuplePattern>(
|
||||
line_num, paren_contents.TupleElements<TuplePattern::Field>(line_num));
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ auto ParenExpressionToParenPattern(const ParenContents<Expression>& contents)
|
||||
for (const auto& element : contents.elements) {
|
||||
result.elements.push_back(
|
||||
{.name = element.name,
|
||||
.term = global_arena->New<ExpressionPattern>(element.term)});
|
||||
.term = global_arena->RawNew<ExpressionPattern>(element.term)});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ TEST(PatternTest, UnaryNoCommaAsPattern) {
|
||||
// ```
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/2)}},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/2)}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
const Pattern* pattern = PatternFromParenContents(/*line_num=*/1, contents);
|
||||
@@ -63,7 +63,7 @@ TEST(PatternTest, UnaryNoCommaAsPattern) {
|
||||
TEST(PatternTest, UnaryNoCommaAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/2)}},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/2)}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
const TuplePattern* tuple =
|
||||
@@ -75,7 +75,7 @@ TEST(PatternTest, UnaryNoCommaAsTuplePattern) {
|
||||
TEST(PatternTest, UnaryWithCommaAsPattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/2)}},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/2)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const Pattern* pattern = PatternFromParenContents(/*line_num=*/1, contents);
|
||||
@@ -88,7 +88,7 @@ TEST(PatternTest, UnaryWithCommaAsPattern) {
|
||||
TEST(PatternTest, UnaryWithCommaAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/2)}},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/2)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const TuplePattern* tuple =
|
||||
@@ -100,9 +100,9 @@ TEST(PatternTest, UnaryWithCommaAsTuplePattern) {
|
||||
TEST(PatternTest, BinaryAsPattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/2)},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/2)},
|
||||
{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/3)}},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/3)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const Pattern* pattern = PatternFromParenContents(/*line_num=*/1, contents);
|
||||
@@ -115,9 +115,9 @@ TEST(PatternTest, BinaryAsPattern) {
|
||||
TEST(PatternTest, BinaryAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/2)},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/2)},
|
||||
{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(/*line_num=*/3)}},
|
||||
.term = global_arena->RawNew<AutoPattern>(/*line_num=*/3)}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
const TuplePattern* tuple =
|
||||
|
||||
@@ -132,7 +132,7 @@ void Statement::PrintDepth(int depth, llvm::raw_ostream& out) const {
|
||||
|
||||
Return::Return(int line_num, const Expression* exp, bool is_omitted_exp)
|
||||
: Statement(Kind::Return, line_num),
|
||||
exp(exp != nullptr ? exp : global_arena->New<TupleLiteral>(line_num)),
|
||||
exp(exp != nullptr ? exp : global_arena->RawNew<TupleLiteral>(line_num)),
|
||||
is_omitted_exp(is_omitted_exp) {
|
||||
CHECK(exp != nullptr || is_omitted_exp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user