Skip to content

Commit db78e7e

Browse files
author
SlavaRa
authored
Fixed conversion of SomeClass['staticFieldName']. closes HaxeFoundation#234 (HaxeFoundation#272)
1 parent a6d525e commit db78e7e

7 files changed

Lines changed: 97 additions & 70 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bin/
22
build/
33
report/
4-
run.n
4+
run.n
5+
*.hxproj

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: haxe
33
haxe:
44
- development
55
- 3.4.2
6-
- 3.4.3
6+
- 3.4.4
77

88
os:
99
- linux

‎CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## dev
2+
- Fixed Conversion of `SomeClass['staticFieldName']` (fixes issue #234)
23
- Replace `navigateToURL` with `flash.Lib.getURL` (fixes issue #257)
34

45
## 2017-09-13(1.0.5)

‎src/as3hx/Writer.hx‎

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,75 @@ class Writer
950950
writeExpr(e);
951951
}
952952

953+
function writeEArray(e:Expr, index:Expr) {
954+
//write("/* EArray ("+Std.string(e)+","+Std.string(index)+") " + Std.string(getExprType(e, true)) + " */ ");
955+
var old = inArrayAccess;
956+
inArrayAccess = true;
957+
// this test can be generalized to any array[]->get() translation
958+
var etype = getExprType(e);
959+
var itype = getExprType(index);
960+
if(etype == "FastXML" || etype == "FastXMLList") {
961+
writeExpr(e);
962+
inArrayAccess = old;
963+
write(".get(");
964+
writeExpr(index);
965+
write(")");
966+
} else if(isMapType(etype)) {
967+
writeExpr(e);
968+
inArrayAccess = old;
969+
var oldInLVA = inLvalAssign;
970+
inLvalAssign = false;
971+
if (oldInLVA) {
972+
write(".set(");
973+
} else {
974+
write(".get(");
975+
}
976+
writeExpr(index);
977+
if (oldInLVA) {
978+
write(", ");
979+
writeExpr(rvalue);
980+
rvalue = null;
981+
}
982+
inLvalAssign = oldInLVA;
983+
write(")");
984+
} else {
985+
//write("/*!!!" + etype + "!!!*/");
986+
if(isDynamicType(etype) || ((isArrayType(etype) || e.match(EIdent(_))) && itype != null && itype != "Int" && itype != "UInt")) {
987+
if(cfg.debugInferredType) {
988+
write("/* etype: " + etype + " itype: " + itype + " */");
989+
}
990+
var isString = (itype == "String");
991+
var oldInLVA = inLvalAssign;
992+
inLvalAssign = false;
993+
if(oldInLVA)
994+
write("Reflect.setField(");
995+
else
996+
write("Reflect.field(");
997+
writeExpr(e);
998+
inArrayAccess = old;
999+
write(", ");
1000+
if(!isString)
1001+
write("Std.string(");
1002+
writeExpr(index);
1003+
if(!isString)
1004+
write(")");
1005+
if(oldInLVA) {
1006+
write(", ");
1007+
writeExpr(rvalue);
1008+
rvalue = null;
1009+
}
1010+
inLvalAssign = oldInLVA;
1011+
write(")");
1012+
} else {
1013+
writeExpr(e);
1014+
inArrayAccess = old;
1015+
write("[");
1016+
writeExpr(index);
1017+
write("]");
1018+
}
1019+
}
1020+
}
1021+
9531022
function writeLoop(incrs:Array<Expr>, f:Void->Void) {
9541023
var old = loopIncrements;
9551024
loopIncrements = incrs.slice(0);
@@ -1122,73 +1191,7 @@ class Writer
11221191
case EContinue: rv = writeEContinue();
11231192
case EFunction(f, name): writeFunction(f, false, false, false, name);
11241193
case EReturn(e): writeEReturn(e);
1125-
case EArray(e, index):
1126-
//write("/* EArray ("+Std.string(e)+","+Std.string(index)+") " + Std.string(getExprType(e, true)) + " */ ");
1127-
var old = inArrayAccess;
1128-
inArrayAccess = true;
1129-
// this test can be generalized to any array[]->get() translation
1130-
var etype = getExprType(e);
1131-
var itype = getExprType(index);
1132-
if(etype == "FastXML" || etype == "FastXMLList") {
1133-
writeExpr(e);
1134-
inArrayAccess = old;
1135-
write(".get(");
1136-
writeExpr(index);
1137-
write(")");
1138-
} else if (isMapType(etype)) {
1139-
writeExpr(e);
1140-
inArrayAccess = old;
1141-
var oldInLVA = inLvalAssign;
1142-
inLvalAssign = false;
1143-
if (oldInLVA) {
1144-
write(".set(");
1145-
} else {
1146-
write(".get(");
1147-
}
1148-
writeExpr(index);
1149-
if (oldInLVA) {
1150-
write(", ");
1151-
writeExpr(rvalue);
1152-
rvalue = null;
1153-
}
1154-
inLvalAssign = oldInLVA;
1155-
write(")");
1156-
} else {
1157-
//write("/*!!!" + etype + "!!!*/");
1158-
if(isDynamicType(etype) || (isArrayType(etype) && itype != null && itype != "Int" && itype != "UInt")) {
1159-
if (cfg.debugInferredType) {
1160-
write("/* etype: " + etype + " itype: " + itype + " */");
1161-
}
1162-
var isString = (itype == "String");
1163-
var oldInLVA = inLvalAssign;
1164-
inLvalAssign = false;
1165-
if(oldInLVA)
1166-
write("Reflect.setField(");
1167-
else
1168-
write("Reflect.field(");
1169-
writeExpr(e);
1170-
inArrayAccess = old;
1171-
write(", ");
1172-
if(!isString)
1173-
write("Std.string(");
1174-
writeExpr(index);
1175-
if(!isString)
1176-
write(")");
1177-
if(oldInLVA) {
1178-
write(", ");
1179-
writeExpr(rvalue);
1180-
rvalue = null;
1181-
}
1182-
inLvalAssign = oldInLVA;
1183-
write(")");
1184-
} else {
1185-
writeExpr(e);
1186-
inArrayAccess = old;
1187-
write("[");
1188-
writeExpr(index);
1189-
write("]");
1190-
}
1191-
}
1194+
case EArray(e, index): writeEArray(e, index);
11921195
case EArrayDecl(e):
11931196
var enl = false;
11941197
write("[");
@@ -3043,7 +3046,7 @@ class Writer
30433046
* Checks if 'e' represents a numerical constant value
30443047
* @return true if so
30453048
*/
3046-
static inline function isNumericConst(e:Expr) : Bool return switch(e) {
3049+
static inline function isNumericConst(e:Expr):Bool return switch(e) {
30473050
case EConst(c): c.match(CInt(_)) || c.match(CFloat(_));
30483051
default: false;
30493052
}

‎test/issues/Issue234.as‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package {
2+
import flash.display3D.Context3D;
3+
public class Issue234 {
4+
public function Issue234() {
5+
var supportsVideoTexture:Boolean = Context3D["supportsVideoTexture"];
6+
}
7+
}
8+
}

‎test/issues/Issue234.hx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import flash.display3D.Context3D;
2+
3+
class Issue234
4+
{
5+
public function new()
6+
{
7+
var supportsVideoTexture : Bool = Reflect.field(Context3D, "supportsVideoTexture");
8+
}
9+
}

‎test/unit/as3hx/AS3HXTest.hx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ class AS3HXTest {
466466
generate("Issue257.as", "Issue257.hx");
467467
}
468468

469+
@Test("flash.display3D.Context3D['supportsVideoTexture'] -> Reflect.field(flash.display3D.Context3D, 'supportsVideoTexture')")
470+
public function issue234() {
471+
generate("Issue234.as", "Issue234.hx");
472+
}
473+
469474
function generate(as3FileName:String, expectedHaxeFileName:String) {
470475
var issuesDirectory = FileSystem.absolutePath("test/issues");
471476
var generatedDirectoryPath = '$issuesDirectory/generated';

0 commit comments

Comments
 (0)