Skip to content

Commit fa2e6f5

Browse files
chqrliebvdberg
authored andcommitted
Ast: improve consistency in instantiators
* add missing stats * use direct return statements with casts
1 parent 28e1c59 commit fa2e6f5

11 files changed

+41
-41
lines changed

ast/array_designated_init_expr.c2

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public fn ArrayDesignatedInitExpr* ArrayDesignatedInitExpr.create(ast_context.Co
4242
}
4343

4444
fn Expr* ArrayDesignatedInitExpr.instantiate(ArrayDesignatedInitExpr* e, Instantiator* inst) {
45-
ArrayDesignatedInitExpr* f = ArrayDesignatedInitExpr.create(inst.c,
46-
e.base.base.loc,
47-
e.designator.instantiate(inst),
48-
e.initValue.instantiate(inst));
49-
return (Expr*)f;
45+
return (Expr*)ArrayDesignatedInitExpr.create(inst.c,
46+
e.base.base.loc,
47+
e.designator.instantiate(inst),
48+
e.initValue.instantiate(inst));
5049
}
5150

5251
public fn Expr* ArrayDesignatedInitExpr.getDesignator(const ArrayDesignatedInitExpr* e) {

ast/array_subscript_expr.c2

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ public fn ArraySubscriptExpr* ArraySubscriptExpr.create(ast_context.Context* c,
4848
}
4949

5050
fn Expr* ArraySubscriptExpr.instantiate(ArraySubscriptExpr* e, Instantiator* inst) {
51-
ArraySubscriptExpr* a = ArraySubscriptExpr.create(inst.c,
52-
e.base.base.loc,
53-
e.base.base.arraySubscriptExprBits.src_len,
54-
e.lhs.instantiate(inst),
55-
e.idx.instantiate(inst));
56-
return (Expr*)a;
51+
return (Expr*)ArraySubscriptExpr.create(inst.c,
52+
e.base.base.loc,
53+
e.base.base.arraySubscriptExprBits.src_len,
54+
e.lhs.instantiate(inst),
55+
e.idx.instantiate(inst));
5756
}
5857

5958
public fn Expr* ArraySubscriptExpr.getBase(const ArraySubscriptExpr* e) { return e.lhs; }

ast/asm_stmt.c2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public fn AsmStmt* AsmStmt.create(ast_context.Context* c,
9797
return s;
9898
}
9999

100-
fn Stmt* AsmStmt.instantiate(AsmStmt* s, Instantiator* inst) @(unused) {
100+
fn Stmt* AsmStmt.instantiate(AsmStmt* s, Instantiator* inst) {
101101
// TODO
102102
return (Stmt*)s;
103103
}

ast/assert_stmt.c2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public fn AssertStmt* AssertStmt.create(ast_context.Context* c,
3838
}
3939

4040
fn Stmt* AssertStmt.instantiate(AssertStmt* s, Instantiator* inst) {
41-
AssertStmt* s2 = AssertStmt.create(inst.c, s.base.loc, s.inner.instantiate(inst));
42-
return (Stmt*)s2;
41+
return (Stmt*)AssertStmt.create(inst.c, s.base.loc, s.inner.instantiate(inst));
4342
}
4443

4544
public fn Expr* AssertStmt.getInner(const AssertStmt* s) { return s.inner; }

ast/bitoffset_expr.c2

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public fn BitOffsetExpr* BitOffsetExpr.create(ast_context.Context* c, SrcLoc loc
4242
}
4343

4444
fn Expr* BitOffsetExpr.instantiate(BitOffsetExpr* e, Instantiator* inst) {
45-
BitOffsetExpr* b = BitOffsetExpr.create(inst.c,
46-
e.base.base.loc,
47-
e.lhs.instantiate(inst),
48-
e.rhs.instantiate(inst));
49-
return (Expr*)b;
45+
return (Expr*)BitOffsetExpr.create(inst.c,
46+
e.base.base.loc,
47+
e.lhs.instantiate(inst),
48+
e.rhs.instantiate(inst));
5049
}
5150

5251
public fn Expr* BitOffsetExpr.getLHS(const BitOffsetExpr* e) { return e.lhs; }

ast/builtin_expr.c2

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,24 @@ public fn BuiltinExpr* BuiltinExpr.createToContainer(ast_context.Context* c, Src
111111
}
112112

113113
fn Expr* BuiltinExpr.instantiate(BuiltinExpr* e, Instantiator* inst) {
114-
BuiltinExpr* bi = nil;
115114
switch (e.getKind()) {
116115
case Sizeof:
117116
case Elemsof:
118117
case EnumMin:
119118
case EnumMax:
120-
bi = BuiltinExpr.create(inst.c, e.base.base.loc, e.base.base.builtinExprBits.src_len, e.inner.instantiate(inst), e.getKind());
121-
break;
119+
return (Expr*)BuiltinExpr.create(inst.c, e.base.base.loc, e.base.base.builtinExprBits.src_len,
120+
e.inner.instantiate(inst), e.getKind());
122121
case OffsetOf:
123-
bi = BuiltinExpr.createOffsetOf(inst.c, e.base.base.loc, e.base.base.builtinExprBits.src_len, e.inner.instantiate(inst), e.offset[0].member.instantiate(inst));
124-
break;
122+
return (Expr*)BuiltinExpr.createOffsetOf(inst.c, e.base.base.loc, e.base.base.builtinExprBits.src_len,
123+
e.inner.instantiate(inst),
124+
e.offset[0].member.instantiate(inst));
125125
case ToContainer:
126-
bi = BuiltinExpr.createToContainer(inst.c, e.base.base.loc, e.base.base.builtinExprBits.src_len,
127-
e.inner.instantiate(inst),
128-
e.container[0].member.instantiate(inst),
129-
e.container[0].pointer.instantiate(inst));
130-
break;
126+
return (Expr*)BuiltinExpr.createToContainer(inst.c, e.base.base.loc, e.base.base.builtinExprBits.src_len,
127+
e.inner.instantiate(inst),
128+
e.container[0].member.instantiate(inst),
129+
e.container[0].pointer.instantiate(inst));
131130
}
132-
return (Expr*)bi;
131+
return nil;
133132
}
134133

135134
public fn BuiltinExprKind BuiltinExpr.getKind(const BuiltinExpr* e) {

ast/compound_stmt.c2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ fn CompoundStmt* CompoundStmt.instantiate(CompoundStmt* s, Instantiator* inst) {
5858
for (u32 i=0; i<count; i++) {
5959
s2.stmts[i] = s.stmts[i].instantiate(inst);
6060
}
61-
61+
#if AstStatistics
62+
Stats.addStmt(StmtKind.Compound, size);
63+
#endif
6264
return s2;
6365
}
6466

ast/conditional_operator.c2

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ public fn ConditionalOperator* ConditionalOperator.create(ast_context.Context* c
4747
}
4848

4949
fn Expr* ConditionalOperator.instantiate(ConditionalOperator* e, Instantiator* inst) {
50-
ConditionalOperator* o = ConditionalOperator.create(inst.c,
51-
e.base.base.loc,
52-
e.colonLoc,
53-
e.cond.instantiate(inst),
54-
e.lhs.instantiate(inst),
55-
e.rhs.instantiate(inst));
56-
return (Expr*)o;
50+
return (Expr*)ConditionalOperator.create(inst.c,
51+
e.base.base.loc,
52+
e.colonLoc,
53+
e.cond.instantiate(inst),
54+
e.lhs.instantiate(inst),
55+
e.rhs.instantiate(inst));
5756
}
5857

5958
public fn Expr* ConditionalOperator.getCond(const ConditionalOperator* e) {

ast/explicit_cast_expr.c2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ fn Expr* ExplicitCastExpr.instantiate(ExplicitCastExpr* e, Instantiator* inst) {
6161
e2.inner = e.inner.instantiate(inst);
6262
e2.dest_type = QualType_Invalid;
6363
e2.dest.instantiate(&e.dest, inst);
64+
#if AstStatistics
65+
Stats.addExpr(ExprKind.ExplicitCast, size);
66+
#endif
6467
return (Expr*)e2;
6568
}
6669

ast/member_expr.c2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ fn Expr* MemberExpr.instantiate(MemberExpr* e, Instantiator* inst) {
106106
string.memcpy(e2, e, size);
107107
if (base) e2.refs[0].expr = base.instantiate(inst);
108108

109+
#if AstStatistics
110+
Stats.addExpr(ExprKind.Member, size);
111+
#endif
109112
return (Expr*)e2;
110113
}
111114

0 commit comments

Comments
 (0)