Skip to content

ENH: parse C++ pure virtual function, and if a class only contains C++ pure virtual function, translate to D interface. #339

@mw66

Description

@mw66
$ cat source/cpp.dpp 

class PriceBarI {
 public:
  // OHLC chart
  virtual double open_()   = 0;
  virtual double high_()   = 0;
  virtual double low_()    = 0;
  virtual double close_()  = 0;
  virtual double volume_() = 0;
  virtual int64  millis_() = 0;
};

$ ~/.dub/packages/dpp/0.5.4/dpp/bin/d++ --keep-d-files --preprocess-only --parse-as-cpp source/cpp.dpp

$ tail  source/cpp.d
class PriceBarI {
 public:
  // OHLC chart
  virtual double open_() = 0;
  virtual double high_() = 0;
  virtual double low_() = 0;
  virtual double close_() = 0;
  virtual double volume_() = 0;
  virtual int64 millis_() = 0;
};

Looks like the C++ pure virtual function is not recognized.

It will be nice to parse C++ pure virtual function, and if a class only contains C++ pure virtual function:

  1. translate to D interface
  2. translate C++ pure virtual functions to D abstract methods.

Then it will be easier to interface D and C++:

https://dlang.org/spec/cpp_interface.html#using_d_classes_from_cpp

so the expected output are:

extern (C++) {                                                                                                                                                                                                          
interface PriceBarI {                                                                                                                                                                                                   
 public:                                                                                                                                                                                                                
  // OHLC chart                                                                                                                                                                                                         
  abstract double open_();                                                                                                                                                                                              
  abstract double high_();                                                                                                                                                                                              
  abstract double low_();                                                                                                                                                                                               
  abstract double close_();                                                                                                                                                                                             
  abstract double volume_();                                                                                                                                                                                            
  abstract long millis_();                                                                                                                                                                                              
};                                                                                                                                                                                                                      
}    

This example can be used as unittest case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions