@@ -1109,8 +1109,7 @@ export class Compiler extends DiagnosticEmitter {
1109
1109
if ( instance . is ( CommonFlags . CONSTRUCTOR ) ) {
1110
1110
let nativeSizeType = this . options . nativeSizeType ;
1111
1111
assert ( instance . is ( CommonFlags . INSTANCE ) ) ;
1112
- let parent = assert ( instance . parent ) ;
1113
- assert ( parent . kind == ElementKind . CLASS ) ;
1112
+ let classInstance = assert ( instance . parent ) ; assert ( classInstance . kind == ElementKind . CLASS ) ;
1114
1113
1115
1114
// implicitly return `this` if the constructor doesn't always return on its own
1116
1115
if ( ! flow . is ( FlowFlags . RETURNS ) ) {
@@ -1128,19 +1127,19 @@ export class Compiler extends DiagnosticEmitter {
1128
1127
module . createGetLocal ( 0 , nativeSizeType )
1129
1128
) ,
1130
1129
module . createSetLocal ( 0 ,
1131
- this . makeAllocation ( < Class > parent )
1130
+ this . makeAllocation ( < Class > classInstance )
1132
1131
)
1133
1132
)
1134
1133
) ;
1135
- this . makeFieldInitialization ( < Class > parent , stmts ) ;
1134
+ this . makeFieldInitialization ( < Class > classInstance , stmts ) ;
1136
1135
}
1137
1136
stmts . push (
1138
1137
module . createGetLocal ( 0 , nativeSizeType )
1139
1138
) ;
1140
1139
}
1141
1140
1142
1141
// check that super has been called if this is a derived class
1143
- if ( ( < Class > parent ) . base && ! flow . is ( FlowFlags . CALLS_SUPER ) ) {
1142
+ if ( ( < Class > classInstance ) . base && ! flow . is ( FlowFlags . CALLS_SUPER ) ) {
1144
1143
this . error (
1145
1144
DiagnosticCode . Constructors_for_derived_classes_must_contain_a_super_call ,
1146
1145
instance . prototype . declaration . range
@@ -4699,8 +4698,7 @@ export class Compiler extends DiagnosticEmitter {
4699
4698
var argumentExpressions : Expression [ ] ;
4700
4699
var thisArg : ExpressionRef = 0 ;
4701
4700
if ( operatorInstance . is ( CommonFlags . INSTANCE ) ) {
4702
- let parent = assert ( operatorInstance . parent ) ;
4703
- assert ( parent . kind == ElementKind . CLASS ) ;
4701
+ let classInstance = assert ( operatorInstance . parent ) ; assert ( classInstance . kind == ElementKind . CLASS ) ;
4704
4702
thisArg = leftExpr ; // can reuse the previously evaluated leftExpr as the this value here
4705
4703
argumentExpressions = [ right ] ;
4706
4704
} else {
@@ -5521,8 +5519,7 @@ export class Compiler extends DiagnosticEmitter {
5521
5519
// here, with their respective locals being blocked. There is no 'makeCallInline'.
5522
5520
var body = [ ] ;
5523
5521
if ( thisArg ) {
5524
- let parent = assert ( instance . parent ) ;
5525
- assert ( parent . kind == ElementKind . CLASS ) ;
5522
+ let classInstance = assert ( instance . parent ) ; assert ( classInstance . kind == ElementKind . CLASS ) ;
5526
5523
let thisType = assert ( instance . signature . thisType ) ;
5527
5524
let classType = thisType . classReference ;
5528
5525
let superType = classType
@@ -6093,8 +6090,7 @@ export class Compiler extends DiagnosticEmitter {
6093
6090
}
6094
6091
if ( currentFunction . is ( CommonFlags . INSTANCE ) ) {
6095
6092
let thisLocal = assert ( flow . getScopedLocal ( "this" ) ) ;
6096
- let parent = assert ( currentFunction . parent ) ;
6097
- assert ( parent . kind == ElementKind . CLASS ) ;
6093
+ let classInstance = assert ( currentFunction . parent ) ; assert ( classInstance . kind == ElementKind . CLASS ) ;
6098
6094
let nativeSizeType = this . options . nativeSizeType ;
6099
6095
if ( currentFunction . is ( CommonFlags . CONSTRUCTOR ) ) {
6100
6096
if ( ! flow . is ( FlowFlags . ALLOCATES ) ) {
@@ -6111,11 +6107,11 @@ export class Compiler extends DiagnosticEmitter {
6111
6107
module . createGetLocal ( thisLocal . index , nativeSizeType )
6112
6108
) ,
6113
6109
module . createSetLocal ( thisLocal . index ,
6114
- this . makeAllocation ( < Class > parent )
6110
+ this . makeAllocation ( < Class > classInstance )
6115
6111
)
6116
6112
)
6117
6113
] ;
6118
- this . makeFieldInitialization ( < Class > parent , stmts ) ;
6114
+ this . makeFieldInitialization ( < Class > classInstance , stmts ) ;
6119
6115
stmts . push (
6120
6116
module . createGetLocal ( thisLocal . index , nativeSizeType )
6121
6117
) ;
@@ -6158,11 +6154,10 @@ export class Compiler extends DiagnosticEmitter {
6158
6154
}
6159
6155
}
6160
6156
if ( currentFunction . is ( CommonFlags . INSTANCE ) ) {
6161
- let parent = assert ( currentFunction . parent ) ;
6162
- assert ( parent . kind == ElementKind . CLASS ) ;
6163
- let base = ( < Class > parent ) . base ;
6164
- if ( base ) {
6165
- let superType = base . type ;
6157
+ let classInstance = assert ( currentFunction . parent ) ; assert ( classInstance . kind == ElementKind . CLASS ) ;
6158
+ let baseClassInstance = ( < Class > classInstance ) . base ;
6159
+ if ( baseClassInstance ) {
6160
+ let superType = baseClassInstance . type ;
6166
6161
this . currentType = superType ;
6167
6162
return module . createGetLocal ( 0 , superType . toNativeType ( ) ) ;
6168
6163
}
@@ -6774,10 +6769,18 @@ export class Compiler extends DiagnosticEmitter {
6774
6769
ctorInstance . set ( CommonFlags . INSTANCE | CommonFlags . CONSTRUCTOR | CommonFlags . COMPILED ) ;
6775
6770
classInstance . constructorInstance = ctorInstance ;
6776
6771
6777
- // start with a conditional allocation (i.e. if called with zero as the first argument)
6772
+ // generate body
6778
6773
var module = this . module ;
6779
6774
var nativeSizeType = this . options . nativeSizeType ;
6780
6775
var stmts = new Array < ExpressionRef > ( ) ;
6776
+
6777
+ // {
6778
+ // if (!this) this = <ALLOC>
6779
+ // IF_DERIVED: this = super(this, ...args)
6780
+ // this.a = X
6781
+ // this.b = Y
6782
+ // return this
6783
+ // }
6781
6784
stmts . push (
6782
6785
module . createIf (
6783
6786
module . createUnary ( nativeSizeType == NativeType . I64 ? UnaryOp . EqzI64 : UnaryOp . EqzI32 ,
@@ -6788,8 +6791,6 @@ export class Compiler extends DiagnosticEmitter {
6788
6791
)
6789
6792
)
6790
6793
) ;
6791
-
6792
- // call the super constructor if this is a derived class
6793
6794
if ( baseClass ) {
6794
6795
let parameterTypes = signature . parameterTypes ;
6795
6796
let numParameters = parameterTypes . length ;
@@ -6804,8 +6805,6 @@ export class Compiler extends DiagnosticEmitter {
6804
6805
)
6805
6806
) ;
6806
6807
}
6807
-
6808
- // initialize own fields and return `this`
6809
6808
this . makeFieldInitialization ( classInstance , stmts ) ;
6810
6809
stmts . push (
6811
6810
module . createGetLocal ( 0 , nativeSizeType )
@@ -6876,9 +6875,8 @@ export class Compiler extends DiagnosticEmitter {
6876
6875
return module . createGetGlobal ( ( < Global > target ) . internalName , globalType . toNativeType ( ) ) ;
6877
6876
}
6878
6877
case ElementKind . ENUMVALUE : { // enum value
6879
- let parent = ( < EnumValue > target ) . parent ;
6880
- assert ( parent !== null && parent . kind == ElementKind . ENUM ) ;
6881
- if ( ! this . compileEnum ( < Enum > parent ) ) {
6878
+ let theEnum = assert ( ( < EnumValue > target ) . parent ) ; assert ( theEnum . kind == ElementKind . ENUM ) ;
6879
+ if ( ! this . compileEnum ( < Enum > theEnum ) ) {
6882
6880
this . currentType = Type . i32 ;
6883
6881
return this . module . createUnreachable ( ) ;
6884
6882
}
@@ -6939,8 +6937,7 @@ export class Compiler extends DiagnosticEmitter {
6939
6937
}
6940
6938
let inline = ( instance . decoratorFlags & DecoratorFlags . INLINE ) != 0 ;
6941
6939
if ( instance . is ( CommonFlags . INSTANCE ) ) {
6942
- let parent = assert ( instance . parent ) ;
6943
- assert ( parent . kind == ElementKind . CLASS ) ;
6940
+ let classInstance = assert ( instance . parent ) ; assert ( classInstance . kind == ElementKind . CLASS ) ;
6944
6941
let thisExpression = assert ( this . resolver . currentThisExpression ) ; //!!!
6945
6942
let thisExpr = this . compileExpressionRetainType (
6946
6943
thisExpression ,
0 commit comments