IDL compiler front-end library
IDL_Print.cpp

This is an example of how to use IDL_FrontEnd class.

// IDL_Print.h Demonstrates the IDL compiler class.
#ifndef NIDLFE_EXAMPLE_IDL_PRINT_H_
#define NIDLFE_EXAMPLE_IDL_PRINT_H_
#if __cplusplus < 201703L && _MSVC_LANG < 201703L
#error C++17 compliant compiler is required.
#endif
#include <IDL_FrontEnd.h>
#include <filesystem>
// Derive the compiler class from IDL_FrontEnd.
class IDL_Print : public IDL_FrontEnd
{
public:
IDL_Print () :
{}
private:
// Override print_usage_info for additional usage information.
virtual void print_usage_info (const char* exe_name) override;
// Override parse_command_line to parse own command line switches.
virtual bool parse_command_line (CmdLine& args) override;
// Override generate_code to build output from the AST.
virtual void generate_code (const AST::Root& tree) override;
private:
std::filesystem::path out_dir_;
};
#endif
Abstract Syntax Tree root.
Definition: Root.h:62
IDL front-end.
Definition: IDL_FrontEnd.h:63
IDL_FrontEnd(unsigned flags=0, std::ostream &err_out=std::cerr)
Constructor.
Definition: IDL_FrontEnd.h:166
virtual void generate_code(const AST::Root &tree)=0
Generate user code from AST.
virtual void print_usage_info(const char *exe_name)
Prints usage information to std::cout.
static const unsigned FLAG_ENABLE_CONST_OBJREF
Allow Nirvana const interface references.
Definition: IDL_FrontEnd.h:103
virtual bool parse_command_line(CmdLine &args)
Parse command line parameter.
// IDL_Print.cpp Demonstrates the IDL compiler class.
#include "IDL_Print.h"
#include "Printer.h"
#include <iostream>
using namespace std;
using namespace std::filesystem;
void IDL_Print::print_usage_info (const char* exe_name)
{
cout << "Compile and print IDL.\n";
cout << "Output options:\n"
"\t-d directory\tDirectory for output files.\n";
}
bool IDL_Print::parse_command_line (CmdLine& args)
{
return true;
if (args.arg () [1] == 'd') {
out_dir_ = args.parameter (args.arg () + 2);
assert (!out_dir_.empty ());
args.next ();
return true;
}
return false;
}
void IDL_Print::generate_code (const AST::Root& tree)
{
path file = out_dir_ / tree.file ().filename ();
file.replace_extension (".txt");
Printer printer (file);
if (tree.visit (printer))
cerr << "Warning, some unsupported Building Blocks were ignored.\n";
}
const std::filesystem::path & file() const noexcept
Definition: Root.h:65
bool visit(CodeGen &cg) const
Visit all items for the code generation.