Skip to content

Commit bbeb2f2

Browse files
committed
added @throws to documentation
1 parent d764cb2 commit bbeb2f2

2 files changed

Lines changed: 57 additions & 31 deletions

File tree

simplecpp.cpp

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ class StdCharBufStream : public simplecpp::TokenList::Stream {
414414

415415
class FileStream : public simplecpp::TokenList::Stream {
416416
public:
417+
/**
418+
* @throws simplecpp::Output thrown is file is not found
419+
*/
417420
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
418421
explicit FileStream(const std::string &filename, std::vector<std::string> &files)
419422
: file(fopen(filename.c_str(), "rb"))
@@ -1488,6 +1491,9 @@ namespace simplecpp {
14881491
public:
14891492
explicit Macro(std::vector<std::string> &f) : nameTokDef(nullptr), valueToken(nullptr), endToken(nullptr), files(f), tokenListDefine(f), variadic(false), variadicOpt(false), valueDefinedInCode_(false) {}
14901493

1494+
/**
1495+
* @throws std::runtime_error thrown on bad macro syntax
1496+
*/
14911497
Macro(const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(true) {
14921498
if (sameline(tok->previousSkipComments(), tok))
14931499
throw std::runtime_error("bad macro syntax");
@@ -1504,6 +1510,9 @@ namespace simplecpp {
15041510
throw std::runtime_error("bad macro syntax");
15051511
}
15061512

1513+
/**
1514+
* @throws std::runtime_error thrown on bad macro syntax
1515+
*/
15071516
Macro(const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(false) {
15081517
const std::string def(name + ' ' + value);
15091518
StdCharBufStream stream(reinterpret_cast<const unsigned char*>(def.data()), def.size());
@@ -1552,7 +1561,9 @@ namespace simplecpp {
15521561
* @param macros list of macros
15531562
* @param inputFiles the input files
15541563
* @return token after macro
1555-
* @throw Can throw wrongNumberOfParameters or invalidHashHash
1564+
* @throws Error thrown on missing or invalid preprocessor directives
1565+
* @throws wrongNumberOfParameters thrown on invalid number of parameters
1566+
* @throws invalidHashHash thrown on invalid ## usage
15561567
*/
15571568
const Token * expand(TokenList & output,
15581569
const Token * rawtok,
@@ -2544,7 +2555,9 @@ namespace simplecpp {
25442555
}
25452556
}
25462557

2547-
/** Evaluate sizeof(type) */
2558+
/** Evaluate sizeof(type)
2559+
* @throws std::runtime_error thrown on missing arguments or invalid expression
2560+
*/
25482561
static void simplifySizeof(simplecpp::TokenList &expr, const std::map<std::string, std::size_t> &sizeOfType)
25492562
{
25502563
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
@@ -2612,6 +2625,10 @@ static std::string dirPath(const std::string& path, bool withTrailingSlash=true)
26122625
}
26132626

26142627
static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const std::string &sourcefile, const std::string &header, bool systemheader);
2628+
2629+
/** Evaluate sizeof(type)
2630+
* @throws std::runtime_error thrown on missing arguments or invalid expression
2631+
*/
26152632
static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI &dui)
26162633
{
26172634
if (!isCpp17OrLater(dui) && !isGnu(dui))
@@ -2668,6 +2685,9 @@ static void simplifyHasInclude(simplecpp::TokenList &expr, const simplecpp::DUI
26682685
}
26692686
}
26702687

2688+
/** Evaluate sizeof(type)
2689+
* @throws std::runtime_error thrown on undefined function-like macro
2690+
*/
26712691
static void simplifyName(simplecpp::TokenList &expr)
26722692
{
26732693
for (simplecpp::Token *tok = expr.front(); tok; tok = tok->next) {
@@ -2696,7 +2716,7 @@ static void simplifyName(simplecpp::TokenList &expr)
26962716
* unsigned long long value, updating pos to point to the first
26972717
* unused element of s.
26982718
* Returns ULLONG_MAX if the result is not representable and
2699-
* throws if the above requirements were not possible to satisfy.
2719+
* @throws std::runtime_error thrown if the above requirements were not possible to satisfy.
27002720
*/
27012721
static unsigned long long stringToULLbounded(
27022722
const std::string& s,
@@ -2716,34 +2736,6 @@ static unsigned long long stringToULLbounded(
27162736
return value;
27172737
}
27182738

2719-
/* Converts character literal (including prefix, but not ud-suffix)
2720-
* to long long value.
2721-
*
2722-
* Assumes ASCII-compatible single-byte encoded str for narrow literals
2723-
* and UTF-8 otherwise.
2724-
*
2725-
* For target assumes
2726-
* - execution character set encoding matching str
2727-
* - UTF-32 execution wide-character set encoding
2728-
* - requirements for __STDC_UTF_16__, __STDC_UTF_32__ and __STDC_ISO_10646__ satisfied
2729-
* - char16_t is 16bit wide
2730-
* - char32_t is 32bit wide
2731-
* - wchar_t is 32bit wide and unsigned
2732-
* - matching char signedness to host
2733-
* - matching sizeof(int) to host
2734-
*
2735-
* For host assumes
2736-
* - ASCII-compatible execution character set
2737-
*
2738-
* For host and target assumes
2739-
* - CHAR_BIT == 8
2740-
* - two's complement
2741-
*
2742-
* Implements multi-character narrow literals according to GCC's behavior,
2743-
* except multi code unit universal character names are not supported.
2744-
* Multi-character wide literals are not supported.
2745-
* Limited support of universal character names for non-UTF-8 execution character set encodings.
2746-
*/
27472739
long long simplecpp::characterLiteralToLL(const std::string& str)
27482740
{
27492741
// default is wide/utf32

simplecpp.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,18 @@ namespace simplecpp {
338338
void combineOperators();
339339

340340
void constFoldUnaryNotPosNeg(Token *tok);
341+
/**
342+
* @throws std::overflow_error thrown on overflow or division by zero
343+
*/
341344
void constFoldMulDivRem(Token *tok);
342345
void constFoldAddSub(Token *tok);
343346
void constFoldShift(Token *tok);
344347
void constFoldComparison(Token *tok);
345348
void constFoldBitwise(Token *tok);
346349
void constFoldLogicalOp(Token *tok);
350+
/**
351+
* @throws std::runtime_error thrown on invalid expressions
352+
*/
347353
void constFoldQuestionOp(Token *&tok1);
348354

349355
std::string readUntil(Stream &stream, const Location &location, char start, char end, OutputList *outputList);
@@ -501,6 +507,34 @@ namespace simplecpp {
501507
id_map_type mIdMap;
502508
};
503509

510+
/** Converts character literal (including prefix, but not ud-suffix) to long long value.
511+
*
512+
* Assumes ASCII-compatible single-byte encoded str for narrow literals
513+
* and UTF-8 otherwise.
514+
*
515+
* For target assumes
516+
* - execution character set encoding matching str
517+
* - UTF-32 execution wide-character set encoding
518+
* - requirements for __STDC_UTF_16__, __STDC_UTF_32__ and __STDC_ISO_10646__ satisfied
519+
* - char16_t is 16bit wide
520+
* - char32_t is 32bit wide
521+
* - wchar_t is 32bit wide and unsigned
522+
* - matching char signedness to host
523+
* - matching sizeof(int) to host
524+
*
525+
* For host assumes
526+
* - ASCII-compatible execution character set
527+
*
528+
* For host and target assumes
529+
* - CHAR_BIT == 8
530+
* - two's complement
531+
*
532+
* Implements multi-character narrow literals according to GCC's behavior,
533+
* except multi code unit universal character names are not supported.
534+
* Multi-character wide literals are not supported.
535+
* Limited support of universal character names for non-UTF-8 execution character set encodings.
536+
* @throws std::runtime_error thrown on invalid literal
537+
*/
504538
SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str);
505539

506540
SIMPLECPP_LIB FileDataCache load(const TokenList &rawtokens, std::vector<std::string> &filenames, const DUI &dui, OutputList *outputList = nullptr, FileDataCache cache = {});

0 commit comments

Comments
 (0)