Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved compile time #10

Merged
merged 16 commits into from
Aug 19, 2016
Prev Previous commit
Next Next commit
Finished implementation
xspx is now generating optional source.  Now going to add to
cmake and see if it works.
  • Loading branch information
intrig committed Aug 18, 2016
commit ab54e3c809ff5803e7dc2cdd713b951b455b85ed
1 change: 1 addition & 0 deletions src/xddl.xspx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- declare types used by attributes. -->
<type cpp="bool" def="false">bool</type>
<type cpp="int64_t" def="0">integer</type>

<type cpp="size_t" def="1">pos_integer</type>
<type cpp="size_t" def="0">size</type>
<type cpp="std::string">string</type>
Expand Down
17 changes: 10 additions & 7 deletions tools/xspx/xspx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ int main(int argc, char **argv) {
p.open(line.targets[0]);

if (dispatch) xspx::to_dispatch(std::cout, p, dispatch_name);
else {
if (!hfile.empty()) {
std::ofstream s(hfile, std::ios::out | std::ios::binary);
s << p.header();
} else {
std::cout << p.header();
}
else if (!hfile.empty() && !sfile.empty()) {
std::ofstream h(hfile, std::ios::out | std::ios::binary);
std::ofstream s(sfile, std::ios::out | std::ios::binary);
p.to_stream(h, s);

} else if (!hfile.empty()) {
std::ofstream h(hfile, std::ios::out | std::ios::binary);
p.to_stream(h);
} else {
p.to_stream(std::cout);
}

} catch (std::exception & e) {
Expand Down
69 changes: 45 additions & 24 deletions tools/xspx/xspx_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,7 @@ void generate_uid_constants(S & os, T first, T last) {
});
}

#if 0
std::string xsp_parser::source() const {
return "";
}
#endif

std::string xsp_parser::header() const {
void xsp_parser::header(std::ostream & h, st::type t) const {
std::ostringstream os;
os << "#pragma once //\n";
os << code_seg(code_refs, "head");
Expand All @@ -256,13 +250,28 @@ std::string xsp_parser::header() const {

os << "}";

os << parser_impl();
os << parser_impl(t);

os << code_seg(code_refs, "tail");

xenon::cpp_code code;
code.add(os.str());
return code.str();
h << code.str();
}

void xsp_parser::to_stream(std::ostream & h) const {
header(h, st::header_impl);
}

void xsp_parser::to_stream(std::ostream & h, std::ostream & s) const {
header(h, st::header_decl);

std::ostringstream os;
xenon::cpp_code code;
os << "#include <xenon/xddl.h>";
parser_const(os, st::source_impl);
code.add(os.str());
s << code.str();
}

std::ostream& xsp_parser::to_decl(std::ostream& os, const elem_type & elem, const std::string & root) const {
Expand Down Expand Up @@ -435,21 +444,8 @@ std::string xsp_parser::parser_header() const {
return os.str();
}

#if 0
std::string xsp_parser::constuctor() const {
}
#endif

std::string xsp_parser::parser_impl() const {
std::ostringstream os;
os <<
"#include <xenon/xml_parser.h>\n" <<
head <<
"namespace " << name_space << " {"
"struct " << class_name << " {"
"public:" <<
class_name << "() {";

void xsp_parser::const_content(std::ostream & os) const {
os << "{ ";
os << "parents.push_back(ast.root());";
os << "p.root_tag(" << qt(root) << ");";

Expand All @@ -464,7 +460,32 @@ std::string xsp_parser::parser_impl() const {
for (const auto & choice : choices) to_choice_init(os, choice);

os << "}";
}
void xsp_parser::parser_const(std::ostream & os, st::type t) const {
switch (t) {
case st::header_decl :
os << class_name << "()";
break;
case st::header_impl :
os << class_name << "()";
const_content(os);
break;
case st::source_impl :
os << class_name << "::" << class_name << "()";
const_content(os);
}
}

std::string xsp_parser::parser_impl(st::type t) const {
std::ostringstream os;
os <<
"#include <xenon/xml_parser.h>\n" <<
head <<
"namespace " << name_space << " {"
"struct " << class_name << " {"
"public:";

parser_const(os, t);
os << class_name << "(const std::string & filename) : " << class_name << "() {" <<
"file = filename; p.open(filename); }";

Expand Down
17 changes: 15 additions & 2 deletions tools/xspx/xspx_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ inline std::ostream& add_children(std::ostream & os, const T & elem) {

elem_type merge_elems(const elem_type & a, const elem_type & b);

namespace st { // source type
enum type {
header_decl,
header_impl,
source_impl
};
}

class xsp_parser {
public:
Expand All @@ -167,9 +174,15 @@ class xsp_parser {
}

void parser_destructor(std::ostream & os) const;
std::string header() const;

void to_stream(std::ostream & h) const;
void to_stream(std::ostream & h, std::ostream & s) const;

void header(std::ostream &, st::type) const;
std::string parser_header() const;
std::string parser_impl() const;
std::string parser_impl(st::type) const;
void const_content(std::ostream & os) const;
void parser_const(std::ostream & os, st::type t = st::header_impl) const;

std::ostream& to_init(std::ostream& os, const elem_type & elem) const;
std::ostream& to_decl(std::ostream& os, const elem_type & elem, const std::string & root) const;
Expand Down