Skip to content

Commit 26e794d

Browse files
committed
impl glayzzle#119 : add a new raw property on cast nodes
1 parent d10921c commit 26e794d

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

src/ast/cast.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const KIND = "cast";
1313
* @constructor Cast
1414
* @extends {Operation}
1515
* @property {String} type
16+
* @property {String} raw
1617
* @property {Expression} what
1718
*/
18-
const Cast = Operation.extends(function Cast(type, what, docs, location) {
19+
const Cast = Operation.extends(function Cast(type, raw, what, docs, location) {
1920
Operation.apply(this, [KIND, docs, location]);
2021
this.type = type;
22+
this.raw = raw;
2123
this.what = what;
2224
});
2325

src/parser/expr.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,28 +246,33 @@ module.exports = {
246246
return result(expr);
247247

248248
case this.tok.T_INT_CAST:
249-
return this.node("cast")("int", this.next().read_expr());
249+
return this.node("cast")("int", this.text(), this.next().read_expr());
250250

251251
case this.tok.T_DOUBLE_CAST:
252-
return this.node("cast")("float", this.next().read_expr());
252+
return this.node("cast")("float", this.text(), this.next().read_expr());
253253

254254
case this.tok.T_STRING_CAST:
255255
return this.node("cast")(
256-
this.text() === "(binary)" ? "binary" : "string",
256+
this.text().indexOf("binary") !== -1 ? "binary" : "string",
257+
this.text(),
257258
this.next().read_expr()
258259
);
259260

260261
case this.tok.T_ARRAY_CAST:
261-
return this.node("cast")("array", this.next().read_expr());
262+
return this.node("cast")("array", this.text(), this.next().read_expr());
262263

263264
case this.tok.T_OBJECT_CAST:
264-
return this.node("cast")("object", this.next().read_expr());
265+
return this.node("cast")(
266+
"object",
267+
this.text(),
268+
this.next().read_expr()
269+
);
265270

266271
case this.tok.T_BOOL_CAST:
267-
return this.node("cast")("bool", this.next().read_expr());
272+
return this.node("cast")("bool", this.text(), this.next().read_expr());
268273

269274
case this.tok.T_UNSET_CAST:
270-
return this.node("cast")("unset", this.next().read_expr());
275+
return this.node("cast")("unset", this.text(), this.next().read_expr());
271276

272277
case this.tok.T_EXIT: {
273278
const useDie = this.lexer.yytext.toLowerCase() === "die";

test/snapshot/__snapshots__/acid.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,6 +3103,7 @@ Program {
31033103
"offset": 1806,
31043104
},
31053105
},
3106+
"raw": "(int)",
31063107
"type": "int",
31073108
"what": Bin {
31083109
"kind": "bin",
@@ -5469,6 +5470,7 @@ next:
54695470
"offset": 2018,
54705471
},
54715472
},
5473+
"raw": "(int)",
54725474
"type": "int",
54735475
"what": Bin {
54745476
"kind": "bin",

test/snapshot/__snapshots__/expr.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ Program {
482482
"children": Array [
483483
Cast {
484484
"kind": "cast",
485+
"raw": "(int)",
485486
"type": "int",
486487
"what": Variable {
487488
"byref": false,
@@ -492,6 +493,7 @@ Program {
492493
},
493494
Cast {
494495
"kind": "cast",
496+
"raw": "(integer)",
495497
"type": "int",
496498
"what": Variable {
497499
"byref": false,
@@ -502,6 +504,7 @@ Program {
502504
},
503505
Cast {
504506
"kind": "cast",
507+
"raw": "(bool)",
505508
"type": "bool",
506509
"what": Variable {
507510
"byref": false,
@@ -512,6 +515,7 @@ Program {
512515
},
513516
Cast {
514517
"kind": "cast",
518+
"raw": "(boolean)",
515519
"type": "bool",
516520
"what": Variable {
517521
"byref": false,
@@ -522,6 +526,7 @@ Program {
522526
},
523527
Cast {
524528
"kind": "cast",
529+
"raw": "(float)",
525530
"type": "float",
526531
"what": Variable {
527532
"byref": false,
@@ -532,6 +537,7 @@ Program {
532537
},
533538
Cast {
534539
"kind": "cast",
540+
"raw": "(double)",
535541
"type": "float",
536542
"what": Variable {
537543
"byref": false,
@@ -542,6 +548,7 @@ Program {
542548
},
543549
Cast {
544550
"kind": "cast",
551+
"raw": "(real)",
545552
"type": "float",
546553
"what": Variable {
547554
"byref": false,
@@ -552,6 +559,7 @@ Program {
552559
},
553560
Cast {
554561
"kind": "cast",
562+
"raw": "(string)",
555563
"type": "string",
556564
"what": Variable {
557565
"byref": false,
@@ -562,6 +570,7 @@ Program {
562570
},
563571
Cast {
564572
"kind": "cast",
573+
"raw": "(binary)",
565574
"type": "binary",
566575
"what": Variable {
567576
"byref": false,
@@ -572,6 +581,7 @@ Program {
572581
},
573582
Cast {
574583
"kind": "cast",
584+
"raw": "(array)",
575585
"type": "array",
576586
"what": Variable {
577587
"byref": false,
@@ -582,6 +592,7 @@ Program {
582592
},
583593
Cast {
584594
"kind": "cast",
595+
"raw": "(object)",
585596
"type": "object",
586597
"what": Variable {
587598
"byref": false,
@@ -592,6 +603,7 @@ Program {
592603
},
593604
Cast {
594605
"kind": "cast",
606+
"raw": "(unset)",
595607
"type": "unset",
596608
"what": Variable {
597609
"byref": false,

0 commit comments

Comments
 (0)