Skip to content

Commit

Permalink
drag more abstract information through XmlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jun 15, 2013
1 parent 25030ce commit fca88c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 5 additions & 3 deletions genxml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ let rec gen_type_decl com pos t =
| TAbstractDecl a ->
let doc = gen_doc_opt a.a_doc in
let meta = gen_meta a.a_meta in
let sub = (match a.a_from with [] -> [] | l -> [node "from" [] (List.map (fun (t,_) -> gen_type t) l)]) in
let super = (match a.a_to with [] -> [] | l -> [node "to" [] (List.map (fun (t,_) -> gen_type t) l)]) in
let mk_cast (t,cfo) = node "icast" (match cfo with None -> [] | Some cf -> ["field",cf.cf_name]) [gen_type t] in
let sub = (match a.a_from with [] -> [] | l -> [node "from" [] (List.map mk_cast l)]) in
let super = (match a.a_to with [] -> [] | l -> [node "to" [] (List.map mk_cast l)]) in
let impl = (match a.a_impl with None -> [] | Some c -> [node "impl" [] [gen_type_decl com pos (TClassDecl c)]]) in
node "abstract" (gen_type_params pos a.a_private (tpath t) a.a_types a.a_pos m) (sub @ super @ doc @ meta @ impl)
let this = [node "this" [] [gen_type a.a_this]] in
node "abstract" (gen_type_params pos a.a_private (tpath t) a.a_types a.a_pos m) (sub @ this @ super @ doc @ meta @ impl)

let att_str att =
String.concat "" (List.map (fun (a,v) -> Printf.sprintf " %s=\"%s\"" a v) att)
Expand Down
5 changes: 3 additions & 2 deletions std/haxe/rtti/CType.hx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ typedef Typedef = {> TypeInfos,
}

typedef Abstractdef = {> TypeInfos,
var subs : Array<CType>;
var supers : Array<CType>;
var to : Array<{t:CType, field:Null<String>}>;
var from : Array<{t:CType, field:Null<String>}>;
var impl : Classdef;
var athis : CType;
}

enum TypeTree {
Expand Down
25 changes: 14 additions & 11 deletions std/haxe/rtti/XmlParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ class XmlParser {
function mergeAbstracts( a : Abstractdef, a2 : Abstractdef ) {
if( curplatform == null )
return false;
if( a.subs.length != a2.subs.length || a.supers.length != a2.supers.length )
if( a.to.length != a2.to.length || a.from.length != a2.from.length )
return false;
for( i in 0...a.subs.length )
if( !TypeApi.typeEq(a.subs[i],a2.subs[i]) )
for( i in 0...a.to.length )
if( !TypeApi.typeEq(a.to[i].t,a2.to[i].t) )
return false;
for( i in 0...a.supers.length )
if( !TypeApi.typeEq(a.supers[i],a2.supers[i]) )
for( i in 0...a.from.length )
if( !TypeApi.typeEq(a.from[i].t,a2.from[i].t) )
return false;
if (a2.impl != null) mergeClasses(a.impl, a2.impl);
a.platforms.add(curplatform);
Expand Down Expand Up @@ -478,8 +478,8 @@ class XmlParser {
}

function xabstract( x : Fast ) : Abstractdef {
var doc = null, impl = null;
var meta = [], subs = [], supers = [];
var doc = null, impl = null, athis = null;
var meta = [], to = [], from = [];
for( c in x.elements )
switch( c.name ) {
case "haxe_doc":
Expand All @@ -488,12 +488,14 @@ class XmlParser {
meta = xmeta(c);
case "to":
for( t in c.elements )
subs.push(xtype(t));
to.push({t: xtype(new Fast(t.x.firstElement())), field: t.has.field ? t.att.field : null});
case "from":
for( t in c.elements )
supers.push(xtype(t));
from.push({t: xtype(new Fast(t.x.firstElement())), field: t.has.field ? t.att.field : null});
case "impl":
impl = xclass(c.node.resolve("class"));
case "this":
athis = xtype(new Fast(c.x.firstElement()));
default:
xerror(c);
}
Expand All @@ -506,8 +508,9 @@ class XmlParser {
params : mkTypeParams(x.att.params),
platforms : defplat(),
meta : meta,
subs : subs,
supers : supers,
athis : athis,
to : to,
from : from,
impl: impl
};
}
Expand Down

0 comments on commit fca88c3

Please sign in to comment.