Explorar el Código

new haxe.rtti package.

Nicolas Cannasse hace 19 años
padre
commit
300d9ae731

+ 4 - 0
std/haxe/ImportAll.hx

@@ -72,6 +72,10 @@ import haxe.remoting.SocketBuffer;
 import haxe.remoting.SocketConnection;
 #end
 
+import haxe.rtti.Infos;
+import haxe.rtti.Type;
+import haxe.rtti.XmlParser;
+
 import haxe.xml.Check;
 import haxe.xml.Fast;
 

+ 32 - 0
std/haxe/rtti/Infos.hx

@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2006, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package haxe.rtti;
+
+/**
+	This is a magic interface. When a class implements [haxe.rtti.Infos], this class and all its
+	subclass will get an additional static field [__rtti] storing the class type informations.
+**/
+interface Infos {
+}

+ 1 - 1
std/tools/haxedoc/Type.hx → std/haxe/rtti/Type.hx

@@ -1,4 +1,4 @@
-package tools.haxedoc;
+package haxe.rtti;
 
 typedef Path = String
 

+ 21 - 18
std/tools/haxedoc/XmlParser.hx → std/haxe/rtti/XmlParser.hx

@@ -1,5 +1,5 @@
-package tools.haxedoc;
-import tools.haxedoc.Type;
+package haxe.rtti;
+import haxe.rtti.Type;
 import haxe.xml.Fast;
 
 class XmlParser {
@@ -10,7 +10,7 @@ class XmlParser {
 	public function new() {
 		root = new Array();
 	}
-	
+
 	public function sort( ?l ) {
 		if( l == null ) l = root;
 		l.sort(function(e1,e2) {
@@ -147,7 +147,11 @@ class XmlParser {
 		}
 		var prev = null;
 		for( ct in cur ) {
-			var tinf = try TypeApi.typeInfos(ct) catch( e : Dynamic ) continue;
+			var tinf;
+			try
+				tinf = TypeApi.typeInfos(ct)
+			catch( e : Dynamic )
+				continue;			
 			// compare params ?
 			if( tinf.path == inf.path ) {
 				if( tinf.module == inf.module && tinf.doc == inf.doc && tinf.isPrivate == inf.isPrivate )					
@@ -204,20 +208,19 @@ class XmlParser {
 	}
 	
 	function xroot( x : Fast ) {		
-		for( c in x.elements )
-			switch( c.name ) {
-			case "class":
-				var cl = xclass(c);
-				merge(TClassdecl(cl));
-			case "enum":
-				var e = xenum(c);
-				merge(TEnumdecl(e));
-			case "typedef":
-				var td = xtypedef(c);
-				merge(TTypedecl(td));
-			default:
-				xerror(c);
-			}
+		for( c in x.x.elements() )
+			merge(processElement(c));
+			
+	}
+	
+	public function processElement( x : Xml ) {
+		var c = new haxe.xml.Fast(x);
+		return switch( c.name ) {
+		case "class": TClassdecl(xclass(c));
+		case "enum": TEnumdecl(xenum(c));
+		case "typedef": TTypedecl(xtypedef(c));
+		default: xerror(c);
+		}
 	}
 	
 	function xpath( x : Fast ) : PathParams {

+ 1 - 1
std/neko/db/Object.hx

@@ -28,7 +28,7 @@ package neko.db;
 	SPOD Object : the persistent object base type. See the tutorial on haXe
 	website to learn how to use SPOD.
 **/
-class Object {
+class Object implements haxe.rtti.Infos {
 
 /*
 	(optional)

+ 1 - 1
std/tools/haxedoc/HtmlPrinter.hx

@@ -1,5 +1,5 @@
 package tools.haxedoc;
-import tools.haxedoc.Type;
+import haxe.rtti.Type;
 
 class HtmlPrinter {
 

+ 2 - 2
std/tools/haxedoc/Main.hx

@@ -23,11 +23,11 @@
  * DAMAGE.
  */
 package tools.haxedoc;
-import tools.haxedoc.Type;
+import haxe.rtti.Type;
 
 class Main {
 
-	static var parser = new XmlParser();
+	static var parser = new haxe.rtti.XmlParser();
 
 	static function loadFile(file,platform) {
 		var data = neko.io.File.getContent(neko.Web.getCwd()+file);

+ 0 - 1
std/tools/haxedoc/haxedoc.hxml

@@ -2,4 +2,3 @@
 -neko haxedoc.n
 -main tools.haxedoc.Main
 -cmd nekotools boot haxedoc.n
-tools.haxedoc.XmlParser

+ 1 - 1
typer.ml

@@ -2398,7 +2398,7 @@ type state =
 let rec has_rtti c =
 	List.exists (function (t,pl) -> 
 		match t, pl with 
-		| { cl_path = ["haxe"],"Rtti" },[] -> true
+		| { cl_path = ["haxe";"rtti"],"Infos" },[] -> true
 		| _ -> false
 	) c.cl_implements || (match c.cl_super with None -> false | Some (c,_) -> has_rtti c)