-
Notifications
You must be signed in to change notification settings - Fork 38
/
binary.go
633 lines (560 loc) · 19.2 KB
/
binary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
// This file contains functions for transpiling binary operator expressions.
package transpiler
import (
"fmt"
goast "go/ast"
"go/token"
"strings"
"github.com/Konstantin8105/c4go/ast"
"github.com/Konstantin8105/c4go/program"
"github.com/Konstantin8105/c4go/types"
"github.com/Konstantin8105/c4go/util"
)
// Comma problem. Example:
// for (int i=0,j=0;i+=1,j<5;i++,j++){...}
// For solving - we have to separate the
// binary operator "," to 2 parts:
// part 1(pre ): left part - typically one or more some expressions
// part 2(stmt): right part - always only one expression, with or without
//
// logical operators like "==", "!=", ...
func transpileBinaryOperatorComma(n *ast.BinaryOperator, p *program.Program) (
stmt goast.Stmt, preStmts []goast.Stmt, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("cannot transpile operator comma : err = %v", err)
p.AddMessage(p.GenerateWarningMessage(err, n))
}
}()
left, err := transpileToStmts(n.Children()[0], p)
if err != nil {
return nil, nil, err
}
right, err := transpileToStmts(n.Children()[1], p)
if err != nil {
return nil, nil, err
}
if left == nil || right == nil {
return nil, nil,
fmt.Errorf("cannot transpile binary operator comma: right = %v , left = %v",
right, left)
}
preStmts = append(preStmts, left...)
preStmts = append(preStmts, right...)
if len(preStmts) >= 2 {
return preStmts[len(preStmts)-1], preStmts[:len(preStmts)-1], nil
}
if len(preStmts) == 1 {
return preStmts[0], nil, nil
}
return nil, nil, nil
}
func transpileBinaryOperator(n *ast.BinaryOperator, p *program.Program, exprIsStmt bool) (
expr goast.Expr, eType string, preStmts []goast.Stmt, postStmts []goast.Stmt, err error) {
defer func() {
if err != nil {
err = fmt.Errorf(
"cannot transpile BinaryOperator with type '%s' :"+
" result type = {%s}. Error: %v", n.Type, eType, err)
p.AddMessage(p.GenerateWarningMessage(err, n))
}
}()
operator := getTokenForOperatorNoError(n.Operator)
n.Type = util.GenerateCorrectType(n.Type)
n.Type2 = util.GenerateCorrectType(n.Type2)
defer func() {
if err != nil {
err = fmt.Errorf("operator is `%v`. %v", operator, err)
}
}()
// Char overflow
// BinaryOperator 'int' '!='
// |-ImplicitCastExpr 'int' <IntegralCast>
// | `-ImplicitCastExpr 'char' <LValueToRValue>
// | `-...
// `-ParenExpr 'int'
// `-UnaryOperator 'int' prefix '-'
// `-IntegerLiteral 'int' 1
if n.Operator == "!=" {
var leftOk bool
if l0, ok := n.ChildNodes[0].(*ast.ImplicitCastExpr); ok && l0.Type == "int" {
if len(l0.ChildNodes) > 0 {
if l1, ok := l0.ChildNodes[0].(*ast.ImplicitCastExpr); ok && l1.Type == "char" {
leftOk = true
}
}
}
if leftOk {
if r0, ok := n.ChildNodes[1].(*ast.ParenExpr); ok && r0.Type == "int" {
if len(r0.ChildNodes) > 0 {
if r1, ok := r0.ChildNodes[0].(*ast.UnaryOperator); ok && r1.IsPrefix && r1.Operator == "-" {
if r2, ok := r1.ChildNodes[0].(*ast.IntegerLiteral); ok && r2.Type == "int" {
r0.ChildNodes[0] = &ast.BinaryOperator{
Type: "int",
Type2: "int",
Operator: "+",
ChildNodes: []ast.Node{
r1,
&ast.IntegerLiteral{
Type: "int",
Value: "256",
},
},
}
}
}
}
}
}
}
// Example of C code
// a = b = 1
// // Operation equal transpile from right to left
// Solving:
// b = 1, a = b
// // Operation comma transpile from left to right
// If we have for example:
// a = b = c = 1
// then solution is:
// c = 1, b = c, a = b
// |-----------|
// this part, created in according to
// recursive working
// Example of AST tree for problem:
// |-BinaryOperator 0x2f17870 <line:13:2, col:10> 'int' '='
// | |-DeclRefExpr 0x2f177d8 <col:2> 'int' lvalue Var 0x2f176d8 'x' 'int'
// | `-BinaryOperator 0x2f17848 <col:6, col:10> 'int' '='
// | |-DeclRefExpr 0x2f17800 <col:6> 'int' lvalue Var 0x2f17748 'y' 'int'
// | `-IntegerLiteral 0x2f17828 <col:10> 'int' 1
//
// Example of AST tree for solution:
// |-BinaryOperator 0x368e8d8 <line:13:2, col:13> 'int' ','
// | |-BinaryOperator 0x368e820 <col:2, col:6> 'int' '='
// | | |-DeclRefExpr 0x368e7d8 <col:2> 'int' lvalue Var 0x368e748 'y' 'int'
// | | `-IntegerLiteral 0x368e800 <col:6> 'int' 1
// | `-BinaryOperator 0x368e8b0 <col:9, col:13> 'int' '='
// | |-DeclRefExpr 0x368e848 <col:9> 'int' lvalue Var 0x368e6d8 'x' 'int'
// | `-ImplicitCastExpr 0x368e898 <col:13> 'int' <LValueToRValue>
// | `-DeclRefExpr 0x368e870 <col:13> 'int' lvalue Var 0x368e748 'y' 'int'
//
// Example
// BinaryOperator 'const char *' '='
// |-...
// `-ImplicitCastExpr 'const char *' <BitCast>
// `-BinaryOperator 'char *' '='
// |-...
// `-...
if getTokenForOperatorNoError(n.Operator) == token.ASSIGN {
child := n.Children()[1]
if impl, ok := child.(*ast.ImplicitCastExpr); ok {
child = impl.Children()[0]
}
switch c := child.(type) {
case *ast.BinaryOperator:
if getTokenForOperatorNoError(c.Operator) == token.ASSIGN {
bSecond := ast.BinaryOperator{
Type: c.Type,
Operator: "=",
}
bSecond.AddChild(n.Children()[0])
var impl ast.ImplicitCastExpr
impl.Type = c.Type
impl.Kind = "LValueToRValue"
impl.AddChild(c.Children()[0])
bSecond.AddChild(&impl)
var bComma ast.BinaryOperator
bComma.Operator = ","
bComma.Type = c.Type
bComma.AddChild(c)
bComma.AddChild(&bSecond)
// exprIsStmt now changes to false to stop any AST children from
// not being safely wrapped in a closure.
return transpileBinaryOperator(&bComma, p, false)
}
}
}
// Example of C code
// a = 1, b = a
// Solving
// a = 1; // preStmts
// b = a; // n
// Example of AST tree for problem:
// |-BinaryOperator 0x368e8d8 <line:13:2, col:13> 'int' ','
// | |-BinaryOperator 0x368e820 <col:2, col:6> 'int' '='
// | | |-DeclRefExpr 0x368e7d8 <col:2> 'int' lvalue Var 0x368e748 'y' 'int'
// | | `-IntegerLiteral 0x368e800 <col:6> 'int' 1
// | `-BinaryOperator 0x368e8b0 <col:9, col:13> 'int' '='
// | |-DeclRefExpr 0x368e848 <col:9> 'int' lvalue Var 0x368e6d8 'x' 'int'
// | `-ImplicitCastExpr 0x368e898 <col:13> 'int' <LValueToRValue>
// | `-DeclRefExpr 0x368e870 <col:13> 'int' lvalue Var 0x368e748 'y' 'int'
//
// Example of AST tree for solution:
// |-BinaryOperator 0x21a7820 <line:13:2, col:6> 'int' '='
// | |-DeclRefExpr 0x21a77d8 <col:2> 'int' lvalue Var 0x21a7748 'y' 'int'
// | `-IntegerLiteral 0x21a7800 <col:6> 'int' 1
// |-BinaryOperator 0x21a78b0 <line:14:2, col:6> 'int' '='
// | |-DeclRefExpr 0x21a7848 <col:2> 'int' lvalue Var 0x21a76d8 'x' 'int'
// | `-ImplicitCastExpr 0x21a7898 <col:6> 'int' <LValueToRValue>
// | `-DeclRefExpr 0x21a7870 <col:6> 'int' lvalue Var 0x21a7748 'y' 'int'
if getTokenForOperatorNoError(n.Operator) == token.COMMA {
stmts, _, newPre, newPost, err := transpileToExpr(n.Children()[0], p, false)
if err != nil {
err = fmt.Errorf("cannot transpile expr `token.COMMA` child 0. %v", err)
return nil, "unknown50", nil, nil, err
}
preStmts = append(preStmts, newPre...)
preStmts = append(preStmts, util.NewExprStmt(stmts))
preStmts = append(preStmts, newPost...)
var st string
stmts, st, newPre, newPost, err = transpileToExpr(n.Children()[1], p, false)
if err != nil {
err = fmt.Errorf("cannot transpile expr `token.COMMA` child 1. %v", err)
return nil, "unknown51", nil, nil, err
}
// Theoretically , we don't have any preStmts or postStmts
// from n.Children()[1]
if len(newPre) > 0 || len(newPost) > 0 {
p.AddMessage(p.GenerateWarningMessage(
fmt.Errorf("not support length pre or post stmts: {%d,%d}",
len(newPre), len(newPost)), n))
}
return stmts, st, preStmts, postStmts, nil
}
// pointer arithmetic
if types.IsPointer(n.Type, p) {
if operator == token.ADD || // +
false {
// not acceptable binaryOperator with operator `-`
haveSub := false
{
var check func(ast.Node)
check = func(node ast.Node) {
if node == nil {
return
}
if bin, ok := node.(*ast.BinaryOperator); ok && bin.Operator == "-" {
haveSub = true
}
for i := range node.Children() {
check(node.Children()[i])
}
}
check(n)
}
if !haveSub {
fakeUnary := &ast.UnaryOperator{
Type: n.Type,
Operator: "*",
ChildNodes: []ast.Node{
n,
},
}
var newPre, newPost []goast.Stmt
expr, eType, newPre, newPost, err =
transpilePointerArith(fakeUnary, p)
eType = n.Type
if err != nil {
return
}
if expr == nil {
return nil, "", nil, nil, fmt.Errorf("expr is nil")
}
preStmts, postStmts =
combinePreAndPostStmts(preStmts, postStmts, newPre, newPost)
if ind, ok := expr.(*goast.IndexExpr); ok {
expr = &goast.SliceExpr{
X: ind.X,
Low: ind.Index,
Slice3: false,
}
}
return
}
}
}
left, leftType, newPre, newPost, err := atomicOperation(n.Children()[0], p)
if err != nil {
err = fmt.Errorf("cannot atomic for left part. %v", err)
return nil, "unknown52", nil, nil, err
}
preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, newPre, newPost)
right, rightType, newPre, newPost, err := atomicOperation(n.Children()[1], p)
if err != nil {
err = fmt.Errorf("cannot atomic for right part. %v", err)
return nil, "unknown53", nil, nil, err
}
if types.IsPointer(leftType, p) && types.IsPointer(rightType, p) {
switch operator {
case token.SUB: // -
p.AddImport("unsafe")
var sizeof int
sizeof, err = types.SizeOf(p, types.GetBaseType(leftType))
if err != nil {
return nil, "PointerOperation_unknown01", nil, nil, err
}
var e goast.Expr
var newPost []goast.Stmt
e, newPost, err = SubTwoPnts(p, left, leftType, right, rightType, sizeof)
if err != nil {
return nil, "PointerOperation_unknown02", nil, nil, err
}
postStmts = append(postStmts, newPost...)
expr, err = types.CastExpr(p, e, "long long", n.Type)
if err != nil {
return nil, "PointerOperation_unknown03", nil, nil, err
}
eType = n.Type
return
case token.GTR, token.GEQ, // > >=
token.LOR, // ||
token.LAND, // &&
token.LSS, token.LEQ, // < <=
token.EQL, token.NEQ: // == !=
// IfStmt 0x2369a68 <line:210:3, line:211:11>
// |-BinaryOperator 0x2369a00 <line:210:7, col:21> 'int' '=='
// | |-ImplicitCastExpr 0x23699d0 <col:7, col:16> 'struct font *' <LValueToRValue>
// | | `-ArraySubscriptExpr 0x2369990 <col:7, col:16> 'struct font *' lvalue
// | | |-ImplicitCastExpr 0x2369960 <col:7> 'struct font **' <ArrayToPointerDecay>
// | | | `-DeclRefExpr 0x2369920 <col:7> 'struct font *[32]' lvalue Var 0x235fbe8 'fn_font' 'struct font *[32]'
// | | `-ImplicitCastExpr 0x2369978 <col:15> 'int' <LValueToRValue>
// | | `-DeclRefExpr 0x2369940 <col:15> 'int' lvalue Var 0x2369790 'i' 'int'
// | `-ImplicitCastExpr 0x23699e8 <col:21> 'struct font *' <LValueToRValue>
// | `-DeclRefExpr 0x23699b0 <col:21> 'struct font *' lvalue ParmVar 0x2369638 'fn' 'struct font *'
// `-ReturnStmt 0x2369a58 <line:211:4, col:11>
// `-ImplicitCastExpr 0x2369a40 <col:11> 'int' <LValueToRValue>
// `-DeclRefExpr 0x2369a20 <col:11> 'int' lvalue Var 0x2369790 'i' 'int'
var sizeof int
baseType := types.GetBaseType(leftType)
sizeof, err = types.SizeOf(p, baseType)
if err != nil {
err = fmt.Errorf("{'%s' %v '%s'}. sizeof = %d for baseType = '%s'. %v",
leftType, operator, rightType, sizeof, baseType, err)
return nil, "PointerOperation_unknown04", nil, nil, err
}
var e goast.Expr
var newPost []goast.Stmt
e, newPost, err = PntCmpPnt(
p,
left, leftType,
right, rightType,
sizeof, operator,
)
if err != nil {
err = fmt.Errorf("{'%s' %v '%s'}. for base type: `%s`. %v",
leftType, operator, rightType, baseType, err)
return nil, "PointerOperation_unknown05", nil, nil, err
}
postStmts = append(postStmts, newPost...)
expr = e
eType = "bool"
return
case token.ASSIGN: // =
// ignore
default:
err = fmt.Errorf("not implemented pointer operation: %v", operator)
return
}
}
preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, newPre, newPost)
returnType := types.ResolveTypeForBinaryOperator(p, n.Operator, leftType, rightType)
if operator == token.LAND || operator == token.LOR { // && ||
left, err = types.CastExpr(p, left, leftType, "bool")
if err != nil {
p.AddMessage(p.GenerateWarningMessage(err, n))
// ignore error
left = util.NewNil()
err = nil
}
right, err = types.CastExpr(p, right, rightType, "bool")
if err != nil {
p.AddMessage(p.GenerateWarningMessage(err, n))
// ignore error
right = util.NewNil()
err = nil
}
resolvedLeftType, err := types.ResolveType(p, leftType)
if err != nil {
p.AddMessage(p.GenerateWarningMessage(err, n))
}
expr := util.NewBinaryExpr(left, operator, right, resolvedLeftType, exprIsStmt)
return expr, "bool", preStmts, postStmts, nil
}
// The right hand argument of the shift left or shift right operators
// in Go must be unsigned integers. In C, shifting with a negative shift
// count is undefined behaviour (so we should be able to ignore that case).
// To handle this, cast the shift count to a uint64.
if operator == token.SHL || // <<
operator == token.SHR || // >>
operator == token.SHL_ASSIGN || // <<=
operator == token.SHR_ASSIGN || // <<=
false {
right, err = types.CastExpr(p, right, rightType, "unsigned long long")
p.AddMessage(p.GenerateWarningMessage(err, n))
if right == nil {
right = util.NewNil()
}
}
// pointer arithmetic
if types.IsPointer(n.Type, p) {
if operator == token.ADD || // +
operator == token.SUB || // -
false {
el, extl, prel, postl, errl := atomicOperation(n.Children()[0], p)
er, extr, prer, postr, errr := atomicOperation(n.Children()[1], p)
if errl != nil || errr != nil {
err = fmt.Errorf("pointer operation is not valid : %v. %v", errl, errr)
return
}
preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, prel, postl)
preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, prer, postr)
if types.IsCPointer(extl, p) {
expr, eType, prel, postl, errl = pointerArithmetic(p, el, extl, er, extr, operator)
} else {
expr, eType, prel, postl, errl = pointerArithmetic(p, er, extr, el, extl, operator)
}
if errl != nil {
err = fmt.Errorf("pointer operation is not valid : %v", errl)
return
}
preStmts, postStmts = combinePreAndPostStmts(preStmts, postStmts, prel, postl)
return
}
}
if operator == token.NEQ || // !=
operator == token.EQL || // ==
operator == token.LSS || // <
operator == token.GTR || // >
operator == token.AND || // &
operator == token.ADD || // +
operator == token.SUB || // -
operator == token.MUL || // *
operator == token.QUO || // /
operator == token.REM || // %
operator == token.LEQ || // <=
operator == token.GEQ || // >=
operator == token.ADD_ASSIGN || // +=
operator == token.SUB_ASSIGN || // -=
operator == token.MUL_ASSIGN || // *=
operator == token.QUO_ASSIGN || // /=
operator == token.REM_ASSIGN || // %=
operator == token.AND_ASSIGN || // &=
operator == token.OR_ASSIGN || // |=
operator == token.XOR_ASSIGN || // ^=
operator == token.SHL_ASSIGN || // <<=
operator == token.SHR_ASSIGN || // >>=
operator == token.AND_NOT_ASSIGN || // &^=
false {
if rightType == types.NullPointer && leftType == types.NullPointer {
// example C code :
// if ( NULL == NULL )
right = goast.NewIdent("1")
rightType = "int"
left = goast.NewIdent("1")
leftType = "int"
} else if rightType != types.NullPointer && leftType != types.NullPointer {
// We may have to cast the right side to the same type as the left
// side. This is a bit crude because we should make a better
// decision of which type to cast to instead of only using the type
// of the left side.
if operator == token.ADD || // +
operator == token.SUB || // -
operator == token.MUL || // *
operator == token.QUO || // /
operator == token.REM || // %
false {
if rightType == "bool" {
right, err = types.CastExpr(p, right, rightType, "int")
rightType = "int"
p.AddMessage(p.GenerateWarningMessage(err, n))
}
if leftType == "bool" {
left, err = types.CastExpr(p, left, leftType, "int")
leftType = "int"
p.AddMessage(p.GenerateWarningMessage(err, n))
}
}
right, err = types.CastExpr(p, right, rightType, leftType)
rightType = leftType
p.AddMessage(p.GenerateWarningMessage(err, n))
// compare pointers
//
// BinaryOperator 'int' '<'
// |-ImplicitCastExpr 'char *' <LValueToRValue>
// | `-DeclRefExpr 'char *' lvalue Var 0x26ba988 'c' 'char *'
// `-ImplicitCastExpr 'char *' <LValueToRValue>
// `-DeclRefExpr 'char *' lvalue Var 0x26ba8a8 'b' 'char *'
if types.IsPointer(leftType, p) || types.IsPointer(rightType, p) {
err = fmt.Errorf("need add pointer operator : %s %v %s",
leftType, n.Operator, rightType)
return
}
}
}
if operator == token.ASSIGN { // =
// BinaryOperator 'double *' '='
// |-DeclRefExpr 'double *' lvalue Var 0x2a7fa48 'd' 'double *'
// `-ImplicitCastExpr 'double *' <BitCast>
// `-CStyleCastExpr 'char *' <BitCast>
// `-...
right, err = types.CastExpr(p, right, rightType, returnType)
rightType = returnType
if err != nil {
return
}
if _, ok := right.(*goast.UnaryExpr); ok && types.IsDereferenceType(rightType) {
deref, err := types.GetDereferenceType(rightType)
if !p.AddMessage(p.GenerateWarningMessage(err, n)) {
resolvedDeref, err := types.ResolveType(p, deref)
// FIXME: I'm not sure how this situation arises.
if resolvedDeref == "" {
resolvedDeref = "interface{}"
}
if !p.AddMessage(p.GenerateWarningMessage(err, n)) {
p.AddImport("unsafe")
right = CreateSliceFromReference(resolvedDeref, right)
}
}
}
if p.AddMessage(p.GenerateWarningMessage(err, n)) && right == nil {
right = util.NewNil()
}
}
var resolvedLeftType = n.Type
if !util.IsFunction(n.Type) && !types.IsTypedefFunction(p, n.Type) {
if leftType != types.NullPointer {
resolvedLeftType, err = types.ResolveType(p, leftType)
} else {
resolvedLeftType, err = types.ResolveType(p, rightType)
}
p.AddMessage(p.GenerateWarningMessage(err, n))
}
// Enum casting
if operator != token.ASSIGN && strings.Contains(rightType, "enum ") {
right, err = types.CastExpr(p, right, rightType, "int")
if err != nil {
p.AddMessage(p.GenerateWarningMessage(err, n))
}
}
if left == nil {
err = fmt.Errorf("left part of binary operation is nil. left : %#v", n.Children()[0])
p.AddMessage(p.GenerateWarningMessage(err, n))
return nil, "", nil, nil, err
}
if right == nil {
err = fmt.Errorf("right part of binary operation is nil. right : %#v", n.Children()[1])
p.AddMessage(p.GenerateWarningMessage(err, n))
return nil, "", nil, nil, err
}
return util.NewBinaryExpr(left, operator, right, resolvedLeftType, exprIsStmt),
types.ResolveTypeForBinaryOperator(p, n.Operator, leftType, rightType),
preStmts, postStmts, nil
}
func foundCallExpr(n ast.Node) *ast.CallExpr {
switch v := n.(type) {
case *ast.ImplicitCastExpr, *ast.CStyleCastExpr:
return foundCallExpr(n.Children()[0])
case *ast.CallExpr:
return v
}
return nil
}