Skip to content

Commit de969b7

Browse files
committed
cast: convert new-style casts to old style
1 parent 1b2e40a commit de969b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+616
-624
lines changed

analyser/conversion_checker.c2

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ fn bool Checker.checkTypes(Checker* c, const Type* lcanon, const Type* rcanon) {
226226

227227
fn bool Checker.checkBuiltins(Checker* c, const Type* lcanon, const Type* rcanon) {
228228
// Note: lhs and rhs are not the same, otherwise ptr-check would have succeeded
229-
const BuiltinType* lbuiltin = cast<BuiltinType*>(lcanon);
230-
const BuiltinType* rbuiltin = cast<BuiltinType*>(rcanon);
229+
const BuiltinType* lbuiltin = (BuiltinType*)lcanon;
230+
const BuiltinType* rbuiltin = (BuiltinType*)rcanon;
231231

232232
if ((*c.expr_ptr).isCtv()) {
233233
// TODO check value instead of type
@@ -280,8 +280,8 @@ fn bool Checker.checkBuiltins(Checker* c, const Type* lcanon, const Type* rcanon
280280

281281
fn bool Checker.checkBuiltin2Pointer(Checker* c, const Type* lcanon, const Type* rcanon) {
282282
// Note: only allow usize/(u32/u64) -> void*
283-
const PointerType* ptr = cast<PointerType*>(lcanon);
284-
const BuiltinType* bi = cast<BuiltinType*>(rcanon);
283+
const PointerType* ptr = (PointerType*)lcanon;
284+
const BuiltinType* bi = (BuiltinType*)rcanon;
285285

286286
QualType inner = ptr.getInner();
287287
bool ok = inner.isVoid();
@@ -300,15 +300,15 @@ fn bool Checker.checkBuiltin2Pointer(Checker* c, const Type* lcanon, const Type*
300300

301301
fn bool Checker.checkPointer2Builtin(Checker* c, const Type* lcanon, const Type* rcanon) {
302302
// Note: only allow void* -> usize/(u32/u64) / bool
303-
const BuiltinType* bi = cast<BuiltinType*>(lcanon);
303+
const BuiltinType* bi = (BuiltinType*)lcanon;
304304

305305
BuiltinKind kind = bi.getKind();
306306
if (kind == BuiltinKind.Bool) {
307307
c.builder.insertImplicitCast(ImplicitCastKind.PointerToBoolean, c.expr_ptr, builtins[BuiltinKind.Bool]);
308308
return true;
309309
}
310310

311-
const PointerType* ptr = cast<PointerType*>(rcanon);
311+
const PointerType* ptr = (PointerType*)rcanon;
312312
QualType inner = ptr.getInner();
313313

314314
// TODO or u32 (arch)
@@ -331,7 +331,7 @@ fn bool Checker.checkPointer2Builtin(Checker* c, const Type* lcanon, const Type*
331331

332332
fn bool Checker.checkPointer2Func(Checker* c, const Type* lcanon, const Type* rcanon) {
333333
// only allow if pointer is void*
334-
const PointerType* ptr = cast<PointerType*>(rcanon);
334+
const PointerType* ptr = (PointerType*)rcanon;
335335
QualType inner = ptr.getInner();
336336
if (!inner.isVoid()) {
337337
c.diags.error(c.loc, "incompatible pointer to function conversion '%s' to '%s'",
@@ -344,7 +344,7 @@ fn bool Checker.checkPointer2Func(Checker* c, const Type* lcanon, const Type* rc
344344

345345
fn bool Checker.checkIntConversion(Checker* c, const BuiltinType* bi) {
346346
Expr* e = *c.expr_ptr;
347-
const u8 wl = cast<u8>(bi.getWidth());
347+
const u8 wl = (u8)bi.getWidth();
348348
ExprWidth w = getExprWidth(e);
349349
//stdio.printf("INT CONVERSION signed|width: %d %d -> %d %d\n", w.is_signed, w.width, bi.isSigned(), w.width);
350350

@@ -365,7 +365,7 @@ fn bool Checker.try_to_fix_type(Checker* c) {
365365
Expr* e = *c.expr_ptr;
366366

367367
if (e.isImplicitCast()) {
368-
const ImplicitCastExpr* ic = cast<ImplicitCastExpr*>(e);
368+
const ImplicitCastExpr* ic = (ImplicitCastExpr*)e;
369369
if (ic.isArrayToPointerDecay()) {
370370
e = ic.getInner();
371371
c.rhs = e.getType();
@@ -396,8 +396,8 @@ fn bool pointer_conversion_allowed(QualType linner, QualType rinner) {
396396

397397
fn bool Checker.checkPointers(Checker* c, const Type* lcanon, const Type* rcanon) {
398398

399-
const PointerType* ltype = cast<PointerType*>(lcanon);
400-
const PointerType* rtype = cast<PointerType*>(rcanon);
399+
const PointerType* ltype = (PointerType*)lcanon;
400+
const PointerType* rtype = (PointerType*)rcanon;
401401
/*
402402
if (ltype == rtype) { // this will only happen with AliasTypes
403403
printf(" SAME, diff quals\n");
@@ -431,7 +431,7 @@ fn bool Checker.checkPointers(Checker* c, const Type* lcanon, const Type* rcanon
431431
}
432432

433433
fn bool Checker.checkFunc2Pointer(Checker* c, const Type* lcanon, const Type* rcanon) {
434-
PointerType* pt = cast<PointerType*>(lcanon);
434+
PointerType* pt = (PointerType*)lcanon;
435435
QualType inner = pt.getInner();
436436
if (inner.isVoid()) return true; // always allow conversion to 'void*'
437437

@@ -441,7 +441,7 @@ fn bool Checker.checkFunc2Pointer(Checker* c, const Type* lcanon, const Type* rc
441441

442442
fn bool Checker.checkEnum2Int(Checker* c, const Type* lcanon, const Type* rcanon) {
443443
// Note: enum constant values can never be negative
444-
const BuiltinType* bi = cast<BuiltinType*>(lcanon);
444+
const BuiltinType* bi = (BuiltinType*)lcanon;
445445
u32 width = bi.getWidth();
446446
if (width == 64) return true; // 64-bit
447447

@@ -450,7 +450,7 @@ fn bool Checker.checkEnum2Int(Checker* c, const Type* lcanon, const Type* rcanon
450450
return ctv_analyser.check(c.diags, c.lhs, *c.expr_ptr);
451451
} else {
452452
// compare impl type
453-
const EnumType* et = cast<EnumType*>(rcanon);
453+
const EnumType* et = (EnumType*)rcanon;
454454
const EnumTypeDecl* etd = et.getDecl();
455455
QualType impl = etd.getImplType();
456456

@@ -461,9 +461,9 @@ fn bool Checker.checkEnum2Int(Checker* c, const Type* lcanon, const Type* rcanon
461461
}
462462

463463
fn bool Checker.checkFunc2Func(Checker* c, const Type* lcanon, const Type* rcanon) {
464-
FunctionType* ftl = cast<FunctionType*>(lcanon);
464+
FunctionType* ftl = (FunctionType*)lcanon;
465465
FunctionDecl* fdl = ftl.getDecl();
466-
FunctionType* ftr = cast<FunctionType*>(rcanon);
466+
FunctionType* ftr = (FunctionType*)rcanon;
467467
FunctionDecl* fdr = ftr.getDecl();
468468

469469
if (fdr.getNumAutoArgs()) {
@@ -489,8 +489,8 @@ fn bool checkFunc2Func(const FunctionDecl* fdl, const FunctionDecl* fdr) {
489489
u32 num2 = fdr.getNumParams();
490490
if (num1 != num2) return false;
491491

492-
Decl** args1 = cast<Decl**>(fdl.getParams());
493-
Decl** args2 = cast<Decl**>(fdr.getParams());
492+
Decl** args1 = (Decl**)fdl.getParams();
493+
Decl** args2 = (Decl**)fdr.getParams();
494494
for (u32 i=0; i<num1; i++) {
495495
Decl* a1 = args1[i];
496496
Decl* a2 = args2[i];
@@ -506,13 +506,13 @@ fn bool checkFunc2Func(const FunctionDecl* fdl, const FunctionDecl* fdr) {
506506

507507
fn bool Checker.checkFunc2Builtin(Checker* c, const Type* lcanon, const Type* rcanon, bool* other_error) {
508508
u32 wordsize = ast.getWordSize();
509-
const BuiltinType* bi = cast<BuiltinType*>(lcanon);
509+
const BuiltinType* bi = (BuiltinType*)lcanon;
510510

511511
BuiltinKind kind = bi.getKind();
512512
if (kind == BuiltinKind.USize) return true;
513513
if (kind == BuiltinKind.Bool) {
514514
// only allow Callback types or weak-functions
515-
FunctionType* ft = cast<FunctionType*>(rcanon);
515+
FunctionType* ft = (FunctionType*)rcanon;
516516
FunctionDecl* fd = ft.getDecl();
517517
if (fd.isType() || fd.hasAttrWeak()) return true; // Variable with Function type (eg callback)
518518

@@ -607,7 +607,7 @@ public fn bool Checker.checkCast(Checker* c, QualType lhs, QualType rhs, SrcLoc
607607
fn bool Checker.checkBuiltin2PointerCast(Checker* c, const Type* lcanon, const Type* rcanon) {
608608
// only allow cast from pointer-size int (u32/u64 depending on arch) to pointer
609609
u32 wordsize = ast.getWordSize();
610-
const BuiltinType* bi = cast<BuiltinType*>(rcanon);
610+
const BuiltinType* bi = (BuiltinType*)rcanon;
611611

612612
BuiltinKind kind = bi.getKind();
613613
if (kind == BuiltinKind.USize) return true;
@@ -624,7 +624,7 @@ fn bool Checker.checkBuiltin2PointerCast(Checker* c, const Type* lcanon, const T
624624
fn bool Checker.checkPointer2BuiltinCast(Checker* c, const Type* lcanon, const Type* rcanon) {
625625
// only allow cast from pointer to pointer-size int (u32/u64 depending on arch)
626626
u32 wordsize = ast.getWordSize();
627-
const BuiltinType* bi = cast<BuiltinType*>(lcanon);
627+
const BuiltinType* bi = (BuiltinType*)lcanon;
628628

629629
BuiltinKind kind = bi.getKind();
630630
if (kind == BuiltinKind.USize) return true;
@@ -679,7 +679,7 @@ public fn QualType get_common_arithmetic_type(QualType t1, QualType t2) {
679679

680680
BuiltinType* bi1 = t1.getBuiltin();
681681
BuiltinType* bi2 = t2.getBuiltin();
682-
BuiltinKind kind = cast<BuiltinKind>(ConditionalOperatorResult[bi2.getKind()][bi1.getKind()]);
682+
BuiltinKind kind = (BuiltinKind)ConditionalOperatorResult[bi2.getKind()][bi1.getKind()];
683683
return ast.builtins[kind];
684684
}
685685

analyser/conversion_checker_expr.c2

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ fn ExprWidth getExprWidth(const Expr* e) {
6767
qt = qt.getCanonicalType();
6868
if (qt.isBuiltin()) {
6969
BuiltinType* bi = qt.getBuiltin();
70-
result.width = cast<u8>(bi.getWidth());
70+
result.width = (u8)bi.getWidth();
7171
result.is_signed = bi.isSigned();
7272
} else {
7373
// pointer or something
74-
result.width = cast<u8>(ast.getWordSize() * 8);
74+
result.width = (u8)(ast.getWordSize() * 8);
7575
result.is_signed = true;
7676
}
7777
return result;
@@ -86,29 +86,29 @@ fn ExprWidth getExprWidth(const Expr* e) {
8686
case ArrayDesignatedInit:
8787
break;
8888
case BinaryOperator:
89-
return getBinOpWidth(cast<BinaryOperator*>(e));
89+
return getBinOpWidth((BinaryOperator*)e);
9090
case UnaryOperator:
91-
return getUnaryOpWidth(cast<UnaryOperator*>(e));
91+
return getUnaryOpWidth((UnaryOperator*)e);
9292
case ConditionalOperator:
93-
return getCondOpWidth(cast<ConditionalOperator*>(e));
93+
return getCondOpWidth((ConditionalOperator*)e);
9494
case Builtin:
9595
break;
9696
case ArraySubscript:
9797
case Member:
9898
QualType qt = e.getType();
9999
qt = qt.getCanonicalType();
100100
if (qt.isPointer()) {
101-
result.width = cast<u8>(ast.getWordSize() * 8);
101+
result.width = (u8)(ast.getWordSize() * 8);
102102
result.is_signed = false;
103103
return result;
104104
}
105105
assert(qt.isBuiltin());
106106
BuiltinType* bi = qt.getBuiltin();
107-
result.width = cast<u8>(bi.getWidth());
107+
result.width = (u8)bi.getWidth();
108108
result.is_signed = bi.isSigned();
109109
return result;
110110
case Paren:
111-
const ParenExpr* p = cast<ParenExpr*>(e);
111+
const ParenExpr* p = (ParenExpr*)e;
112112
return getExprWidth(p.getInner());
113113
case BitOffset:
114114
break;
@@ -117,14 +117,14 @@ fn ExprWidth getExprWidth(const Expr* e) {
117117
qt = qt.getCanonicalType();
118118
assert(qt.isBuiltin());
119119
BuiltinType* bi = qt.getBuiltin();
120-
result.width = cast<u8>(bi.getWidth());
120+
result.width = (u8)bi.getWidth();
121121
result.is_signed = bi.isSigned();
122122
return result;
123123
case ImplicitCast:
124-
const ImplicitCastExpr* c = cast<ImplicitCastExpr*>(e);
124+
const ImplicitCastExpr* c = (ImplicitCastExpr*)e;
125125
return getExprWidth(c.getInner());
126126
case Range:
127-
RangeExpr* b = cast<RangeExpr*>(e);
127+
RangeExpr* b = (RangeExpr*)e;
128128
ExprWidth lhs = getExprWidth(b.getLHS());
129129
ExprWidth rhs = getExprWidth(b.getRHS());
130130
return ExprWidth.mergeWider(&lhs, &rhs);
@@ -152,21 +152,21 @@ fn ExprWidth getUnaryOpWidth(const UnaryOperator* u) {
152152
// TODO adjust for integer promotion?
153153
return getExprWidth(u.getInner());
154154
case AddrOf:
155-
w.width = cast<u8>(ast.getWordSize() * 8);
155+
w.width = (u8)(ast.getWordSize() * 8);
156156
w.is_signed = false;
157157
break;
158158
case Deref:
159-
Expr* e = cast<Expr*>(u);
159+
Expr* e = (Expr*)u;
160160
QualType qt = e.getType();
161161
qt = qt.getCanonicalType();
162162
if (qt.isPointer()) {
163-
w.width = cast<u8>(ast.getWordSize() * 8);
163+
w.width = (u8)(ast.getWordSize() * 8);
164164
w.is_signed = false;
165165
break;
166166
}
167167
assert(qt.isBuiltin());
168168
BuiltinType* bi = qt.getBuiltin();
169-
w.width = cast<u8>(bi.getWidth());
169+
w.width = (u8)bi.getWidth();
170170
w.is_signed = bi.isSigned();
171171
break;
172172
case Minus:
@@ -252,7 +252,7 @@ fn ExprWidth getTypeWidth(QualType qt) {
252252
assert(qt.isBuiltin());
253253
const BuiltinType* bi = qt.getBuiltin();
254254
ExprWidth result;
255-
result.width = cast<u8>(bi.getWidth());
255+
result.width = (u8)bi.getWidth();
256256
result.is_signed = bi.isSigned();
257257
return result;
258258
}

0 commit comments

Comments
 (0)