ソースを参照

[php7] wipe out untyped code from _std

Alexander Kuzmenko 8 年 前
コミット
25a63f4d9f

+ 15 - 0
std/php7/Global.hx

@@ -1050,4 +1050,19 @@ extern class Global {
 		@see http://php.net/manual/en/function.getprotobyname.php
 	**/
 	static function getprotobyname( name:String ) : EitherType<Int,Bool>;
+
+	/**
+		@see http://php.net/manual/en/function.mktime.php
+	**/
+	static function mktime( ?hour:Int, ?minute:Int, ?second:Int, ?month:Int, ?day:Int, ?year:Int, ?is_dst:Int ) : EitherType<Int,Bool>;
+
+	/**
+		@see http://php.net/manual/en/function.date.php
+	**/
+	static function date( format:String, ?timestamp:Int ) : EitherType<String,Bool>;
+
+	/**
+		@see http://php.net/manual/en/function.strtotime.php
+	**/
+	static function strtotime( time:String, ?now:Int ) : EitherType<Int,Bool>;
 }

+ 18 - 14
std/php7/_std/Date.hx

@@ -19,16 +19,20 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
+
+import php.Global.*;
+import php.Syntax.*;
+
 @:coreApi @:final class Date
 {
 	private var __t : Float;
 
 	public function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) : Void {
-		__t = untyped __call__("mktime", hour, min, sec, month+1, day, year);
+		__t = mktime(hour, min, sec, month + 1, day, year);
 	}
 
 	public function getTime() : Float {
-		return __t * 1000;
+		return __t * 1000.0;
 	}
 
 	private function getPhpTime() : Float {
@@ -36,56 +40,56 @@
 	}
 
 	public function getFullYear() : Int {
-		return untyped __call__("intval", __call__("date", "Y", this.__t));
+		return int(date("Y", int(__t)));
 	}
 
 	public function getMonth() : Int {
-		var m : Int = untyped __call__("intval", __call__("date", "n", this.__t));
+		var m : Int = int(date("n", int(__t)));
 		return -1 + m;
 	}
 
 	public function getDate() : Int {
-		return untyped __call__("intval", __call__("date", "j", this.__t));
+		return int(date("j", int(__t)));
 	}
 
 	public function getHours() : Int {
-		return untyped __call__("intval", __call__("date", "G", this.__t));
+		return int(date("G", int(__t)));
 	}
 
 	public function getMinutes() : Int {
-		return untyped __call__("intval", __call__("date", "i", this.__t));
+		return int(date("i", int(__t)));
 	}
 
 	public function getSeconds() : Int {
-		return untyped __call__("intval", __call__("date", "s", this.__t));
+		return int(date("s", int(__t)));
 	}
 
 	public function getDay() : Int {
-		return untyped __call__("intval", __call__("date", "w", this.__t));
+		return int(date("w", int(__t)));
 	}
 
 	public function toString():String {
-		return untyped __call__("date", "Y-m-d H:i:s", this.__t);
+		return date("Y-m-d H:i:s", int(__t));
 	}
 
 	public static function now() : Date {
-		return fromPhpTime(untyped __call__("round", __call__("microtime", true), 3));
+		return fromPhpTime(round(microtime(true), 3));
 	}
 
 	static function fromPhpTime( t : Float ) : Date {
-		var d = new Date(2000,1,1,0,0,0);
+		var d = new Date(2000, 1, 1, 0, 0, 0);
 		d.__t = t;
 		return d;
 	}
 
 	public static function fromTime( t : Float ) : Date {
-		var d = new Date(2000,1,1,0,0,0);
+		var d = new Date(2000, 1, 1, 0, 0, 0);
 		d.__t = t / 1000;
 		return d;
 	}
 
 	public static function fromString( s : String ) : Date {
-		return fromPhpTime(untyped __call__("strtotime", s));
+		return fromPhpTime(strtotime(s));
 	}
 }
 

+ 4 - 3
std/php7/_std/Math.hx

@@ -22,6 +22,7 @@
 
 import php.Global;
 import php.Const;
+import php.Syntax.*;
 
 @:coreApi class Math {
 	public static var PI(default,null) : Float = Const.M_PI;
@@ -39,9 +40,9 @@ import php.Const;
 	public static inline function exp( v:Float ) : Float return Global.exp(v);
 	public static inline function log( v:Float ) : Float return Global.log(v);
 	public static inline function sqrt( v:Float ) : Float return Global.sqrt(v);
-	public static inline function round( v:Float ) : Int return untyped __call__("(int)floor", v + 0.5);
-	public static inline function floor( v:Float ) : Int return untyped __call__("(int)floor", v);
-	public static inline function ceil( v:Float ) : Int return untyped __call__("(int)ceil", v);
+	public static inline function round( v:Float ) : Int return int(Global.floor(v + 0.5));
+	public static inline function floor( v:Float ) : Int return int(Global.floor(v));
+	public static inline function ceil( v:Float ) : Int return int(Global.ceil(v));
 	public static inline function atan( v:Float ) : Float return Global.atan(v);
 	public static inline function asin( v:Float ) : Float return Global.asin(v);
 	public static inline function acos( v:Float ) : Float return Global.acos(v);

+ 1 - 1
std/php7/_std/Reflect.hx

@@ -151,7 +151,7 @@ using php.Global;
 
 	public static function deleteField( o : Dynamic, field : String ) : Bool {
 		if (hasField(o, field)) {
-			untyped Global.unset(Syntax.getField(o, field));
+			Global.unset(Syntax.getField(o, field));
 			return true;
 		} else {
 			return false;

+ 3 - 1
std/php7/_std/Std.hx

@@ -24,6 +24,8 @@ import php.Boot;
 
 import php.Global;
 import php.Const;
+import php.Syntax;
+
 @:keep
 @:coreApi class Std {
 
@@ -40,7 +42,7 @@ import php.Const;
 	}
 
 	public static inline function int( x : Float ) : Int {
-		return untyped __call__('(int)', x);
+		return Syntax.int(x);
 	}
 
 	public static function parseInt( x : String ) : Null<Int> {

+ 11 - 2
std/php7/_std/StringBuf.hx

@@ -19,6 +19,10 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
+
+import php.Global;
+import php.Syntax;
+
 @:coreApi class StringBuf {
 	private var b : String;
 
@@ -33,8 +37,13 @@
 	}
 
 	public function add<T>( x : T ) : Void {
-		untyped if( __call__('is_null',x) ) x = cast 'null' else if( __call__('is_bool',x) ) x = cast (x?'true':'false');
-		b += x;
+		if( x == null ) {
+			Syntax.binop(b, '.=', 'null');
+		} else if( Global.is_bool(x) ) {
+			Syntax.binop(b, '.=', ((x:Dynamic) ? 'true' : 'false'));
+		} else {
+			b += x;
+		}
 	}
 
 	public inline function addSub( s : String, pos : Int, ?len : Int ) : Void {