mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:21:16 +01:00
change all expression and statement pointers to be const (#449)
* change all expression and statement pointers to be const * const in paren tests
This commit is contained in:
@@ -127,10 +127,11 @@ struct StructDeclaration {
|
||||
struct ChoiceDeclaration {
|
||||
int line_num;
|
||||
std::string name;
|
||||
std::list<std::pair<std::string, Expression*>> alternatives;
|
||||
std::list<std::pair<std::string, const Expression*>> alternatives;
|
||||
|
||||
ChoiceDeclaration(int line_num, std::string name,
|
||||
std::list<std::pair<std::string, Expression*>> alternatives)
|
||||
ChoiceDeclaration(
|
||||
int line_num, std::string name,
|
||||
std::list<std::pair<std::string, const Expression*>> alternatives)
|
||||
: line_num(line_num), name(name), alternatives(alternatives) {}
|
||||
|
||||
void Print() const;
|
||||
@@ -143,8 +144,8 @@ struct ChoiceDeclaration {
|
||||
// Global variable definition implements the Declaration concept.
|
||||
class VariableDeclaration {
|
||||
public:
|
||||
VariableDeclaration(int source_location, std::string name, Expression* type,
|
||||
Expression* initializer)
|
||||
VariableDeclaration(int source_location, std::string name,
|
||||
const Expression* type, const Expression* initializer)
|
||||
: source_location(source_location),
|
||||
name(name),
|
||||
type(type),
|
||||
@@ -159,8 +160,8 @@ class VariableDeclaration {
|
||||
private:
|
||||
int source_location;
|
||||
std::string name;
|
||||
Expression* type;
|
||||
Expression* initializer;
|
||||
const Expression* type;
|
||||
const Expression* initializer;
|
||||
};
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
@@ -8,28 +8,28 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeTypeType(int line_num) -> Expression* {
|
||||
auto MakeTypeType(int line_num) -> const Expression* {
|
||||
auto* t = new Expression();
|
||||
t->tag = ExpressionKind::TypeT;
|
||||
t->line_num = line_num;
|
||||
return t;
|
||||
}
|
||||
|
||||
auto MakeIntType(int line_num) -> Expression* {
|
||||
auto MakeIntType(int line_num) -> const Expression* {
|
||||
auto* t = new Expression();
|
||||
t->tag = ExpressionKind::IntT;
|
||||
t->line_num = line_num;
|
||||
return t;
|
||||
}
|
||||
|
||||
auto MakeBoolType(int line_num) -> Expression* {
|
||||
auto MakeBoolType(int line_num) -> const Expression* {
|
||||
auto* t = new Expression();
|
||||
t->tag = ExpressionKind::BoolT;
|
||||
t->line_num = line_num;
|
||||
return t;
|
||||
}
|
||||
|
||||
auto MakeAutoType(int line_num) -> Expression* {
|
||||
auto MakeAutoType(int line_num) -> const Expression* {
|
||||
auto* t = new Expression();
|
||||
t->tag = ExpressionKind::AutoT;
|
||||
t->line_num = line_num;
|
||||
@@ -37,15 +37,15 @@ auto MakeAutoType(int line_num) -> Expression* {
|
||||
}
|
||||
|
||||
// Returns a Continuation type AST node at the given source location.
|
||||
auto MakeContinuationType(int line_num) -> Expression* {
|
||||
auto MakeContinuationType(int line_num) -> const Expression* {
|
||||
auto* type = new Expression();
|
||||
type->tag = ExpressionKind::ContinuationT;
|
||||
type->line_num = line_num;
|
||||
return type;
|
||||
}
|
||||
|
||||
auto MakeFunType(int line_num, Expression* param, Expression* ret)
|
||||
-> Expression* {
|
||||
auto MakeFunType(int line_num, const Expression* param, const Expression* ret)
|
||||
-> const Expression* {
|
||||
auto* t = new Expression();
|
||||
t->tag = ExpressionKind::FunctionT;
|
||||
t->line_num = line_num;
|
||||
@@ -54,7 +54,7 @@ auto MakeFunType(int line_num, Expression* param, Expression* ret)
|
||||
return t;
|
||||
}
|
||||
|
||||
auto MakeVar(int line_num, std::string var) -> Expression* {
|
||||
auto MakeVar(int line_num, std::string var) -> const Expression* {
|
||||
auto* v = new Expression();
|
||||
v->line_num = line_num;
|
||||
v->tag = ExpressionKind::Variable;
|
||||
@@ -62,8 +62,8 @@ auto MakeVar(int line_num, std::string var) -> Expression* {
|
||||
return v;
|
||||
}
|
||||
|
||||
auto MakeVarPat(int line_num, std::string var, Expression* type)
|
||||
-> Expression* {
|
||||
auto MakeVarPat(int line_num, std::string var, const Expression* type)
|
||||
-> const Expression* {
|
||||
auto* v = new Expression();
|
||||
v->line_num = line_num;
|
||||
v->tag = ExpressionKind::PatternVariable;
|
||||
@@ -72,7 +72,7 @@ auto MakeVarPat(int line_num, std::string var, Expression* type)
|
||||
return v;
|
||||
}
|
||||
|
||||
auto MakeInt(int line_num, int i) -> Expression* {
|
||||
auto MakeInt(int line_num, int i) -> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::Integer;
|
||||
@@ -80,7 +80,7 @@ auto MakeInt(int line_num, int i) -> Expression* {
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeBool(int line_num, bool b) -> Expression* {
|
||||
auto MakeBool(int line_num, bool b) -> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::Boolean;
|
||||
@@ -88,8 +88,8 @@ auto MakeBool(int line_num, bool b) -> Expression* {
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeOp(int line_num, enum Operator op, std::vector<Expression*>* args)
|
||||
-> Expression* {
|
||||
auto MakeOp(int line_num, enum Operator op,
|
||||
std::vector<const Expression*>* args) -> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::PrimitiveOp;
|
||||
@@ -98,31 +98,33 @@ auto MakeOp(int line_num, enum Operator op, std::vector<Expression*>* args)
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeUnOp(int line_num, enum Operator op, Expression* arg) -> Expression* {
|
||||
auto MakeUnOp(int line_num, enum Operator op, const Expression* arg)
|
||||
-> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::PrimitiveOp;
|
||||
e->u.primitive_op.op = op;
|
||||
auto* args = new std::vector<Expression*>();
|
||||
auto* args = new std::vector<const Expression*>();
|
||||
args->push_back(arg);
|
||||
e->u.primitive_op.arguments = args;
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeBinOp(int line_num, enum Operator op, Expression* arg1,
|
||||
Expression* arg2) -> Expression* {
|
||||
auto MakeBinOp(int line_num, enum Operator op, const Expression* arg1,
|
||||
const Expression* arg2) -> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::PrimitiveOp;
|
||||
e->u.primitive_op.op = op;
|
||||
auto* args = new std::vector<Expression*>();
|
||||
auto* args = new std::vector<const Expression*>();
|
||||
args->push_back(arg1);
|
||||
args->push_back(arg2);
|
||||
e->u.primitive_op.arguments = args;
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeCall(int line_num, Expression* fun, Expression* arg) -> Expression* {
|
||||
auto MakeCall(int line_num, const Expression* fun, const Expression* arg)
|
||||
-> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::Call;
|
||||
@@ -131,8 +133,8 @@ auto MakeCall(int line_num, Expression* fun, Expression* arg) -> Expression* {
|
||||
return e;
|
||||
}
|
||||
|
||||
auto MakeGetField(int line_num, Expression* exp, std::string field)
|
||||
-> Expression* {
|
||||
auto MakeGetField(int line_num, const Expression* exp, std::string field)
|
||||
-> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::GetField;
|
||||
@@ -142,8 +144,8 @@ auto MakeGetField(int line_num, Expression* exp, std::string field)
|
||||
}
|
||||
|
||||
auto MakeTuple(int line_num,
|
||||
std::vector<std::pair<std::string, Expression*>>* args)
|
||||
-> Expression* {
|
||||
std::vector<std::pair<std::string, const Expression*>>* args)
|
||||
-> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::Tuple;
|
||||
@@ -161,16 +163,17 @@ auto MakeTuple(int line_num,
|
||||
// Create an AST node for an empty tuple.
|
||||
// TODO(geoffromer): remove this and rewrite its callers to use
|
||||
// `MakeTuple(line_num, {})`, once that works.
|
||||
auto MakeUnit(int line_num) -> Expression* {
|
||||
auto MakeUnit(int line_num) -> const Expression* {
|
||||
auto* unit = new Expression();
|
||||
unit->line_num = line_num;
|
||||
unit->tag = ExpressionKind::Tuple;
|
||||
auto* args = new std::vector<std::pair<std::string, Expression*>>();
|
||||
auto* args = new std::vector<std::pair<std::string, const Expression*>>();
|
||||
unit->u.tuple.fields = args;
|
||||
return unit;
|
||||
}
|
||||
|
||||
auto MakeIndex(int line_num, Expression* exp, Expression* i) -> Expression* {
|
||||
auto MakeIndex(int line_num, const Expression* exp, const Expression* i)
|
||||
-> const Expression* {
|
||||
auto* e = new Expression();
|
||||
e->line_num = line_num;
|
||||
e->tag = ExpressionKind::Index;
|
||||
@@ -206,7 +209,7 @@ static void PrintOp(Operator op) {
|
||||
}
|
||||
|
||||
static void PrintFields(
|
||||
std::vector<std::pair<std::string, Expression*>>* fields) {
|
||||
std::vector<std::pair<std::string, const Expression*>>* fields) {
|
||||
int i = 0;
|
||||
for (auto iter = fields->begin(); iter != fields->end(); ++iter, ++i) {
|
||||
if (i != 0) {
|
||||
|
||||
@@ -47,73 +47,77 @@ struct Expression {
|
||||
} variable;
|
||||
|
||||
struct {
|
||||
Expression* aggregate;
|
||||
const Expression* aggregate;
|
||||
std::string* field;
|
||||
} get_field;
|
||||
|
||||
struct {
|
||||
Expression* aggregate;
|
||||
Expression* offset;
|
||||
const Expression* aggregate;
|
||||
const Expression* offset;
|
||||
} index;
|
||||
|
||||
struct {
|
||||
std::string* name;
|
||||
Expression* type;
|
||||
const Expression* type;
|
||||
} pattern_variable;
|
||||
|
||||
int integer;
|
||||
bool boolean;
|
||||
|
||||
struct {
|
||||
std::vector<std::pair<std::string, Expression*>>* fields;
|
||||
std::vector<std::pair<std::string, const Expression*>>* fields;
|
||||
} tuple;
|
||||
|
||||
struct {
|
||||
Operator op;
|
||||
std::vector<Expression*>* arguments;
|
||||
std::vector<const Expression*>* arguments;
|
||||
} primitive_op;
|
||||
|
||||
struct {
|
||||
Expression* function;
|
||||
Expression* argument;
|
||||
const Expression* function;
|
||||
const Expression* argument;
|
||||
} call;
|
||||
|
||||
struct {
|
||||
Expression* parameter;
|
||||
Expression* return_type;
|
||||
const Expression* parameter;
|
||||
const Expression* return_type;
|
||||
} function_type;
|
||||
|
||||
} u;
|
||||
};
|
||||
|
||||
auto MakeVar(int line_num, std::string var) -> Expression*;
|
||||
auto MakeVarPat(int line_num, std::string var, Expression* type) -> Expression*;
|
||||
auto MakeInt(int line_num, int i) -> Expression*;
|
||||
auto MakeBool(int line_num, bool b) -> Expression*;
|
||||
auto MakeOp(int line_num, Operator op, std::vector<Expression*>* args)
|
||||
-> Expression*;
|
||||
auto MakeUnOp(int line_num, enum Operator op, Expression* arg) -> Expression*;
|
||||
auto MakeBinOp(int line_num, enum Operator op, Expression* arg1,
|
||||
Expression* arg2) -> Expression*;
|
||||
auto MakeCall(int line_num, Expression* fun, Expression* arg) -> Expression*;
|
||||
auto MakeGetField(int line_num, Expression* exp, std::string field)
|
||||
-> Expression*;
|
||||
auto MakeVar(int line_num, std::string var) -> const Expression*;
|
||||
auto MakeVarPat(int line_num, std::string var, const Expression* type)
|
||||
-> const Expression*;
|
||||
auto MakeInt(int line_num, int i) -> const Expression*;
|
||||
auto MakeBool(int line_num, bool b) -> const Expression*;
|
||||
auto MakeOp(int line_num, Operator op, std::vector<const Expression*>* args)
|
||||
-> const Expression*;
|
||||
auto MakeUnOp(int line_num, enum Operator op, const Expression* arg)
|
||||
-> const Expression*;
|
||||
auto MakeBinOp(int line_num, enum Operator op, const Expression* arg1,
|
||||
const Expression* arg2) -> const Expression*;
|
||||
auto MakeCall(int line_num, const Expression* fun, const Expression* arg)
|
||||
-> const Expression*;
|
||||
auto MakeGetField(int line_num, const Expression* exp, std::string field)
|
||||
-> const Expression*;
|
||||
auto MakeTuple(int line_num,
|
||||
std::vector<std::pair<std::string, Expression*>>* args)
|
||||
-> Expression*;
|
||||
std::vector<std::pair<std::string, const Expression*>>* args)
|
||||
-> const Expression*;
|
||||
// Create an AST node for an empty tuple.
|
||||
auto MakeUnit(int line_num) -> Expression*;
|
||||
auto MakeIndex(int line_num, Expression* exp, Expression* i) -> Expression*;
|
||||
auto MakeUnit(int line_num) -> const Expression*;
|
||||
auto MakeIndex(int line_num, const Expression* exp, const Expression* i)
|
||||
-> const Expression*;
|
||||
|
||||
auto MakeTypeType(int line_num) -> Expression*;
|
||||
auto MakeIntType(int line_num) -> Expression*;
|
||||
auto MakeBoolType(int line_num) -> Expression*;
|
||||
auto MakeFunType(int line_num, Expression* param, Expression* ret)
|
||||
-> Expression*;
|
||||
auto MakeAutoType(int line_num) -> Expression*;
|
||||
auto MakeTypeType(int line_num) -> const Expression*;
|
||||
auto MakeIntType(int line_num) -> const Expression*;
|
||||
auto MakeBoolType(int line_num) -> const Expression*;
|
||||
auto MakeFunType(int line_num, const Expression* param, const Expression* ret)
|
||||
-> const Expression*;
|
||||
auto MakeAutoType(int line_num) -> const Expression*;
|
||||
// Returns a Continuation type AST node at the given source location,
|
||||
// which is the type of a continuation value.
|
||||
auto MakeContinuationType(int line_num) -> Expression*;
|
||||
auto MakeContinuationType(int line_num) -> const Expression*;
|
||||
|
||||
void PrintExp(const Expression* exp);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeFunDef(int line_num, std::string name, Expression* ret_type,
|
||||
Expression* param_pattern, Statement* body)
|
||||
auto MakeFunDef(int line_num, std::string name, const Expression* ret_type,
|
||||
const Expression* param_pattern, const Statement* body)
|
||||
-> struct FunctionDefinition* {
|
||||
auto* f = new struct FunctionDefinition();
|
||||
f->line_num = line_num;
|
||||
|
||||
@@ -13,13 +13,14 @@ namespace Carbon {
|
||||
struct FunctionDefinition {
|
||||
int line_num;
|
||||
std::string name;
|
||||
Expression* param_pattern;
|
||||
Expression* return_type;
|
||||
Statement* body;
|
||||
const Expression* param_pattern;
|
||||
const Expression* return_type;
|
||||
const Statement* body;
|
||||
};
|
||||
|
||||
auto MakeFunDef(int line_num, std::string name, Expression* ret_type,
|
||||
Expression* param, Statement* body) -> FunctionDefinition*;
|
||||
auto MakeFunDef(int line_num, std::string name, const Expression* ret_type,
|
||||
const Expression* param, const Statement* body)
|
||||
-> FunctionDefinition*;
|
||||
void PrintFunDef(const FunctionDefinition*);
|
||||
void PrintFunDefDepth(const FunctionDefinition*, int);
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeField(int line_num, std::string name, Expression* type) -> Member* {
|
||||
auto MakeField(int line_num, std::string name, const Expression* type)
|
||||
-> Member* {
|
||||
auto m = new Member();
|
||||
m->line_num = line_num;
|
||||
m->tag = MemberKind::FieldMember;
|
||||
|
||||
@@ -19,12 +19,13 @@ struct Member {
|
||||
union {
|
||||
struct {
|
||||
std::string* name;
|
||||
Expression* type;
|
||||
const Expression* type;
|
||||
} field;
|
||||
} u;
|
||||
};
|
||||
|
||||
auto MakeField(int line_num, std::string name, Expression* type) -> Member*;
|
||||
auto MakeField(int line_num, std::string name, const Expression* type)
|
||||
-> Member*;
|
||||
|
||||
void PrintMember(Member* m);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto MakeExpStmt(int line_num, Expression* exp) -> Statement* {
|
||||
auto MakeExpStmt(int line_num, const Expression* exp) -> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::ExpressionStatement;
|
||||
@@ -16,7 +16,8 @@ auto MakeExpStmt(int line_num, Expression* exp) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeAssign(int line_num, Expression* lhs, Expression* rhs) -> Statement* {
|
||||
auto MakeAssign(int line_num, const Expression* lhs, const Expression* rhs)
|
||||
-> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Assign;
|
||||
@@ -25,7 +26,8 @@ auto MakeAssign(int line_num, Expression* lhs, Expression* rhs) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeVarDef(int line_num, Expression* pat, Expression* init) -> Statement* {
|
||||
auto MakeVarDef(int line_num, const Expression* pat, const Expression* init)
|
||||
-> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::VariableDefinition;
|
||||
@@ -34,8 +36,8 @@ auto MakeVarDef(int line_num, Expression* pat, Expression* init) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeIf(int line_num, Expression* cond, Statement* then_stmt,
|
||||
Statement* else_stmt) -> Statement* {
|
||||
auto MakeIf(int line_num, const Expression* cond, const Statement* then_stmt,
|
||||
const Statement* else_stmt) -> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::If;
|
||||
@@ -45,7 +47,8 @@ auto MakeIf(int line_num, Expression* cond, Statement* then_stmt,
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeWhile(int line_num, Expression* cond, Statement* body) -> Statement* {
|
||||
auto MakeWhile(int line_num, const Expression* cond, const Statement* body)
|
||||
-> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::While;
|
||||
@@ -54,21 +57,21 @@ auto MakeWhile(int line_num, Expression* cond, Statement* body) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeBreak(int line_num) -> Statement* {
|
||||
auto MakeBreak(int line_num) -> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Break;
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeContinue(int line_num) -> Statement* {
|
||||
auto MakeContinue(int line_num) -> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Continue;
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeReturn(int line_num, Expression* e) -> Statement* {
|
||||
auto MakeReturn(int line_num, const Expression* e) -> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Return;
|
||||
@@ -76,7 +79,8 @@ auto MakeReturn(int line_num, Expression* e) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeSeq(int line_num, Statement* s1, Statement* s2) -> Statement* {
|
||||
auto MakeSeq(int line_num, const Statement* s1, const Statement* s2)
|
||||
-> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Sequence;
|
||||
@@ -85,7 +89,7 @@ auto MakeSeq(int line_num, Statement* s1, Statement* s2) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeBlock(int line_num, Statement* stmt) -> Statement* {
|
||||
auto MakeBlock(int line_num, const Statement* stmt) -> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Block;
|
||||
@@ -93,9 +97,10 @@ auto MakeBlock(int line_num, Statement* stmt) -> Statement* {
|
||||
return s;
|
||||
}
|
||||
|
||||
auto MakeMatch(int line_num, Expression* exp,
|
||||
std::list<std::pair<Expression*, Statement*>>* clauses)
|
||||
-> Statement* {
|
||||
auto MakeMatch(
|
||||
int line_num, const Expression* exp,
|
||||
std::list<std::pair<const Expression*, const Statement*>>* clauses)
|
||||
-> const Statement* {
|
||||
auto* s = new Statement();
|
||||
s->line_num = line_num;
|
||||
s->tag = StatementKind::Match;
|
||||
@@ -107,7 +112,7 @@ auto MakeMatch(int line_num, Expression* exp,
|
||||
// Returns an AST node for a continuation statement give its line number and
|
||||
// parts.
|
||||
auto MakeContinuationStatement(int line_num, std::string continuation_variable,
|
||||
Statement* body) -> Statement* {
|
||||
const Statement* body) -> const Statement* {
|
||||
auto* continuation = new Statement();
|
||||
continuation->line_num = line_num;
|
||||
continuation->tag = StatementKind::Continuation;
|
||||
@@ -118,7 +123,7 @@ auto MakeContinuationStatement(int line_num, std::string continuation_variable,
|
||||
}
|
||||
|
||||
// Returns an AST node for a run statement give its line number and argument.
|
||||
auto MakeRun(int line_num, Expression* argument) -> Statement* {
|
||||
auto MakeRun(int line_num, const Expression* argument) -> const Statement* {
|
||||
auto* run = new Statement();
|
||||
run->line_num = line_num;
|
||||
run->tag = StatementKind::Run;
|
||||
@@ -127,14 +132,14 @@ auto MakeRun(int line_num, Expression* argument) -> Statement* {
|
||||
}
|
||||
|
||||
// Returns an AST node for an await statement give its line number.
|
||||
auto MakeAwait(int line_num) -> Statement* {
|
||||
auto MakeAwait(int line_num) -> const Statement* {
|
||||
auto* await = new Statement();
|
||||
await->line_num = line_num;
|
||||
await->tag = StatementKind::Await;
|
||||
return await;
|
||||
}
|
||||
|
||||
void PrintStatement(Statement* s, int depth) {
|
||||
void PrintStatement(const Statement* s, int depth) {
|
||||
if (!s) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,71 +33,76 @@ struct Statement {
|
||||
StatementKind tag;
|
||||
|
||||
union {
|
||||
Expression* exp;
|
||||
const Expression* exp;
|
||||
|
||||
struct {
|
||||
Expression* lhs;
|
||||
Expression* rhs;
|
||||
const Expression* lhs;
|
||||
const Expression* rhs;
|
||||
} assign;
|
||||
|
||||
struct {
|
||||
Expression* pat;
|
||||
Expression* init;
|
||||
const Expression* pat;
|
||||
const Expression* init;
|
||||
} variable_definition;
|
||||
|
||||
struct {
|
||||
Expression* cond;
|
||||
Statement* then_stmt;
|
||||
Statement* else_stmt;
|
||||
const Expression* cond;
|
||||
const Statement* then_stmt;
|
||||
const Statement* else_stmt;
|
||||
} if_stmt;
|
||||
|
||||
Expression* return_stmt;
|
||||
const Expression* return_stmt;
|
||||
|
||||
struct {
|
||||
Statement* stmt;
|
||||
Statement* next;
|
||||
const Statement* stmt;
|
||||
const Statement* next;
|
||||
} sequence;
|
||||
|
||||
struct {
|
||||
Statement* stmt;
|
||||
const Statement* stmt;
|
||||
} block;
|
||||
|
||||
struct {
|
||||
Expression* cond;
|
||||
Statement* body;
|
||||
const Expression* cond;
|
||||
const Statement* body;
|
||||
} while_stmt;
|
||||
|
||||
struct {
|
||||
Expression* exp;
|
||||
std::list<std::pair<Expression*, Statement*>>* clauses;
|
||||
const Expression* exp;
|
||||
std::list<std::pair<const Expression*, const Statement*>>* clauses;
|
||||
} match_stmt;
|
||||
|
||||
struct {
|
||||
std::string* continuation_variable;
|
||||
Statement* body;
|
||||
const Statement* body;
|
||||
} continuation;
|
||||
|
||||
struct {
|
||||
Expression* argument;
|
||||
const Expression* argument;
|
||||
} run;
|
||||
|
||||
} u;
|
||||
};
|
||||
|
||||
auto MakeExpStmt(int line_num, Expression* exp) -> Statement*;
|
||||
auto MakeAssign(int line_num, Expression* lhs, Expression* rhs) -> Statement*;
|
||||
auto MakeVarDef(int line_num, Expression* pat, Expression* init) -> Statement*;
|
||||
auto MakeIf(int line_num, Expression* cond, Statement* then_stmt,
|
||||
Statement* else_stmt) -> Statement*;
|
||||
auto MakeReturn(int line_num, Expression* e) -> Statement*;
|
||||
auto MakeSeq(int line_num, Statement* s1, Statement* s2) -> Statement*;
|
||||
auto MakeBlock(int line_num, Statement* s) -> Statement*;
|
||||
auto MakeWhile(int line_num, Expression* cond, Statement* body) -> Statement*;
|
||||
auto MakeBreak(int line_num) -> Statement*;
|
||||
auto MakeContinue(int line_num) -> Statement*;
|
||||
auto MakeMatch(int line_num, Expression* exp,
|
||||
std::list<std::pair<Expression*, Statement*>>* clauses)
|
||||
-> Statement*;
|
||||
auto MakeExpStmt(int line_num, const Expression* exp) -> const Statement*;
|
||||
auto MakeAssign(int line_num, const Expression* lhs, const Expression* rhs)
|
||||
-> const Statement*;
|
||||
auto MakeVarDef(int line_num, const Expression* pat, const Expression* init)
|
||||
-> const Statement*;
|
||||
auto MakeIf(int line_num, const Expression* cond, const Statement* then_stmt,
|
||||
const Statement* else_stmt) -> const Statement*;
|
||||
auto MakeReturn(int line_num, const Expression* e) -> const Statement*;
|
||||
auto MakeSeq(int line_num, const Statement* s1, const Statement* s2)
|
||||
-> const Statement*;
|
||||
auto MakeBlock(int line_num, const Statement* s) -> const Statement*;
|
||||
auto MakeWhile(int line_num, const Expression* cond, const Statement* body)
|
||||
-> const Statement*;
|
||||
auto MakeBreak(int line_num) -> const Statement*;
|
||||
auto MakeContinue(int line_num) -> const Statement*;
|
||||
auto MakeMatch(
|
||||
int line_num, const Expression* exp,
|
||||
std::list<std::pair<const Expression*, const Statement*>>* clauses)
|
||||
-> const Statement*;
|
||||
// Returns an AST node for a continuation statement give its line number and
|
||||
// contituent parts.
|
||||
//
|
||||
@@ -105,17 +110,17 @@ auto MakeMatch(int line_num, Expression* exp,
|
||||
// <body>
|
||||
// }
|
||||
auto MakeContinuationStatement(int line_num, std::string continuation_variable,
|
||||
Statement* body) -> Statement*;
|
||||
const Statement* body) -> const Statement*;
|
||||
// Returns an AST node for a run statement give its line number and argument.
|
||||
//
|
||||
// __run <argument>;
|
||||
auto MakeRun(int line_num, Expression* argument) -> Statement*;
|
||||
auto MakeRun(int line_num, const Expression* argument) -> const Statement*;
|
||||
// Returns an AST node for an await statement give its line number.
|
||||
//
|
||||
// __await;
|
||||
auto MakeAwait(int line_num) -> Statement*;
|
||||
auto MakeAwait(int line_num) -> const Statement*;
|
||||
|
||||
void PrintStatement(Statement*, int);
|
||||
void PrintStatement(const Statement*, int);
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
|
||||
Reference in New Issue
Block a user