📄 jsp_parser.cpp
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
* Toyohashi Univ. of Technology, JAPAN
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* @(#) $Id: jsp_parser.cpp,v 1.1 2006/04/14 02:46:09 9564907 Exp $
*/
// $Header: J:\\SapporoSoft\\usb20\\S1R72V05\\Debug\\Repository/S1R72V05_Toppers/Toppers/cfg/jsp/jsp_parser.cpp,v 1.1 2006/04/14 02:46:09 9564907 Exp $
#include <stdarg.h>
#include "jsp/jsp_defs.h"
#include "base/parser.h"
#include "base/mpstrstream.h"
#include "jsp/jsp_common.h"
#include <set>
#include <map>
#include <cctype>
#include <algorithm>
#include <iomanip>
using namespace ToppersJsp;
using namespace std;
class CoreParser : public ParserComponent
{
protected:
virtual void parseOption(Directory &);
void outputContainer(Directory & container) throw();
void assignID(Directory & container) throw();
public:
CoreParser(void);
virtual bool parse(Parser & p, Directory & container);
} instance_of_Parser;
CoreParser::CoreParser(void)
{
setBanner("=== TOPPERS/JSP Kernel Configurator ver.9.4 (for JSP rel 1.4) ===");
}
void CoreParser::parseOption(Directory & container)
{
ParserComponent::parseOption(container);
if(findOption("h","help"))
{
cerr << Message(
" -obj, --dump-object=filename : Dump the object tree into the file specified\n"
" -ao, --assign-order=order : Specify the order of automatic ID assignment\n"
" You can use three terms below as ordering rule.\n"
" alphabetic (in alphabetic order)\n"
" fcfs (in arrival order [as default])\n"
" reverse (reverse the order)\n"
" -var, --variable-id : Prepare ID-variable for storing its identifier number\n",
" -obj, --dump-object=僼傽僀儖柤 : 巜掕偟偨僼傽僀儖偵僆僽僕僃僋僩忣曬傪弌椡偟傑偡\n"
" -ao, --assign-order=弴彉 : 帺摦ID妱摉偺妱摉弴彉傪巜掕偟傑偡\n"
" 妱摉弴彉偼師偺3偮偺慻崌偣偱巜掕偟傑偡.\n"
" alphabetic (ABC弴), fcfs (愰尵弴 [僨僼僅儖僩]), reverse (媡弴)\n"
" -var, --variable-id : ID斣崋傪奿擺偡傞曄悢傪梡堄偟傑偡");
return;
}
checkOption("D","dump");
checkOption("cpu","cpu");
checkOption("system","system");
checkOption("var","variable-id");
}
namespace {
int displayHandler(Directory & container, const char * category, const char * format)
{
Directory * node = 0;
Directory * scope = 0;
node = container.findChild(OBJECTTREE,category,NULL);
if(node == 0 || node->size() == 0)
return 0;
VerboseMessage("Handler assignment list [%]\n","僴儞僪儔妱晅昞 [%]\n") << category;
scope = node->getFirstChild();
while(scope != 0)
{
VerboseMessage::getStream() << scope->format(format);
scope = scope->getNext();
}
return node->size();
}
//儅僋儘壔偝傟偨toupper傪娭悢壔偡傞 (STL-algorithm梡)
int toupper_function(int c)
{ return toupper(c); }
}
/*
* outputContainer - 僨僶僢僌帪 or 僟儞僾巜掕帪偵僆僽僕僃僋僩忣曬傪強掕偺僼傽僀儖宍幃偱弌椡偡傞
*/
void CoreParser::outputContainer(Directory & container) throw()
{
try {
if(findOption("D","dump") || findOption("debug","debug")) {
fstream file("container.txt", ios::out);
container.drawTree(&file);
file.close();
}
if(findOption("Dx","dump-xml") || findOption("debug","debug")) {
fstream file("container.xml", ios::out);
container.drawTree_byXML(&file);
file.close();
}
}
catch (...) {
}
}
/*
* assignID - 僆僽僕僃僋僩偵懳偟偰ID傪妱傝晅偗傞
* 庢傝崬傫偩僆僽僕僃僋僩柤傪儐乕僓偵採帵偡傞
*/
void CoreParser::assignID(Directory & container) throw()
{
multimap<int, const char *> sorter;
multimap<int, const char *>::iterator scope;
enum Common::tagAssignmentOrder order = Common::FCFS;
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" TASK].size(), TASK));
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" SEMAPHORE].size(), SEMAPHORE));
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" EVENTFLAG].size(), EVENTFLAG));
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" DATAQUEUE].size(), DATAQUEUE));
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" MAILBOX].size(), MAILBOX));
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" FIXEDSIZEMEMORYPOOL].size(), FIXEDSIZEMEMORYPOOL));
sorter.insert(pair<int, const char *>(container[OBJECTTREE "/" CYCLICHANDLER].size(), CYCLICHANDLER));
order = Common::parseOrder(getOption("ao", "assign-order"));
scope = sorter.begin();
while(scope != sorter.end())
{
if( (*scope).first != 0 )
Common::assignID(container, (*scope).second, OBJECTTREE, order);
++ scope;
}
displayHandler(container, INTERRUPTHANDLER, " $@ : $(inthdr)\n");
displayHandler(container, EXCEPTIONHANDLER, " $@ : $(exchdr)\n");
displayHandler(container, INITIALIZER, " $@ : $(inirtn)($(exinf))\n");
displayHandler(container, TERMINATOR, " $@ : $(terrtn)($(exinf))\n");
}
bool CoreParser::parse(Parser & p, Directory & container)
{
Token token;
string work;
bool isParseErrorOccured;
if(findOption("cpu","cpu", &work))
container["/cpu"] = work;
try{
isParseErrorOccured = false;
do {
p.getToken(token);
if(token == Token::IDENTIFIER)
{
/* 僄儔乕偑婲偒偰傕嬌椡懕偗偨偄偺偱丄
婲偒偨偙偲偩偗妎偊偰偍偄偰偳傫偳傫懕偗傞 */
try
{ this->parseStaticAPI(p, container, token); }
catch(...)
{ isParseErrorOccured = true; }
}
}while(token != Token::EOS);
p.setLogBuffer(NULL);
if(isParseErrorOccured)
ExceptionMessage(ExceptionMessage::FATAL,"The configuration process was aborted due to occurence of parse error","峔暥夝愅偵幐攕偟偨偨傔張棟傪拞抐偟傑偡").throwException();
if(container[OBJECTTREE "/" TASK].size() == 0)
ExceptionMessage("Kernel requires one or more task objects.","僞僗僋僆僽僕僃僋僩偑偁傝傑偣傫").throwException();
/* ID妱晅 & 僆僽僕僃僋僩柤昞帵 */
assignID(container);
/* 僆僽僕僃僋僩忣曬傪僼傽僀儖偵弌椡 */
outputContainer(container);
return true;
}
catch(Exception &)
{
/* 椺奜傪搳偘側偍偡慜偵 尰嵼偺僆僽僕僃僋僩忣曬傪奿擺偡傞 */
outputContainer(container);
throw;
}
}
/* ======================================================================== */
DECLARE_DIRECTIVE(assigner,"assign_id")
{
Token name;
Token value;
p.getToken(name, Token::IDENTIFIER);
p.getToken(value, Token::INTEGER);
if(value.value <= 0)
ExceptionMessage("Cannot assign an ID number less or equal to 0.","0埲壓偺ID斣崋傪愝掕偡傞偙偲偼偱偒傑偣傫").throwException();
*container.openChild("/","identifier",name.c_str(),NULL) = value.value;
}
DECLARE_DIRECTIVE(parameter,"parameter")
{
Token token;
string key;
string::size_type i,j;
do {
p.getToken(token);
if(!(token == Token::STRINGLITERAL))
ExceptionMessage("parameter pragma requires additional parameter put in '\"...\"'","parameter僾儔僌儅偵偼\"...\"偱妵傜傟偨捛壛僷儔儊乕僞偑昁梫偱偡").throwException();
token.chopLiteral();
if(token[0] == '-')
{
i = token.find_first_of('=');
j = token.find_first_not_of('-');
if(i == j || j == string::npos)
ExceptionMessage(ExceptionMessage::FATAL,"Wrong option [%]","晄惓側僆僾僔儑儞 [%]") << token << throwException;
if(i != string::npos)
{
key = DEFAULT_PARAMETER;
*container.openChild(string("/Parameter/") + token.substr(1, i-1)) = token.substr(i+1);
}
else
{
key = token.substr(1);
*container.openChild(string("/Parameter/") + key) = string("");
}
}else
*container.openChild(string("/Parameter/") + key) = token;
p.getToken(token);
} while(token.compare(",") == 0);
p.putBack(token);
}
/* ======================================================================== */
class ConfigurationFileGenerator : public Component
{
protected:
bool backward_compatible;
bool libstyle_include;
bool restrict_zero;
bool def_prototype;
enum tagDefinition { HEADER=1, TNUM=2, BUFFER=4, DEFINITION=8, CONTROLBLOCK=16, SHORT_ID=32, TNUMNO=64, INIT=128, PROTOTYPE=256, INITLIST=512 };
void createObjectDefinition(MultipartStream *, Directory &, int, ...);
virtual void parseOption(Directory &);
virtual void body(Directory &);
virtual void onFatalExit(Directory &);
public:
ConfigurationFileGenerator(void) : Component(CODEGENERATOR) {};
} instance_of_Configurator;
namespace {
//僼傽僀儖柤偺庢摼
string get_filename(string category, string _default) throw(Exception)
{
string result(_default);
OptionParameter::OptionItem item = getOptionParameter()[category];
if(item.isValid()) {
if(item.countParameter() == 1)
result = item[0];
else
ExceptionMessage("-% should have just ONE filename.","-%僆僾僔儑儞偵巜掕偱偒傞僼傽僀儖偼1偮偺傒") << category << throwException;
}
if(result.empty())
ExceptionMessage("-% has illegal file name.","-%僆僾僔儑儞偵搉偝傟偨僼傽僀儖柤偼晄惓") << category << throwException;
return result;
}
// 僇乕僱儖峔惉僼傽僀儖偺惗惉
KernelCfg * createKernelCfg(void)
{
KernelCfg * cfg;
cfg = KernelCfg::createInstance(get_filename("kernel_cfg","kernel_cfg.c"));
cfg->disableOutput(); //張棟偑姰椆偡傞傑偱弌椡偝偣側偄
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -