📄 jsp_parser.cpp
字号:
//婎杮揑側僆僽僕僃僋僩偺奿擺応強偼偙偙偱巜掕偟偰偍偔
cfg->createPart("header")
.createPart("include")
.createPart(IDENTIFIER_VARIABLE)
.createPart(TASK)
.createPart(SEMAPHORE)
.createPart(EVENTFLAG)
.createPart(DATAQUEUE)
.createPart(MAILBOX)
.createPart(FIXEDSIZEMEMORYPOOL)
.createPart(CYCLICHANDLER)
.createPart(INTERRUPTHANDLER)
.createPart(EXCEPTIONHANDLER)
.createPart(INITIALIZER)
.createPart(OBJECT_INITIALIZER)
.createPart("others");
//僇乕僱儖峔惉僼傽僀儖惗惉僀儀儞僩偺幚峴
KernelCfg::CreationEvent ev;
ev.file = cfg;
Event<KernelCfg::CreationEvent>::raise(ev);
//僄儔乕僠僃僢僋
if(ev.file == 0)
ExceptionMessage("Internal error : kernel_cfg event handler eliminates the instance.","撪晹僄儔乕 : kernel_cfg偺僴儞僪儔偑僀儞僗僞儞僗傪嶍彍偟偨") << throwException;
if(RuntimeObjectTable::getInstance(typeid(KernelCfg)) != ev.file)
ExceptionMessage("Internal error : kernel_cfg event handler creates the illegal instance.","撪晹僄儔乕 : kernel_cfg偺僴儞僪儔偑晄惓側僀儞僗僞儞僗傪惗惉偟偨") << throwException;
return ev.file; //cfg偱偼僟儊
}
//僼傽僀儖柤偐傜徴撍夞旔梡偺柤慜傪惗惉偡傞
string convert_filename_to_definition(string filename)
{
string result;
string::iterator scope;
scope = filename.begin();
while(scope != filename.end()) {
if(isalnum(*scope))
result += static_cast<char>(toupper(*scope));
else
result += '_';
++ scope;
}
return result;
}
//帺摦ID妱晅寢壥僼傽僀儖偺惗惉
KernelID * createKernelID(void)
{
KernelID * id = 0;
id = KernelID::createInstance(get_filename("kernel_id","kernel_id.h"));
id->disableOutput();
//婎杮揑側僆僽僕僃僋僩偺奿擺応強偼偙偙偱巜掕偟偰偍偔
id-> createPart("__header__")
.createPart("body")
.createPart("__footer__");
//僼傽僀儖惗惉僀儀儞僩偺幚峴
KernelID::CreationEvent ev;
ev.file = id;
Event<KernelID::CreationEvent>::raise(ev);
//僄儔乕僠僃僢僋
if(ev.file == 0)
ExceptionMessage("Internal error : kernel_id event handler eliminates the instance.","撪晹僄儔乕 : kernel_id偺僴儞僪儔偑僀儞僗僞儞僗傪嶍彍偟偨") << throwException;
if(RuntimeObjectTable::getInstance(typeid(KernelID)) != ev.file)
ExceptionMessage("Internal error : kernel_id event handler creates the illegal instance.","撪晹僄儔乕 : kernel_id偺僴儞僪儔偑晄惓側僀儞僗僞儞僗傪惗惉偟偨") << throwException;
//懡廳僀儞僋儖乕僪夞旔梡掕媊偺捛壛
string defname = convert_filename_to_definition(id->getFilename());
id->movePart("__header__");
(*id) // << get_agreement(id->getFilename()) //暥尵偺晅梌
<< "#ifndef " << defname << '\n' //#ifndef KERNELID_H
<< "#define " << defname << "\n\n"; //#define KERNELID_H
id->movePart("__footer__");
(*id) << "\n#endif /* " << defname << " */\n\n"; //#endif /* KERNELID_H */
return ev.file; //id偱偼僟儊
}
//搊榐偝傟偰偄傞暥帤偺嵟戝挿傪摼傞
unsigned int countLongestSymbolName(const std::map<std::string, int> & identifiers) throw()
{
unsigned int max_length = 0;
std::map<std::string, int>::const_iterator scope;
// 傕偭偲傕挿偄柤慜傪帩偮僔儞儃儖柤傪専嶕
scope = identifiers.begin();
while(scope != identifiers.end()) {
if(max_length < scope->first.size())
max_length = scope->first.size();
++ scope;
}
return max_length;
}
//帺摦ID妱晅寢壥弌椡 (偙傟傑偱偲偺屳姺儌乕僪)
void serializeIdentifiers_defineStyle(KernelID * out, std::map<std::string, int> & identifier_pool)
{
std::map<std::string, int>::const_iterator scope;
string::size_type max_length;
(*out) << "\t/* object identifier deifnition */\n\n";
// 傕偭偲傕挿偄柤慜傪帩偮僔儞儃儖柤傪専嶕
max_length = countLongestSymbolName(identifier_pool);
scope = identifier_pool.begin();
while(scope != identifier_pool.end()) {
(*out) << "#define " << scope->first
<< string(max_length - scope->first.size() + 4, ' ') //抣傪偦傠偊傞
<< setw(3)
<< scope->second << '\n';
++ scope;
}
}
//帺摦ID妱晅寢壥弌椡 (掕悢曄悢奿擺曽幃)
void serializeIdentifiers_variableStyle(KernelID * id, std::map<std::string, int> & identifier) throw(Exception)
{
std::map<std::string, int>::const_iterator scope;
string::size_type max_length;
KernelCfg * cfg = getRuntimeObjectInstance(KernelCfg);
/* kernel_id.h偵弌椡 */
(*id) << "#ifdef __cplusplus\n"
"#define KERNELID_EXPORT extern \"C\"\n"
"#else\n"
"#define KERNELID_EXPORT extern\n"
"#endif\n\n";
// 傕偭偲傕挿偄柤慜傪帩偮僔儞儃儖柤傪専嶕
max_length = countLongestSymbolName(identifier);
scope = identifier.begin();
while(scope != identifier.end()) {
(*id) << "KERNELID_EXPORT const int "
<< scope->first
<< ";\n";
++ scope;
}
(*id) << "\n#undef KERNELID_EXPORT\n\n";
/* kernel_cfg.c偵掕悢掕媊傪弌椡 */
cfg->movePart(IDENTIFIER_VARIABLE);
(*cfg) << "\t/* Identifier storage variables */\n";
scope = identifier.begin();
while(scope != identifier.end()) {
(*cfg) << "const int "
<< scope->first
<< string(max_length - scope->first.size() + 4, ' ')
<< " = "
<< scope->second << ";\n";
++ scope;
}
}
//帺摦ID妱晅寢壥弌椡 (暪梡曽幃 - (toppers-dev 28))
void serializeIdentifiers_blendedStyle(KernelID * id, std::map<std::string, int> & identifier) throw(Exception)
{
/* kernel_id.h傊偺弌椡偼廬棃偲摨偠 */
serializeIdentifiers_defineStyle(id, identifier);
/* kernel_cfg.c偵掕悢掕媊傪弌椡 */
std::map<std::string, int>::const_iterator scope;
string::size_type max_length;
KernelCfg * cfg = getRuntimeObjectInstance(KernelCfg);
max_length = countLongestSymbolName(identifier);
cfg->movePart(IDENTIFIER_VARIABLE);
(*cfg) << "\t/* Identifier storage variables */\n";
scope = identifier.begin();
while(scope != identifier.end()) {
(*cfg) << "const int "
<< scope->first
<< "_id"
<< string(max_length - scope->first.size() + 1, ' ')
<< " = "
<< scope->second << ";\n";
++ scope;
}
}
//帺摦ID妱晅寢壥偺弌椡
void serializeIdentifiers(bool varid_style = false) throw(Exception)
{
KernelID * out = getRuntimeObjectInstance(KernelID);
std::map<std::string, int> identifier_pool;
//幆暿巕僾乕儖傪惗惉
{
Directory * scope = Singleton<Directory>::getInstance()->findChild("/identifier")->getFirstChild();
while(scope != 0)
{
identifier_pool[scope->getKey()] = scope->toInteger();
scope = scope->getNext();
}
}
//妱晅寢壥偺弌椡
out->movePart("body");
if(varid_style) {
serializeIdentifiers_blendedStyle(out, identifier_pool);
// serializeIdentifiers_variableStyle(out, identifier_pool);
}
else {
serializeIdentifiers_defineStyle(out, identifier_pool);
}
out->enableOutput();
}
void serializeConfiguration_headerPart(KernelCfg & out) throw(Exception)
{
const bool backward_compatible = getOptionParameter()["1.3"].isValid();
//摢偺晹暘偺弌椡
out.movePart("header");
out // << get_agreement(out.getFilename()) //暥尵偺揧晅
<< "/* Configured with [" //僐儞僼傿僊儏儗乕僔儑儞僆僾僔儑儞傪弌椡偟偰偍偔
<< getOptionParameter().getCommandLine()
<< "] */\n\n";
//1.4埲崀偼kernel_cfg.h傪巊梡
if(!backward_compatible)
out << "#include " << conv_includefile("kernel_cfg.h") << '\n';
//kernel_id.h偺include (kernel_id偼僟僽儖僋僅乕僩偱偔偔傞)
out << "#include \"" << dynamic_cast<KernelID *>(RuntimeObjectTable::getInstance(typeid(KernelID)))->getFilename() <<"\"\n"
<< '\n';
//CFG_INT/EXCHDR_ENTRY
// Q: "<<"偑偁偭偨傝側偐偭偨傝偡傞偺偼側偤? A: 2峴栚偐傜5峴栚傑偱偼else僽儘僢僋偱弌椡偟偰偄傞撪梕偲傑偭偨偔摨偠丅偙偆偡傟偽僐儞僷僀儔偵傛偭偰偼僔儏儕儞僋偝傟偰堦偮偵側傞偟丄壜撉惈傕埆偔側傜側偄丅
if(backward_compatible) {
out << "#if TKERNEL_PRVER >= 0x1040\n"
<< "#error \"This configuration file has no compatibility with"
<< " TOPPERS/JSP rel 1.4 or later version.\"\n"
"#elif TKERNEL_PRVER >= 0x1011\n"
<< "#define CFG_INTHDR_ENTRY(inthdr) INTHDR_ENTRY(inthdr)\n"
"#define CFG_EXCHDR_ENTRY(exchdr) EXCHDR_ENTRY(exchdr)\n"
"#define CFG_INT_ENTRY(inthdr) INT_ENTRY(inthdr)\n"
"#define CFG_EXC_ENTRY(exchdr) EXC_ENTRY(exchdr)\n"
<< "#else\n"
<< "#define CFG_INTHDR_ENTRY(inthdr) INTHDR_ENTRY(ENTRY(inthdr), inthdr)\n"
"#define CFG_EXCHDR_ENTRY(exchdr) EXCHDR_ENTRY(ENTRY(exchdr), exchdr)\n"
"#define CFG_INT_ENTRY(inthdr) ENTRY(inthdr)\n"
"#define CFG_EXC_ENTRY(exchdr) ENTRY(exchdr)\n"
<< "#endif\n\n";
}
else {
out << "#if TKERNEL_PRVER >= 0x1040\n"
<< "#define CFG_INTHDR_ENTRY(inthdr) INTHDR_ENTRY(inthdr)\n"
"#define CFG_EXCHDR_ENTRY(exchdr) EXCHDR_ENTRY(exchdr)\n"
"#define CFG_INT_ENTRY(inthdr) INT_ENTRY(inthdr)\n"
"#define CFG_EXC_ENTRY(exchdr) EXC_ENTRY(exchdr)\n"
<< "#else\n"
<< "#error \"This configuration file has no compatibility with"
<< " TOPPERS/JSP rel 1.3 or earlier.\"\n"
<< "#endif\n\n";
}
//__EMPTY_LABEL儅僋儘偺弌椡
if(!getOptionParameter()["z"].isValid()) {
string zeromacro;
if(getOptionParameter()["ZERO"].isValid())
zeromacro = getOptionParameter()["ZERO"][0];
else
zeromacro.assign("x y[0]");
out << "#ifndef __EMPTY_LABEL\n"
"#define __EMPTY_LABEL(x,y) " << zeromacro << "\n"
"#endif\n\n";
}
/* PRID偺僠僃僢僋 */
out << "#if TKERNEL_PRID != 0x0001u /* TOPPERS/JSP */\n"
"#error \"You can not use this configuration file without TOPPERS/JSP\"\n"
"#endif\n\n";
}
}
void ConfigurationFileGenerator::parseOption(Directory & parameter)
{
string work;
if(findOption("h","help"))
{
cerr << endl << Message(
"Kernel configuration file generator\n"
" -id, --kernel_id=filename : Specify the name of ID assignment file\n"
" -cfg,--kernel_cfg=filename : Specify the name of kernel configuration file\n"
" -il, --include-libstyle : Use #include <...> style for kernel headers\n"
" -oproto, --output-prototype: Output task prototype definitions in kernel_cfg\n"
" -z, --nonzero : Do not output __EMPTY_LABEL macro and related definitions\n"
" -1.3 : Generates kernel_cfg.c for TOPPERS/JSP rel 1.3\n",
"僇乕僱儖峔惉僼傽僀儖偺惗惉\n"
" -id, --kernel_id=僼傽僀儖柤 : ID妱摉僼傽僀儖偺柤慜傪巜掕偟傑偡\n"
" -cfg,--kernel_cfg=僼傽僀儖柤 : 僇乕僱儖峔惉僼傽僀儖偺柤慜傪巜掕偟傑偡\n"
" -il, --include-libstyle : 僇乕僱儖偺僿僢僟僼傽僀儖傪<...>偺宍偱弌椡偟傑偡\n"
" -oproto, --output-prototype : 僞僗僋杮懱側偳偺掕媊傪kernel_cfg.c偵惗惉偟傑偡\n"
" -z, --nonzero : __EMPTY_LABEL儅僋儘偺巊梡傪惂尷偟傑偡\n"
" -1.3 : TOPPERS/JSP rel 1.3 梡偺僐儞僼傿僊儏儗乕僔儑儞僼傽僀儖傪惗惉偟傑偡\n");
return;
}
checkOption("cfg","cfg");
checkOption("id","id");
/*
* 僇乕僱儖僐儞僼傿僊儏儗乕僔儑儞寢壥偺僼傽僀儖 (kernel_cfg.c) 偺弶婜愝掕
*/
createKernelCfg();
/*
* ID妱晅寢壥偺僼傽僀儖 (kernel_id.h) 偺弶婜愝掕
*/
createKernelID();
/* 偦偺懠僆僾僔儑儞 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -