|
|
@ -12,40 +12,44 @@ |
|
|
|
|
|
|
|
program.objects = null; |
|
|
|
|
|
|
|
beginObject(x) { |
|
|
|
beginObject(objectName, typeName) { |
|
|
|
program.objects = {}; |
|
|
|
program.objects.elements = {}; |
|
|
|
program.objects.last = null; |
|
|
|
x == null ? x = "oop" : x; |
|
|
|
program.objects.elements[length(program.objects.elements)] = x; |
|
|
|
program.objects.last = x; |
|
|
|
objectName == null ? objectName = "oop" : objectName; |
|
|
|
typeName == null ? typeName = "type_t" : typeName; |
|
|
|
program.objects.elements[length(program.objects.elements)] = objectName; |
|
|
|
program.objects.last = objectName; |
|
|
|
l = {}; |
|
|
|
enum = `declaration typedef enum {_} type_t;; |
|
|
|
enum.declarators[0].identifier = typeName; |
|
|
|
enum.semicolon.comment = getComment(" "); |
|
|
|
append(l, enum); |
|
|
|
program.objects.enum = treeCopy(enum); |
|
|
|
append(l, program.objects.enum); |
|
|
|
obj = `declaration union object;; |
|
|
|
obj.semicolon.comment = getComment(" "); |
|
|
|
append(l, treeCopy(obj)); |
|
|
|
type_obj = `declaration typedef union object *oop;; |
|
|
|
type_obj.declarators[0].declarators.identifier = x; |
|
|
|
type_obj.declarators[0].declarators.identifier = objectName; |
|
|
|
type_obj.semicolon.comment = getComment(" "); |
|
|
|
append(l, treeCopy(type_obj)); |
|
|
|
l; |
|
|
|
} |
|
|
|
|
|
|
|
addObject() { |
|
|
|
enum = treeCopy(getEnum(program.last.name.identifier)); |
|
|
|
structName = treeCopy(getEnum(program.last.name.identifier)); |
|
|
|
l = length(program.enums.last.enumList); |
|
|
|
if (string(program.enums.last.enumList[0].name.identifier) == "_" && l == 1) { |
|
|
|
program.enums.last.enumList[0] = enum; |
|
|
|
if (string(program.objects.enum.specifiers[1].enumList[0].name.identifier) == "_" && l == 1) { |
|
|
|
program.objects.enum.specifiers[1].enumList[0] = structName; |
|
|
|
} else { |
|
|
|
append(program.enums.last.enumList, getComma()); |
|
|
|
append(program.enums.last.enumList, enum); |
|
|
|
append(program.objects.enum.specifiers[1].enumList, getComma()); |
|
|
|
append(program.objects.enum.specifiers[1].enumList, structName); |
|
|
|
} |
|
|
|
for (i=length(program.last.declarationL); i>0; i--) { |
|
|
|
program.last.declarationL[i] = program.last.declarationL[i-1]; |
|
|
|
}; |
|
|
|
newType = `declaration type_t type;; |
|
|
|
newType = `declaration int type;; |
|
|
|
newType.specifiers[0].text = program.objects.enum.declarators[0].identifier; |
|
|
|
newType.semicolon.comment = getComment("\n "); |
|
|
|
program.last.declarationL[0] = treeCopy(newType); |
|
|
|
nil; |
|
|
@ -98,39 +102,12 @@ |
|
|
|
treeCopy(func); |
|
|
|
} |
|
|
|
|
|
|
|
// makeGeneralObject(x) { |
|
|
|
// func = `fun int makeString(int value) |
|
|
|
// { |
|
|
|
// oop newString = malloc(sizeof(struct String)); |
|
|
|
// newString->type = String; |
|
|
|
// } |
|
|
|
// ; |
|
|
|
// func.declarators.declarators.identifier = "make" + string(x); |
|
|
|
// func.specifiers[0].text = program.objects.last; |
|
|
|
// star = program.structs[x].declarationL[1].declarators[0].declarators.star; |
|
|
|
// if (star != null) { |
|
|
|
// func.declarators.paramTypeL[0].specifiers[0].text = string(checkIdorText(program.structs[x].declarationL[1].specifiers[0])) + " *"; |
|
|
|
// func.declarators.paramTypeL[0].specifiers[0].comment = ""; |
|
|
|
// } else { |
|
|
|
// func.declarators.paramTypeL[0].specifiers[0].text = string(checkIdorText(program.structs[x].declarationL[1].specifiers[0])); |
|
|
|
// } |
|
|
|
// func.compoundS.expression[0].declarators[0].lhs.identifier = "new" + string(x); |
|
|
|
// func.compoundS.expression[0].declarators[0].rhs.paramTypeL[0].typeName.specifiers[0].name.identifier = string(x); |
|
|
|
// func.compoundS.expression[1].expression.rhs.identifier = string(x); |
|
|
|
// func.compoundS.expression[1].expression.lhs.lhs.identifier = "new" + string(x); |
|
|
|
// for (i in program.structs[x].declarationL) { |
|
|
|
// if (i == 0) { continue; } |
|
|
|
// println(program.structs[x].declarationL[i]); |
|
|
|
// } |
|
|
|
// // println(func.compoundS.expression[1]); |
|
|
|
// treeCopy(func); |
|
|
|
// } |
|
|
|
|
|
|
|
endObject() { |
|
|
|
l = {}; |
|
|
|
objectUnion = `declaration union object { type_t type; };; |
|
|
|
objectUnion = `declaration union object { int type; };; |
|
|
|
objectUnion.specifiers[0].declarationL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier; |
|
|
|
objectUnion.semicolon.comment = getComment("\n"); |
|
|
|
obj = select(notToken, program.enums.last.enumList); |
|
|
|
obj = select(notToken, program.objects.enum.specifiers[1].enumList); |
|
|
|
elt = treeCopy(`declaration struct nil nil;); |
|
|
|
for (i in obj) { |
|
|
|
len = length(objectUnion.specifiers[0].declarationL); |
|
|
@ -139,7 +116,8 @@ |
|
|
|
objectUnion.specifiers[0].declarationL[len].semicolon.comment = getComment(" "); |
|
|
|
} |
|
|
|
append(l, objectUnion); |
|
|
|
isDef = `declaration int is(type_t type, int obj);; |
|
|
|
isDef = `declaration int is(int type, int obj);; |
|
|
|
isDef.declarators[0].paramTypeL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier; |
|
|
|
isDef.declarators[0].paramTypeL[2].specifiers[0].text = program.objects.last; |
|
|
|
isDef.semicolon.comment = getComment("\n"); |
|
|
|
append(l, isDef); |
|
|
@ -151,22 +129,18 @@ |
|
|
|
func.compoundS.expression[0].expression.paramTypeL[0].identifier = obj[i].name.identifier; |
|
|
|
append(l, treeCopy(func)); |
|
|
|
} |
|
|
|
func = `fun type_t getType(int ptr) { assert(ptr); return ptr->type; }; |
|
|
|
func = `fun int getType(int ptr) { assert(ptr); return ptr->type; }; |
|
|
|
func.specifiers[0].text = program.objects.enum.declarators[0].identifier; |
|
|
|
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.last; |
|
|
|
func.compoundS.rightCurly.comment = getComment("\n"); |
|
|
|
append(l, treeCopy(func)); |
|
|
|
func = `fun int is(type_t type, int obj) { return type == getType(obj); }; |
|
|
|
func = `fun int is(int type, int obj) { return type == getType(obj); }; |
|
|
|
func.declarators.paramTypeL[0].specifiers[0].text = program.objects.enum.declarators[0].identifier; |
|
|
|
func.declarators.paramTypeL[2].specifiers[0].text = program.objects.last; |
|
|
|
func.compoundS.rightCurly.comment = getComment("\n"); |
|
|
|
append(l, treeCopy(func)); |
|
|
|
append(l, treeCopy(getObjectMacro())); |
|
|
|
append(l, treeCopy(setObjectMacro())); |
|
|
|
// if (i == 0) { continue; } |
|
|
|
// func = getGeneralObject(program.unions.last.declarationL[i].specifiers[0].name.identifier); |
|
|
|
// append(l, func); |
|
|
|
// // func = makeGeneralObject(program.unions.last.declarationL[i].specifiers[0].name.identifier); |
|
|
|
// // append(l, func); |
|
|
|
// } |
|
|
|
program.objects = null; |
|
|
|
l; |
|
|
|
} |
|
|
|