Precompilator oop

Everything else that doesn't fall into one of the other PB categories.
User avatar
microdevweb
Enthusiast
Enthusiast
Posts: 179
Joined: Fri Jun 13, 2014 9:38 am
Location: Belgique

Precompilator oop

Post by microdevweb »

Hello everybody,

I like very much the oop programming style, but pureBasic have not this functionality. But we can define une lite software which is called before the compilation.

It try to make it at this time, and i show to you the result of a small test.

Now i don't share this software because it's not quite advanced, i have lot of work for make that. But i just show to you it is possible.



Image

code of oop layer

Code: Select all

Class Car
  private string name
  private int id
  public Method  Car(string name,int id)
    this.name = name
    this.id = id
  EndMethod
  public Method void teste(string name)
    Debug name
  EndMethod
  public Method string getName()
    return this.name
  EndMethod
EndClass
Class FleetCar
  private string name
  public Method FleetCar(string name)
    this.name = name
  EndMethod
EndClass
Global Car myCar = new Car("volvo",1)

myCar\teste("ok")
Debug myCar\getName()


Generated code by the precompilation

Code: Select all

DeclareModule __OOP_INTERFACES
Interface Car

getName.s()
teste(name.s)

EndInterface
Interface FleetCar


EndInterface

EndDeclareModule
Module __OOP_INTERFACES
EndModule
DeclareModule _Car
Structure _struct
*methods
id.l
name.s
EndStructure

Declare new(name.s,id)
EndDeclareModule
Module _Car
Procedure new(name.s,id)
Protected *this._struct = AllocateStructure(_struct)
With *this
\methods = ?METHODS
    \name = name
    \id = id
ProcedureReturn *this
EndWith
EndProcedure
Procedure.s getName(*this._struct)
With *this
    procedureReturn \name

EndWith
EndProcedure
Procedure teste(*this._struct,name.s)
With *this
    Debug name

EndWith
EndProcedure

DataSection
METHODS:

Data.i @getName()
Data.i @teste()
EndDataSection
EndModule
DeclareModule _FleetCar
Structure _struct
*methods
name.s
EndStructure

Declare new(name.s)
EndDeclareModule
Module _FleetCar
Procedure new(name.s)
Protected *this._struct = AllocateStructure(_struct)
With *this
\methods = ?METHODS
    \name = name
ProcedureReturn *this
EndWith
EndProcedure

DataSection
METHODS:

EndDataSection
EndModule
Global myCar.__OOP_INTERFACES::Car = _Car::new("volvo",1)
myCar\teste("ok")
Debug myCar\getName()
Use Pb 5.73 lst and Windows 10

my mother-language isn't english, in advance excuse my mistakes.