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

Precompilator oop
https://www.purebasic.fr/english/viewtopic.php?f=7&t=69836
Page 1 of 1

Author:  microdevweb [ Tue Dec 26, 2017 1:50 am ]
Post subject:  Precompilator oop

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:
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:
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()

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