mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:21:21 +01:00
Rename Ptr<T> to Nonnull<T*> (#832)
Note that ptr.h also includes an enable_if change, to help avoid https://bugs.llvm.org/show_bug.cgi?id=51881
This commit is contained in:
@@ -58,60 +58,60 @@ class Statement {
|
||||
|
||||
class ExpressionStatement : public Statement {
|
||||
public:
|
||||
ExpressionStatement(SourceLocation loc, Ptr<const Expression> exp)
|
||||
ExpressionStatement(SourceLocation loc, Nonnull<const Expression*> exp)
|
||||
: Statement(Kind::ExpressionStatement, loc), exp(exp) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::ExpressionStatement;
|
||||
}
|
||||
|
||||
auto Exp() const -> Ptr<const Expression> { return exp; }
|
||||
auto Exp() const -> Nonnull<const Expression*> { return exp; }
|
||||
|
||||
private:
|
||||
Ptr<const Expression> exp;
|
||||
Nonnull<const Expression*> exp;
|
||||
};
|
||||
|
||||
class Assign : public Statement {
|
||||
public:
|
||||
Assign(SourceLocation loc, Ptr<const Expression> lhs,
|
||||
Ptr<const Expression> rhs)
|
||||
Assign(SourceLocation loc, Nonnull<const Expression*> lhs,
|
||||
Nonnull<const Expression*> rhs)
|
||||
: Statement(Kind::Assign, loc), lhs(lhs), rhs(rhs) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::Assign;
|
||||
}
|
||||
|
||||
auto Lhs() const -> Ptr<const Expression> { return lhs; }
|
||||
auto Rhs() const -> Ptr<const Expression> { return rhs; }
|
||||
auto Lhs() const -> Nonnull<const Expression*> { return lhs; }
|
||||
auto Rhs() const -> Nonnull<const Expression*> { return rhs; }
|
||||
|
||||
private:
|
||||
Ptr<const Expression> lhs;
|
||||
Ptr<const Expression> rhs;
|
||||
Nonnull<const Expression*> lhs;
|
||||
Nonnull<const Expression*> rhs;
|
||||
};
|
||||
|
||||
class VariableDefinition : public Statement {
|
||||
public:
|
||||
VariableDefinition(SourceLocation loc, Ptr<const Pattern> pat,
|
||||
Ptr<const Expression> init)
|
||||
VariableDefinition(SourceLocation loc, Nonnull<const Pattern*> pat,
|
||||
Nonnull<const Expression*> init)
|
||||
: Statement(Kind::VariableDefinition, loc), pat(pat), init(init) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::VariableDefinition;
|
||||
}
|
||||
|
||||
auto Pat() const -> Ptr<const Pattern> { return pat; }
|
||||
auto Init() const -> Ptr<const Expression> { return init; }
|
||||
auto Pat() const -> Nonnull<const Pattern*> { return pat; }
|
||||
auto Init() const -> Nonnull<const Expression*> { return init; }
|
||||
|
||||
private:
|
||||
Ptr<const Pattern> pat;
|
||||
Ptr<const Expression> init;
|
||||
Nonnull<const Pattern*> pat;
|
||||
Nonnull<const Expression*> init;
|
||||
};
|
||||
|
||||
class If : public Statement {
|
||||
public:
|
||||
If(SourceLocation loc, Ptr<const Expression> cond,
|
||||
Ptr<const Statement> then_stmt,
|
||||
std::optional<Ptr<const Statement>> else_stmt)
|
||||
If(SourceLocation loc, Nonnull<const Expression*> cond,
|
||||
Nonnull<const Statement*> then_stmt,
|
||||
std::optional<Nonnull<const Statement*>> else_stmt)
|
||||
: Statement(Kind::If, loc),
|
||||
cond(cond),
|
||||
then_stmt(then_stmt),
|
||||
@@ -121,23 +121,24 @@ class If : public Statement {
|
||||
return stmt->Tag() == Kind::If;
|
||||
}
|
||||
|
||||
auto Cond() const -> Ptr<const Expression> { return cond; }
|
||||
auto ThenStmt() const -> Ptr<const Statement> { return then_stmt; }
|
||||
auto ElseStmt() const -> std::optional<Ptr<const Statement>> {
|
||||
auto Cond() const -> Nonnull<const Expression*> { return cond; }
|
||||
auto ThenStmt() const -> Nonnull<const Statement*> { return then_stmt; }
|
||||
auto ElseStmt() const -> std::optional<Nonnull<const Statement*>> {
|
||||
return else_stmt;
|
||||
}
|
||||
|
||||
private:
|
||||
Ptr<const Expression> cond;
|
||||
Ptr<const Statement> then_stmt;
|
||||
std::optional<Ptr<const Statement>> else_stmt;
|
||||
Nonnull<const Expression*> cond;
|
||||
Nonnull<const Statement*> then_stmt;
|
||||
std::optional<Nonnull<const Statement*>> else_stmt;
|
||||
};
|
||||
|
||||
class Return : public Statement {
|
||||
public:
|
||||
Return(Ptr<Arena> arena, SourceLocation loc)
|
||||
Return(Nonnull<Arena*> arena, SourceLocation loc)
|
||||
: Return(loc, arena->New<TupleLiteral>(loc), true) {}
|
||||
Return(SourceLocation loc, Ptr<const Expression> exp, bool is_omitted_exp)
|
||||
Return(SourceLocation loc, Nonnull<const Expression*> exp,
|
||||
bool is_omitted_exp)
|
||||
: Statement(Kind::Return, loc),
|
||||
exp(exp),
|
||||
is_omitted_exp(is_omitted_exp) {}
|
||||
@@ -146,63 +147,63 @@ class Return : public Statement {
|
||||
return stmt->Tag() == Kind::Return;
|
||||
}
|
||||
|
||||
auto Exp() const -> Ptr<const Expression> { return exp; }
|
||||
auto Exp() const -> Nonnull<const Expression*> { return exp; }
|
||||
auto IsOmittedExp() const -> bool { return is_omitted_exp; }
|
||||
|
||||
private:
|
||||
Ptr<const Expression> exp;
|
||||
Nonnull<const Expression*> exp;
|
||||
bool is_omitted_exp;
|
||||
};
|
||||
|
||||
class Sequence : public Statement {
|
||||
public:
|
||||
Sequence(SourceLocation loc, Ptr<const Statement> stmt,
|
||||
std::optional<Ptr<const Statement>> next)
|
||||
Sequence(SourceLocation loc, Nonnull<const Statement*> stmt,
|
||||
std::optional<Nonnull<const Statement*>> next)
|
||||
: Statement(Kind::Sequence, loc), stmt(stmt), next(next) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::Sequence;
|
||||
}
|
||||
|
||||
auto Stmt() const -> Ptr<const Statement> { return stmt; }
|
||||
auto Next() const -> std::optional<Ptr<const Statement>> { return next; }
|
||||
auto Stmt() const -> Nonnull<const Statement*> { return stmt; }
|
||||
auto Next() const -> std::optional<Nonnull<const Statement*>> { return next; }
|
||||
|
||||
private:
|
||||
Ptr<const Statement> stmt;
|
||||
std::optional<Ptr<const Statement>> next;
|
||||
Nonnull<const Statement*> stmt;
|
||||
std::optional<Nonnull<const Statement*>> next;
|
||||
};
|
||||
|
||||
class Block : public Statement {
|
||||
public:
|
||||
Block(SourceLocation loc, std::optional<Ptr<const Statement>> stmt)
|
||||
Block(SourceLocation loc, std::optional<Nonnull<const Statement*>> stmt)
|
||||
: Statement(Kind::Block, loc), stmt(stmt) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::Block;
|
||||
}
|
||||
|
||||
auto Stmt() const -> std::optional<Ptr<const Statement>> { return stmt; }
|
||||
auto Stmt() const -> std::optional<Nonnull<const Statement*>> { return stmt; }
|
||||
|
||||
private:
|
||||
std::optional<Ptr<const Statement>> stmt;
|
||||
std::optional<Nonnull<const Statement*>> stmt;
|
||||
};
|
||||
|
||||
class While : public Statement {
|
||||
public:
|
||||
While(SourceLocation loc, Ptr<const Expression> cond,
|
||||
Ptr<const Statement> body)
|
||||
While(SourceLocation loc, Nonnull<const Expression*> cond,
|
||||
Nonnull<const Statement*> body)
|
||||
: Statement(Kind::While, loc), cond(cond), body(body) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::While;
|
||||
}
|
||||
|
||||
auto Cond() const -> Ptr<const Expression> { return cond; }
|
||||
auto Body() const -> Ptr<const Statement> { return body; }
|
||||
auto Cond() const -> Nonnull<const Expression*> { return cond; }
|
||||
auto Body() const -> Nonnull<const Statement*> { return body; }
|
||||
|
||||
private:
|
||||
Ptr<const Expression> cond;
|
||||
Ptr<const Statement> body;
|
||||
Nonnull<const Expression*> cond;
|
||||
Nonnull<const Statement*> body;
|
||||
};
|
||||
|
||||
class Break : public Statement {
|
||||
@@ -226,23 +227,25 @@ class Continue : public Statement {
|
||||
class Match : public Statement {
|
||||
public:
|
||||
Match(
|
||||
SourceLocation loc, Ptr<const Expression> exp,
|
||||
std::vector<std::pair<Ptr<const Pattern>, Ptr<const Statement>>> clauses)
|
||||
SourceLocation loc, Nonnull<const Expression*> exp,
|
||||
std::vector<std::pair<Nonnull<const Pattern*>, Nonnull<const Statement*>>>
|
||||
clauses)
|
||||
: Statement(Kind::Match, loc), exp(exp), clauses(std::move(clauses)) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::Match;
|
||||
}
|
||||
|
||||
auto Exp() const -> Ptr<const Expression> { return exp; }
|
||||
auto Clauses() const -> const
|
||||
std::vector<std::pair<Ptr<const Pattern>, Ptr<const Statement>>>& {
|
||||
auto Exp() const -> Nonnull<const Expression*> { return exp; }
|
||||
auto Clauses() const -> const std::vector<
|
||||
std::pair<Nonnull<const Pattern*>, Nonnull<const Statement*>>>& {
|
||||
return clauses;
|
||||
}
|
||||
|
||||
private:
|
||||
Ptr<const Expression> exp;
|
||||
std::vector<std::pair<Ptr<const Pattern>, Ptr<const Statement>>> clauses;
|
||||
Nonnull<const Expression*> exp;
|
||||
std::vector<std::pair<Nonnull<const Pattern*>, Nonnull<const Statement*>>>
|
||||
clauses;
|
||||
};
|
||||
|
||||
// A continuation statement.
|
||||
@@ -253,7 +256,7 @@ class Match : public Statement {
|
||||
class Continuation : public Statement {
|
||||
public:
|
||||
Continuation(SourceLocation loc, std::string continuation_variable,
|
||||
Ptr<const Statement> body)
|
||||
Nonnull<const Statement*> body)
|
||||
: Statement(Kind::Continuation, loc),
|
||||
continuation_variable(std::move(continuation_variable)),
|
||||
body(body) {}
|
||||
@@ -265,11 +268,11 @@ class Continuation : public Statement {
|
||||
auto ContinuationVariable() const -> const std::string& {
|
||||
return continuation_variable;
|
||||
}
|
||||
auto Body() const -> Ptr<const Statement> { return body; }
|
||||
auto Body() const -> Nonnull<const Statement*> { return body; }
|
||||
|
||||
private:
|
||||
std::string continuation_variable;
|
||||
Ptr<const Statement> body;
|
||||
Nonnull<const Statement*> body;
|
||||
};
|
||||
|
||||
// A run statement.
|
||||
@@ -277,17 +280,17 @@ class Continuation : public Statement {
|
||||
// __run <argument>;
|
||||
class Run : public Statement {
|
||||
public:
|
||||
Run(SourceLocation loc, Ptr<const Expression> argument)
|
||||
Run(SourceLocation loc, Nonnull<const Expression*> argument)
|
||||
: Statement(Kind::Run, loc), argument(argument) {}
|
||||
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->Tag() == Kind::Run;
|
||||
}
|
||||
|
||||
auto Argument() const -> Ptr<const Expression> { return argument; }
|
||||
auto Argument() const -> Nonnull<const Expression*> { return argument; }
|
||||
|
||||
private:
|
||||
Ptr<const Expression> argument;
|
||||
Nonnull<const Expression*> argument;
|
||||
};
|
||||
|
||||
// An await statement.
|
||||
|
||||
Reference in New Issue
Block a user