📄 jsp_parser.cpp
字号:
restrict_zero = findOption("z","zero");
def_prototype = findOption("oproto","output-prototype");
libstyle_include = findOption("il","include-libstyle");
backward_compatible = findOption("1.3","1.3");
checkOption("mcfg","minimize-cfg");
checkOption("ZERO","ZERO");
checkOption("obj", "dump-object");
checkOption("ext");
activateComponent();
}
void ConfigurationFileGenerator::onFatalExit(Directory & container)
{
//椺奜偱堎忢廔椆偟偨傜丄僼傽僀儖傪惗惉偟側偄
dynamic_cast<MultipartStream *>(RuntimeObjectTable::getInstance(typeid(KernelCfg)))->disableOutput();
dynamic_cast<MultipartStream *>(RuntimeObjectTable::getInstance(typeid(KernelID)))->disableOutput();
}
void ConfigurationFileGenerator::createObjectDefinition(MultipartStream * out, Directory & container, int flag, ...)
{
Directory * scope;
const char * buffer;
string work;
map<int, Directory *> sorter;
map<int, Directory *>::iterator psorter;
va_list vl;
int i;
Directory & id = container[string(PREFIX "/") + container.getKey().c_str()];
if(container.size() == 0 && findOption("mcfg","minimize-cfg"))
{
if(!getOptionParameter().find("ext"))
ExceptionMessage("Use of the extended option --minimize-cfg. Please use -ext option together.","--minimize僆僾僔儑儞偼奼挘婡擻偱偡丅巊梡偡傞偵偼-ext傪巜掕偟偰偔偩偝偄丅").throwException();
return;
}
va_start(vl, flag);
//昁梫側忣曬偺嶌惉
work = string(va_arg(vl, const char *));
id["id"] = work;
transform(work.begin(), work.end(), work.begin(), toupper_function);
id["ID"] = work;
if((flag & SHORT_ID) != 0)
{
work = string(va_arg(vl, const char *));
id["sid"] = work;
for(i=0; i<(signed)work.size(); i++) {
if (work[i] >= 'a' && work[i] <= 'z')
work[i] = work[i] - 'a' + 'A';
}
id["SID"] = work;
}else
{
id["sid"] = id["id"].toString();
id["SID"] = id["ID"].toString();
}
if(!backward_compatible)
id["symbolprefix"] = "_kernel_";
work = container.getKey();
id["name"] = work;
out->movePart(work);
//僆僽僕僃僋僩弶婜壔娭悢傪捛壛
if((flag & INIT) != 0 && container.size() != 0)
container["/" OBJECT_INITIALIZER].addChild(new Directory(work));
(*out) << "\n\t/* " << (Message("Object initializer [%]","僆僽僕僃僋僩弶婜壔僽儘僢僋 [%]") << work) << " */\n\n";
if(((flag & HEADER) != 0) && backward_compatible)
(*out) << "#include " << conv_includefile(work) << "\n\n";
if((flag & TNUM) != 0)
{
(*out) << id.format("#define TNUM_$(ID)ID ") << container.size() << "\n\n";
(*out) << id.format("const ID $(symbolprefix,)tmax_$(id)id = (TMIN_$(ID)ID + TNUM_$(ID)ID - 1);\n\n");
}
if((flag & TNUMNO) != 0)
{
(*out) << id.format("#define TNUM_$(ID)NO ") << container.size() << "\n\n";
(*out) << id.format("const UINT $(symbolprefix,)tnum_$(id)no = TNUM_$(ID)NO;\n\n");
}
/* ID弴偵僜乕僩 (偙偺帪揰偱楢斣偑妋掕偟偰偄傞偼偢側偺偱丆僠僃僢僋偼偟側偄) */
if((flag & (BUFFER|DEFINITION)) != 0)
{
const bool is_identifier = (flag & TNUMNO) == 0;
i = 0;
scope = container.getFirstChild();
while(scope != 0)
{
if(is_identifier)
sorter[scope->toInteger(i++)] = scope;
else
sorter[i++] = scope;
scope = scope->getNext();
}
}
//僾儘僩僞僀僾掕媊偺弌椡
if((flag & PROTOTYPE) != 0)
{
buffer = va_arg(vl, const char *);
if(def_prototype)
{
set<string> func;
set<string>::iterator pfunc;
scope = container.getFirstChild();
while(scope != NULL)
{
func.insert(scope->format(buffer));
scope = scope->getNext();
}
pfunc = func.begin();
while(pfunc != func.end())
{
(*out) << (*pfunc) << '\n';
++ pfunc;
}
}
}
//僶僢僼傽偺嶌惉
if((flag & BUFFER) != 0 && container.size() != 0)
{
buffer = va_arg(vl, const char *);
psorter = sorter.begin();
while(psorter != sorter.end())
{
(*out) << (*psorter).second->format(buffer) << '\n';
++ psorter;
}
(*out) << '\n';
}
//掕媊僽儘僢僋(xINIB)偺弌椡
if((flag & DEFINITION) != 0)
{
buffer = va_arg(vl, const char *);
if(container.size() != 0)
{
(*out) << id.format("const $(SID)INIB $(symbolprefix,)$(sid)inib_table[TNUM_$(ID)") << ( (flag & TNUMNO) != 0 ? "NO" : "ID") << "] = {\n";
psorter = sorter.begin();
while(psorter != sorter.end())
{
(*out) << "\t{" << (*psorter).second->format(buffer) << '}';
++ psorter;
if(psorter != sorter.end())
(*out) << ',';
(*out) << '\n';
}
(*out) << "};\n\n";
}else
if( !restrict_zero )
(*out) << id.format("__EMPTY_LABEL(const $(SID)INIB, $(symbolprefix,)$(sid)inib_table);\n");
}
if((flag & INITLIST) != 0)
{
Directory * node;
/* 愰尵弴偱ID斣崋傪僜乕僩 */
sorter.clear();
node = container.getFirstChild();
while(node != NULL)
{
sorter.insert(pair<int,Directory*>(node->findChild("#order")->toInteger(), node));
node = node->getNext();
}
*out << id.format("const ID $(symbolprefix,)$(sid)order_table[TNUM_$(ID)ID] = {");
psorter = sorter.begin();
while(psorter != sorter.end())
{
*out << psorter->second->toInteger();
++ psorter;
if(psorter != sorter.end())
*out << ',';
}
*out << "};\n\n";
}
//惂屼僽儘僢僋(xCB)偺弌椡
if((flag & CONTROLBLOCK) != 0)
{
if(container.size() != 0)
(*out) << id.format("$(SID)CB $(symbolprefix,)$(sid)cb_table[TNUM_$(ID)ID];\n\n");
else
if( !restrict_zero )
(*out) << id.format("__EMPTY_LABEL($(SID)CB, $(symbolprefix,)$(sid)cb_table);\n\n");
}
}
void ConfigurationFileGenerator::body(Directory & container)
{
Directory * scope;
KernelCfg * out;
string work;
const bool varid_style = findOption("var","variable-id");
/* kernel_id.h偺弌椡 */
serializeIdentifiers(varid_style);
/* kernel_cfg.c偺弌椡 */
out = dynamic_cast<KernelCfg *>(RuntimeObjectTable::getInstance(typeid(KernelCfg)));
if(out == 0) {
ExceptionMessage("[Internal error] The stream buffer of kernel_cfg disappeared.","[撪晹僄儔乕] 僼傽僀儖僗僩儕乕儉偑奐偗傑偣傫 (kernel_cfg.c)").throwException();
return;
}
/* 摢偺掕媊晹暘偺嶌惉 */
serializeConfiguration_headerPart(*out);
/* INCLUDE */
out->movePart(INCLUDEFILE);
scope = container(OBJECTTREE "/" INCLUDEFILE)->getFirstChild();
(*out) << "\t/* " << Message("User specified include files","儐乕僓掕媊偺僀儞僋儖乕僪僼傽僀儖") << "*/\n";
while(scope != 0)
{
(*out) << "#include " << scope->toString() << '\n';
scope = scope->getNext();
}
(*out) << '\n';
/* TASK */
work.assign("$(tskatr), (VP_INT)($(exinf)), (FP)($(task)), INT_PRIORITY($(itskpri)), __TROUND_STK_UNIT($(stksz)), __stack_$@, $(texatr), (FP)($(texrtn))");
if(container["/cpu"].toString().compare("nios32") == 0)
work += ", $(hi_limit), $(lo_limit)";
createObjectDefinition(out, container[OBJECTTREE "/" TASK], HEADER|TNUM|SHORT_ID|BUFFER|DEFINITION|CONTROLBLOCK|INIT|PROTOTYPE|INITLIST,"tsk", "t", "void $(task)(VP_INT exinf);", "static __STK_UNIT __stack_$@[__TCOUNT_STK_UNIT($(stksz))];",work.c_str());
/* SEMAPHORE */
createObjectDefinition(out, container[OBJECTTREE "/" SEMAPHORE], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT,"sem", "$(sematr), $(isemcnt), $(maxsem)");
/* EVENTFLAG */
createObjectDefinition(out, container[OBJECTTREE "/" EVENTFLAG], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT,"flg", "$(flgatr), $(iflgptn)");
/* DATAQUEUE */
createObjectDefinition(out, container[OBJECTTREE "/" DATAQUEUE], HEADER|TNUM|BUFFER|DEFINITION|CONTROLBLOCK|INIT,"dtq", "#if ($(dtqcnt)) > 0\n static VP_INT __dataqueue_$@[$(dtqcnt)];\n#else\n #define __dataqueue_$@ NULL\n#endif","$(dtqatr), $(dtqcnt), __dataqueue_$@");
/* MAILBOX */
createObjectDefinition(out, container[OBJECTTREE "/" MAILBOX], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT,"mbx","$(mbxatr), $(maxmpri)");
/* FIXEDSIZEMEMORYPOOL */
createObjectDefinition(out, container[OBJECTTREE "/" FIXEDSIZEMEMORYPOOL], HEADER|TNUM|BUFFER|DEFINITION|CONTROLBLOCK|INIT,"mpf","static __MPF_UNIT __fixedsize_memorypool_$@[__TCOUNT_MPF_UNIT($(blksz)) * (($(blkcnt)))];","$(mpfatr), __TROUND_MPF_UNIT($(blksz)), __fixedsize_memorypool_$@, (VP)((VB *)__fixedsize_memorypool_$@ + sizeof(__fixedsize_memorypool_$@))");
/* CYCLICHANDLER */
createObjectDefinition(out, container[OBJECTTREE "/" CYCLICHANDLER], HEADER|TNUM|DEFINITION|CONTROLBLOCK|INIT|PROTOTYPE,"cyc","void $(cychdr)(VP_INT exinf);","$(cycatr),$(exinf),(FP)($(cychdr)),$(cyctim),$(cycphs)");
/* INTERRUPTHANDLER */
createObjectDefinition(out, container[OBJECTTREE "/" INTERRUPTHANDLER], HEADER|BUFFER|TNUMNO|DEFINITION|INIT|PROTOTYPE,"inh","void $(inthdr)(void);","CFG_INTHDR_ENTRY($(inthdr));","$@,$(inhatr),(FP)CFG_INT_ENTRY($(inthdr))");
/* EXCEPTIONHANDLER */
createObjectDefinition(out, container[OBJECTTREE "/" EXCEPTIONHANDLER], HEADER|BUFFER|TNUMNO|DEFINITION|INIT|PROTOTYPE,"exc","void $(exchdr)(VP p_excinf);","CFG_EXCHDR_ENTRY($(exchdr));","$@,$(excatr),(FP)CFG_EXC_ENTRY($(exchdr))");
/* 僆僽僕僃僋僩弶婜壔儖乕僠儞 */
out->movePart(OBJECT_INITIALIZER);
(*out) << "\t/* " << Message("Object initialization routine","僆僽僕僃僋僩弶婜壔儖乕僠儞") << " */\n\n";
(*out) << "void\n" << conv_kernelobject("object_initialize") << "(void)\n{\n";
scope = container["/" OBJECT_INITIALIZER].getFirstChild();
while(scope != 0)
{
(*out) << '\t' << conv_kernelobject(scope->toString() + "_initialize") << "();\n";
scope = scope->getNext();
}
(*out) << "}\n\n";
/* 弶婜壔僴儞僪儔 */
out->movePart(INITIALIZER);
(*out) << "\t/* " << Message("Initialization handler","弶婜壔僴儞僪儔婲摦儖乕僠儞") << " */\n\n";
(*out) << "void\n" << conv_kernelobject("call_inirtn") << "(void)\n{\n";
scope = container[OBJECTTREE "/" INITIALIZER].getFirstChild();
while(scope != 0)
{
(*out) << scope->format("\t$(inirtn)( (VP_INT)($(exinf)) );\n");
scope = scope->getNext();
}
(*out) << "}\n\n";
/* 廔椆僴儞僪儔 */
scope = container[OBJECTTREE "/" TERMINATOR].getLastChild();
if(!backward_compatible) {
(*out) << "void\n" << conv_kernelobject("call_terrtn") << "(void)\n{\n";
while(scope != 0)
{
(*out) << scope->format("\t$(terrtn)( (VP_INT)($(exinf)) );\n");
scope = scope->getPrev();
}
(*out) << "}\n\n";
}
else {
if(scope->size() != 0)
ExceptionMessage("VATT_TER is not supported for TOPPERS/JSP rel 1.3 or earlier.",
"VATT_TER偼TOPPERS/JSP rel 1.3埲慜偱偼僒億乕僩偝傟傑偣傫").throwException();
}
out->movePart("others");
(*out) << "TMEVTN " << conv_kernelobject("tmevt_heap") << "[TNUM_TSKID + TNUM_CYCID];\n\n";
container["/object_initializer"].erase();
string filename;
if(findOption("obj","dump-object",&filename))
{
if(filename.empty())
filename.assign("kernel_obj.dat");
fstream f(filename.c_str(),ios::out|ios::binary);
if(f.is_open())
{
container[OBJECTTREE].Store(&f);
f.close();
}else
ExceptionMessage(" Failed to open the file % for storing object definitions"," 僆僽僕僃僋僩忣曬傪奿擺偡傞偨傔偺僼傽僀儖(%)偑奐偗傑偣傫") << filename << throwException;
}
out->enableOutput();
}
/* ======================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -