- If objParam And (decl.IsMethod() Or decl.isCtor()) And ((Not decl.IsExtern()) Or (decl.IsExtern() And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct())) Then
- ' object cast to match param type
- If TClassDecl(decl.scope) Then
- t :+ Bra(TransObject(TClassDecl(decl.scope).GetLatestFuncDecl(decl).scope, TClassDecl(decl.scope).IsStruct()))
- End If
- t:+ objParam
- End If
- For Local i:Int=0 Until decl.argDecls.Length
- Local ty:TType = TArgDecl(decl.argDecls[i].actual).ty
-
- If t t:+","
- If i < args.length
- Local arg:TExpr = args[i]
-
- ' object cast to match param type
- If TObjectType(ty) And Not TObjectType(ty).classDecl.IsStruct() Then
- t :+ Bra(TransObject(TObjectType(TArgDecl(fdecl.argDecls[i].actual).ty).classDecl))
- End If
-
- If TNullExpr(arg) Then
- t :+ TransValue(ty, Null)
- Continue
- Else If TIndexExpr(arg) And (ty._flags & TType.T_VAR) Then
- t:+ "&"
- Else If TStringType(ty) And (ty._flags & TType.T_VAR) Then
- If TCastExpr(arg) And TStringType(TCastExpr(arg).expr.exprType) Then
- t:+ "&"
- End If
- Else If TArrayType(ty) And (ty._flags & TType.T_VAR) Then
- If (TVarExpr(arg) And TArrayType(TVarExpr(arg).exprType) Or (TMemberVarExpr(arg) And TArrayType(TMemberVarExpr(arg).exprType))) And Not (arg.exprType._flags & TType.T_VAR) Then
- t:+ "&"
- End If
- Else If TObjectType(ty) And (ty._flags & TType.T_VAR) Then
- If (TVarExpr(arg) Or TMemberVarExpr(arg)) And TObjectType(arg.exprType) And Not (arg.exprType._flags & TType.T_VAR) Then
- t:+ "&"
- End If
- Else If TFunctionPtrType(ty) Or IsPointerType(ty, TType.T_BYTE) Then
-
- If TFunctionPtrType(ty) And (ty._flags & TType.T_VAR) Then
- t:+ "&"
- End If
-
- If TInvokeExpr(arg) And Not TInvokeExpr(arg).decl.IsMethod() Then
- If IsPointerType(ty, TType.T_BYTE) Then
- t:+ TInvokeExpr(arg).Trans()
- Else
- ' need to test scopes to see if we need to use the current instance's function or not
- ' use the "actual", not the copy we made for the function pointer.
- Local fdecl:TFuncDecl = TFuncDecl(TInvokeExpr(arg).decl.actual)
- If Not fdecl.munged Then
- MungDecl fdecl
- TInvokeExpr(arg).decl.munged = fdecl.munged
- End If
-
- If TClassDecl(fdecl.scope) Then
- ' current scope is related to function scope?
- If _env.ClassScope() And _env.FuncScope() And _env.FuncScope().IsMethod() Then
- If _env.ClassScope().ExtendsClass(TClassDecl(fdecl.scope)) Then
- Local scope:TScopeDecl = _env.scope
- Local obj:String = Bra("struct " + scope.munged + "_obj*")
- Local class:String = "o->clas"
-
- t:+ class + "->f_" + fdecl.ident + MangleMethod(fdecl)
- Else
- t:+ fdecl.munged
- End If
- Else
- t:+ fdecl.munged
- End If
- Else
- t:+ fdecl.munged
- End If
- End If
- Continue
- End If
- ' some cases where we are passing a function pointer via a void* parameter.
- If TCastExpr(arg) And TInvokeExpr(TCastExpr(arg).expr) And Not TInvokeExpr(TCastExpr(arg).expr).invokedWithBraces Then
- If Not TInvokeExpr(TCastExpr(arg).expr).decl.munged Then
- If TStringType(stmt.lhs.exprType) 'Or TStringVarPtrType(stmt.lhs.exprType) Then
-' s:+ "{"
-' s:+ "BBSTRING tmp=" + lhs + ";~n"
-
- If stmt.op = ":+" Then
- s :+ lhs+"=bbStringConcat("+lhs+","+rhs+")"
- Else If rhs = "&bbNullObject" Then
- s :+ lhs+TransAssignOp( stmt.op )+"&bbEmptyString"
- Else
- s :+ lhs+TransAssignOp( stmt.op )+rhs
- End If
-
-' s :+ ";~nBBRETAIN(" + lhs +")~n"
-' s :+ "BBRELEASE(tmp)~n"
-
-' s:+ "}"
- Else If TVarPtrType(stmt.lhs.exprType) Then
-
- If TCastExpr(stmt.rhs) And IsNumericType(TCastExpr(stmt.rhs).expr.exprType) Then
- rhs = TCastExpr(stmt.rhs).expr.Trans()
- End If
-
- s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
- Else If TArrayType(stmt.lhs.exprType) Then
- If stmt.op = ":+" Then
- s :+ lhs+"=bbArrayConcat("+ TransArrayType(TArrayType(stmt.lhs.exprType).elemType) + "," + lhs+","+rhs+")"
- Else If rhs = "&bbNullObject" Then
- s :+ lhs+TransAssignOp( stmt.op )+"&bbEmptyArray"
- Else
- s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
- End If
- Else If (TFunctionPtrType(stmt.lhs.exprType) <> Null Or IsPointerType(stmt.lhs.exprType, TType.T_BYTE)) And TInvokeExpr(stmt.rhs) And Not TInvokeExpr(stmt.rhs).invokedWithBraces Then
- ' only initialise fields if we are not chaining to a local (in our class) constructor.
- ' this prevents fields being re-initialised through the call-chain.
- If Not newDecl.chainedCtor Or (newDecl.chainedCtor And classDecl <> newDecl.chainedCtor.ctor.scope) Then
-
- ' field initialisation
- For Local decl:TFieldDecl=EachIn classDecl.Decls()
-
- Local fld:String
-
- ' ((int*)((char*)o + 5))[0] =
- fld :+ TransFieldRef(decl, "o")
-
- If decl.init Then
- If TObjectType(decl.ty) And TObjectType(decl.ty).classdecl.IsExtern() And TObjectType(decl.ty).classdecl.IsStruct() Then
- ' skip for uninitialised extern type
- If Not isPointerType(decl.ty) And TConstExpr(decl.init) And Not TConstExpr(decl.init).value Then
- Continue
- End If
- End If
-
- ' initial value
- If (TConstExpr(decl.init) And Not TConstExpr(decl.init).value) And TIntrinsicType(decl.ty) Then
- fld :+ "= "
- If TFloat64Type(decl.ty) Then
- fld :+ "_mm_setzero_si64();"
- Else If TFloat128Type(decl.ty) Then
- fld :+ "_mm_setzero_ps();"
- Else If TDouble128Type(decl.ty) Then
- fld :+ "_mm_setzero_pd();"
- Else If TInt128Type(decl.ty) Then
- fld :+ "_mm_setzero_si128();"
- End If
- Else
- If TObjectType(decl.ty) And TObjectType(decl.ty).classdecl.IsStruct() And Not isPointerType(decl.ty) And (TConstExpr(decl.init) And Not TConstExpr(decl.init).value) Then
+ If objParam And (decl.IsMethod() Or decl.isCtor()) And ((Not decl.IsExtern()) Or (decl.IsExtern() And TClassDecl(decl.scope) And Not TClassDecl(decl.scope).IsStruct())) Then
+ ' object cast to match param type
+ If TClassDecl(decl.scope) Then
+ t :+ Bra(TransObject(TClassDecl(decl.scope).GetLatestFuncDecl(decl).scope, TClassDecl(decl.scope).IsStruct()))
+ End If
+ t:+ objParam
+ End If
+ For Local i:Int=0 Until decl.argDecls.Length
+ Local ty:TType = TArgDecl(decl.argDecls[i].actual).ty
+
+ If t t:+","
+ If i < args.length
+ Local arg:TExpr = args[i]
+
+ ' object cast to match param type
+ If TObjectType(ty) And Not TObjectType(ty).classDecl.IsStruct() Then
+ t :+ Bra(TransObject(TObjectType(TArgDecl(fdecl.argDecls[i].actual).ty).classDecl))
+ End If
+
+ If TNullExpr(arg) Then
+ t :+ TransValue(ty, Null)
+ Continue
+ Else If TIndexExpr(arg) And (ty._flags & TType.T_VAR) Then
+ t:+ "&"
+ Else If TStringType(ty) And (ty._flags & TType.T_VAR) Then
+ If TCastExpr(arg) And TStringType(TCastExpr(arg).expr.exprType) Then
+ t:+ "&"
+ End If
+ Else If TArrayType(ty) And (ty._flags & TType.T_VAR) Then
+ If (TVarExpr(arg) And TArrayType(TVarExpr(arg).exprType) Or (TMemberVarExpr(arg) And TArrayType(TMemberVarExpr(arg).exprType))) And Not (arg.exprType._flags & TType.T_VAR) Then
+ t:+ "&"
+ End If
+ Else If TObjectType(ty) And (ty._flags & TType.T_VAR) Then
+ If (TVarExpr(arg) Or TMemberVarExpr(arg)) And TObjectType(arg.exprType) And Not (arg.exprType._flags & TType.T_VAR) Then
+ t:+ "&"
+ End If
+ Else If TFunctionPtrType(ty) Or IsPointerType(ty, TType.T_BYTE) Then
+
+ If TFunctionPtrType(ty) And (ty._flags & TType.T_VAR) Then
+ t:+ "&"
+ End If
+
+ If TInvokeExpr(arg) And Not TInvokeExpr(arg).decl.IsMethod() Then
+ If IsPointerType(ty, TType.T_BYTE) Then
+ t:+ TInvokeExpr(arg).Trans()
+ Else
+ ' need to test scopes to see if we need to use the current instance's function or not
+ ' use the "actual", not the copy we made for the function pointer.
+ Local fdecl:TFuncDecl = TFuncDecl(TInvokeExpr(arg).decl.actual)
+ If Not fdecl.munged Then
+ MungDecl fdecl
+ TInvokeExpr(arg).decl.munged = fdecl.munged
+ End If
+
+ If TClassDecl(fdecl.scope) Then
+ ' current scope is related to function scope?
+ If _env.ClassScope() And _env.FuncScope() And _env.FuncScope().IsMethod() Then
+ If _env.ClassScope().ExtendsClass(TClassDecl(fdecl.scope)) Then
+ Local scope:TScopeDecl = _env.scope
+ Local obj:String = Bra("struct " + scope.munged + "_obj*")
+ Local class:String = "o->clas"
+
+ t:+ class + "->f_" + fdecl.ident + MangleMethod(fdecl)
+ Else
+ t:+ fdecl.munged
+ End If
+ Else
+ t:+ fdecl.munged
+ End If
+ Else
+ t:+ fdecl.munged
+ End If
+ End If
+ Continue
+ End If
+ ' some cases where we are passing a function pointer via a void* parameter.
+ If TCastExpr(arg) And TInvokeExpr(TCastExpr(arg).expr) And Not TInvokeExpr(TCastExpr(arg).expr).invokedWithBraces Then
+ If Not TInvokeExpr(TCastExpr(arg).expr).decl.munged Then
+ If TStringType(stmt.lhs.exprType) 'Or TStringVarPtrType(stmt.lhs.exprType) Then
+' s:+ "{"
+' s:+ "BBSTRING tmp=" + lhs + ";~n"
+
+ If stmt.op = ":+" Then
+ s :+ lhs+"=bbStringConcat("+lhs+","+rhs+")"
+ Else If rhs = "&bbNullObject" Then
+ s :+ lhs+TransAssignOp( stmt.op )+"&bbEmptyString"
+ Else
+ s :+ lhs+TransAssignOp( stmt.op )+rhs
+ End If
+
+' s :+ ";~nBBRETAIN(" + lhs +")~n"
+' s :+ "BBRELEASE(tmp)~n"
+
+' s:+ "}"
+ Else If TVarPtrType(stmt.lhs.exprType) Then
+
+ If TCastExpr(stmt.rhs) And IsNumericType(TCastExpr(stmt.rhs).expr.exprType) Then
+ rhs = TCastExpr(stmt.rhs).expr.Trans()
+ End If
+
+ s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
+ Else If TArrayType(stmt.lhs.exprType) Then
+ If stmt.op = ":+" Then
+ s :+ lhs+"=bbArrayConcat("+ TransArrayType(TArrayType(stmt.lhs.exprType).elemType) + "," + lhs+","+rhs+")"
+ Else If rhs = "&bbNullObject" Then
+ s :+ lhs+TransAssignOp( stmt.op )+"&bbEmptyArray"
+ Else
+ s :+ lhs+TransAssignOp( stmt.op )+cast+rhs
+ End If
+ Else If (TFunctionPtrType(stmt.lhs.exprType) <> Null Or IsPointerType(stmt.lhs.exprType, TType.T_BYTE)) And TInvokeExpr(stmt.rhs) And Not TInvokeExpr(stmt.rhs).invokedWithBraces Then
+ ' only initialise fields if we are not chaining to a local (in our class) constructor.
+ ' this prevents fields being re-initialised through the call-chain.
+ If Not newDecl.chainedCtor Or (newDecl.chainedCtor And classDecl <> newDecl.chainedCtor.ctor.scope) Then
+
+ ' field initialisation
+ For Local decl:TFieldDecl=EachIn classDecl.Decls()
+
+ Local fld:String
+
+ ' ((int*)((char*)o + 5))[0] =
+ fld :+ TransFieldRef(decl, "o")
+
+ If decl.init Then
+ If TObjectType(decl.ty) And TObjectType(decl.ty).classdecl.IsExtern() And TObjectType(decl.ty).classdecl.IsStruct() Then
+ ' skip for uninitialised extern type
+ If Not isPointerType(decl.ty) And TConstExpr(decl.init) And Not TConstExpr(decl.init).value Then
+ Continue
+ End If
+ End If
+
+ ' initial value
+ If (TConstExpr(decl.init) And Not TConstExpr(decl.init).value) And TIntrinsicType(decl.ty) Then
+ fld :+ "= "
+ If TFloat64Type(decl.ty) Then
+ fld :+ "_mm_setzero_si64();"
+ Else If TFloat128Type(decl.ty) Then
+ fld :+ "_mm_setzero_ps();"
+ Else If TDouble128Type(decl.ty) Then
+ fld :+ "_mm_setzero_pd();"
+ Else If TInt128Type(decl.ty) Then
+ fld :+ "_mm_setzero_si128();"
+ End If
+ Else
+ If TObjectType(decl.ty) And TObjectType(decl.ty).classdecl.IsStruct() And Not isPointerType(decl.ty) And (TConstExpr(decl.init) And Not TConstExpr(decl.init).value) Then
- If checked Or func.IdentLower() = "tostring" Or func.IdentLower() = "compare" Or func.IdentLower() = "sendmessage" Or func.IdentLower() = "new" Or func.IdentLower() = "delete" Then
- If classDecl.munged = "bbObjectClass" Then
- For Local decl:TFuncDecl = EachIn classDecl.Decls()
- If TIndexExpr(expr.expr) And TArrayType(TIndexExpr(expr.expr).expr.exprType) And TFunctionPtrType(TArrayType(TIndexExpr(expr.expr).expr.exprType).elemType) Then
- Local decl:TDecl = TFunctionPtrType(TArrayType(TIndexExpr(expr.expr).expr.exprType).elemType).func.actual
- If stmt.rhs Return stmt.lhs.TransVar()+TransAssignOp(stmt.op)+stmt.rhs.Trans()
- Return stmt.lhs.Trans()
- End Method
-
- Method TransReturnStmt$( stmt:TReturnStmt )
-
- Local t$="return"
- unreachable=True
- If stmt.expr Then
-
- If TObjectType(stmt.expr.exprType) And TNullDecl(TObjectType(stmt.expr.exprType).classDecl) Then
- If IsPointerType(stmt.fRetType, 0, TType.T_POINTER) Or IsNumericType(stmt.fRetType) Then
- t:+ " 0"
- End If
- If TStringType(stmt.fRetType) Then
- t:+ " &bbEmptyString"
- End If
- If TArrayType(stmt.fRetType) Then
- t:+ " &bbEmptyArray"
- End If
-
- Else
-
- If TObjectType(stmt.expr.exprType) And TObjectType(stmt.expr.exprType).classDecl.IsStruct() And TConstExpr(stmt.expr) And Not TConstExpr(stmt.expr).value Then
- Local lvar:String = CreateLocal(stmt.expr)
- t :+ " " + lvar
- Else
-
- Local s:String
-
- ' cast to function return type
- If TObjectType(stmt.fRetType) Then
- s :+ Bra(transObject(TObjectType(stmt.fRetType).classDecl))
- End If
-
- s :+ stmt.expr.Trans()
-
- ' we have some temp variables that need to be freed before we can return
- ' put the results into a new variable, and return that.
- If customVarStack.Count() > 0 Then
- If Not TFunctionPtrType( stmt.expr.exprType ) Then
+ If checked Or func.IdentLower() = "tostring" Or func.IdentLower() = "compare" Or func.IdentLower() = "sendmessage" Or func.IdentLower() = "new" Or func.IdentLower() = "delete" Then
+ If classDecl.munged = "bbObjectClass" Then
+ For Local decl:TFuncDecl = EachIn classDecl.Decls()
+ If TIndexExpr(expr.expr) And TArrayType(TIndexExpr(expr.expr).expr.exprType) And TFunctionPtrType(TArrayType(TIndexExpr(expr.expr).expr.exprType).elemType) Then
+ Local decl:TDecl = TFunctionPtrType(TArrayType(TIndexExpr(expr.expr).expr.exprType).elemType).func.actual
+ If stmt.rhs Return stmt.lhs.TransVar()+TransAssignOp(stmt.op)+stmt.rhs.Trans()
+ Return stmt.lhs.Trans()
+ End Method
+
+ Method TransReturnStmt$( stmt:TReturnStmt )
+
+ Local t$="return"
+ unreachable=True
+ If stmt.expr Then
+
+ If TObjectType(stmt.expr.exprType) And TNullDecl(TObjectType(stmt.expr.exprType).classDecl) Then
+ If IsPointerType(stmt.fRetType, 0, TType.T_POINTER) Or IsNumericType(stmt.fRetType) Then
+ t:+ " 0"
+ End If
+ If TStringType(stmt.fRetType) Then
+ t:+ " &bbEmptyString"
+ End If
+ If TArrayType(stmt.fRetType) Then
+ t:+ " &bbEmptyArray"
+ End If
+
+ Else
+
+ If TObjectType(stmt.expr.exprType) And TObjectType(stmt.expr.exprType).classDecl.IsStruct() And TConstExpr(stmt.expr) And Not TConstExpr(stmt.expr).value Then
+ Local lvar:String = CreateLocal(stmt.expr)
+ t :+ " " + lvar
+ Else
+
+ Local s:String
+
+ ' cast to function return type
+ If TObjectType(stmt.fRetType) Then
+ s :+ Bra(transObject(TObjectType(stmt.fRetType).classDecl))
+ End If
+
+ s :+ stmt.expr.Trans()
+
+ ' we have some temp variables that need to be freed before we can return
+ ' put the results into a new variable, and return that.
+ If customVarStack.Count() > 0 Then
+ If Not TFunctionPtrType( stmt.expr.exprType ) Then