📄 coverage_defs.h
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 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: coverage_defs.h,v 1.1 2006/04/14 02:46:03 9564907 Exp $
*/
/*
#ifdef娭學
coverage_defs偼丄undefs偱夝彍偟偨偁偲偵撉傒崬傓応崌偑偁傞偺偱丄
僷乕僩傪偄偔偮偐偵暘妱偟偰偄傞.
- COVERAGE : 僇僶儗僢僕婡擻傪巊梡偡傞偐偳偆偐
- COVERAGE_H : coverage.cpp偵娭楢偡傞晹暘偱丄懡廳掕媊偝傟偰偼崲傞傕偺
- COVERAGE_DEFS : 僇僶儗僢僕偵娭楢偡傞晹暘偱丄coverage_undefs.h偱undef偱偒丄傕偆堦搙coverage_defs.h傪撉傫偱傕戝忎晇側傕偺
*/
#ifdef COVERAGE
#include "base/singleton.h"
/* 僿僢僟 */
#include <string>
#include <map>
#include <set>
#include <iostream>
#ifndef COVERAGE_H
#define COVERAGE_H
/*
* 娙扨側僇僶儗僢僕僠僃僢僋
*/
class Coverage {
public:
/* 応強傪曐帩偡傞僋儔僗 */
class Location {
protected:
const char * filename;
unsigned int lineno;
const char * additional;
public:
Location(const char * _filename, unsigned int _lineno, const char * _additional = "") : filename(_filename), lineno(_lineno), additional(_additional) {}
Location(const Location & src) : filename(src.filename), lineno(src.lineno), additional(src.additional) {}
inline Location & operator = (const Location & right)
{
filename = right.filename;
lineno = right.lineno;
additional = right.additional;
return *this;
}
inline bool operator == (const Location & right) const
{ return lineno == right.lineno && std::string(filename).compare(right.filename) == 0 && std::string(additional).compare(right.additional) == 0; }
inline bool operator < (const Location & right) const
{
if(lineno < right.lineno)
return true;
if(std::string(filename).compare(right.filename) < 0)
return true;
return false;
}
inline std::string getFilename(void) const
{ return std::string(filename); }
inline unsigned int getLineno(void) const
{ return lineno; }
inline std::string getAdditional(void) const
{ return std::string(additional); }
//僼僅乕儅僢僩嵪傒僼傽僀儖埵抲忣曬偺庢摼 filename:lineno(additional)
std::string getDetails(void) const;
};
//暘婒僇僶儗僢僕敾掕偺儀乕僗僋儔僗
class BranchBase {
protected:
BranchBase(const Location & location) throw(); //梫慺偺搊榐
static BranchBase * find(const Location & location) throw(); //location偵堦抳偡傞梫慺偺庢摼
public:
virtual ~BranchBase(void) throw() {} //僨僗僩儔僋僞
virtual bool checkValidity(void) const throw(...) = 0; //惓摉惈敾掕
virtual std::string getDetails(void) const throw(...) = 0; //僨乕僞昞帵
};
//if-statement偵堷偭偐偐傞僋儔僗
class If : public BranchBase {
protected:
bool true_case;
bool false_case;
If(const Location & location) throw(); //branch宱桼偱柍偄偲惗惉偝偣側偄
public:
virtual bool checkValidity(void) const throw(); //惓摉惈偺敾掕
virtual std::string getDetails(void) const throw(); //僨乕僞昞帵
static bool branch(const Location & location, bool expression) throw();
};
//while-statement偵堷偭偐偐傞僋儔僗
class While : public BranchBase {
protected:
bool valid;
While(const Location & location) throw();
public:
virtual bool checkValidity(void) const throw(); //惓摉惈偺敾掕
virtual std::string getDetails(void) const throw(); //僨乕僞昞帵
static bool branch(const Location & location, bool expression) throw();
};
//switch-statement偵堷偭偐偐傞僋儔僗
class Switch : public BranchBase {
protected:
std::set<int> checkpoint;
Switch(const Location & location) throw();
static void _branch(const Location & location, int expression) throw();
public:
virtual bool checkValidity(void) const throw(); //惓摉惈偺敾掕
virtual std::string getDetails(void) const throw(); //僨乕僞昞帵
template<class T>
static T branch(const Location & location, T expression) throw()
{
_branch(location, (int)expression);
return expression;
}
};
protected:
class BranchMap : public std::map<Location, BranchBase *> {
public:
SINGLETON_CONSTRUCTOR(BranchMap) {}
~BranchMap(void) throw();
};
class NewBranchList : public std::list<BranchBase *>
{ public: SINGLETON_CONSTRUCTOR(NewBranchList) {} };
//崁栚偺昞帵
static std::string getBranchName(BranchBase * node);
public:
//慡偰捠夁偟偨偐偳偆偐偺僠僃僢僋
static bool checkValidity(void);
//慡偰偺崁栚傪昞帵
static void printCoverage(std::ostream & out);
};
#endif /* COVERAGE_H */
#ifndef COVERAGE_DEFS
#define COVERAGE_DEFS
#define if(x) i##f(Coverage::If::branch(Coverage::Location(__FILE__, __LINE__, "if"), (x) ? true : false))
#define while(x) w##hile(Coverage::While::branch(Coverage::Location(__FILE__, __LINE__, "while"), (x) ? true : false))
#define switch(x) s##witch(Coverage::Switch::branch(Coverage::Location(__FILE__, __LINE__, "switch"), (x)))
#endif /* COVERAGE_DEFS */
#else
#include <iostream>
#ifndef COVERAGE_H
#define COVERAGE_H
class Coverage {
public:
static bool checkValidity(void) { return true; }
static void printCoverage(std::ostream &) {}
};
#endif /* COVERAGE_H */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -