-
-
Save theJenix/30d588b78cd834415240671c834c427c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.macro.Expr; | |
import haxe.macro.Context; | |
class Build { | |
static public function types() { | |
var pos = Context.currentPos(); | |
function mkPath(name:String):TypePath { | |
var parts = name.split('.'); | |
return { | |
sub: null, | |
params: [], | |
name: parts.pop(), | |
pack: parts | |
} | |
} | |
function mkType(s:String):ComplexType | |
return TPath(mkPath(s)); | |
function mkField(name:String, type:ComplexType):Field | |
return { | |
pos: pos, | |
name: name, | |
meta: [], | |
kind: FVar(type), | |
doc: null, | |
access: [] | |
} | |
function declare(name:String, fields:Array<Field>, ?superType:TypePath) | |
Context.defineType({ | |
pos: pos, //the position the type is associated with - should probably point to your XML file | |
params: [], //we have no type parameters in this example | |
pack: [], //no package | |
name: name, | |
fields: [], //we use a different mechanism to add fields, so we pass none here | |
isExtern: false, //not extern | |
meta: [], //no metadata | |
kind: TDAlias( //here we "alias" (which is what a typedef does) to a fitting ComplexType | |
if (superType == null) | |
TAnonymous(fields) | |
else | |
TExtend(superType, fields) | |
) | |
}); | |
declare('Base', [mkField('val', mkType('String'))]); | |
declare('C', [], mkPath('Base')); | |
declare('B', [mkField('c', mkType('C'))], mkPath('Base')); | |
declare('A', [mkField('b', mkType('B'))], mkPath('Base')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment