⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 package.cxx

📁 ecos实时嵌入式操作系统
💻 CXX
📖 第 1 页 / 共 2 页
字号:
//{{{  Banner                           //============================================================================////     package.cxx////     Implementation of the CdlPackage class////============================================================================//####COPYRIGHTBEGIN####//                                                                          // ----------------------------------------------------------------------------// Copyright (C) 2002 Bart Veer// Copyright (C) 1999, 2000 Red Hat, Inc.//// This file is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.//// ----------------------------------------------------------------------------//                                                                          //####COPYRIGHTEND####//============================================================================//#####DESCRIPTIONBEGIN####//// Author(s):   bartv// Contact(s):  bartv// Date:        1999/03/01// Version:     0.02////####DESCRIPTIONEND####//============================================================================//}}}//{{{  #include's                       // ----------------------------------------------------------------------------#include "cdlconfig.h"// Get the infrastructure types, assertions, tracing and similar// facilities.#include <cyg/infra/cyg_ass.h>#include <cyg/infra/cyg_trac.h>// <cdl.hxx> defines everything implemented in this module.// It implicitly supplies <string>, <vector> and <map> because// the class definitions rely on these headers.#include <cdl.hxx>//}}}//{{{  Statics                          // ----------------------------------------------------------------------------CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlPackageBody);//}}}//{{{  Constructor                      // ----------------------------------------------------------------------------// Constructor. The real work is actually done in the base classes// and the parser.CdlPackageBody::CdlPackageBody(std::string name_arg, CdlConfiguration toplevel, std::string dir)    : CdlNodeBody(name_arg),      CdlContainerBody(),      CdlUserVisibleBody(),      CdlValuableBody(CdlValueFlavor_BoolData),      CdlParentableBody(),      CdlBuildableBody(),      CdlDefinableBody(),      CdlLoadableBody(toplevel, dir),      CdlBuildLoadableBody(),      CdlDefineLoadableBody(){    CYG_REPORT_FUNCNAME("CdlPackageBody:: constructor");    CYG_REPORT_FUNCARG1XV(this);    loaded_for_template   = false;    loaded_for_hardware   = false;    cdlpackagebody_cookie = CdlPackageBody_Magic;    CYGDBG_MEMLEAK_CONSTRUCTOR();        CYG_POSTCONDITION_THISC();    CYG_REPORT_RETURN();}//}}}//{{{  Destructor                       // ----------------------------------------------------------------------------// Most of the work is done in the base classes.CdlPackageBody::~CdlPackageBody(){    CYG_REPORT_FUNCNAME("CdlPackageBody:: destructor");    CYG_REPORT_FUNCARG1XV(this);    CYG_PRECONDITION_THISC();    loaded_for_template   = false;    loaded_for_hardware   = false;    cdlpackagebody_cookie = CdlPackageBody_Invalid;    CYGDBG_MEMLEAK_DESTRUCTOR();        CYG_REPORT_RETURN();}//}}}//{{{  parse_package()                  // ----------------------------------------------------------------------------// Parsing a package definition. This routine gets invoked directly from the// Tcl interpreter, when the cdl_package command is encountered. The// command takes two arguments, a name and a body of properties, and there// should only be one cdl_package command per package.//// At the point that the cdl_package command is executed the CdlPackage// object should already exist, and in fact it should be the current// interpreter's loadable. Obviously the name should be checked. The// main purpose of the cdl_package command is to fill in some extra// information in the form of properties.//// A package is a buildable, valuable, uservisible, ... object so it// inherits properties from all three. In practice some of the// properties from the base classes are not actually legal, but that// will be caught by the validation code. Additional properties// relevant to a package are: parent, license_proc, install_proc, and// wizard. It is harmless (but unnecessary) to allow components etc.// to be defined inside a package definition.intCdlPackageBody::parse_package(CdlInterpreter interp, int argc, const char* argv[]){    CYG_REPORT_FUNCNAMETYPE("CdlPackageBody::parse_package", "result %d");    CYG_REPORT_FUNCARG1("argc %d", argc);    CYG_PRECONDITION_CLASSC(interp);        std::string  diag_argv0      = CdlParse::get_tcl_cmd_name(argv[0]);    CdlLoadable  loadable       = interp->get_loadable();    CdlPackage   package        = dynamic_cast<CdlPackage>(loadable);    CdlContainer parent         = package->get_parent();           CdlToplevel  toplevel       = interp->get_toplevel();    std::string filename        = interp->get_context();     CYG_ASSERT_CLASSC(loadable);        // There should always be a loadable during parsing    CYG_ASSERT_CLASSC(package);         // And packages are the only loadable for software CDL    CYG_ASSERT_CLASSC(toplevel);    CYG_ASSERTC(dynamic_cast<CdlToplevel>(parent) == toplevel);    // The package cannot have been reparented yet.    CYG_ASSERTC("" != filename);    CYG_UNUSED_PARAM(CdlContainer, parent);    CYG_UNUSED_PARAM(CdlToplevel, toplevel);    // There should be no current node, in fact the cdl_package command    // can only exist at the toplevel of the original script courtesy    // of commands being pushed and popped.    CYG_ASSERTC(0 == interp->get_node());        // Also, the package should be the current container.    CYG_ASSERTC(package == dynamic_cast<CdlPackage>(interp->get_container()));        // Declare these outside the scope of the try statement, to allow    // goto calls for the error handling.    const std::vector<CdlProperty>& properties = package->get_properties();    CdlInterpreterBody::NodeSupport interp_node(interp, package);    static CdlInterpreterCommandEntry commands[] =    {        CdlInterpreterCommandEntry("hardware",           &parse_hardware                    ),        CdlInterpreterCommandEntry("license_proc",       &parse_license_proc                ),        CdlInterpreterCommandEntry("install_proc",       &parse_install_proc                ),        CdlInterpreterCommandEntry("cdl_component",      &CdlComponentBody::parse_component ),        CdlInterpreterCommandEntry("cdl_option",         &CdlOptionBody::parse_option       ),        CdlInterpreterCommandEntry("cdl_interface",      &CdlInterfaceBody::parse_interface ),        CdlInterpreterCommandEntry("cdl_dialog",         &CdlDialogBody::parse_dialog       ),        CdlInterpreterCommandEntry("cdl_wizard",         &CdlWizardBody::parse_wizard       ),        CdlInterpreterCommandEntry("",                   0                                  )    };    std::vector<CdlInterpreterCommandEntry>  new_commands;    int i;        // All parsing errors may result in an exception, under the control of    // application code. This exception must not pass through the Tcl interpreter.    int result = TCL_OK;    try {        // Currently there are no options. This may change in future.        if (3 != argc) {            CdlParse::report_error(interp, "",                                   std::string("Incorrect number of arguments to `") + diag_argv0 +                                   "'\nExpecting name and properties list.");        } else if (argv[1] != loadable->get_name()) {            CdlParse::report_error(interp, "",                                   std::string("Incorrect package name in CDL script.\n") +                                   "This package is `" + loadable->get_name() + "'\n" +                                   "The CDL script `" + filename + "' defines a package `" + argv[1] + "'.");        } else if (0 != properties.size()) {            CdlParse::report_error(interp, "",                                   std::string("Duplicate cdl_package commands for package `") + argv[1] + "'.");        } else if (!Tcl_CommandComplete(CDL_TCL_CONST_CAST(char*, argv[2]))) {            CdlParse::report_error(interp, "",                                   std::string("Invalid property list for cdl_package `") + argv[1] + "'.");        } else {            for (i = 0; 0 != commands[i].command; i++) {                new_commands.push_back(commands[i]);            }                    CdlBuildLoadableBody::add_property_parsers(new_commands);            CdlBuildableBody::add_property_parsers(new_commands);            CdlDefineLoadableBody::add_property_parsers(new_commands);            CdlDefinableBody::add_property_parsers(new_commands);            CdlParentableBody::add_property_parsers(new_commands);            CdlValuableBody::add_property_parsers(new_commands);            CdlUserVisibleBody::add_property_parsers(new_commands);            CdlNodeBody::add_property_parsers(new_commands);            // Now evaluate the body. If an error occurs then typically            // this will be reported via CdlParse::report_error(),            // but any exceptions will have been intercepted and            // turned into a Tcl error.            CdlInterpreterBody::CommandSupport interp_cmds(interp, new_commands);            result = interp->eval(argv[2]);            if (TCL_OK == result) {                // Even if there were errors, they were not fatal. There may                // now be a number of properties for this package, and some                // validation should take place. Start with the base classes.                package->CdlNodeBody::check_properties(interp);                package->CdlUserVisibleBody::check_properties(interp);                package->CdlValuableBody::check_properties(interp);                package->CdlParentableBody::check_properties(interp);                package->CdlBuildableBody::check_properties(interp);                package->CdlBuildLoadableBody::check_properties(interp);                package->CdlDefinableBody::check_properties(interp);                package->CdlDefineLoadableBody::check_properties(interp);                // Some of the properties in the base classes are not actually                // appropriate. A package is valuable, but it can only be                // modified by loading and unloading. Many of the value-related                // properties do not make sense.                if (package->count_properties(CdlPropertyId_Flavor) > 0) {                    CdlParse::report_error(interp, "", "A package should not have a `flavor' property.");                }                if (package->count_properties(CdlPropertyId_EntryProc) > 0) {                    CdlParse::report_error(interp, "", "A package should not have an `entry_proc' property.");                }                if (package->count_properties(CdlPropertyId_CheckProc) > 0) {                    CdlParse::report_error(interp, "", "A package should not have a `check_proc' property.");                }                // BLV: this reasoning is faulty, it should be possible to                // control the enabled aspect via an expression. That would                // need option processing for the default_value property.                if (package->count_properties(CdlPropertyId_DefaultValue) > 0) {                    CdlParse::report_error(interp, "", "A package should not have a `default_value' property.");                }                if (package->count_properties(CdlPropertyId_LegalValues) > 0) {                    CdlParse::report_error(interp, "", "A package should not have a `legal_values' property.");                }                if (package->count_properties(CdlPropertyId_Calculated) > 0) {                    CdlParse::report_error(interp, "", "A package should not have a `calculated' property.");                }                if (package->count_properties(CdlPropertyId_Dialog) > 0) {                    CdlParse::report_error(interp, "", "A package should not have a `dialog' property.");                }                // There should be at most one each of license_proc, install_proc, include_dir,                // export_to, library, makefile, and wizard.                if (package->count_properties(CdlPropertyId_LicenseProc) > 1) {                    CdlParse::report_error(interp, "", "A package should have at most one `license_proc' property.");                }                if (package->count_properties(CdlPropertyId_InstallProc) > 1) {                    CdlParse::report_error(interp, "", "A package should have at most one `install_proc' property.");                }            }        }            } catch (std::bad_alloc e) {        // Errors at this stage should be reported via Tcl, not via C++        interp->set_result(CdlParse::construct_diagnostic(interp, "internal error", "", "Out of memory"));        result = TCL_ERROR;    } catch (CdlParseException e) {        interp->set_result(e.get_message());        result = TCL_ERROR;    } catch(...) {        interp->set_result(CdlParse::construct_diagnostic(interp, "internal error", "", "Unexpected C++ exception"));        result = TCL_ERROR;    }        CYG_REPORT_RETVAL(result);    return result;}//}}}//{{{  Package properties               // ----------------------------------------------------------------------------// Syntax: hardwareintCdlPackageBody::parse_hardware(CdlInterpreter interp, int argc, const char* argv[]){    CYG_REPORT_FUNCNAMETYPE("parse_hardware", "result %d");    int result = CdlParse::parse_minimal_property(interp, argc, argv, CdlPropertyId_Hardware, 0, 0);        CYG_REPORT_RETVAL(result);    return result;}// ----------------------------------------------------------------------------// Syntax: install_proc <tclcode>intCdlPackageBody::parse_install_proc(CdlInterpreter interp, int argc, const char* argv[]){    CYG_REPORT_FUNCNAMETYPE("parse_install_proc", "result %d");    int result = CdlParse::parse_tclcode_property(interp, argc, argv, CdlPropertyId_InstallProc, 0, 0);        CYG_REPORT_RETVAL(result);    return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -