|
|
@ -184,51 +184,39 @@ typedef struct __oop *oop; |
|
|
|
} |
|
|
|
tmp = {}; |
|
|
|
// @@ problem for variable changement |
|
|
|
tmp[0] = makeln(`declaration struct @@(newId(string(program.objects.currentClassName))) *self = (struct @@(newId(string(program.objects.currentClassName))) *) __self;, 1); |
|
|
|
tmp[0] = makeln(`declaration struct @@(newId(string(program.objects.currentClassName), " ")) *self = (struct @@(newId(string(program.objects.currentClassName))) *) __self;, 1); |
|
|
|
s.compoundS.expression = treeCopy(fusion(tmp, s.compoundS.expression)); |
|
|
|
program.objects.function = "none"; |
|
|
|
return s; |
|
|
|
} |
|
|
|
/*********** Constructor function ************/ |
|
|
|
if (program.objects.function == "constructor") { |
|
|
|
structDeclaration = makeln(`declaration struct @@(newId(string(program.objects.currentClassName))) *self = calloc(1, sizeof *self);, 1); |
|
|
|
rawDeclaration = makeln(`declaration class = findClass(@@(newText("\"" + string(program.objects.currentClassName) + "\"")));, 1); |
|
|
|
returnSTMT = makeln(`statement return (struct __oop *) self;); |
|
|
|
t = {}; |
|
|
|
append(t, treeCopy(structDeclaration)); |
|
|
|
append(t, treeCopy(makeln(`declaration struct @@(newId(string(program.objects.currentClassName), " ")) *self = calloc(1, sizeof *self);, 1))); |
|
|
|
// take the structure of self->foo |
|
|
|
lhs = treeCopy(s.compoundS.expression[0].expression.lhs); |
|
|
|
lhs.rhs = rawDeclaration.declarators[0].lhs; |
|
|
|
lhs.rhs = newId("class", " "); |
|
|
|
// Change foo to Class |
|
|
|
rawDeclaration.declarators[0].lhs = lhs; |
|
|
|
// prepare the right object to return |
|
|
|
append(s.compoundS.expression, rawDeclaration); |
|
|
|
append(s.compoundS.expression, returnSTMT); |
|
|
|
append(s.compoundS.expression, makeln(`statement return (struct __oop *) self;)); |
|
|
|
s.compoundS.expression = fusion(t, s.compoundS.expression); |
|
|
|
program.objects.function = "none"; |
|
|
|
return s; |
|
|
|
} |
|
|
|
/*********** Main function ************/ |
|
|
|
if (s.declarators != null && s.declarators.declarators != null && string(s.declarators.declarators.identifier) == "main") { |
|
|
|
rawSelector = makeln(`declaration int _selector_ = findSelector("foo");, 1); |
|
|
|
rawClass = makeln(`declaration int _class_ = findClass("foo");, 1); |
|
|
|
t = {}; |
|
|
|
for (i in program.objects.methods) { |
|
|
|
rawSelector.declarators[0].lhs.identifier = "_selector_" + string(program.objects.methods[i]); |
|
|
|
rawSelector.declarators[0].rhs.paramTypeL[0].text[0].value = "\"" + string(program.objects.methods[i]) + "\""; |
|
|
|
append(t, treeCopy(rawSelector)); |
|
|
|
} |
|
|
|
classKeys = keys(program.objects.class); |
|
|
|
for (i in classKeys) { |
|
|
|
rawClass.declarators[0].lhs.identifier = "_class_" + string(classKeys[i]); |
|
|
|
rawClass.declarators[0].rhs.paramTypeL[0].text[0].value = "\"" + string(classKeys[i]) + "\""; |
|
|
|
append(t, treeCopy(rawClass)); |
|
|
|
} |
|
|
|
rawAddMethod = makeln(`declaration addMethod(_class_, _selector_, foo);, 1); |
|
|
|
for (i in program.objects.class) { |
|
|
|
className = string(i); // can't work other way |
|
|
|
append(t, treeCopy(makeln(`declaration int @@(newId("_class_" + className)) = findClass(@@(newId("\"" + className + "\"")));, 1))); |
|
|
|
for (k in program.objects.class[i]) { |
|
|
|
newObject = treeCopy(rawAddMethod); |
|
|
|
newObject.declarators[0].paramTypeL[0].identifier = string(rawAddMethod.declarators[0].paramTypeL[0].identifier) + string(i); |
|
|
|
newObject.declarators[0].paramTypeL[2].identifier = string(rawAddMethod.declarators[0].paramTypeL[2].identifier) + string(program.objects.class[i][k]); |
|
|
|
newObject.declarators[0].paramTypeL[4].identifier = "(method_t) " + string(i) + "_" + string(program.objects.class[i][k]); |
|
|
|
append(t, treeCopy(newObject)); |
|
|
|
linkedMethod = string(program.objects.class[i][k]); |
|
|
|
append(t, treeCopy(makeln(`declaration int @@(newId("_selector_" + linkedMethod)) = findSelector(@@(newId("\"" + linkedMethod + "\"")));, 1))); |
|
|
|
castMethod = "(method_t) " + string(i) + "_" + string(program.objects.class[i][k]); |
|
|
|
append(t, treeCopy(makeln(`declaration addMethod(@@(newId("_class_" + className)), @@(newId("_selector_" + linkedMethod)), @@(newId(castMethod)));, 1))); |
|
|
|
} |
|
|
|
} |
|
|
|
s.compoundS.expression = fusion(t, s.compoundS.expression); |
|
|
|