📄 build.cxx
字号:
// ----------------------------------------------------------------------------// Syntax: if_define sym1 sym2static voidparse_if_define_final_check(CdlInterpreter interp, CdlProperty_StringVector prop){ CYG_REPORT_FUNCNAME("parse_if_define_final_check"); CYG_PRECONDITION_CLASSC(interp); CYG_PRECONDITION_CLASSC(prop); // There should be exactly two entries in the vector, and both of them should be // valid preprocessor symbols. const std::vector<std::string>& strings = prop->get_strings(); if (2 != strings.size()) { CdlParse::report_property_parse_error(interp, prop, "There should be exactly two arguments."); } if (!Cdl::is_valid_c_preprocessor_symbol(strings[0])) { CdlParse::report_property_parse_error(interp, prop, strings[0] + " is not a valid C preprocessor symbol."); } if (!Cdl::is_valid_c_preprocessor_symbol(strings[1])) { CdlParse::report_property_parse_error(interp, prop, strings[1] + " 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); }}intCdlDefinableBody::parse_if_define(CdlInterpreter interp, int argc, char** argv){ CYG_REPORT_FUNCNAMETYPE("parse_if_define", "result %d"); char* options[] = { "file:", 0 }; int result = CdlParse::parse_stringvector_property(interp, argc, argv, CdlPropertyId_IfDefine, options, &parse_if_define_final_check, false); CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ generate_config_header() // ----------------------------------------------------------------------------// This code needs to allow for the following properties.//// 1) no_define. This suppresses the default #define generation. //// 2) define_format <format_string.//// 3) define [-file <filename>][-format <format_string>] symbol//// 4) define_proc//// 5) if_definevoidCdlDefinableBody::generate_config_header(Tcl_Channel this_hdr, Tcl_Channel system_h) const{ CYG_REPORT_FUNCNAME("CdlDefinable::generate_config_header"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlLoadable loadable = get_owner(); CdlInterpreter interp = loadable->get_interpreter(); // This definable is known to be active. However it may or may not be enabled. CYG_PRECONDITIONC(is_active()); std::string name = get_name(); CdlValueFlavor flavor = CdlValueFlavor_Bool; std::string value = "1"; CdlConstValuable valuable = dynamic_cast<CdlConstValuable>(this); if (0 != valuable) { // It is always possible to check the enabled() flag. if (!valuable->is_enabled()) { CYG_REPORT_RETURN(); return; } // The value is only valid for BoolData and Data flavors, and may // not have been provided. If there is no value then this option // should not generate a #define flavor = valuable->get_flavor(); if ((CdlValueFlavor_BoolData == flavor) || (CdlValueFlavor_Data == flavor)) { value = valuable->get_value(); } } // Flavor and value are now both set to sensible strings. // First, check the no_define property. If this is present then the default // #define generation should be suppressed. if (!has_property(CdlPropertyId_NoDefine)) { // OK, it is necessary to generate at least one #define. // If this node is actually a loadable then the #define should go // into system.h, otherwise into the current header Tcl_Channel chan = this_hdr; if (dynamic_cast<CdlConstLoadable>((CdlConstNode)this) == loadable) { chan = system_h; } // For flavors None and Bool, there should be just one #define if ((CdlValueFlavor_None == flavor) || (CdlValueFlavor_Bool == flavor)) { std::string define = "#define " + name + " 1\n"; Tcl_Write(chan, const_cast<char*>(define.c_str()), -1); } else { // If there is a format string then that controls the default // value display. if (!has_property(CdlPropertyId_DefineFormat)) { std::string define = "#define " + name + " " + value + "\n"; Tcl_Write(chan, const_cast<char*>(define.c_str()), -1); } else { CdlProperty_String strprop = dynamic_cast<CdlProperty_String>(get_property(CdlPropertyId_DefineFormat)); CYG_ASSERT_CLASSC(strprop); std::string format = strprop->get_string(); std::string cmd = "return \"#define " + name + " [format " + format + " " + value + "]\n\""; std::string define; if (TCL_OK != interp->eval(cmd, define)) { throw CdlInputOutputException("Internal error executing tcl fragment to process define_format property"); } Tcl_Write(chan, const_cast<char*>(define.c_str()), -1); } // There may also be a separate #define of the form <name>_<value>, // if that is a valid preprocessor symbol. std::string tmp = name + "_" + value; if (Cdl::is_valid_c_preprocessor_symbol(tmp)) { tmp = "#define "+ tmp + "\n"; Tcl_Write(chan, const_cast<char*>(tmp.c_str()), -1); } // For loadables, add additional version information to system_h if (dynamic_cast<CdlConstLoadable>((CdlConstNode)this) == loadable) { system_h_add_package_versioning(system_h, name, value); } } } // Next, check for any additional define properties std::vector<CdlProperty> define_props; get_properties(CdlPropertyId_Define, define_props); std::vector<CdlProperty>::const_iterator prop_i; for (prop_i = define_props.begin(); prop_i != define_props.end(); prop_i++) { CdlProperty_String strprop = dynamic_cast<CdlProperty_String>(*prop_i); CYG_ASSERT_CLASSC(strprop); std::string symbol = strprop->get_string(); std::string file = strprop->get_option("file"); Tcl_Channel chan = this_hdr; if (("" != file) && ("system.h" == file)) { chan = system_h; } if ((CdlValueFlavor_None == flavor) || (CdlValueFlavor_Bool == flavor)) { std::string define = "#define " + symbol + " 1\n"; Tcl_Write(chan, const_cast<char*>(define.c_str()), -1); } else { std::string format = strprop->get_option("format"); if ("" == format) { std::string define = "#define " + symbol + " " + value + "\n"; Tcl_Write(chan, const_cast<char*>(define.c_str()), -1); } else { std::string cmd = "return \"#define " + symbol + " [format " + format + " " + value + "]\n\""; std::string define; if (TCL_OK != interp->eval(cmd, define)) { throw CdlInputOutputException("Internal error executing tcl fragment to process format option"); } Tcl_Write(chan, const_cast<char*>(define.c_str()), -1); } std::string tmp = symbol + "_" + value; if (Cdl::is_valid_c_preprocessor_symbol(tmp)) { tmp = "#define " + tmp + "\n"; Tcl_Write(chan, const_cast<char*>(tmp.c_str()), -1); } } } // Now check for if_define properties std::vector<CdlProperty> if_define_props; get_properties(CdlPropertyId_IfDefine, if_define_props); for (prop_i = if_define_props.begin(); prop_i != if_define_props.end(); prop_i++) { CdlProperty_StringVector strprop = dynamic_cast<CdlProperty_StringVector>(*prop_i); CYG_ASSERT_CLASSC(strprop); CYG_ASSERTC(2 == strprop->get_number_of_strings()); std::string sym1 = strprop->get_string(0); std::string sym2 = strprop->get_string(1); Tcl_Channel chan = this_hdr; std::string file = strprop->get_option("file"); if (("" != file) && ("system.h" == file)) { chan = system_h; } std::string data = "#ifdef " + sym1 + "\n# define " + sym2 + " 1\n#endif\n"; Tcl_Write(chan, const_cast<char*>(data.c_str()), -1); } // And define_proc properties std::vector<CdlProperty> define_proc_props; get_properties(CdlPropertyId_DefineProc, define_proc_props); for (prop_i = define_proc_props.begin(); prop_i != define_proc_props.end(); prop_i++) { CdlProperty_TclCode codeprop = dynamic_cast<CdlProperty_TclCode>(*prop_i); CYG_ASSERT_CLASSC(codeprop); cdl_tcl_code code = codeprop->get_code(); std::string result; if (TCL_OK != interp->eval(code, result)) { throw CdlInputOutputException("Error evaluating define_proc property for " + name + "\n" + result); } } CYG_REPORT_RETURN();}//}}}//}}}//{{{ CdlDefineLoadableBody //{{{ Basics // ----------------------------------------------------------------------------CdlDefineLoadableBody::CdlDefineLoadableBody(){ CYG_REPORT_FUNCNAME("CdlDefineLoadable:: default constructor"); CYG_REPORT_FUNCARG1XV(this); cdldefineloadablebody_cookie = CdlDefineLoadableBody_Magic; CYGDBG_MEMLEAK_CONSTRUCTOR(); CYG_POSTCONDITION_THISC(); CYG_REPORT_RETURN();}CdlDefineLoadableBody::~CdlDefineLoadableBody(){ CYG_REPORT_FUNCNAME("CdlDefineLoadable:: destructor"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); cdldefineloadablebody_cookie = CdlDefineLoadableBody_Invalid; CYGDBG_MEMLEAK_DESTRUCTOR(); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------std::stringCdlDefineLoadableBody::get_class_name() const{ CYG_REPORT_FUNCNAME("CdlDefineLoadable::get_class_name"); CYG_PRECONDITION_THISC(); CYG_REPORT_RETURN(); return "define_loadable";}// ----------------------------------------------------------------------------boolCdlDefineLoadableBody::check_this(cyg_assert_class_zeal zeal) const{ if (CdlDefineLoadableBody_Magic != cdldefineloadablebody_cookie) { return false; } CYGDBG_MEMLEAK_CHECKTHIS(); return CdlLoadableBody::check_this(zeal) && CdlNodeBody::check_this(zeal);}//}}}//{{{ Property parsing // ----------------------------------------------------------------------------voidCdlDefineLoadableBody::add_property_parsers(std::vector<CdlInterpreterCommandEntry>& parsers){ CYG_REPORT_FUNCNAME("CdlDefineLoadable::add_property_parsers"); static CdlInterpreterCommandEntry commands[] = { CdlInterpreterCommandEntry("define_header", &parse_define_header), 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();}voidCdlDefineLoadableBody::check_properties(CdlInterpreter interp){ CYG_REPORT_FUNCNAME("CdlDefineLoadable::check_properties"); CYG_REPORT_FUNCARG2XV(this, interp); CYG_PRECONDITION_THISC(); CYG_PRECONDITION_CLASSC(interp); // There should be at most one define_header property int count = count_properties(CdlPropertyId_DefineHeader); if (count> 1) { CdlParse::report_error(interp, "", "There should be at most one define_header property."); } // FIXME: filename validation CdlNodeBody::check_properties(interp); CYG_REPORT_RETURN();}// ----------------------------------------------------------------------------// syntax: define_header <header file name>intCdlDefineLoadableBody::parse_define_header(CdlInterpreter interp, int argc, char** argv){ CYG_REPORT_FUNCNAMETYPE("parse_define_header", "result %d"); int result = CdlParse::parse_string_property(interp, argc, argv, CdlPropertyId_DefineHeader, 0, 0); CYG_REPORT_RETVAL(result); return result;}//}}}//{{{ generate_config_header() // ----------------------------------------------------------------------------voidCdlDefineLoadableBody::generate_config_header(Tcl_Channel this_hdr, Tcl_Channel system_h) const{ CYG_REPORT_FUNCNAME("CdlDefineLoadable::generate_config_header"); CYG_REPORT_FUNCARG1XV(this); CYG_PRECONDITION_THISC(); CdlInterpreter interp = get_interpreter(); Tcl_RegisterChannel(interp->get_tcl_interpreter(), this_hdr); Tcl_RegisterChannel(interp->get_tcl_interpreter(), system_h); CdlInterpreterBody::ContextSu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -