Re: Object-oriented preprocessor
- Posted by jmduro in August
- 1868 views
With a drop of inheritance, OOP style would be:
include win32lib_r2.ew as win class TWin32() integer id = 0 sequence caption = "" atom pOwner = 0 object x = 0, y = 0, cx = 0, cy = 0 object styleFlags = 0 procedure create(sequence params) self.caption = params[1] self.pOwner = params[2] self.x = params[3] self.y = params[4] self.cx = params[5] self.cy = params[6] self.styleFlags = params[7] end procedure end class class TWindow(TWin32) procedure create(sequence params) super.create(params) self.id = win:create(Window, self.caption, self.pOwner, self.x, self.y, self.cx, self.cy, self.styleFlags) end procedure end class class TMleText(TWin32) procedure create(sequence params) super.create(params) self.id = win:create(MleText, self.caption, self.pOwner, self.x, self.y, self.cx, self.cy, self.styleFlags) end procedure procedure set(sequence params) win:setText(self.id, params[1]) end procedure function get(sequence params) win:getText(MleText) end function end class sequence win = new(TWindow) win.create({"MLE Test", 0, 0, 0, 400, 300, 0}) sequence mle = new(TMleText) mle.create({"", w, 10, 10, 200, 200, 0}) mle.set({"Line 1\nLine 2\nLine 3"}) WinMain(win.id, Normal)
targeted translated code should be:
include win32lib_r2.ew as win without warning procedure class_proc(sequence entity, integer method, sequence params = {}) call_proc(entity[method], {entity, params}) end procedure function class_func(sequence entity, integer method, sequence params = {}) return call_func(entity[method], {entity, params}) end function enum type TWIN32 TWIN32_ID, TWIN32_CAPTION, TWIN32_POWNER, TWIN32_X, TWIN32_Y, TWIN32_CX, TWIN32_CY, TWIN32_STYLEFLAGS, TWIN32_CREATE end type sequence TWin32 = {0,"",0,0,0,0,0,0} enum type TWINDOW TWINDOW_CREATE = TWIN32_CREATE end type sequence TWindow = TWin32 & { routine_id("TWindow_create") } function TWindow_create(sequence entity, sequence params) entity[TWIN32_CAPTION] = params[1] entity[TWIN32_POWNER] = params[2] entity[TWIN32_X] = params[3] entity[TWIN32_Y] = params[4] entity[TWIN32_CX] = params[5] entity[TWIN32_CY] = params[6] entity[TWIN32_STYLEFLAGS] = params[7] entity[TWIN32_ID] = win:create(Window, entity[TWIN32_CAPTION], entity[TWIN32_POWNER], entity[TWIN32_X], entity[TWIN32_Y], entity[TWIN32_CX], entity[TWIN32_CY], entity[TWIN32_STYLEFLAGS]) return entity end function enum type TMLETEXT TMLETEXT_CREATE = TWIN32_CREATE, TMLETEXT_SET, TMLETEXT_GET end type sequence TMleText = TWin32 & { routine_id("TMleText_create"), routine_id("TMleText_set"), routine_id("TMleText_get") } function TMleText_create(sequence entity, sequence params) entity[TWIN32_CAPTION] = params[1] entity[TWIN32_POWNER] = params[2] entity[TWIN32_X] = params[3] entity[TWIN32_Y] = params[4] entity[TWIN32_CX] = params[5] entity[TWIN32_CY] = params[6] entity[TWIN32_STYLEFLAGS] = params[7] entity[TWIN32_ID] = win:create(MleText, entity[TWIN32_CAPTION], entity[TWIN32_POWNER], entity[TWIN32_X], entity[TWIN32_Y], entity[TWIN32_CX], entity[TWIN32_CY], entity[TWIN32_STYLEFLAGS]) return entity end function procedure TMleText_set(sequence entity, sequence params) win:setText(entity[TWIN32_ID], params[1]) end procedure function TMleText_get(sequence entity, sequence params) return win:getText(entity[TWIN32_ID]) end function sequence win = TWindow win = class_func(win, TWINDOW_CREATE, {"MLE Test", 0, 0, 0, 400, 300, 0}) sequence mle = TMleText mle = class_func(mle, TMLETEXT_CREATE, {"", win[TWIN32_ID], 10, 10, 200, 200, 0}) class_proc(mle, TMLETEXT_SET, {"Line 1\nLine 2\nLine 3"}) WinMain(win[TWIN32_ID], Normal)
Target code has been tested OK.
Jean-Marc