PureBasic Forum
https://www.purebasic.fr/english/

Another OOP PreCompiler
https://www.purebasic.fr/english/viewtopic.php?f=27&t=30774
Page 1 of 4

Author:  mk-soft [ Sat Jan 26, 2008 1:25 pm ]
Post subject:  Another OOP PreCompiler

Hi,

here now my oop-precompiler.

Update v0.44
New:
- Parameters for NewClassName(...) --> Call InitObject(...)

Update v0.45
Bugfix:
- Memory Manager

Download OOP-PreCompiler (Window x86 and x64)
Download OOP-PreCompiler (Linux)


IDE-Properties
Image
Image
Image

Examples Code Update v0.43
Code:
; Example Part 1

; Defined first class

Class(MasterClass)
  ; This methods are generate the oop precomiler
  ;    - QueryInterface(*UIID.iid, *ppv.long)
  ;    - AddRef()
  ;    - Release()
  ; All others methods automatically included
   
  ; Attributes
  LastName.s
  FirstName.s
  Datum.l
EndClass

; Syntax for Method:
; Method [Overwrite] ClassName_Function(*this.ClassName, ...)
;   ...
; EndMethod

; Method for Class MasterClass
Method MasterClass_SetLastName(*this.MasterClass, Name.s)
  *this\LastName = Name
EndMethod

Method MasterClass_SetFirstName(*this.MasterClass, Name.s)
  *this\FirstName = Name
EndMethod

Method MasterClass_SetDatum(*this.MasterClass, Datum.l)
  *this\Datum = Datum
EndMethod

Method.s MasterClass_GetDaten(*this.MasterClass, Separator.s)
  Protected Result.s
  Result = *this\LastName + Separator + *this\FirstName + Separator + FormatDate("%dd.%mm.%yyyy", *this\Datum)
  ProcedureReturn Result
EndMethod

; Test Part 1

Debug "Test Part 1"
Define.IMasterClass *User1 ; <- Object declare - Syntax: I + ClassName
; Create Object
*User1 = NewObject(MasterClass)
; Call Methods any Properties
*User1\SetLastName("Meyer")
*User1\SetFirstName("Hans")
*User1\SetDatum(Date())
Debug "User1: " + *User1\GetDaten(";")
; Release Object
DeleteObject(*User1)
; or *User1\Release()

Debug ""
; ***************************************************************************************

; Example Part 2 - inheritance and overwrite inherited method

; Defined second Class
Class(SubClass, MasterClass) ; <- inheritance method and attributes from MasterClass
  ; Attributes
  Street.s
  Sity.s
EndClass

; Method for Class SubClass
Method SubClass_SetStreet(*this.SubClass, Street.s)
  *this\Street = Street
EndMethod

Method SubClass_SetSity(*this.SubClass, Sity.s)
  *this\Sity = Sity
EndMethod

Method.s SubClass_GetAdresse(*this.SubClass, Separator.s)
  Protected Result.s
  Result = *this\Street + Separator + *this\Sity
  ProcedureReturn Result
EndMethod

Method.s Overwrite SubClass_GetDaten(*this.SubClass, Separator.s) ; <- Overwrite inherited method GetDaten(...)
  Protected *self.ISubClass = *this ; <- declare self methods
  Protected Result.s
  Result = *this\LastName + Separator + *this\FirstName + Separator + FormatDate("%dd.%mm.%yyyy", *this\Datum)
  Result + Separator + *self\GetAdresse(Separator)
  ProcedureReturn Result
EndMethod

; Test Part 2

Debug "Test Part 2"
Define.ISubClass *User2, *User3
; Create Object
*User2 = NewObject(SubClass)
*User2\SetLastName("Smith")
*User2\SetFirstName("Jon")
*User2\SetDatum(Date())
*User2\SetStreet("Linenstr. 44")
*User2\SetSity("Irgendwo")
Debug "User2: " + *User2\GetDaten(";")
; Release Object
*User2\Release()
; or DeleteObject(*User2)
Debug ""

; ***************************************************************************************

; Example Part 3 - avoidance of memory leak with method InitObject and DestroyObject

Class(MemClass)
  *mem1
  *mem2
EndClass

; Init memory
Method MemClass_InitObject(*this.MemClass) ; <- NewObject calling InitObject
  With *this
    Debug "InitObject: AllocateMemory."
    \mem1 = AllocateMemory(10*1024)
    \mem2 = AllocateMemory(20*1024)
  EndWith
EndMethod

Method MemClass_GetMemPointer(*this.MemClass, number.l)
  Select number
    Case 1 : ProcedureReturn *this\mem1
    Case 2 : ProcedureReturn *this\mem2
    Default : ProcedureReturn 0
  EndSelect
EndMethod

Method MemClass_DestroyObject(*this.MemClass) ; <- DeleteObject or Release calling DestroyObject
 
  Debug "DestroyObject: Free Memory."
  FreeMemory(*this\mem1)
  FreeMemory(*this\mem2)
 
EndMethod

; Test Part 3
Debug "Test Part 3"
Debug ""
Debug "Mem Test 1"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of Obj : " + Str(*mem)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
*mem\Release()
Debug ""

Debug "Mem Test 2"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of Obj : " + Str(*mem)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
DeleteObject(*mem)
Debug ""

Debug "Mem Test 3"
*mem.IMemClass = NewObject(MemClass)
Debug "Address of Obj : " + Str(*mem)
Debug "Address of mem1: " + Str(*mem\GetMemPointer(1))
Debug "Address of mem2: " + Str(*mem\GetMemPointer(2))
*mem\Release()
Debug ""


Please testing for bugs. Thanks

GT :wink:

Author:  yoxola [ Sat Jan 26, 2008 3:31 pm ]
Post subject: 

Sounds pretty fun, I'll have a try.

Thank for contribution :D

Author:  SFSxOI [ Sat Jan 26, 2008 3:41 pm ]
Post subject: 

makes me want to convert my curent project....Thank You :)

Author:  mk-soft [ Sat Jan 26, 2008 5:29 pm ]
Post subject: 

Bugfix v0.34

Lower and upper case searching was errors in the translation.

Sorry :oops:

Author:  superadnim [ Sat Jan 26, 2008 6:12 pm ]
Post subject: 

could you go a little more OOP for the parser? for instance I know why you are using the underscores, but... using a \ or a dot would make much more sense, really.

Even if you use :: as C++, it'll be much more solid.

May I ask, can you call encapsulated classes from public? or only privately?.

Just a few ideas: you could call "this" for yourself, ie as a reserved variable label and thus prevent from using the pointer all together, you can parse this one easily.

this->var = 10 ; var being a variable in the class

etc..

Another idea: don't pass *this by yourself, use the parser to add this pointer... thats the whole principle and idea of an oop parser, to do this stuff so you don't have to...

If you take my ideas it'll become a cleaner and more solid tool to work with :)

PS: as parser I mean preprocessor, etc...
PS2: baseclass? wtf?

Author:  mk-soft [ Sat Jan 26, 2008 6:49 pm ]
Post subject: 

the precomiler read only the code and bind a topfile and a bottomfile to the mainfile as includefile.
The syntax with *this as Pointer to encapsulated data and "\" as bind to structures and Interfaces come from PB
I won´t to translate all code, because it´s a big problem with includefiles und debuging code.

Quote:
May I ask, can you call encapsulated classes from public? or only privately?


All Attributes with Class allways privatly but you can definded all attributes as Public with a new pointer to object . That´s not right method.
Code:
*publicMaster.MasterClass = *User1
Debug "Public: " + *publicMaster\LastName


Sorry for my english.
:wink:

Author:  superadnim [ Sat Jan 26, 2008 6:56 pm ]
Post subject: 

I mean, what if I want to do this:

myfile\read\string()


Too bad about the "can't be arsed to make a proper preprocessor" part :? I guess I'll have to continue mine after all... Both existent OOP tools are flawed in many points and the authors don't seem to care :cry: - I appreciate the effort but it's not good enough IMO as to start porting code and use it on a regular basis... Since it's not full OOP by any means.

Author:  mk-soft [ Sat Jan 26, 2008 7:09 pm ]
Post subject: 

superadnim wrote:
I mean, what if I want to do this:
myfile\read\string()


Sorry, this not supported PB directly, but I have a germany sample.

Please wait to translate to englisch sample

Code:

; *****************************************************************************

Class SubClass Extends BaseClass
  ; Private
  num.l
  text.s
EndClass

Class MasterClass Extends BaseClass
  ; Private
  Value.l
  *subclass.ISubClass[100]
EndClass

; *****************************************************************************

Method SubClass_SetText(*this.SubClass, text.s)
  *this\text = text
EndMethod

Method.s SubClass_GetText(*this.SubClass)
  ProcedureReturn *this\Text
EndMethod

Method SubClass_SetNum(*this.SubClass, Num.l)
  *this\num = num
EndMethod

Method SubClass_GetNum(*this.SubClass)
  ProcedureReturn *this\num
EndMethod

Method MasterClass_NewSubClass(*this.MasterClass)
 
  Protected count.l
 
  For i = 0 To 99
    If *this\subclass[i] = 0
      *this\subclass[i] = NewObject(SubClass)
      ProcedureReturn *this\subclass[i]
    EndIf
  Next
  ProcedureReturn 0
 
EndMethod

Method MasterClass_FreeSubClass(*this.MasterClass, *subclass)
 
  Protected count.l
 
  For i = 0 To 99
    If *this\subclass[i] = *subclass
      *this\subclass[i]\Release()
      *this\subclass[i] = 0
      ProcedureReturn 0
    EndIf
  Next
  ProcedureReturn *subclass
 
EndMethod

Method MasterClass_FreeAllSubClass(*this.MasterClass)
 
  For i = 0 To 99
    If *this\subclass[i] <> 0
      *this\subclass[i]\Release()
      *this\subclass[i] = 0
    EndIf
  Next
 
EndMethod

Method Overwrite MasterClass_Release(*this.MasterClass)
 
  If *this\__Ref > 1
    *this\__Ref - 1
    ProcedureReturn *this\__Ref
  Else
    For i = 0 To 99
      If *this\subclass[i] <> 0
        While *this\subclass[i]\Release() : Wend
        *this\subclass[i] = 0
      EndIf
    Next
    ProcedureReturn DeleteObject(*this)
  EndIf
 
EndMethod

; *****************************************************************************

*master.IMasterClass = NewObject(MasterClass)
*subclass1.ISubClass = *master\NewSubClass()
If *subclass1
  *subclass1\SetText("Hallo World")
EndIf

*subclass2.ISubClass = *master\NewSubClass()
If *subclass2
  *subclass2\SetText("OOP with PureBasic")
EndIf
*subclass3.ISubClass = *master\NewSubClass()
If *subclass3
  *subclass3\SetText(";)")
EndIf

Debug *subclass1\Gettext()
Debug *subclass2\Gettext()
Debug *subclass3\Gettext()

*master\FreeSubClass(*subclass1)

While *master\Release() : Wend


It´s the same method when you using DCOM-Object in PB

GT :roll:

Author:  superadnim [ Sat Jan 26, 2008 7:26 pm ]
Post subject: 

I know, I know... but again, the purpose of a preprocessor is to enable this sort of things :P

Thanks.

Author:  LuCiFeR[SD] [ Sat Jan 26, 2008 8:48 pm ]
Post subject: 

superadnim wrote:
Too bad about the "can't be arsed to make a proper preprocessor" part :? I guess I'll have to continue mine after all...


Is there REALLY any need for that? This isn't the first occasion you have gone out of your way to be as insultive as you possibly can towards somebody who is doing code in their spare time for free. Perhaps you SHOULD put your money where your big mouth is and bloody well write some code and realease it in the same manner so WE can all sit back and tear you to shreds for a change eh?

Author:  superadnim [ Sat Jan 26, 2008 8:50 pm ]
Post subject: 

Or perhaps you could get laid and we could all sit back and laugh at you.
I said thanks, I said it was a good tool, I did add my constructive criticism if you don't like it, there you are. I also mentioned I'm working on my own preprocessor, but for people like you I would rather not share a bit. :wink:

Author:  LuCiFeR[SD] [ Sat Jan 26, 2008 8:53 pm ]
Post subject: 

Ahhhh, I really love cheap shots... especially as you keep turning me down for sex.. I guess you'll be waiting a while for the laughter to errupt ;)

Author:  mk-soft [ Sun Jan 27, 2008 4:45 am ]
Post subject: 

Information:

The PreCompiler produces additional program code and macros.
This is merged at the beginning and at the end of the Main file.
The syntax of purebasic uses all techniques for the programming of objects.
No source codes are changed or replaced. I do not have also before this
differently to reallisieren around the full to purebasic to keep kompalitaet.

To produce all objects in LinkedList over put on after the release by objects no memory leakages.
This is unfortunately often not considered with the use AllocateMemory and FreeMemory.

Purebasic is a procedurale programming language however object orientation supported.
I use this support for the PreCompiler.

For complete object-oriented programming there are Visual studio or C++.

/* Translate by Yahoo! Babel Fish */

Author:  Dare [ Sun Jan 27, 2008 7:52 am ]
Post subject: 

Thanks, mk-soft


@superadnim

I agree with LuCiFeR[SD], mate. You can make the odd good point but you almost always deliver these things in an obnoxious way. Yours is destructive, not constructive criticism.

LuCiFeR[SD] makes an excellent point about the generous contributions to these forums.

Posts like yours make some people think twice about releasing things and so you spite yourself and the rest of us when you belittle other people's efforts.

You imply you have all this (usually unfinished) but awesome code lying around. In different areas of expertise. Mate, I think you're skiting. It is put up or shut up time - so let's see this OOP masterpiece of yours.

Author:  inc. [ Sun Jan 27, 2008 12:51 pm ]
Post subject: 

MK-Soft ... just don't care ...

If you dont agree with his " xyz must be available in an OOP paradigm" he just presumes that you got less skills and no idea how an oop language has to be. So be prepared ;-)
http://www.phpbbserver.com/pboop/viewto ... m=pboop#31
http://www.purebasic.fr/english/viewtop ... 823#227823
http://www.phpbbserver.com/pboop/viewto ... orum=pboop

Quote:
Both existent OOP tools are flawed in many points and the authors don't seem to care Crying or Very sad ... Since it's not full OOP by any means.

Its not the way of the C# approach you "would like to have" but IT IS OOP.
The authors maybe just don't want to follow your order giving style, your teasings and presumtions regarding skills.

And btw: You know, not everything is "flawed" or as you say monkey-style builded just cause you are the one who can't handle it.

Page 1 of 4 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/