typegraph/scripts/debug/typesToDot.gml

113 lines
3.5 KiB
Plaintext

///typesToDot()
/**
* typesToDot :: () -> String
*
* Builds a DOT string for all types.
*
* @returns the DOT string representation of all types
*/
var nl = chr(13)+chr(10);
var dq = '"';
var str = "digraph {";
str += "{rank = same"+nl;
with (Block) {
str += format("i%i[shape=rectangle,style=dashed,label=%'%o%']%n", id, id);
}
if (DEBUG)
with (BlockTemplate) {
str += format("i%i[shape=rectangle,color=%'%c%',style=dashed,label=%'%o%']%n",id,self.image_blend,id);
}
str += "}"+nl;
if (DEBUG) {
str += "{rank = same"+nl;
with (HigherOrderLink) {
str += format("i%i[shape=rectangle,color=darkgreen,style=dashed,label=%'%o%']%n", id, id);
}
with (AnchorTemplate) {
str += format("i%i[shape=rectangle,color=darkgreen,style=dashed,label=%'%o%']%n", id, id);
}
str += "}"+nl;
}
with (Block) {
for (var i = 0; i < ds_list_size(self.children); i++)
if (instanceof(self.children[|i], Anchor)) {
str += format("i%i->i%i[style=dashed,label=%'curr%i%']%n", id, self.children[|i].currentType, i);
str += format("i%i->i%i[style=dashed,label=%'fresh%i%']%n", id, self.children[|i].freshType, i);
}
}
if (DEBUG) {
with (BlockTemplate) {
for (var i = 0; i < ds_list_size(self.inputs); i++)
str += format("i%i->i%i[color=%'%c%',style=dashed,label=%'%o%']%n", id, self.inputs[|i], self.image_blend, id);
for (var i = 0; i < ds_list_size(self.outputs); i++)
str += format("i%i->i%i[color=%'%c%',style=dashed,label=%'%o%']%n", id, self.outputs[|i], self.image_blend, id);
var coll = id;
with (AnchorTemplate)
if (place_meeting(self.x, self.y, coll))
str += format("i%i->i%i[color=%'%c%',style=dashed]%n", coll, id, coll.image_blend);
}
with (HigherOrderLink)
str += format("i%i->i%i[color=darkgreen,style=dashed]%n", id, self.con);
with (AnchorTemplate)
str += format("i%i->i%i[color=darkgreen,style=dashed]%n", id, self.con);
with (ParameterLink)
str += format("i%i->i%i[color=%'%c%',label=%'%o%']%n", self.source, self.drain, self.image_blend, id);
}
with (TypeConLink) {
if (instanceof(id, TypeCon1Link)) {
str += format("i%i[shape=diamond,label=%'s-con%']%n", id);
str += format("i%i->i%i%n", id, self.type);
}
else {
str += format("i%i[shape=diamond,label=%'%i-con%']%n", id, ds_list_size(self.to));
}
for (var i = 0; i < ds_list_size(self.to); i++) {
var err = "";
if (!ds_set_exists(self.to[|i].from, id))
err = "color=red,";
str += format("i%i->i%i[%slabel=%'%i%']%n", id, self.to[|i], err, i);
}
for (var from = ds_set_first(self.from); ds_set_exists(self.from, from); from = ds_set_next(self.from, from)) {
if (ds_list_find_index(from.to, id) == -1)
str += format("i%i->i%i[color=red,style=dashed]%n", from, id);
}
}
with (Parametric) {
if (instanceof(id, FreeType))
str += format("i%i[shape=ellipse,label=%'%o%']%n", id, id);
else if (instanceof(id, ConcreteType))
str += format("i%i[shape=rectangle,label=%'%o%']%n", id, id);
else
str += format("i%i[shape=ellipse,style=dashed,color=%'%c%',label=%'%o%']%n", id, self.image_blend, id);
if (instanceof(id, Type))
for (var trait = ds_set_first(self.traits); ds_set_exists(self.traits, trait); trait = ds_set_next(self.traits, trait))
str += format("i%i->i%i%n", id, trait);
}
with (Trait) {
str += format("i%i[shape=house,label=%'%o%']%n", id, id);
for (var trait = ds_set_first(self.traits); ds_set_exists(self.traits, trait); trait = ds_set_next(self.traits, trait))
str += format("i%i->i%i%n", id, trait);
}
str += "}";
return str;