📄 build.cxx
字号:
std::vector<CdlNode>::const_iterator node_i; for (node_i = contents.begin(); node_i != contents.end(); node_i++) { CdlBuildable buildable = dynamic_cast<CdlBuildable>(*node_i); if (0 != buildable) { buildable->update_build_info(this_info, loadable_library); } } CYG_REPORT_RETURN(); CYG_REPORT_RETURN();}//}}}//}}}//{{{ Version number #define's // ----------------------------------------------------------------------------// Given a package xxxPKG_A_B_C with a version V1_2_3, generate additional// #define's of the form://// #define xxxNUM_A_B_C_VERSION_MAJOR 1// #define xxxNUM_A_B_C_VERSION_MINOR 2// #define xxxNUM_A_B_C_VERSION_RELEASE 3//// The goal here is to allow application code to cope with API// changes (which of course should be a rare event but cannot be// eliminated completely). C preprocessor #if statements are// essentially limited to numerical values, so there is no easy// way of coping with V1_2_3 at the preprocessor level. However it// is possible to cope with VERSION_NUMBER #define's.//// Note that only application code and third party packages are// affected. //// These #define's go into system.h, alongside the main definition of// the package. There seems to be little point in putting them in the// package's own configuration header.//// There are three problems. First, what should be done for packages// which do not follow the naming conventions? Given a completely// random package rather than something like xxxPKG_..., what symbol// names should be used? Basically, if the package does not follow the// naming convention then there is no safe way of generating new// symbols. Any names that are chosen might clash. Of course even for// packages that do follow the naming convention a clash is still// possible, just a lot less likely.//// Conclusion: if a package does not follow the naming convention, do// not generate version #define's for it.//// Second, what happens if a different version numbering scheme is// used? For example the release number might be absent. Version// numbering schemes might change between releases, but application// code may still check the #define's.//// Third and related, what should happen for "current" and anoncvs? Do// we want to look at what other versions are installed and bump one// of the numbers?//// Conclusion: the version #define's always have to be generated,// even if they are not present in the version string, to allow// application code to test these symbols anyway. A safe default is// necessary, and -1 is probably the best bet. For example, if// the version is bumped from 1.3.287 to 1.4 then the release number// for the latter is set to -1. Another possible default would be// 0, but that could cause problems for packages that start counting// from 0 (not a common practice, but...)//// This leaves the question of what to do about "current". Chances are// that "current" comes from anoncvs and is always more recent than// any official release, so when comparing versions "current" should// always be greater than anything else. This can be achieved by using// a sufficiently large number for the major version. In practice// it is cleaner to have another #define to indicate the current// version, and then define package versions to match, i.e.://// #define CYGNUM_VERSION_CURRENT 0x7fffff00// ...// #define xxxNUM_A_B_C_VERSION_MAJOR CYGNUM_VERSION_CURRENT// #define xxxNUM_A_B_C_VERSION_MINOR -1// #define xxxNUM_A_B_C_VERSION_RELEASE -1//// All comparisons should now work sensibly. Leaving a little bit// of slack for VERSION_CURRENT seems like a good precaution.static voidsystem_h_add_version_header(Tcl_Channel system_h){ CYG_REPORT_FUNCNAME("system_h_add_version_header"); Tcl_Write(system_h, "#define CYGNUM_VERSION_CURRENT 0x7fffff00\n", -1); CYG_REPORT_RETURN();}static voidsystem_h_add_package_versioning(Tcl_Channel system_h, std::string name, std::string value){ CYG_REPORT_FUNCNAME("system_h_add_package_versioning"); char name_buf[256]; char line_buf[512]; // The first thing to check is that the package name can be used // as the basis for the version symbols. bool ok = false; unsigned int i; for (i = 0; i < name.size(); i++) { if ('_' == name[i]) { if (3 < i) { if ((name[i-3] == 'P') && (name[i-2] == 'K') && (name[i-1] == 'G')) { ok = true; } } break; } } if (name.size() >= 256) { ok = false; } if (!ok) { CYG_REPORT_RETURN(); return; } strcpy(name_buf, name.c_str()); // Change from xxxPKG to xxxNUM name_buf[i - 3] = 'N'; name_buf[i - 2] = 'U'; name_buf[i - 1] = 'M'; // Now determine the version strings. std::string major = "-1"; std::string minor = "-1"; std::string release = "-1"; if ("current" == value) { major = "CYGNUM_VERSION_CURRENT"; } else { Cdl::split_version_string(value, major, minor, release); } sprintf(line_buf, "#define %s_VERSION_MAJOR %s\n", name_buf, major.c_str()); Tcl_Write(system_h, line_buf, -1); sprintf(line_buf, "#define %s_VERSION_MINOR %s\n", name_buf, minor.c_str()); Tcl_Write(system_h, line_buf, -1); sprintf(line_buf, "#define %s_VERSION_RELEASE %s\n", name_buf, release.c_str()); Tcl_Write(system_h, line_buf, -1); CYG_REPORT_RETURN();}//}}}//{{{ CdlDefinableBody //{{{ Basics // ----------------------------------------------------------------------------CdlDefinableBody::CdlDefinableBody(){ CYG_REPORT_FUNCNAME("CdlDefinable:: default constructor"); CYG_REPORT_FUNCARG1XV(this); // There is no data to initialize cdldefinablebody_cookie = CdlDefinableBody_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}CdlDefinableBody::~CdlDefinableBody(){ CYG_REPORT_FUNCNAME("CdlDefinable:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); cdldefinablebody_cookie = CdlDefinableBody_Invalid; CYGDBG_MEMLEAK_DESTRUCTOR(); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------std::stringCdlDefinableBody::get_class_name() const{ CYG_REPORT_FUNCNAME("CdlDefinable::get_class_name"); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return "definable";}// ----------------------------------------------------------------------------boolCdlDefinableBody::check_this(cyg_assert_class_zeal zeal) const{ if (CdlDefinableBody_Magic != cdldefinablebody_cookie) { return false; } CYGDBG_MEMLEAK_CHECKTHIS(); return CdlNodeBody::check_this(zeal);}//}}}//{{{ add_property_parser() and check_properties() // ----------------------------------------------------------------------------voidCdlDefinableBody::add_property_parsers(std::vector<CdlInterpreterCommandEntry>& parsers){ CYG_REPORT_FUNCNAME("CdlDefinable::add_property_parsers"); static CdlInterpreterCommandEntry commands[] = { CdlInterpreterCommandEntry("no_define", &parse_no_define ), CdlInterpreterCommandEntry("define", &parse_define ), CdlInterpreterCommandEntry("define_format", &parse_define_format ), CdlInterpreterCommandEntry("define_proc", &parse_define_proc ), CdlInterpreterCommandEntry("if_define", &parse_if_define ), CdlInterpreterCommandEntry("", 0 ) }; for (int i = 0; commands[i].command != 0; i++) { std::vector<CdlInterpreterCommandEntry>::const_iterator j; for (j = parsers.begin(); j != parsers.end(); j++) { if (commands[i].name == j->name) { if (commands[i].command != j->command) { CYG_FAIL("Property names are being re-used"); } break; } } if (j == parsers.end()) { parsers.push_back(commands[i]); } } CdlNodeBody::add_property_parsers(parsers); CYG_REPORT_RETURN();}voidCdlDefinableBody::check_properties(CdlInterpreter interp){ CYG_REPORT_FUNCNAME("CdlDefinable::check_properties"); CYG_REPORT_FUNCARG2XV(this, interp); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(interp); // There should be at most one each of no_define and define_format. if (count_properties(CdlPropertyId_NoDefine) > 1) { CdlParse::report_error(interp, "", "There should be at most one no_define property."); } if (count_properties(CdlPropertyId_DefineFormat) > 1) { CdlParse::report_error(interp, "", "There should be at most one define_format property."); } if (has_property(CdlPropertyId_NoDefine) && has_property(CdlPropertyId_DefineFormat)) { CdlParse::report_error(interp, "", "The no_define and define_format properties are mutually exclusive."); } // FIXME: the define_format property only makes sense for certain // flavors. However the flavor property may not have been processed yet. CdlNodeBody::check_properties(interp); CYG_REPORT_RETURN();}//}}}//{{{ Definable properties // ----------------------------------------------------------------------------// Syntax: no_defineintCdlDefinableBody::parse_no_define(CdlInterpreter interp, int argc, char** argv){ CYG_REPORT_FUNCNAMETYPE("parse_no_define", "result %d"); int result = CdlParse::parse_minimal_property(interp, argc, argv, CdlPropertyId_NoDefine, 0, 0); CYG_REPORT_RETVAL(result); return result;}// ----------------------------------------------------------------------------// syntax: define <symbol>// The argument to "define" should be a valid C preprocessor symbol.static voidparse_define_final_check(CdlInterpreter interp, CdlProperty_String prop){ CYG_REPORT_FUNCNAME("parse_define_final_check"); CYG_PRECONDITION_CLASSC(prop); CYG_PRECONDITION_CLASSC(interp); const std::string& str = prop->get_string(); if (!Cdl::is_valid_c_preprocessor_symbol(str)) { CdlParse::report_property_parse_error(interp, prop, str + " is not a valid C preprocessor symbol"); } // There may be a file option. At this stage the only valid filename // that can be used here is system.h std::string file_option = prop->get_option("file"); if (("" != file_option) && ("system.h" != file_option)) { CdlParse::report_property_parse_error(interp, prop, "Invalid -file option " + file_option); } // FIXME: validate the format string CYG_REPORT_RETURN();}intCdlDefinableBody::parse_define(CdlInterpreter interp, int argc, char** argv){ CYG_REPORT_FUNCNAMETYPE("parse_define", "result %d"); static char* options[] = { "file:", "format:", 0 }; int result = CdlParse::parse_string_property(interp, argc, argv, CdlPropertyId_Define, options, &parse_define_final_check); CYG_REPORT_RETVAL(result); return result;}// ----------------------------------------------------------------------------// syntax: define_format <string>//// FIXME: it is possible to apply some checks to the string, e.g. that there// is only one conversion operation.//// FIXME: also check that the flavor is sensible, define_format has no effect// for none or bool//// FIXME: enforce mutual exclusion with no_defineintCdlDefinableBody::parse_define_format(CdlInterpreter interp, int argc, char** argv){ CYG_REPORT_FUNCNAMETYPE("parse_format", "result %d"); int result = CdlParse::parse_string_property(interp, argc, argv, CdlPropertyId_DefineFormat, 0, 0); CYG_REPORT_RETVAL(result); return result;}// ----------------------------------------------------------------------------// syntax: define_proc <tclcode>intCdlDefinableBody::parse_define_proc(CdlInterpreter interp, int argc, char** argv){ CYG_REPORT_FUNCNAMETYPE("parse_define_proc", "result %d"); int result = CdlParse::parse_tclcode_property(interp, argc, argv, CdlPropertyId_DefineProc, 0, 0); CYG_REPORT_RETVAL(result); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -