diff --git a/include/ulib/event/event_time.h b/include/ulib/event/event_time.h index 9b691a84c..7dbf42b39 100644 --- a/include/ulib/event/event_time.h +++ b/include/ulib/event/event_time.h @@ -126,16 +126,6 @@ class U_EXPORT UEventTime : public UTimeVal { UTimeVal::setMilliSecond(ms = timeoutMS); } - void setMilliSecond() - { - U_TRACE_NO_PARAM(0, "UEventTime::setMilliSecond()") - - ms = ((ctime.tv_sec + tv_sec - timeout1.tv_sec) * 1000L) + - ((ctime.tv_usec + tv_usec - timeout1.tv_usec) / 1000L); - - U_ASSERT(checkTolerance()) - } - bool checkMilliSecond() const { U_TRACE_NO_PARAM(0, "UEventTime::checkMilliSecond()") diff --git a/include/ulib/file.h b/include/ulib/file.h index 75afc8e22..514c9d201 100644 --- a/include/ulib/file.h +++ b/include/ulib/file.h @@ -852,8 +852,8 @@ class U_EXPORT UFile : public stat { bool write(const struct iovec* iov, int n, bool append = false, bool bmkdirs = false); bool write(const UString& data, bool append = false, bool bmkdirs = false) { return write(U_STRING_TO_PARAM(data), append, bmkdirs); } - static int setSysParam( const char* name, int value, bool force = false); - static int getSysParam( const char* name); + static long setSysParam( const char* name, long value, bool force = false); + static long getSysParam( const char* name); static UString getSysContent(const char* name); static bool writeToTmp(const char* data, uint32_t sz, bool append, const char* fmt, ...); @@ -950,7 +950,7 @@ class U_EXPORT UFile : public stat { # if defined(U_LINUX) && defined(U_MEMALLOC_WITH_HUGE_PAGE) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB)) // (since Linux 3.8) if (nr_hugepages) { - U_INTERNAL_DUMP("nr_hugepages = %u rlimit_memfree = %u", nr_hugepages, rlimit_memfree) + U_INTERNAL_DUMP("nr_hugepages = %ld rlimit_memfree = %u", nr_hugepages, rlimit_memfree) U_INTERNAL_ASSERT_EQUALS(rlimit_memfree, U_2M) @@ -973,7 +973,7 @@ class U_EXPORT UFile : public stat { # if defined(U_LINUX) && defined(U_MEMALLOC_WITH_HUGE_PAGE) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB)) // (since Linux 3.8) if (nr_hugepages) { - U_INTERNAL_DUMP("nr_hugepages = %u rlimit_memfree = %u", nr_hugepages, rlimit_memfree) + U_INTERNAL_DUMP("nr_hugepages = %ld rlimit_memfree = %u", nr_hugepages, rlimit_memfree) U_INTERNAL_ASSERT_EQUALS(rlimit_memfree, U_2M) @@ -1067,8 +1067,9 @@ class U_EXPORT UFile : public stat { static char* cwd_save; static uint32_t cwd_save_len; - static char* pfree; - static uint32_t nfree, rlimit_memfree, rlimit_memalloc, nr_hugepages; + static char* pfree; + static long nr_hugepages; + static uint32_t nfree, rlimit_memfree, rlimit_memalloc; void substitute(UFile& file); bool creatForWrite(bool append, bool bmkdirs); diff --git a/include/ulib/string.h b/include/ulib/string.h index 5f626cbca..2ebe2a0a9 100644 --- a/include/ulib/string.h +++ b/include/ulib/string.h @@ -1283,6 +1283,8 @@ class U_EXPORT UString { { U_TRACE(0, "UString::substr(%.*S,%u)", tlen, t, tlen) + if (tlen == 0) return *string_null; + UString result(rep, t, tlen); U_RETURN_STRING(result); @@ -1398,7 +1400,7 @@ class U_EXPORT UString { void swap(UString& lhs, UString& rhs) { lhs.swap(rhs); } #ifdef U_COMPILER_RVALUE_REFS -# if defined(DEBUG) || !defined(__GNUC__) // || GCC_VERSION_NUM >= 60000 // hope +# if !defined(__GNUC__) // || GCC_VERSION_NUM >= 60000 // hope UString(UString && str) { U_TRACE_NO_PARAM(0, "UString::UString(move)") @@ -1562,9 +1564,9 @@ class U_EXPORT UString { // operator + - friend UString operator+(const UString& lhs, const char* rhs) { UString str(lhs); (void) str.append(rhs, u__strlen(rhs, __PRETTY_FUNCTION__)); return str; } - friend UString operator+(const UString& lhs, char rhs) { UString str(lhs); (void) str.append(1U, rhs); return str; } - friend UString operator+(const UString& lhs, const UString& rhs) { UString str(lhs); (void) str.append(rhs); return str; } + friend UString operator+(const UString& lhs, const char* rhs); + friend UString operator+(const UString& lhs, char rhs); + friend UString operator+(const UString& lhs, const UString& rhs); friend UString operator+(char lhs, const UString& rhs); friend UString operator+(const char* lhs, const UString& rhs); diff --git a/include/ulib/tokenizer.h b/include/ulib/tokenizer.h index 7704c5f15..33a89ac99 100644 --- a/include/ulib/tokenizer.h +++ b/include/ulib/tokenizer.h @@ -184,7 +184,7 @@ class U_EXPORT UTokenizer { } UString getTokenQueryParser(); - int getTokenId(UString& token); + int getTokenId(UString* ptoken); bool tokenSeen(const UString* x); bool skipNumber(bool& isReal); diff --git a/src/ulib/file.cpp b/src/ulib/file.cpp index 0a5457c80..70200f2cf 100644 --- a/src/ulib/file.cpp +++ b/src/ulib/file.cpp @@ -24,8 +24,8 @@ char* UFile::cwd_save; char* UFile::pfree; +long UFile::nr_hugepages; uint32_t UFile::nfree; -uint32_t UFile::nr_hugepages; uint32_t UFile::cwd_save_len; #if defined(U_LINUX) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB)) // (since Linux 3.8) @@ -482,7 +482,7 @@ char* UFile::mmap_anon_huge(uint32_t* plength, int flags) char* ptr; uint32_t length; - U_INTERNAL_DUMP("nr_hugepages = %u rlimit_memfree = %u", nr_hugepages, rlimit_memfree) + U_INTERNAL_DUMP("nr_hugepages = %ld rlimit_memfree = %u", nr_hugepages, rlimit_memfree) U_INTERNAL_ASSERT_EQUALS(rlimit_memfree, U_2M) @@ -527,11 +527,13 @@ char* UFile::mmap_anon_huge(uint32_t* plength, int flags) u_get_memusage(&vsz, &rss); - U_ERROR("cannot allocate %u bytes (%u MB) of memory MAP_HUGE_2MB - " - "address space usage: %.2f MBytes - " - "rss usage: %.2f MBytes", - *plength, *plength / (1024U*1024U), (double)vsz / (1024.0 * 1024.0), - (double)rss / (1024.0 * 1024.0)); + U_WARNING("cannot allocate %u bytes (%u MB) of memory MAP_HUGE_2MB - " + "address space usage: %.2f MBytes - " + "rss usage: %.2f MBytes", + *plength, *plength / (1024U*1024U), (double)vsz / (1024.0 * 1024.0), + (double)rss / (1024.0 * 1024.0)); + + nr_hugepages = 0; } # endif } @@ -589,14 +591,13 @@ char* UFile::mmap(uint32_t* plength, int _fd, int prot, int flags, uint32_t offs { U_DEBUG("we are going to allocate from file system (%u KB - %u bytes)", *plength / 1024, *plength); - if (fallocate(fd, *plength)) - { - _ptr = (char*)U_SYSCALL(mmap, "%d,%u,%d,%d,%d,%u", 0, *plength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0); - - if (_ptr != (char*)MAP_FAILED) return _ptr; - } + _ptr = (fallocate(fd, *plength) + ? (char*)U_SYSCALL(mmap, "%d,%u,%d,%d,%d,%u", 0, *plength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0) + : (char*)MAP_FAILED); close(fd); + + if (_ptr != (char*)MAP_FAILED) return _ptr; } if (_abort) @@ -1219,18 +1220,27 @@ UString UFile::getSysContent(const char* name) U_RETURN_STRING(fileContent); } -int UFile::getSysParam(const char* name) +long UFile::getSysParam(const char* name) { U_TRACE(0, "UFile::getSysParam(%S)", name) - int value = -1, - fd = open(name, O_RDONLY, PERM_FILE); + long value = -1; + int fd = open(name, O_RDONLY, PERM_FILE); if (fd != -1) { char buffer[32]; - if (U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1) > 0) value = strtol(buffer, 0, 10); + ssize_t bytes_read = U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1); + + if (bytes_read > 0) + { + U_INTERNAL_ASSERT_MINOR((uint32_t)bytes_read, sizeof(buffer)) + + buffer[bytes_read] = '\0'; + + value = strtol(buffer, 0, 10); + } close(fd); } @@ -1238,27 +1248,37 @@ int UFile::getSysParam(const char* name) U_RETURN(value); } -int UFile::setSysParam(const char* name, int value, bool force) +long UFile::setSysParam(const char* name, long value, bool force) { - U_TRACE(0, "UFile::setSysParam(%S,%u,%b)", name, value, force) + U_TRACE(0, "UFile::setSysParam(%S,%ld,%b)", name, value, force) - int old_value = -1, - fd = open(name, O_RDWR, PERM_FILE); + long old_value = -1; + int fd = open(name, O_RDWR, PERM_FILE); if (fd != -1) { char buffer[32]; - if (U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1) > 0) + ssize_t bytes_read = U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1); + + if (bytes_read > 0) { + U_INTERNAL_ASSERT_MINOR((uint32_t)bytes_read, sizeof(buffer)) + + buffer[bytes_read] = '\0'; + old_value = strtol(buffer, 0, 10); - + if (force || old_value < value) { char* ptr = buffer; +# if SIZEOF_LONG == 4 if (pwrite(fd, buffer, u_num2str32s(ptr, value), 0) > 0) old_value = value; +# else + if (pwrite(fd, buffer, u_num2str64s(ptr, value), 0) > 0) old_value = value; +# endif } } diff --git a/src/ulib/internal/memory_pool.cpp b/src/ulib/internal/memory_pool.cpp index 294114961..aad752243 100644 --- a/src/ulib/internal/memory_pool.cpp +++ b/src/ulib/internal/memory_pool.cpp @@ -619,7 +619,7 @@ void UMemoryPool::deallocate(void* ptr, uint32_t length) # if defined(U_LINUX) && defined(HAVE_ARCH64) # if defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB) // (since Linux 3.8) - U_INTERNAL_DUMP("UFile::nr_hugepages = %u", UFile::nr_hugepages) + U_INTERNAL_DUMP("UFile::nr_hugepages = %ld", UFile::nr_hugepages) if (UFile::nr_hugepages == 0) // NB: MADV_DONTNEED cannot be applied to locked pages, Huge TLB pages, or VM_PFNMAP pages... # endif diff --git a/src/ulib/lemon/expression.cpp b/src/ulib/lemon/expression.cpp index f6d1fe880..7786efc01 100644 --- a/src/ulib/lemon/expression.cpp +++ b/src/ulib/lemon/expression.cpp @@ -1,11 +1,30 @@ -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. +/* +** 2000-05-29 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** Driver template for the LEMON parser generator. +** +** The "lemon" program processes an LALR(1) input grammar file, then uses +** this template to construct a parser. The "lemon" program inserts text +** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the +** interstitial "-" characters) contained in this template is changed into +** the value of the %name directive from the grammar. Otherwise, the content +** of this template is copied straight through into the generate parser +** source file. +** +** The following is the concatenation of all %include directives from the +** input grammar file: */ -/* First off, code is include which follows the "include" declaration -** in the input file. */ #include -#include #include +/************ Begin %include sections from the grammar ************************/ #line 1 "expression.y" #include @@ -25,66 +44,75 @@ extern void expressionParser(void* yyp, int yymajor, UString* yyminor, UString* extern void token_destructor(UString* token); void token_destructor(UString* token) { - U_TRACE(0, "::token_destructor(%.*S)", U_STRING_TO_TRACE(*token)) - + U_TRACE(0, "::token_destructor(%V)", token->rep) delete token; } -#line 35 "expression.c" -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* -** These constants (all generated automatically by the parser generator) -** specify the various kinds of tokens (terminals) that the parser -** understands. -** -** Each symbol here is a terminal symbol in the grammar. -*/ -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control +#line 51 "expression.c" +/**************** End of %include directives **********************************/ +/* These constants specify the various numeric values for terminal symbols +** in a format understandable to "makeheaders". This section is blank unless +** "lemon" is run with the "-m" command-line option. +***************** Begin makeheaders token definitions *************************/ +/**************** End makeheaders token definitions ***************************/ + +/* The next sections is a series of control #defines. ** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. +** YYCODETYPE is the data type used to store the integer codes +** that represent terminal and non-terminal symbols. +** "unsigned char" is used if there are fewer than +** 256 symbols. Larger types otherwise. +** YYNOCODE is a number of type YYCODETYPE that is not used for +** any terminal or nonterminal symbol. ** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** expressionParserTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. +** (also known as: "terminal symbols") have fall-back +** values which should be used if the original symbol +** would not parse. This permits keywords to sometimes +** be used as identifiers, for example. +** YYACTIONTYPE is the data type used for "action codes" - numbers +** that indicate what to do in response to the next +** token. +** expressionParserTOKENTYPE is the data type used for minor type for terminal +** symbols. Background: A "minor type" is a semantic +** value associated with a terminal or non-terminal +** symbols. For example, for an "ID" terminal symbol, +** the minor type might be the name of the identifier. +** Each non-terminal can have a different minor type. +** Terminal symbols all have the same minor type, though. +** This macros defines the minor type for terminal +** symbols. +** YYMINORTYPE is the data type used for all minor types. ** This is typically a union of many types, one of ** which is expressionParserTOKENTYPE. The entry in the union -** for base tokens is called "yy0". +** for terminal symbols is called "yy0". ** YYSTACKDEPTH is the maximum depth of the parser's stack. If ** zero the stack is dynamically sized using realloc() ** expressionParserARG_SDECL A static variable declaration for the %extra_argument ** expressionParserARG_PDECL A parameter declaration for the %extra_argument ** expressionParserARG_STORE Code to store %extra_argument into yypParser ** expressionParserARG_FETCH Code to extract %extra_argument from yypParser -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. +** YYNSTATE the combined number of states. +** YYNRULE the number of rules in the grammar +** YY_MAX_SHIFT Maximum value for shift actions +** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions +** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions +** YY_MIN_REDUCE Maximum value for reduce actions +** YY_ERROR_ACTION The yy_action[] code for syntax error +** YY_ACCEPT_ACTION The yy_action[] code for accept +** YY_NO_ACTION The yy_action[] code for no-op */ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned char #define YYNOCODE 41 #define YYACTIONTYPE unsigned char #define expressionParserTOKENTYPE UString* typedef union { + int yyinit; expressionParserTOKENTYPE yy0; UString* yy3; int yy12; @@ -97,30 +125,57 @@ typedef union { #define expressionParserARG_PDECL , UString* result #define expressionParserARG_FETCH UString* result = yypParser->result #define expressionParserARG_STORE yypParser->result = result -#define YYNSTATE 51 -#define YYNRULE 38 -#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) -#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) -#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) +#define YYNSTATE 23 +#define YYNRULE 38 +#define YY_MAX_SHIFT 22 +#define YY_MIN_SHIFTREDUCE 51 +#define YY_MAX_SHIFTREDUCE 88 +#define YY_MIN_REDUCE 89 +#define YY_MAX_REDUCE 126 +#define YY_ERROR_ACTION 127 +#define YY_ACCEPT_ACTION 128 +#define YY_NO_ACTION 129 +/************* End control #defines *******************************************/ + +/* The yyzerominor constant is used to initialize instances of +** YYMINORTYPE objects to zero. */ +static const YYMINORTYPE yyzerominor = { 0 }; + +/* Define the yytestcase() macro to be a no-op if is not already defined +** otherwise. +** +** Applications can choose to define yytestcase() in the %include section +** to a macro that can assist in verifying code coverage. For production +** code the yytestcase() macro should be turned off. But it is useful +** for testing. +*/ +#ifndef yytestcase +# define yytestcase(X) +#endif + -/* Next are that tables used to determine what action to take based on the +/* Next are the tables used to determine what action to take based on the ** current state and lookahead token. These tables are used to implement ** functions that take a state number and lookahead value and return an -** action integer. +** action integer. ** ** Suppose the action integer is N. Then the action is determined as ** follows ** -** 0 <= N < YYNSTATE Shift N. That is, push the lookahead +** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead ** token onto the stack and goto state N. ** -** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. +** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then +** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE. ** -** N == YYNSTATE+YYNRULE A syntax error has occurred. +** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE +** and YY_MAX_REDUCE + +** N == YY_ERROR_ACTION A syntax error has occurred. ** -** N == YYNSTATE+YYNRULE+1 The parser accepts its input. +** N == YY_ACCEPT_ACTION The parser accepts its input. ** -** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused +** N == YY_NO_ACTION No such action. Denotes unused ** slots in the yy_action[] table. ** ** The action table is constructed as a single large table named yy_action[]. @@ -131,7 +186,7 @@ typedef union { ** If the index value yy_shift_ofst[S]+X is out of range or if the value ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. +** and that yy_default[S] should be used instead. ** ** The formula above is for computing the action when the lookahead is ** a terminal symbol. If the lookahead is a non-terminal (as occurs after @@ -149,17 +204,19 @@ typedef union { ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. -*/ +** +*********** Begin parsing tables **********************************************/ +#define YY_ACTTAB_COUNT (87) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 90, 12, 9, 11, 17, 15, 43, 44, 20, 14, - /* 10 */ 9, 11, 17, 15, 43, 44, 20, 8, 11, 17, - /* 20 */ 15, 43, 44, 20, 10, 17, 15, 43, 44, 20, - /* 30 */ 28, 29, 13, 43, 44, 20, 30, 31, 32, 33, - /* 40 */ 16, 15, 43, 44, 20, 3, 7, 21, 1, 4, - /* 50 */ 46, 2, 34, 35, 36, 37, 23, 44, 20, 21, - /* 60 */ 1, 6, 46, 51, 27, 26, 40, 41, 42, 27, - /* 70 */ 26, 24, 20, 38, 39, 47, 50, 48, 5, 22, - /* 80 */ 19, 45, 18, 49, 91, 91, 91, 91, 91, 25, + /* 0 */ 128, 15, 8, 10, 17, 12, 61, 63, 22, 13, + /* 10 */ 8, 10, 17, 12, 61, 63, 22, 9, 10, 17, + /* 20 */ 12, 61, 63, 22, 11, 17, 12, 61, 63, 22, + /* 30 */ 70, 71, 14, 61, 63, 22, 72, 73, 74, 75, + /* 40 */ 18, 12, 61, 63, 22, 3, 7, 21, 1, 4, + /* 50 */ 66, 2, 76, 77, 78, 79, 60, 63, 22, 21, + /* 60 */ 1, 6, 66, 82, 83, 84, 69, 68, 89, 69, + /* 70 */ 68, 62, 22, 5, 85, 87, 80, 81, 86, 19, + /* 80 */ 20, 88, 16, 67, 91, 91, 64, }; static const YYCODETYPE yy_lookahead[] = { /* 0 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 32, @@ -168,42 +225,47 @@ static const YYCODETYPE yy_lookahead[] = { /* 30 */ 3, 4, 36, 37, 38, 39, 9, 10, 11, 12, /* 40 */ 35, 36, 37, 38, 39, 27, 18, 19, 20, 28, /* 50 */ 22, 26, 5, 6, 7, 8, 37, 38, 39, 19, - /* 60 */ 20, 30, 22, 0, 1, 2, 15, 16, 17, 1, - /* 70 */ 2, 38, 39, 13, 14, 21, 22, 21, 29, 23, - /* 80 */ 25, 22, 20, 22, 40, 40, 40, 40, 40, 21, + /* 60 */ 20, 30, 22, 15, 16, 17, 1, 2, 0, 1, + /* 70 */ 2, 38, 39, 29, 21, 22, 13, 14, 21, 25, + /* 80 */ 23, 22, 20, 22, 40, 40, 21, }; #define YY_SHIFT_USE_DFLT (-1) -#define YY_SHIFT_MAX 22 +#define YY_SHIFT_COUNT (22) +#define YY_SHIFT_MIN (0) +#define YY_SHIFT_MAX (68) static const signed char yy_shift_ofst[] = { /* 0 */ 28, 28, 28, 28, 28, 28, 28, 40, 27, 27, - /* 10 */ 47, 47, 63, 51, 68, 51, 60, 60, 54, 56, + /* 10 */ 47, 47, 48, 65, 48, 68, 53, 63, 63, 57, /* 20 */ 59, 62, 61, }; #define YY_REDUCE_USE_DFLT (-32) -#define YY_REDUCE_MAX 18 +#define YY_REDUCE_COUNT (18) +#define YY_REDUCE_MIN (-31) +#define YY_REDUCE_MAX (54) static const signed char yy_reduce_ofst[] = { /* 0 */ -31, -23, -16, -10, 5, -4, 19, 33, 18, 18, - /* 10 */ 21, 21, 25, 31, 25, 31, 49, 49, 55, + /* 10 */ 21, 21, 31, 25, 31, 25, 54, 44, 44, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 89, 89, 89, 89, 89, 89, 89, 89, 52, 53, - /* 10 */ 54, 55, 89, 58, 89, 59, 56, 57, 89, 89, - /* 20 */ 65, 89, 89, 60, 62, 64, 68, 69, 70, 71, - /* 30 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - /* 40 */ 82, 83, 84, 61, 63, 67, 66, 85, 86, 88, - /* 50 */ 87, + /* 0 */ 127, 127, 127, 127, 127, 127, 127, 127, 91, 90, + /* 10 */ 93, 92, 97, 127, 96, 127, 127, 95, 94, 127, + /* 20 */ 127, 127, 103, }; -#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) +/********** End of lemon-generated parsing tables *****************************/ -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** +/* The next table maps tokens (terminal symbols) into fallback tokens. +** If a construct like the following: +** ** %fallback ID X Y Z. ** -** appears in the grammer, then ID becomes a fallback token for X, Y, +** appears in the grammar, then ID becomes a fallback token for X, Y, ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser ** but it does not parse, the type of the token is changed to ID and ** the parse is retried before an error is thrown. +** +** This feature can be used, for example, to cause some keywords in a language +** to revert to identifiers if they keyword does not apply in the context where +** it appears. */ #ifdef YYFALLBACK static const YYCODETYPE yyFallback[] = { @@ -221,13 +283,17 @@ static const YYCODETYPE yyFallback[] = { ** + The semantic value stored at this level of the stack. This is ** the information used by the action routines in the grammar. ** It is sometimes called the "minor" token. +** +** After the "shift" half of a SHIFTREDUCE action, the stateno field +** actually contains the reduce action for the second half of the +** SHIFTREDUCE. */ struct yyStackEntry { - int stateno; /* The state-number */ - int major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ + YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */ + YYCODETYPE major; /* The major token value. This is the code + ** number for the token at this stack level */ + YYMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ }; typedef struct yyStackEntry yyStackEntry; @@ -235,6 +301,9 @@ typedef struct yyStackEntry yyStackEntry; ** the following structure */ struct yyParser { int yyidx; /* Index of top element in stack */ +#ifdef YYTRACKMAXSTACKDEPTH + int yyidxMax; /* Maximum value of yyidx */ +#endif int yyerrcnt; /* Shifts left before out of the error */ expressionParserARG_SDECL /* A place to hold %extra_argument */ #if YYSTACKDEPTH<=0 @@ -253,10 +322,10 @@ static char *yyTracePrompt = 0; #endif /* NDEBUG */ #ifndef NDEBUG -/* +/* ** Turn parser tracing on by giving a stream to which to write the trace ** and a prompt to preface each trace message. Tracing is turned off -** by making either argument NULL +** by making either argument NULL ** ** Inputs: **
    @@ -281,7 +350,7 @@ void expressionParserTrace(FILE *TraceFILE, char *zTracePrompt){ #ifndef NDEBUG /* For tracing shifts, the names of all terminals and nonterminals ** are required. The following table supplies these names */ -static const char *const yyTokenName[] = { +static const char *const yyTokenName[] = { "$", "AND", "OR", "EQ", "NE", "GT", "GE", "LT", "LE", "STARTS_WITH", "ENDS_WITH", "IS_PRESENT", @@ -364,7 +433,16 @@ static void yyGrowStack(yyParser *p){ } #endif -/* +/* Datatype of the argument to the memory allocated passed as the +** second argument to expressionParserAlloc() below. This can be changed by +** putting an appropriate #define in the %include section of the input +** grammar. +*/ +#ifndef YYMALLOCARGTYPE +# define YYMALLOCARGTYPE size_t +#endif + +/* ** This function allocates a new parser. ** The only argument is a pointer to a function which works like ** malloc. @@ -376,35 +454,49 @@ static void yyGrowStack(yyParser *p){ ** A pointer to a parser. This pointer is used in subsequent calls ** to expressionParser and expressionParserFree. */ -void *expressionParserAlloc(void *(*mallocProc)(size_t)){ +void *expressionParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); if( pParser ){ pParser->yyidx = -1; +#ifdef YYTRACKMAXSTACKDEPTH + pParser->yyidxMax = 0; +#endif #if YYSTACKDEPTH<=0 + pParser->yystack = NULL; + pParser->yystksz = 0; yyGrowStack(pParser); #endif } return pParser; } -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. +/* The following function deletes the "minor type" or semantic value +** associated with a symbol. The symbol can be either a terminal +** or nonterminal. "yymajor" is the symbol code, and "yypminor" is +** a pointer to the value to be deleted. The code used to do the +** deletions is derived from the %destructor and/or %token_destructor +** directives of the input grammar. */ -static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ +static void yy_destructor( + yyParser *yypParser, /* The parser */ + YYCODETYPE yymajor, /* Type code for object to destroy */ + YYMINORTYPE *yypminor /* The object to be destroyed */ +){ + expressionParserARG_FETCH; switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is + ** reduce or during error processing or when a parser is ** being destroyed before it is finished parsing. ** ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used + ** which appear on the RHS of the rule, but which are *not* used ** inside the C code. */ +/********* Begin destructor definitions ***************************************/ + /* TERMINAL Destructor */ case 1: /* AND */ case 2: /* OR */ case 3: /* EQ */ @@ -428,18 +520,23 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ case 21: /* RPAREN */ case 22: /* VALUE */ case 23: /* COMMA */ -#line 31 "expression.y" -{ token_destructor((yypminor->yy0)); } -#line 435 "expression.c" +{ +#line 30 "expression.y" + token_destructor((yypminor->yy0)); +#line 526 "expression.c" +} break; case 25: /* params */ -#line 33 "expression.y" { +#line 32 "expression.y" + U_TRACE(0, "::params_destructor(%p)", (yypminor->yy49)) delete (yypminor->yy49); + +#line 536 "expression.c" } -#line 443 "expression.c" break; +/********* End destructor definitions *****************************************/ default: break; /* If no destructor action specified: do nothing */ } } @@ -449,47 +546,37 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ ** ** If there is a destructor routine associated with the token which ** is popped from the stack, then call it. -** -** Return the major token number for the symbol popped. */ -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - -#ifndef U_COVERITY_FALSE_POSITIVE - if( pParser->yyidx<0 ) return 0; +static void yy_pop_parser_stack(yyParser *pParser){ + yyStackEntry *yytos; + assert( pParser->yyidx>=0 ); + yytos = &pParser->yystack[pParser->yyidx--]; #ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ + if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sPopping %s\n", yyTracePrompt, yyTokenName[yytos->major]); } #endif -#endif - yymajor = yytos->major; - yy_destructor( yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; + yy_destructor(pParser, yytos->major, &yytos->minor); } -/* -** Deallocate and destroy a parser. Destructors are all called for +/* +** Deallocate and destroy a parser. Destructors are called for ** all stack elements before shutting the parser down. ** -** Inputs: -**
      -**
    • A pointer to the parser. This should be a pointer -** obtained from expressionParserAlloc. -**
    • A pointer to a function used to reclaim memory obtained -** from malloc. -**
    +** If the YYPARSEFREENEVERNULL macro exists (for example because it +** is defined in a %include section of the input grammar) then it is +** assumed that the input pointer is never NULL. */ void expressionParserFree( void *p, /* The parser to be deleted */ void (*freeProc)(void*) /* Function used to reclaim memory */ ){ yyParser *pParser = (yyParser*)p; +#ifndef YYPARSEFREENEVERNULL if( pParser==0 ) return; +#endif while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); #if YYSTACKDEPTH<=0 free(pParser->yystack); @@ -497,13 +584,19 @@ void expressionParserFree( (*freeProc)((void*)pParser); } +/* +** Return the peak depth of the stack for a parser. +*/ +#ifdef YYTRACKMAXSTACKDEPTH +int expressionParserStackPeak(void *p){ + yyParser *pParser = (yyParser*)p; + return pParser->yyidxMax; +} +#endif + /* ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. */ static int yy_find_shift_action( yyParser *pParser, /* The parser */ @@ -511,68 +604,90 @@ static int yy_find_shift_action( ){ int i; int stateno = pParser->yystack[pParser->yyidx].stateno; - - if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){ - return yy_default[stateno]; - } - assert( iLookAhead!=YYNOCODE ); - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ - if( iLookAhead>0 ){ + + if( stateno>=YY_MIN_REDUCE ) return stateno; + assert( stateno <= YY_SHIFT_COUNT ); + do{ + i = yy_shift_ofst[stateno]; + if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno]; + assert( iLookAhead!=YYNOCODE ); + i += iLookAhead; + if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ + if( iLookAhead>0 ){ #ifdef YYFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } #endif - return yy_find_shift_action(pParser, iFallback); - } + assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */ + iLookAhead = iFallback; + continue; + } #endif #ifdef YYWILDCARD - { - int j = i - iLookAhead + YYWILDCARD; - if( j>=0 && j=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); - } + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], + yyTokenName[YYWILDCARD]); + } #endif /* NDEBUG */ - return yy_action[j]; + return yy_action[j]; + } } - } #endif /* YYWILDCARD */ + } + return yy_default[stateno]; + }else{ + return yy_action[i]; } - return yy_default[stateno]; - }else{ - return yy_action[i]; - } + }while(1); } /* ** Find the appropriate action for a parser given the non-terminal ** look-ahead token iLookAhead. -** -** If the look-ahead token is YYNOCODE, then check to see if the action is -** independent of the look-ahead. If it is, return the action, otherwise -** return YY_NO_ACTION. */ static int yy_find_reduce_action( int stateno, /* Current state number */ YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; - assert( stateno<=YY_REDUCE_MAX ); +#ifdef YYERRORSYMBOL + if( stateno>YY_REDUCE_COUNT ){ + return yy_default[stateno]; + } +#else + assert( stateno<=YY_REDUCE_COUNT ); +#endif i = yy_reduce_ofst[stateno]; assert( i!=YY_REDUCE_USE_DFLT ); assert( iLookAhead!=YYNOCODE ); i += iLookAhead; - assert( i>=0 && i=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){ + return yy_default[stateno]; + } +#else + assert( i>=0 && iyyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will execute if the parser ** stack every overflows */ -#line 55 "expression.y" +/******** Begin %stack_overflow code ******************************************/ +#line 54 "expression.y" - U_TRACE(0, "::stack_overflow()") + U_TRACE_NO_PARAM(0, "::stack_overflow()") U_WARNING("Parse stack overflow"); -#line 598 "expression.c" +#line 713 "expression.c" +/******** End %stack_overflow code ********************************************/ expressionParserARG_STORE; /* Suppress warning about unused %extra_argument var */ } +/* +** Print tracing information for a SHIFT action +*/ +#ifndef NDEBUG +static void yyTraceShift(yyParser *yypParser, int yyNewState){ + if( yyTraceFILE ){ + if( yyNewStateyystack[yypParser->yyidx].major], + yyNewState); + }else{ + fprintf(yyTraceFILE,"%sShift '%s'\n", + yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]); + } + } +} +#else +# define yyTraceShift(X,Y) +#endif + /* ** Perform a shift action. */ @@ -605,11 +742,16 @@ static void yy_shift( yyParser *yypParser, /* The parser to be shifted */ int yyNewState, /* The new state to shift in */ int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ + YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */ ){ yyStackEntry *yytos; yypParser->yyidx++; -#if YYSTACKDEPTH>0 +#ifdef YYTRACKMAXSTACKDEPTH + if( yypParser->yyidx>yypParser->yyidxMax ){ + yypParser->yyidxMax = yypParser->yyidx; + } +#endif +#if YYSTACKDEPTH>0 if( yypParser->yyidx>=YYSTACKDEPTH ){ yyStackOverflow(yypParser, yypMinor); return; @@ -624,19 +766,10 @@ static void yy_shift( } #endif yytos = &yypParser->yystack[yypParser->yyidx]; - yytos->stateno = yyNewState; - yytos->major = yyMajor; + yytos->stateno = (YYACTIONTYPE)yyNewState; + yytos->major = (YYCODETYPE)yyMajor; yytos->minor = *yypMinor; -#ifndef NDEBUG - if( yyTraceFILE && yypParser->yyidx>0 ){ - int i; - fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); - fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); - } -#endif + yyTraceShift(yypParser, yyNewState); } /* The following table contains information about every rule that @@ -704,29 +837,14 @@ static void yy_reduce( expressionParserARG_FETCH; yymsp = &yypParser->yystack[yypParser->yyidx]; #ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 + if( yyTraceFILE && yyruleno>=0 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, - yyRuleName[yyruleno]); + yysize = yyRuleInfo[yyruleno].nrhs; + fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt, + yyRuleName[yyruleno], yymsp[-yysize].stateno); } #endif /* NDEBUG */ - - /* Silence complaints from purify about yygotominor being uninitialized - ** in some cases when it is copied into the stack after the following - ** switch. yygotominor is uninitialized when a rule reduces that does - ** not set the value of its left-hand side nonterminal. Leaving the - ** value of the nonterminal uninitialized is utterly harmless as long - ** as the value is never used. So really the only thing this code - ** accomplishes is to quieten purify. - ** - ** 2007-01-16: The wireshark project (www.wireshark.org) reports that - ** without this code, their parser segfaults. I'm not sure what there - ** parser is doing to make this happen. This is the second bug report - ** from wireshark this week. Clearly they are stressing Lemon in ways - ** that it has not been previously stressed... (SQLite ticket #2172) - */ - memset(&yygotominor, 0, sizeof(yygotominor)); - + yygotominor = yyzerominor; switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example @@ -737,31 +855,32 @@ static void yy_reduce( ** #line ** break; */ +/********** Begin reduce actions **********************************************/ case 0: /* input ::= booleanExpression */ -#line 78 "expression.y" +#line 77 "expression.y" { - U_TRACE(0, "input ::= booleanExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "input ::= booleanExpression(yymsp[0].minor.yy3)") U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy3) U_INTERNAL_ASSERT_POINTER(result) - U_INTERNAL_DUMP("yymsp[0].minor.yy3 = %.*S result = %.*S", U_STRING_TO_TRACE(*yymsp[0].minor.yy3), U_STRING_TO_TRACE(*result)) + U_INTERNAL_DUMP("yymsp[0].minor.yy3 = %V result = %V", yymsp[0].minor.yy3->rep, result->rep) *result = *yymsp[0].minor.yy3; delete yymsp[0].minor.yy3; } -#line 755 "expression.c" +#line 873 "expression.c" break; case 1: /* booleanExpression ::= booleanExpression booleanCond equalityExpression */ -#line 91 "expression.y" +#line 90 "expression.y" { - U_TRACE(0, "booleanExpression(yygotominor.yy3) ::= booleanExpression(yymsp[-2].minor.yy3) booleanCond(yymsp[-1].minor.yy12) equalityExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "booleanExpression(yygotominor.yy3) ::= booleanExpression(yymsp[-2].minor.yy3) booleanCond(yymsp[-1].minor.yy12) equalityExpression(yymsp[0].minor.yy3)") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy3) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy3) - U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %.*S yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %.*S", U_STRING_TO_TRACE(*yymsp[-2].minor.yy3), yymsp[-1].minor.yy12, U_STRING_TO_TRACE(*yymsp[0].minor.yy3)) + U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %V yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %V", yymsp[-2].minor.yy3->rep, yymsp[-1].minor.yy12, yymsp[0].minor.yy3->rep) bool Bbo = (yymsp[-2].minor.yy3->empty() == false), Dbo = (yymsp[0].minor.yy3->empty() == false), @@ -773,14 +892,14 @@ static void yy_reduce( delete yymsp[-2].minor.yy3; delete yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 779 "expression.c" +#line 897 "expression.c" break; case 2: /* booleanExpression ::= equalityExpression */ -#line 112 "expression.y" +#line 111 "expression.y" { - U_TRACE(0, "booleanExpression(yygotominor.yy3) ::= equalityExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "booleanExpression(yygotominor.yy3) ::= equalityExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -788,19 +907,19 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 794 "expression.c" +#line 912 "expression.c" break; case 3: /* equalityExpression ::= equalityExpression equalityCond relationalExpression */ -#line 124 "expression.y" +#line 123 "expression.y" { - U_TRACE(0, "equalityExpression(yygotominor.yy3) ::= equalityExpression(yymsp[-2].minor.yy3) equalityCond(yymsp[-1].minor.yy12) relationalExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "equalityExpression(yygotominor.yy3) ::= equalityExpression(yymsp[-2].minor.yy3) equalityCond(yymsp[-1].minor.yy12) relationalExpression(yymsp[0].minor.yy3)") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy3) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy3) - U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %.*S yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %.*S", U_STRING_TO_TRACE(*yymsp[-2].minor.yy3), yymsp[-1].minor.yy12, U_STRING_TO_TRACE(*yymsp[0].minor.yy3)) + U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %V yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %V", yymsp[-2].minor.yy3->rep, yymsp[-1].minor.yy12, yymsp[0].minor.yy3->rep) bool bo = false, Bbo = (yymsp[-2].minor.yy3->empty() == false), @@ -826,14 +945,14 @@ static void yy_reduce( delete yymsp[-2].minor.yy3; delete yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 832 "expression.c" +#line 950 "expression.c" break; case 4: /* equalityExpression ::= relationalExpression */ -#line 159 "expression.y" +#line 158 "expression.y" { - U_TRACE(0, "equalityExpression(yygotominor.yy3) ::= relationalExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "equalityExpression(yygotominor.yy3) ::= relationalExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -841,19 +960,19 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 847 "expression.c" +#line 965 "expression.c" break; case 5: /* relationalExpression ::= relationalExpression relationalCond additiveExpression */ -#line 171 "expression.y" +#line 170 "expression.y" { - U_TRACE(0, "relationalExpression(yygotominor.yy3) ::= relationalExpression(yymsp[-2].minor.yy3) relationalCond(yymsp[-1].minor.yy12) additiveExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "relationalExpression(yygotominor.yy3) ::= relationalExpression(yymsp[-2].minor.yy3) relationalCond(yymsp[-1].minor.yy12) additiveExpression(yymsp[0].minor.yy3)") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy3) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy3) - U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %.*S yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %.*S", U_STRING_TO_TRACE(*yymsp[-2].minor.yy3), yymsp[-1].minor.yy12, U_STRING_TO_TRACE(*yymsp[0].minor.yy3)) + U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %V yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %V", yymsp[-2].minor.yy3->rep, yymsp[-1].minor.yy12, yymsp[0].minor.yy3->rep) bool bo = false, Bbo = (yymsp[-2].minor.yy3->empty() == false), @@ -876,14 +995,14 @@ static void yy_reduce( delete yymsp[-2].minor.yy3; delete yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 882 "expression.c" +#line 1000 "expression.c" break; case 6: /* relationalExpression ::= additiveExpression */ -#line 203 "expression.y" +#line 202 "expression.y" { - U_TRACE(0, "relationalExpression(yygotominor.yy3) ::= additiveExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "relationalExpression(yygotominor.yy3) ::= additiveExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -891,19 +1010,19 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 897 "expression.c" +#line 1015 "expression.c" break; case 7: /* additiveExpression ::= additiveExpression additiveCond multiplicativeExpression */ -#line 215 "expression.y" +#line 214 "expression.y" { - U_TRACE(0, "additiveExpression(yygotominor.yy3) ::= additiveExpression(yymsp[-2].minor.yy3) additiveCond(yymsp[-1].minor.yy12) multiplicativeExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "additiveExpression(yygotominor.yy3) ::= additiveExpression(yymsp[-2].minor.yy3) additiveCond(yymsp[-1].minor.yy12) multiplicativeExpression(yymsp[0].minor.yy3)") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy3) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy3) - U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %.*S yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %.*S", U_STRING_TO_TRACE(*yymsp[-2].minor.yy3), yymsp[-1].minor.yy12, U_STRING_TO_TRACE(*yymsp[0].minor.yy3)) + U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %V yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %V", yymsp[-2].minor.yy3->rep, yymsp[-1].minor.yy12, yymsp[0].minor.yy3->rep) long Blo = yymsp[-2].minor.yy3->strtol(), Dlo = yymsp[0].minor.yy3->strtol(), @@ -915,14 +1034,14 @@ static void yy_reduce( delete yymsp[-2].minor.yy3; delete yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 921 "expression.c" +#line 1039 "expression.c" break; case 8: /* additiveExpression ::= multiplicativeExpression */ -#line 236 "expression.y" +#line 235 "expression.y" { - U_TRACE(0, "additiveExpression(yygotominor.yy3) ::= multiplicativeExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "additiveExpression(yygotominor.yy3) ::= multiplicativeExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -930,39 +1049,45 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 936 "expression.c" +#line 1054 "expression.c" break; case 9: /* multiplicativeExpression ::= multiplicativeExpression multiplicativeCond unaryExpression */ -#line 248 "expression.y" +#line 247 "expression.y" { - U_TRACE(0, "multiplicativeExpression(yygotominor.yy3) ::= multiplicativeExpression(yymsp[-2].minor.yy3) multiplicativeCond(yymsp[-1].minor.yy12) unaryExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "multiplicativeExpression(yygotominor.yy3) ::= multiplicativeExpression(yymsp[-2].minor.yy3) multiplicativeCond(yymsp[-1].minor.yy12) unaryExpression(yymsp[0].minor.yy3)") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy3) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy3) - U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %.*S yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %.*S", U_STRING_TO_TRACE(*yymsp[-2].minor.yy3), yymsp[-1].minor.yy12, U_STRING_TO_TRACE(*yymsp[0].minor.yy3)) + U_INTERNAL_DUMP("yymsp[-2].minor.yy3 = %V yymsp[-1].minor.yy12 = %d yymsp[0].minor.yy3 = %V", yymsp[-2].minor.yy3->rep, yymsp[-1].minor.yy12, yymsp[0].minor.yy3->rep) - long Blo = yymsp[-2].minor.yy3->strtol(), - Dlo = yymsp[0].minor.yy3->strtol(), - lo = (yymsp[-1].minor.yy12 == U_TK_MULT ? Blo * Dlo : - yymsp[-1].minor.yy12 == U_TK_DIV ? Blo / Dlo : - Blo % Dlo); + long lo, + Blo = yymsp[-2].minor.yy3->strtol(), + Dlo = yymsp[0].minor.yy3->strtol(); - yygotominor.yy3 = U_NEW(UString(UStringExt::stringFromNumber(lo))); + if (Dlo == 0) yygotominor.yy3 = U_NEW(UString(U_STRING_FROM_CONSTANT("0"))); + else + { + lo = (yymsp[-1].minor.yy12 == U_TK_MULT ? Blo * Dlo : + yymsp[-1].minor.yy12 == U_TK_DIV ? Blo / Dlo : + Blo % Dlo); + + yygotominor.yy3 = U_NEW(UString(UStringExt::stringFromNumber(lo))); + } delete yymsp[-2].minor.yy3; delete yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 961 "expression.c" +#line 1085 "expression.c" break; case 10: /* multiplicativeExpression ::= unaryExpression */ -#line 270 "expression.y" +#line 275 "expression.y" { - U_TRACE(0, "multiplicativeExpression(yygotominor.yy3) ::= unaryExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "multiplicativeExpression(yygotominor.yy3) ::= unaryExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -970,14 +1095,14 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 976 "expression.c" +#line 1100 "expression.c" break; case 11: /* unaryExpression ::= NOT primaryExpression */ -#line 282 "expression.y" +#line 287 "expression.y" { - U_TRACE(0, "unaryExpression(yygotominor.yy3) ::= NOT primaryExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "unaryExpression(yygotominor.yy3) ::= NOT primaryExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -987,15 +1112,15 @@ static void yy_reduce( delete yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) - yy_destructor(18,&yymsp[-1].minor); + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) + yy_destructor(yypParser,18,&yymsp[-1].minor); } -#line 994 "expression.c" +#line 1118 "expression.c" break; case 12: /* unaryExpression ::= primaryExpression */ -#line 296 "expression.y" +#line 301 "expression.y" { - U_TRACE(0, "unaryExpression(yygotominor.yy3) ::= primaryExpression(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "unaryExpression(yygotominor.yy3) ::= primaryExpression(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -1003,14 +1128,14 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 1009 "expression.c" +#line 1133 "expression.c" break; case 13: /* primaryExpression ::= LPAREN booleanExpression RPAREN */ -#line 308 "expression.y" +#line 313 "expression.y" { - U_TRACE(0, "primaryExpression(yygotominor.yy3) ::= LPAREN booleanExpression(yymsp[-1].minor.yy3) RPAREN") + U_TRACE_NO_PARAM(0, "primaryExpression(yygotominor.yy3) ::= LPAREN booleanExpression(yymsp[-1].minor.yy3) RPAREN") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[-1].minor.yy3 = %p", yygotominor.yy3, yymsp[-1].minor.yy3) @@ -1018,16 +1143,16 @@ static void yy_reduce( yygotominor.yy3 = yymsp[-1].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) - yy_destructor(20,&yymsp[-2].minor); - yy_destructor(21,&yymsp[0].minor); + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) + yy_destructor(yypParser,20,&yymsp[-2].minor); + yy_destructor(yypParser,21,&yymsp[0].minor); } -#line 1026 "expression.c" +#line 1150 "expression.c" break; case 14: /* primaryExpression ::= value */ -#line 320 "expression.y" +#line 325 "expression.y" { - U_TRACE(0, "primaryExpression(yygotominor.yy3) ::= value(yymsp[0].minor.yy3)") + U_TRACE_NO_PARAM(0, "primaryExpression(yygotominor.yy3) ::= value(yymsp[0].minor.yy3)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy3 = %p", yygotominor.yy3, yymsp[0].minor.yy3) @@ -1035,14 +1160,14 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy3; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 1041 "expression.c" +#line 1165 "expression.c" break; case 15: /* value ::= VALUE */ -#line 332 "expression.y" +#line 337 "expression.y" { - U_TRACE(0, "value(yygotominor.yy3) ::= VALUE(yymsp[0].minor.yy0)") + U_TRACE_NO_PARAM(0, "value(yygotominor.yy3) ::= VALUE(yymsp[0].minor.yy0)") U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[0].minor.yy0 = %p", yygotominor.yy3, yymsp[0].minor.yy0) @@ -1050,193 +1175,193 @@ static void yy_reduce( yygotominor.yy3 = yymsp[0].minor.yy0; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 1056 "expression.c" +#line 1180 "expression.c" break; case 16: /* value ::= value VALUE */ -#line 344 "expression.y" +#line 349 "expression.y" { - U_TRACE(0, "value(yygotominor.yy3) ::= value(yymsp[-1].minor.yy3) VALUE(yymsp[0].minor.yy0)") + U_TRACE_NO_PARAM(0, "value(yygotominor.yy3) ::= value(yymsp[-1].minor.yy3) VALUE(yymsp[0].minor.yy0)") U_INTERNAL_ASSERT_POINTER(yymsp[-1].minor.yy3) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy0) - U_INTERNAL_DUMP("yymsp[-1].minor.yy3 = %.*S yymsp[0].minor.yy0 = %.*S", U_STRING_TO_TRACE(*yymsp[-1].minor.yy3), U_STRING_TO_TRACE(*yymsp[0].minor.yy0)) + U_INTERNAL_DUMP("yymsp[-1].minor.yy3 = %V yymsp[0].minor.yy0 = %V", yymsp[-1].minor.yy3->rep, yymsp[0].minor.yy0->rep) yygotominor.yy3 = yymsp[-1].minor.yy3; *yygotominor.yy3 += *yymsp[0].minor.yy0; delete yymsp[0].minor.yy0; - U_INTERNAL_DUMP("yygotominor.yy3 = %.*S", U_STRING_TO_TRACE(*yygotominor.yy3)) + U_INTERNAL_DUMP("yygotominor.yy3 = %V", yygotominor.yy3->rep) } -#line 1075 "expression.c" +#line 1199 "expression.c" break; case 17: /* booleanCond ::= OR */ -#line 360 "expression.y" +#line 365 "expression.y" { - U_TRACE(0, "booleanCond(yygotominor.yy12) ::= OR") + U_TRACE_NO_PARAM(0, "booleanCond(yygotominor.yy12) ::= OR") yygotominor.yy12 = U_TK_OR; - yy_destructor(2,&yymsp[0].minor); + yy_destructor(yypParser,2,&yymsp[0].minor); } -#line 1084 "expression.c" +#line 1208 "expression.c" break; case 18: /* booleanCond ::= AND */ -#line 364 "expression.y" +#line 369 "expression.y" { - U_TRACE(0, "booleanCond(yygotominor.yy12) ::= AND") + U_TRACE_NO_PARAM(0, "booleanCond(yygotominor.yy12) ::= AND") yygotominor.yy12 = U_TK_AND; - yy_destructor(1,&yymsp[0].minor); + yy_destructor(yypParser,1,&yymsp[0].minor); } -#line 1093 "expression.c" +#line 1217 "expression.c" break; case 19: /* equalityCond ::= EQ */ -#line 368 "expression.y" +#line 373 "expression.y" { - U_TRACE(0, "equalityCond(yygotominor.yy12) ::= EQ") + U_TRACE_NO_PARAM(0, "equalityCond(yygotominor.yy12) ::= EQ") yygotominor.yy12 = U_TK_EQ; - yy_destructor(3,&yymsp[0].minor); + yy_destructor(yypParser,3,&yymsp[0].minor); } -#line 1102 "expression.c" +#line 1226 "expression.c" break; case 20: /* equalityCond ::= NE */ -#line 372 "expression.y" +#line 377 "expression.y" { - U_TRACE(0, "equalityCond(yygotominor.yy12) ::= NE") + U_TRACE_NO_PARAM(0, "equalityCond(yygotominor.yy12) ::= NE") yygotominor.yy12 = U_TK_NE; - yy_destructor(4,&yymsp[0].minor); + yy_destructor(yypParser,4,&yymsp[0].minor); } -#line 1111 "expression.c" +#line 1235 "expression.c" break; case 21: /* equalityCond ::= STARTS_WITH */ -#line 376 "expression.y" +#line 381 "expression.y" { - U_TRACE(0, "equalityCond(yygotominor.yy12) ::= STARTS_WITH") + U_TRACE_NO_PARAM(0, "equalityCond(yygotominor.yy12) ::= STARTS_WITH") yygotominor.yy12 = U_TK_STARTS_WITH; - yy_destructor(9,&yymsp[0].minor); + yy_destructor(yypParser,9,&yymsp[0].minor); } -#line 1120 "expression.c" +#line 1244 "expression.c" break; case 22: /* equalityCond ::= ENDS_WITH */ -#line 380 "expression.y" +#line 385 "expression.y" { - U_TRACE(0, "equalityCond(yygotominor.yy12) ::= ENDS_WITH") + U_TRACE_NO_PARAM(0, "equalityCond(yygotominor.yy12) ::= ENDS_WITH") yygotominor.yy12 = U_TK_ENDS_WITH; - yy_destructor(10,&yymsp[0].minor); + yy_destructor(yypParser,10,&yymsp[0].minor); } -#line 1129 "expression.c" +#line 1253 "expression.c" break; case 23: /* equalityCond ::= IS_PRESENT */ -#line 384 "expression.y" +#line 389 "expression.y" { - U_TRACE(0, "equalityCond(yygotominor.yy12) ::= IS_PRESENT") + U_TRACE_NO_PARAM(0, "equalityCond(yygotominor.yy12) ::= IS_PRESENT") yygotominor.yy12 = U_TK_IS_PRESENT; - yy_destructor(11,&yymsp[0].minor); + yy_destructor(yypParser,11,&yymsp[0].minor); } -#line 1138 "expression.c" +#line 1262 "expression.c" break; case 24: /* equalityCond ::= CONTAINS */ -#line 388 "expression.y" +#line 393 "expression.y" { - U_TRACE(0, "equalityCond(yygotominor.yy12) ::= CONTAINS") + U_TRACE_NO_PARAM(0, "equalityCond(yygotominor.yy12) ::= CONTAINS") yygotominor.yy12 = U_TK_CONTAINS; - yy_destructor(12,&yymsp[0].minor); + yy_destructor(yypParser,12,&yymsp[0].minor); } -#line 1147 "expression.c" +#line 1271 "expression.c" break; case 25: /* relationalCond ::= GT */ -#line 392 "expression.y" +#line 397 "expression.y" { - U_TRACE(0, "relationalCond(yygotominor.yy12) ::= GT") + U_TRACE_NO_PARAM(0, "relationalCond(yygotominor.yy12) ::= GT") yygotominor.yy12 = U_TK_GT; - yy_destructor(5,&yymsp[0].minor); + yy_destructor(yypParser,5,&yymsp[0].minor); } -#line 1156 "expression.c" +#line 1280 "expression.c" break; case 26: /* relationalCond ::= GE */ -#line 396 "expression.y" +#line 401 "expression.y" { - U_TRACE(0, "relationalCond(yygotominor.yy12) ::= GE") + U_TRACE_NO_PARAM(0, "relationalCond(yygotominor.yy12) ::= GE") yygotominor.yy12 = U_TK_GE; - yy_destructor(6,&yymsp[0].minor); + yy_destructor(yypParser,6,&yymsp[0].minor); } -#line 1165 "expression.c" +#line 1289 "expression.c" break; case 27: /* relationalCond ::= LT */ -#line 400 "expression.y" +#line 405 "expression.y" { - U_TRACE(0, "relationalCond(yygotominor.yy12) ::= LT") + U_TRACE_NO_PARAM(0, "relationalCond(yygotominor.yy12) ::= LT") yygotominor.yy12 = U_TK_LT; - yy_destructor(7,&yymsp[0].minor); + yy_destructor(yypParser,7,&yymsp[0].minor); } -#line 1174 "expression.c" +#line 1298 "expression.c" break; case 28: /* relationalCond ::= LE */ -#line 404 "expression.y" +#line 409 "expression.y" { - U_TRACE(0, "relationalCond(yygotominor.yy12) ::= LE") + U_TRACE_NO_PARAM(0, "relationalCond(yygotominor.yy12) ::= LE") yygotominor.yy12 = U_TK_LE; - yy_destructor(8,&yymsp[0].minor); + yy_destructor(yypParser,8,&yymsp[0].minor); } -#line 1183 "expression.c" +#line 1307 "expression.c" break; case 29: /* additiveCond ::= PLUS */ -#line 408 "expression.y" +#line 413 "expression.y" { - U_TRACE(0, "additiveCond(yygotominor.yy12) ::= PLUS") + U_TRACE_NO_PARAM(0, "additiveCond(yygotominor.yy12) ::= PLUS") yygotominor.yy12 = U_TK_PLUS; - yy_destructor(13,&yymsp[0].minor); + yy_destructor(yypParser,13,&yymsp[0].minor); } -#line 1192 "expression.c" +#line 1316 "expression.c" break; case 30: /* additiveCond ::= MINUS */ -#line 412 "expression.y" +#line 417 "expression.y" { - U_TRACE(0, "additiveCond(yygotominor.yy12) ::= MINUS") + U_TRACE_NO_PARAM(0, "additiveCond(yygotominor.yy12) ::= MINUS") yygotominor.yy12 = U_TK_MINUS; - yy_destructor(14,&yymsp[0].minor); + yy_destructor(yypParser,14,&yymsp[0].minor); } -#line 1201 "expression.c" +#line 1325 "expression.c" break; case 31: /* multiplicativeCond ::= MULT */ -#line 416 "expression.y" +#line 421 "expression.y" { - U_TRACE(0, "multiplicativeCond(yygotominor.yy12) ::= MULT") + U_TRACE_NO_PARAM(0, "multiplicativeCond(yygotominor.yy12) ::= MULT") yygotominor.yy12 = U_TK_MULT; - yy_destructor(15,&yymsp[0].minor); + yy_destructor(yypParser,15,&yymsp[0].minor); } -#line 1210 "expression.c" +#line 1334 "expression.c" break; case 32: /* multiplicativeCond ::= DIV */ -#line 420 "expression.y" +#line 425 "expression.y" { U_TRACE(0, "multiplicativeCond(yygotominor.yy12) ::= DIV") yygotominor.yy12 = U_TK_DIV; - yy_destructor(16,&yymsp[0].minor); + yy_destructor(yypParser,16,&yymsp[0].minor); } -#line 1219 "expression.c" +#line 1343 "expression.c" break; case 33: /* multiplicativeCond ::= MOD */ -#line 424 "expression.y" +#line 429 "expression.y" { - U_TRACE(0, "multiplicativeCond(yygotominor.yy12) ::= MOD") + U_TRACE_NO_PARAM(0, "multiplicativeCond(yygotominor.yy12) ::= MOD") yygotominor.yy12 = U_TK_MOD; - yy_destructor(17,&yymsp[0].minor); + yy_destructor(yypParser,17,&yymsp[0].minor); } -#line 1228 "expression.c" +#line 1352 "expression.c" break; case 34: /* primaryExpression ::= FN_CALL LPAREN RPAREN */ -#line 429 "expression.y" +#line 434 "expression.y" { - U_TRACE(0, "primaryExpression(yygotominor.yy3) ::= FN_CALL(yymsp[-2].minor.yy0) LPAREN RPAREN") + U_TRACE_NO_PARAM(0, "primaryExpression(yygotominor.yy3) ::= FN_CALL(yymsp[-2].minor.yy0) LPAREN RPAREN") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy0) - U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[-2].minor.yy0 = %.*S", yygotominor.yy3, U_STRING_TO_TRACE(*yymsp[-2].minor.yy0)) + U_INTERNAL_DUMP("yygotominor.yy3 = %p yymsp[-2].minor.yy0 = %V", yygotominor.yy3, yymsp[-2].minor.yy0->rep) long lo; -#ifdef _MSWINDOWS_ +#ifdef __MINGW32__ lPFv addr = (lPFv) ::GetProcAddress((HMODULE)0, yymsp[-2].minor.yy0->c_str()); #else lPFv addr = (lPFv) U_SYSCALL(dlsym, "%p,%S", RTLD_DEFAULT, yymsp[-2].minor.yy0->c_str()); @@ -1245,23 +1370,23 @@ static void yy_reduce( yygotominor.yy3 = (addr ? (lo = (*addr)(), U_NEW(UString(UStringExt::stringFromNumber(lo)))) : U_NEW(UString)); delete yymsp[-2].minor.yy0; - yy_destructor(20,&yymsp[-1].minor); - yy_destructor(21,&yymsp[0].minor); + yy_destructor(yypParser,20,&yymsp[-1].minor); + yy_destructor(yypParser,21,&yymsp[0].minor); } -#line 1252 "expression.c" +#line 1376 "expression.c" break; case 35: /* primaryExpression ::= FN_CALL LPAREN params RPAREN */ -#line 448 "expression.y" +#line 453 "expression.y" { - U_TRACE(0, "primaryExpression(yygotominor.yy3) ::= FN_CALL(yymsp[-3].minor.yy0) LPAREN params(yymsp[-1].minor.yy49) RPAREN") + U_TRACE_NO_PARAM(0, "primaryExpression(yygotominor.yy3) ::= FN_CALL(yymsp[-3].minor.yy0) LPAREN params(yymsp[-1].minor.yy49) RPAREN") U_INTERNAL_ASSERT_POINTER(yymsp[-3].minor.yy0) U_INTERNAL_ASSERT_POINTER(yymsp[-1].minor.yy49) - U_INTERNAL_DUMP("yymsp[-3].minor.yy0 = %.*S yymsp[-1].minor.yy49 = %p", U_STRING_TO_TRACE(*yymsp[-3].minor.yy0), yymsp[-1].minor.yy49) + U_INTERNAL_DUMP("yymsp[-3].minor.yy0 = %V yymsp[-1].minor.yy49 = %p", yymsp[-3].minor.yy0->rep, yymsp[-1].minor.yy49) long lo, lo0, lo1; -#ifdef _MSWINDOWS_ +#ifdef __MINGW32__ lPFll addr = (lPFll) ::GetProcAddress((HMODULE)0, yymsp[-3].minor.yy0->c_str()); #else lPFll addr = (lPFll) U_SYSCALL(dlsym, "%p,%S", RTLD_DEFAULT, yymsp[-3].minor.yy0->c_str()); @@ -1270,19 +1395,19 @@ static void yy_reduce( yygotominor.yy3 = (addr ? (lo0 = (*yymsp[-1].minor.yy49)[0].strtol(), lo1 = (*yymsp[-1].minor.yy49)[1].strtol(), lo = (*addr)(lo0, lo1), U_NEW(UString(UStringExt::stringFromNumber(lo)))) : U_NEW(UString)); delete yymsp[-3].minor.yy0; - yy_destructor(20,&yymsp[-2].minor); - yy_destructor(21,&yymsp[0].minor); + yy_destructor(yypParser,20,&yymsp[-2].minor); + yy_destructor(yypParser,21,&yymsp[0].minor); } -#line 1277 "expression.c" +#line 1401 "expression.c" break; case 36: /* params ::= VALUE */ -#line 468 "expression.y" +#line 473 "expression.y" { - U_TRACE(0, "params(yygotominor.yy49) ::= VALUE(yymsp[0].minor.yy0)") + U_TRACE_NO_PARAM(0, "params(yygotominor.yy49) ::= VALUE(yymsp[0].minor.yy0)") U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy0) - U_INTERNAL_DUMP("yygotominor.yy49 = %p yymsp[0].minor.yy0 = %.*S", yygotominor.yy49, U_STRING_TO_TRACE(*yymsp[0].minor.yy0)) + U_INTERNAL_DUMP("yygotominor.yy49 = %p yymsp[0].minor.yy0 = %V", yygotominor.yy49, yymsp[0].minor.yy0->rep) yygotominor.yy49 = U_NEW(Items); @@ -1290,51 +1415,54 @@ static void yy_reduce( delete yymsp[0].minor.yy0; } -#line 1294 "expression.c" +#line 1418 "expression.c" break; case 37: /* params ::= params COMMA VALUE */ -#line 482 "expression.y" +#line 487 "expression.y" { - U_TRACE(0, "params(yygotominor.yy49) ::= params(yymsp[-2].minor.yy49) COMMA VALUE(yymsp[0].minor.yy0)") + U_TRACE_NO_PARAM(0, "params(yygotominor.yy49) ::= params(yymsp[-2].minor.yy49) COMMA VALUE(yymsp[0].minor.yy0)") U_INTERNAL_ASSERT_POINTER(yymsp[-2].minor.yy49) U_INTERNAL_ASSERT_POINTER(yymsp[0].minor.yy0) - U_INTERNAL_DUMP("yymsp[-2].minor.yy49 = %p yymsp[0].minor.yy0 = %.*S", yymsp[-2].minor.yy49, U_STRING_TO_TRACE(*yymsp[0].minor.yy0)) + U_INTERNAL_DUMP("yymsp[-2].minor.yy49 = %p yymsp[0].minor.yy0 = %V", yymsp[-2].minor.yy49, yymsp[0].minor.yy0->rep) yymsp[-2].minor.yy49->push_back(*yymsp[0].minor.yy0); yygotominor.yy49 = yymsp[-2].minor.yy49; delete yymsp[0].minor.yy0; - yy_destructor(23,&yymsp[-1].minor); + yy_destructor(yypParser,23,&yymsp[-1].minor); } -#line 1313 "expression.c" +#line 1437 "expression.c" break; + default: + break; +/********** End reduce actions ************************************************/ }; + assert( yyruleno>=0 && yyrulenoyyidx -= yysize; - yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto); - if( yyact < YYNSTATE ){ -#ifdef NDEBUG - /* If we are not debugging and the reduce action popped at least + yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto); + if( yyact <= YY_MAX_SHIFTREDUCE ){ + if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; + /* If the reduce action popped at least ** one element off the stack, then we can push the new element back ** onto the stack here, and skip the stack overflow test in yy_shift(). ** That gives a significant speed improvement. */ if( yysize ){ yypParser->yyidx++; yymsp -= yysize-1; - yymsp->stateno = yyact; - yymsp->major = yygoto; + yymsp->stateno = (YYACTIONTYPE)yyact; + yymsp->major = (YYCODETYPE)yygoto; yymsp->minor = yygotominor; - }else -#endif - { + yyTraceShift(yypParser, yyact); + }else{ yy_shift(yypParser,yyact,yygoto,&yygotominor); } }else{ - assert( yyact == YYNSTATE + YYNRULE + 1 ); + assert( yyact == YY_ACCEPT_ACTION ); yy_accept(yypParser); } } @@ -1342,6 +1470,7 @@ static void yy_reduce( /* ** The following code executes when the parse fails */ +#ifndef YYNOERRORRECOVERY static void yy_parse_failed( yyParser *yypParser /* The parser */ ){ @@ -1354,15 +1483,18 @@ static void yy_parse_failed( while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser fails */ -#line 43 "expression.y" +/************ Begin %parse_failure code ***************************************/ +#line 42 "expression.y" - U_TRACE(0, "::parse_failure()") + U_TRACE_NO_PARAM(0, "::parse_failure()") U_INTERNAL_ASSERT_POINTER(result) result->clear(); U_WARNING("Parse failure!"); -#line 1365 "expression.c" +#line 1493 "expression.c" +/************ End %parse_failure code *****************************************/ expressionParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } +#endif /* YYNOERRORRECOVERY */ /* ** The following code executes when a syntax error first occurs. @@ -1374,13 +1506,15 @@ static void yy_syntax_error( ){ expressionParserARG_FETCH; #define TOKEN (yyminor.yy0) -#line 49 "expression.y" +/************ Begin %syntax_error code ****************************************/ +#line 48 "expression.y" - U_TRACE(0, "::syntax_error()") + U_TRACE_NO_PARAM(0, "::syntax_error()") U_INTERNAL_ASSERT_POINTER(result) result->clear(); U_WARNING("Syntax error!"); -#line 1386 "expression.c" +#line 1516 "expression.c" +/************ End %syntax_error code ******************************************/ expressionParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -1399,12 +1533,14 @@ static void yy_accept( while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); /* Here code is inserted which will be executed whenever the ** parser accepts */ -#line 38 "expression.y" +/*********** Begin %parse_accept code *****************************************/ +#line 37 "expression.y" - U_TRACE(0, "::parse_accept()") + U_TRACE_NO_PARAM(0, "::parse_accept()") U_INTERNAL_ASSERT_POINTER(result) - U_INTERNAL_DUMP("result = %.*S", U_STRING_TO_TRACE(*result)) -#line 1411 "expression.c" + U_INTERNAL_DUMP("result = %V", result->rep) +#line 1542 "expression.c" +/*********** End %parse_accept code *******************************************/ expressionParserARG_STORE; /* Suppress warning about unused %extra_argument variable */ } @@ -1435,7 +1571,9 @@ void expressionParser( ){ YYMINORTYPE yyminorunion; int yyact; /* The parser action. */ +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ +#endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif @@ -1446,7 +1584,8 @@ void expressionParser( if( yypParser->yyidx<0 ){ #if YYSTACKDEPTH<=0 if( yypParser->yystksz <=0 ){ - memset(&yyminorunion, 0, sizeof(yyminorunion)); + /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/ + yyminorunion = yyzerominor; yyStackOverflow(yypParser, &yyminorunion); return; } @@ -1455,26 +1594,34 @@ void expressionParser( yypParser->yyerrcnt = -1; yypParser->yystack[0].stateno = 0; yypParser->yystack[0].major = 0; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n", + yyTracePrompt); + } +#endif } yyminorunion.yy0 = yyminor; +#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); +#endif expressionParserARG_STORE; #ifndef NDEBUG if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + fprintf(yyTraceFILE,"%sInput '%s'\n",yyTracePrompt,yyTokenName[yymajor]); } #endif do{ - yyact = yy_find_shift_action(yypParser,yymajor); - if( yyact YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE; yy_shift(yypParser,yyact,yymajor,&yyminorunion); yypParser->yyerrcnt--; yymajor = YYNOCODE; - }else if( yyact < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); + }else if( yyact <= YY_MAX_REDUCE ){ + yy_reduce(yypParser,yyact-YY_MIN_REDUCE); }else{ assert( yyact == YY_ERROR_ACTION ); #ifdef YYERRORSYMBOL @@ -1488,7 +1635,7 @@ void expressionParser( #ifdef YYERRORSYMBOL /* A syntax error has occurred. ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". + ** grammar defines an error token "ERROR". ** ** This is what we do if the grammar does define ERROR: ** @@ -1516,7 +1663,7 @@ void expressionParser( yyTracePrompt,yyTokenName[yymajor]); } #endif - yy_destructor(yymajor,&yyminorunion); + yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion); yymajor = YYNOCODE; }else{ while( @@ -1524,12 +1671,12 @@ void expressionParser( yymx != YYERRORSYMBOL && (yyact = yy_find_reduce_action( yypParser->yystack[yypParser->yyidx].stateno, - YYERRORSYMBOL)) >= YYNSTATE + YYERRORSYMBOL)) >= YY_MIN_REDUCE ){ yy_pop_parser_stack(yypParser); } if( yypParser->yyidx < 0 || yymajor==0 ){ - yy_destructor(yymajor,&yyminorunion); + yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); yymajor = YYNOCODE; }else if( yymx!=YYERRORSYMBOL ){ @@ -1540,6 +1687,18 @@ void expressionParser( } yypParser->yyerrcnt = 3; yyerrorhit = 1; +#elif defined(YYNOERRORRECOVERY) + /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to + ** do any kind of error recovery. Instead, simply invoke the syntax + ** error routine and continue going as if nothing had happened. + ** + ** Applications can set this macro (for example inside %include) if + ** they intend to abandon the parse upon the first syntax error seen. + */ + yy_syntax_error(yypParser,yymajor,yyminorunion); + yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); + yymajor = YYNOCODE; + #else /* YYERRORSYMBOL is not defined */ /* This is what we do if the grammar does not define ERROR: ** @@ -1554,7 +1713,7 @@ void expressionParser( yy_syntax_error(yypParser,yymajor,yyminorunion); } yypParser->yyerrcnt = 3; - yy_destructor(yymajor,&yyminorunion); + yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); if( yyendofinput ){ yy_parse_failed(yypParser); } @@ -1562,5 +1721,15 @@ void expressionParser( #endif } }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); +#ifndef NDEBUG + if( yyTraceFILE ){ + int i; + fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt); + for(i=1; i<=yypParser->yyidx; i++) + fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ', + yyTokenName[yypParser->yystack[i].major]); + fprintf(yyTraceFILE,"]\n"); + } +#endif return; } diff --git a/src/ulib/net/server/plugin/mod_rpc.cpp b/src/ulib/net/server/plugin/mod_rpc.cpp index 3f542db17..c3f0b215b 100644 --- a/src/ulib/net/server/plugin/mod_rpc.cpp +++ b/src/ulib/net/server/plugin/mod_rpc.cpp @@ -68,10 +68,7 @@ int URpcPlugIn::handlerREAD() { is_rpc_msg = URPC::readRequest(UServer_Base::csocket); // NB: URPC::resetInfo() it is already called by clearData()... - if (is_rpc_msg) - { - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_FINISHED); - } + if (is_rpc_msg) U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_FINISHED); } U_RETURN(U_PLUGIN_HANDLER_GO_ON); diff --git a/src/ulib/net/server/server.cpp b/src/ulib/net/server/server.cpp index c9ae78641..1b526a6d0 100644 --- a/src/ulib/net/server/server.cpp +++ b/src/ulib/net/server/server.cpp @@ -975,7 +975,7 @@ UOCSPStapling* UServer_Base::pthread_ocsp; #endif #ifdef U_LINUX -static int sysctl_somaxconn, tcp_abort_on_overflow, sysctl_max_syn_backlog, tcp_fin_timeout; +static long sysctl_somaxconn, tcp_abort_on_overflow, sysctl_max_syn_backlog, tcp_fin_timeout; #endif UServer_Base::UServer_Base(UFileConfig* pcfg) @@ -1493,7 +1493,7 @@ void UServer_Base::loadConfigParam() U_INTERNAL_ASSERT(x.isNullTerminated()) - old_pid = UFile::getSysParam(x.data()); + old_pid = (int) UFile::getSysParam(x.data()); (void) UFile::writeTo(x, UString(u_pid_str, u_pid_str_len)); } diff --git a/src/ulib/string.cpp b/src/ulib/string.cpp index c4683a00a..1c8f1118c 100644 --- a/src/ulib/string.cpp +++ b/src/ulib/string.cpp @@ -349,6 +349,10 @@ void UString::str_allocate(int which) U_INTERNAL_ASSERT_EQUALS(str_response, 0) U_INTERNAL_ASSERT_EQUALS(UHashMap::pkey, 0) +# if defined(__GNUC__) && GCC_VERSION_NUM == 50300 + // UStringRep::string_rep_null->hold(); +# endif + U_NEW_ULIB_OBJECT(str_host, UString(stringrep_storage+0)); U_NEW_ULIB_OBJECT(str_chunked, UString(stringrep_storage+1)); U_NEW_ULIB_OBJECT(str_without_mac, UString(stringrep_storage+2)); @@ -798,16 +802,14 @@ void UStringRep::_release() U_INTERNAL_DUMP("_capacity = %u str(%u) = %.*S", _capacity, _length, _length, str) U_INTERNAL_ASSERT_EQUALS(references, 0) -#if defined(__GNUC__) && GCC_VERSION_NUM >= 50300 - if (this == string_rep_null) return; -#else U_INTERNAL_ASSERT_DIFFERS(this, string_rep_null) -#endif + +// if (this == string_rep_null) return; #if defined(U_SUBSTR_INC_REF) || defined(DEBUG) if (parent) # ifdef U_SUBSTR_INC_REF - parent->release(); // NB: solo la morte della substring de-referenzia la source... + parent->release(); // NB: only the death of substring de-reference the source... # else { U_INTERNAL_ASSERT_EQUALS(child, 0) @@ -2583,23 +2585,65 @@ U_EXPORT ostream& operator<<(ostream& out, const UString& str) // operator + +U_EXPORT UString operator+(const UString& lhs, const UString& rhs) +{ + uint32_t sz1 = lhs.size(), + sz2 = rhs.size(); + + UString str(sz1 + sz2); + + (void) str.append(lhs.data(), sz1); + (void) str.append(rhs.data(), sz2); + + return str; +} + +U_EXPORT UString operator+(const UString& lhs, const char* rhs) +{ + uint32_t sz1 = lhs.size(), + sz2 = u__strlen(rhs, __PRETTY_FUNCTION__); + + UString str(sz1 + sz2); + + (void) str.append(lhs.data(), sz1); + (void) str.append(rhs, sz2); + + return str; +} + U_EXPORT UString operator+(const char* lhs, const UString& rhs) { - uint32_t len = u__strlen(lhs, __PRETTY_FUNCTION__); - UString str(len + rhs.size()); + uint32_t sz2 = rhs.size(), + sz1 = u__strlen(lhs, __PRETTY_FUNCTION__); + + UString str(sz1 + sz2); + + (void) str.append(lhs, sz1); + (void) str.append(rhs.data(), sz2); + + return str; +} + +U_EXPORT UString operator+(const UString& lhs, char rhs) +{ + uint32_t sz = lhs.size(); + + UString str(sz + 1U); - (void) str.append(lhs, len); - (void) str.append(rhs); + (void) str.append(lhs.data(), sz); + (void) str.append(1U, rhs); return str; } U_EXPORT UString operator+(char lhs, const UString& rhs) { - UString str(1U + rhs.size()); + uint32_t sz = rhs.size(); + + UString str(sz + 1U); (void) str.append(1U, lhs); - (void) str.append(rhs); + (void) str.append(rhs.data(), sz); return str; } diff --git a/src/ulib/timer.cpp b/src/ulib/timer.cpp index 7e8e00638..f3238fa48 100644 --- a/src/ulib/timer.cpp +++ b/src/ulib/timer.cpp @@ -81,15 +81,7 @@ void UTimer::callHandlerTimeout() U_INTERNAL_DUMP("UEventTime::timeout1 = %#19D (next alarm expire) = %#19D", UEventTime::timeout1.tv_sec, item->next ? item->next->alarm->expire() : 0L) - if (item->alarm->handlerTime() == 0) // 0 => monitoring - { - // add it back in to its new list, sorted correctly - - item->insertEntry(); - - item->alarm->setMilliSecond(); - } - else + if (item->alarm->handlerTime()) { // put it on the free list @@ -97,6 +89,19 @@ void UTimer::callHandlerTimeout() item->next = pool; pool = item; } + else // 0 => monitoring + { + // add it back in to its new list, sorted correctly + + item->insertEntry(); + + UEventTime* a = item->alarm; + + UEventTime::ms = ((a->ctime.tv_sec + a->tv_sec - UEventTime::timeout1.tv_sec) * 1000L) + + ((a->ctime.tv_usec + a->tv_usec - UEventTime::timeout1.tv_usec) / 1000L); + + U_ASSERT(a->checkTolerance()) + } } void UTimer::run() diff --git a/src/ulib/tokenizer.cpp b/src/ulib/tokenizer.cpp index ed7f1d526..5bc294b5e 100644 --- a/src/ulib/tokenizer.cpp +++ b/src/ulib/tokenizer.cpp @@ -352,9 +352,9 @@ UString UTokenizer::getTokenQueryParser() * starts_with: ~= */ -int UTokenizer::getTokenId(UString& token) +int UTokenizer::getTokenId(UString* ptoken) { - U_TRACE(0, "UTokenizer::getTokenId(%p)", &token) + U_TRACE(0, "UTokenizer::getTokenId(%p)", ptoken) static const int dispatch_table[] = { (int)((char*)&&case_exclamation-(char*)&&cvalue),/* '!' */ @@ -454,6 +454,7 @@ int UTokenizer::getTokenId(UString& token) }; char c; + long sz; int tid = 0; const char* p1; const char* p2; @@ -602,9 +603,17 @@ case_tilde: tid = (*s == '=' ? (++s, U_TK_IS_PRESENT) : U_TK_ERROR); p2 = s; go tid = (c == '(' ? U_TK_FN_CALL : U_TK_VALUE); end: - token = str.substr(p1, p2 - p1); + if (ptoken) + { + sz = (p2 -p1); + + if (sz) + { + *ptoken = str.substr(p1, sz); - U_INTERNAL_DUMP("token = %V", token.rep) + U_INTERNAL_DUMP("token = %V", ptoken->rep) + } + } U_RETURN(tid); } diff --git a/src/ulib/utility/string_ext.cpp b/src/ulib/utility/string_ext.cpp index 8a9694759..c39f4717a 100644 --- a/src/ulib/utility/string_ext.cpp +++ b/src/ulib/utility/string_ext.cpp @@ -761,38 +761,58 @@ UString UStringExt::evalExpression(const UString& expr, const UString& environme int token_id; UTokenizer t(expr); - UString token, result = *UString::str_true; + UString* ptoken = 0; + UString result = *UString::str_true; + + static UString* token; + + if (token == 0) token = U_NEW(UString); void* pParser = expressionParserAlloc(malloc); -#ifdef DEBUG -// (void) fprintf(stderr, "start parsing expr: \"%v\"\n", expr)); -// expressionParserTrace(stderr, (char*)"parser: "); -#endif + /** + * #ifdef DEBUG + * (void) fprintf(stderr, "start parsing expr: \"%v\"\n", expr)); + * + * expressionParserTrace(stderr, (char*)"parser: "); + * #endif + */ while (result && (token_id = t.getTokenId(token)) > 0) { if (token_id == U_TK_NAME) { - token = UStringExt::getEnvironmentVar(token, &environment); - token_id = U_TK_VALUE; + *token = UStringExt::getEnvironmentVar(*token, &environment); + token_id = U_TK_VALUE; } else if (token_id == U_TK_PID) { - token = UStringExt::getPidProcess(); - token_id = U_TK_VALUE; + *token = UStringExt::getPidProcess(); + token_id = U_TK_VALUE; } - expressionParser( pParser, token_id, U_NEW(UString(token)), &result); + expressionParser( pParser, token_id, ptoken = U_NEW(UString(*token)), &result); } - expressionParser( pParser, 0, 0, &result); + expressionParser(pParser, 0, 0, &result); expressionParserFree(pParser, free); -#ifdef DEBUG -// (void) fprintf(stderr, "ended parsing expr: \"%v\"\n", expr)); +#if defined(DEBUG) && !defined(U_SUBSTR_INC_REF) + if (ptoken) + { + // (void) fprintf(stderr, "ended parsing expr: \"%v\"\n", expr)); + + U_INTERNAL_DUMP("ptoken->rep->parent->child = %d", ptoken->rep->parent->child) + + if (ptoken->rep->parent->child >= 1) + { + token->clear(); + + // delete ptoken; + } + } #endif U_RETURN_STRING(result); diff --git a/tests/ulib/string.test b/tests/ulib/string.test index eeaa295bc..829588985 100755 --- a/tests/ulib/string.test +++ b/tests/ulib/string.test @@ -6,7 +6,7 @@ start_msg string -#UTRACE="0 50M 0" +#UTRACE="0 50M -1" #UOBJDUMP="0 100k 10" #USIMERR="error.sim" UMEMPOOL=0,0,0,0,0,0,0,0,0:20971520,2097152 diff --git a/tests/ulib/test_string.cpp b/tests/ulib/test_string.cpp index cf16c9e1e..47a1f77c9 100644 --- a/tests/ulib/test_string.cpp +++ b/tests/ulib/test_string.cpp @@ -42,7 +42,7 @@ static void test_memmove_01() const char str_lit1[] = "montara and ocean beach"; char array2[sizeof(str_lit1) + sizeof(array1) - 1] = { '\0', '\0' }; - U_ASSERT( str_lit1[0] == 'm' ); + U_ASSERT( str_lit1[0] == 'm' ) char c1 = array2[0]; char c2 = str_lit1[0]; @@ -51,35 +51,35 @@ static void test_memmove_01() // memmove(array2, str_lit1, 0); - U_ASSERT( array2[0] == c1 ); - U_ASSERT( str_lit1[0] == c2 ); + U_ASSERT( array2[0] == c1 ) + U_ASSERT( str_lit1[0] == c2 ) memmove(array2, str_lit1, 1); - U_ASSERT( array2[0] == c2 ); - U_ASSERT( str_lit1[0] == c2 ); - U_ASSERT( array2[1] == c3 ); - U_ASSERT( str_lit1[1] == c4 ); + U_ASSERT( array2[0] == c2 ) + U_ASSERT( str_lit1[0] == c2 ) + U_ASSERT( array2[1] == c3 ) + U_ASSERT( str_lit1[1] == c4 ) memmove(array2, str_lit1, 2); - U_ASSERT( array2[0] == c2 ); - U_ASSERT( str_lit1[0] == c2 ); - U_ASSERT( array2[1] == c4 ); - U_ASSERT( str_lit1[1] == c4 ); + U_ASSERT( array2[0] == c2 ) + U_ASSERT( str_lit1[0] == c2 ) + U_ASSERT( array2[1] == c4 ) + U_ASSERT( str_lit1[1] == c4 ) char* pc1 = array1 + 1; c1 = pc1[0]; c2 = array1[0]; - U_ASSERT( c1 != c2 ); + U_ASSERT( c1 != c2 ) char* pc2 = (char*)memmove(array1, pc1, 0); c3 = pc1[0]; c4 = array1[0]; - U_ASSERT( c1 == c3 ); - U_ASSERT( c2 == c4 ); - U_ASSERT( pc2 == array1 ); + U_ASSERT( c1 == c3 ) + U_ASSERT( c2 == c4 ) + U_ASSERT( pc2 == array1 ) c1 = pc1[0]; c2 = array1[0]; @@ -89,13 +89,13 @@ static void test_memmove_01() c3 = pc1[0]; c4 = array1[0]; - U_ASSERT( c1 != c3 ); // underlying char array changed. - U_ASSERT( c4 != c3 ); - U_ASSERT( pc2 == array1 ); - U_ASSERT( pc3 == pc1 ); // but pointers o-tay + U_ASSERT( c1 != c3 ) // underlying char array changed. + U_ASSERT( c4 != c3 ) + U_ASSERT( pc2 == array1 ) + U_ASSERT( pc3 == pc1 ) // but pointers o-tay c1 = *(str_01.data()); c2 = array1[0]; - U_ASSERT( c1 != c2 ); + U_ASSERT( c1 != c2 ) } #endif @@ -118,14 +118,14 @@ static void test_assign_01() // UString& append(const UString&) str05 = str02; str05.append(str05); - U_ASSERT( str05 == "corpus, corpus, " ); + U_ASSERT( str05 == "corpus, corpus, " ) str05.append(str01); - U_ASSERT( str05 == "corpus, corpus, point bolivar, texas" ); + U_ASSERT( str05 == "corpus, corpus, point bolivar, texas" ) str05.append(str03); - U_ASSERT( str05 == "corpus, corpus, point bolivar, texas" ); + U_ASSERT( str05 == "corpus, corpus, point bolivar, texas" ) UString str06; str06.append(str05); - U_ASSERT( str06 == str05 ); + U_ASSERT( str06 == str05 ) // UString& append(const UString&, unsigned pos, unsigned n) str05.erase(); @@ -134,67 +134,67 @@ static void test_assign_01() str05 = str02; str05.append(str01, 0, npos); U_ASSERT( str05 == "corpus, point bolivar, texas" ); - U_ASSERT( str05 != str02 ); + U_ASSERT( str05 != str02 ) str06 = str02; str06.append(str01, 15, npos); - U_ASSERT( str06 == "corpus, texas" ); - U_ASSERT( str02 != str06 ); + U_ASSERT( str06 == "corpus, texas" ) + U_ASSERT( str02 != str06 ) // UString& append(const char* s) str05.erase(); str06.erase(); str05.append(""); - U_ASSERT( str05 == str03 ); + U_ASSERT( str05 == str03 ) str05.append(str_lit01); - U_ASSERT( str05 == str01 ); + U_ASSERT( str05 == str01 ) str06 = str02; str06.append("corpus, "); - U_ASSERT( str06 == "corpus, corpus, " ); + U_ASSERT( str06 == "corpus, corpus, " ) // UString& append(const char* s, unsigned n) str05.erase(); str06.erase(); str05.append("", 0); - U_ASSERT( str05.size() == 0 ); - U_ASSERT( str05 == str03 ); + U_ASSERT( str05.size() == 0 ) + U_ASSERT( str05 == str03 ) str05.append(str_lit01, sizeof(str_lit01) - 1); - U_ASSERT( str05 == str01 ); + U_ASSERT( str05 == str01 ) str06 = str02; str06.append("corpus, ", 6); - U_ASSERT( str06 == "corpus, corpus" ); + U_ASSERT( str06 == "corpus, corpus" ) str06 = str02; str06.append(U_CONSTANT_TO_PARAM("corpus, ")); - U_ASSERT( str06 == "corpus, corpus, " ); + U_ASSERT( str06 == "corpus, corpus, " ) // UString& append(unsigned n, char c) str05.erase(); str06.erase(); str05.append(0, 'a'); - U_ASSERT( str05 == str03 ); + U_ASSERT( str05 == str03 ) str06.append(8, '.'); - U_ASSERT( str06 == "........" ); + U_ASSERT( str06 == "........" ) str05.erase(); str06.erase(); str05.append(str03); - U_ASSERT( str05 == str03 ); + U_ASSERT( str05 == str03 ) str06 = str02; str06.append(str01.data(), str01.find('r')); - U_ASSERT( str06 == "corpus, point boliva" ); - U_ASSERT( str06 != str01 ); - U_ASSERT( str06 != str02 ); + U_ASSERT( str06 == "corpus, point boliva" ) + U_ASSERT( str06 != str01 ) + U_ASSERT( str06 != str02 ) str05 = str01; str05.append(str05.data(), str05.find('r')); - U_ASSERT( str05 == "point bolivar, texaspoint boliva" ); - U_ASSERT( str05 != str01 ); + U_ASSERT( str05 == "point bolivar, texaspoint boliva" ) + U_ASSERT( str05 != str01 ) } #endif @@ -210,27 +210,27 @@ static void test_capacity_01() unsigned sz01 = str01.capacity(); str01.reserve(100); unsigned sz02 = str01.capacity(); - U_ASSERT( sz02 >= sz01 ); - U_ASSERT( sz02 >= 100 ); + U_ASSERT( sz02 >= sz01 ) + U_ASSERT( sz02 >= 100 ) str01.reserve(1); sz01 = str01.capacity(); - U_ASSERT( sz01 > 0 ); + U_ASSERT( sz01 > 0 ) sz01 = str01.size() + 5; str01.resize(sz01); sz02 = str01.size(); - U_ASSERT( sz01 == sz02 ); + U_ASSERT( sz01 == sz02 ) sz01 = str01.size() - 5; str01.resize(sz01); sz02 = str01.size(); - U_ASSERT( sz01 == sz02 ); + U_ASSERT( sz01 == sz02 ) UString str05(30, 'q'); UString str06 = str05; str05 = str06 + str05; - U_ASSERT( str05.capacity() >= str05.size() ); - U_ASSERT( str06.capacity() >= str06.size() ); + U_ASSERT( str05.capacity() >= str05.size() ) + U_ASSERT( str06.capacity() >= str06.size() ) UString str02; unsigned sz03; @@ -239,52 +239,54 @@ static void test_capacity_01() sz03 = str02.capacity(); str02.reserve(100); sz04 = str02.capacity(); - U_ASSERT( sz04 >= sz03 ); - U_ASSERT( sz04 >= 100 ); + U_ASSERT( sz04 >= sz03 ) + U_ASSERT( sz04 >= 100 ) str02.reserve(1); sz03 = str02.capacity(); - U_ASSERT( sz03 > 0 ); + U_ASSERT( sz03 > 0 ) sz03 = str02.size() + 5; str02.resize(sz03); sz04 = str02.size(); - U_ASSERT( sz03 == sz04 ); + U_ASSERT( sz03 == sz04 ) sz03 = str02.size() - 5; str02.resize(sz03); sz04 = str02.size(); - U_ASSERT( sz03 == sz04 ); + U_ASSERT( sz03 == sz04 ) char inst_obj = '\0'; UString str07(30, inst_obj); UString str08 = str07; str07 = str08 + str07; - U_ASSERT( str07.capacity() >= str07.size() ); - U_ASSERT( str08.capacity() >= str08.size() ); + U_ASSERT( str07.capacity() >= str07.size() ) + U_ASSERT( str08.capacity() >= str08.size() ) // 3 POD types: size, length, max_size, clear(), empty() bool b01; UString str011; b01 = str01.empty(); - U_ASSERT( b01 == true ); + U_ASSERT( b01 ) sz01 = str01.size(); sz02 = str01.length(); - U_ASSERT( sz01 == sz02 ); + U_ASSERT( sz01 == sz02 ) str01.c_str(); sz01 = str01.size(); sz02 = str01.length(); - U_ASSERT( sz01 == sz02 ); + U_ASSERT( sz01 == sz02 ) sz01 = str01.length(); str01.c_str(); + + U_INTERNAL_DUMP("_LINE_ = %u __PRETTY_FUNCTION__ = %S", __LINE__, __PRETTY_FUNCTION__) + str011 = str01 + "_addendum_"; str01.c_str(); sz02 = str01.length(); - U_ASSERT( sz01 == sz02 ); + U_ASSERT( sz01 == sz02 ) sz02 = str011.length(); - U_ASSERT( sz02 > sz01 ); + U_ASSERT( sz02 > sz01 ) - // trickster allocator (__USE_MALLOC, luke) issues involved with these: UString str3 = U_STRING_FROM_CONSTANT("8-chars_8-chars_"); (void) str3.c_str(); UString str4 = str3 + U_STRING_FROM_CONSTANT("7-chars"); @@ -292,34 +294,34 @@ static void test_capacity_01() sz01 = str01.size(); sz02 = str01.max_size(); - U_ASSERT( sz02 >= sz01 ); + U_ASSERT( sz02 >= sz01 ) sz01 = str01.size(); str01.clear(); b01 = str01.empty(); - U_ASSERT( b01 == true ); + U_ASSERT( b01 ) sz02 = str01.size(); - U_ASSERT( sz01 >= sz02 ); + U_ASSERT( sz01 >= sz02 ) b01 = str02.empty(); - U_ASSERT( b01 == true ); + U_ASSERT( b01 ) sz03 = str02.size(); sz04 = str02.length(); - U_ASSERT( sz03 == sz04 ); + U_ASSERT( sz03 == sz04 ) str02.c_str(); sz03 = str02.size(); sz04 = str02.length(); - U_ASSERT( sz03 == sz04 ); + U_ASSERT( sz03 == sz04 ) sz03 = str02.max_size(); - U_ASSERT( sz03 >= sz04 ); + U_ASSERT( sz03 >= sz04 ) sz03 = str02.size(); str02.clear(); b01 = str02.empty(); - U_ASSERT( b01 == true ); + U_ASSERT( b01 ) sz04 = str02.size(); - U_ASSERT( sz03 >= sz04 ); + U_ASSERT( sz03 >= sz04 ) } static void test_capacity_02() @@ -330,7 +332,7 @@ static void test_capacity_02() // str01 becomes shared UString str02 = str01; str01.reserve(1); - U_ASSERT( str01.capacity() >= 12 ); + U_ASSERT( str01.capacity() >= 12 ) } #endif @@ -357,7 +359,7 @@ static void test_value(int result, want_value expected) default: pass = false; // should not get here } - U_ASSERT( pass == true ) + U_ASSERT( pass ) } static void test_compare_01() @@ -431,22 +433,22 @@ static void test_constructors_01() // UString(const UString&, unsigned pos = 0, unsigned n = npos) csz01 = str01.size(); UString str03(str01, csz01); - U_ASSERT( str03.size() == 0 ); - U_ASSERT( str03.size() <= str03.capacity() ); + U_ASSERT( str03.size() == 0 ) + U_ASSERT( str03.size() <= str03.capacity() ) // UString(const char* s) UString str04(str_lit01); - U_ASSERT( str01 == str04 ); + U_ASSERT( str01 == str04 ) // UString(unsigned n, char c) csz01 = str01.max_size() / 1024; UString str05(csz01 - 1, 'z'); - U_ASSERT( str05.size() != 0 ); - U_ASSERT( str05.size() <= str05.capacity() ); + U_ASSERT( str05.size() != 0 ) + U_ASSERT( str05.size() <= str05.capacity() ) UString str06(str01.data(), str01.size()); - U_ASSERT( str06 == str01 ); + U_ASSERT( str06 == str01 ) } static void test_constructors_02() @@ -454,7 +456,7 @@ static void test_constructors_02() U_TRACE(5, "test_constructors_02()") UString s(10,0); - U_ASSERT( s.size() == 10 ); + U_ASSERT( s.size() == 10 ) } static void test_constructors_03() @@ -467,9 +469,9 @@ static void test_constructors_03() // bytes. Obviously UString(char*) will halt at the first one, but // nothing else should. UString s1 (with_nulls, 28); - U_ASSERT( s1.size() == 28 ); + U_ASSERT( s1.size() == 28 ) UString s2 (s1); - U_ASSERT( s2.size() == 28 ); + U_ASSERT( s2.size() == 28 ) } #endif @@ -485,22 +487,22 @@ static void test_access_01() // char operator[] (unsigned pos) const; csz01 = str01.size(); char ref1 = str01[csz01 - 1]; - U_ASSERT( ref1 == 'a' ); + U_ASSERT( ref1 == 'a' ) ref1 = str01[csz01 - 2]; - U_ASSERT( ref1 == 'c' ); + U_ASSERT( ref1 == 'c' ) csz02 = str02.size(); char ref2 = str02[csz02 - 1]; - U_ASSERT( ref2 == 'a' ); + U_ASSERT( ref2 == 'a' ) ref2 = str02[1]; - U_ASSERT( ref2 == '4' ); + U_ASSERT( ref2 == '4' ) // char at(unsigned pos) const; ref1 = str01.at(csz01 - 1); - U_ASSERT( ref1 == 'a' ); + U_ASSERT( ref1 == 'a' ) ref2 = str02.at(csz02 - 1); - U_ASSERT( ref2 == 'a' ); + U_ASSERT( ref2 == 'a' ) } #endif @@ -519,73 +521,73 @@ static void test_find_01() // unsigned find(const UString&, unsigned pos = 0) const; csz01 = str01.find(str01); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find(str01, 4); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) csz01 = str01.find(str02, 0); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find(str02, 3); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) csz01 = str01.find(str03, 0); - U_ASSERT( csz01 == 8 ); + U_ASSERT( csz01 == 8 ) csz01 = str01.find(str03, 3); - U_ASSERT( csz01 == 8 ); + U_ASSERT( csz01 == 8 ) csz01 = str01.find(str03, 12); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) // An empty UString consists of no characters // therefore it should be found at every point in a UString, // except beyond the end /* csz01 = str01.find(str04, 0); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find(str04, 5); - U_ASSERT( csz01 == 5 ); + U_ASSERT( csz01 == 5 ) csz01 = str01.find(str04, str01.size()); - U_ASSERT( csz01 == str01.size() ); + U_ASSERT( csz01 == str01.size() ); csz01 = str01.find(str04, str01.size()+1); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) */ // unsigned find(const char* s, unsigned pos, unsigned n) const; csz01 = str01.find(str_lit01, 0, 3); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) // csz01 = str01.find(str_lit01.c_str(), 3, 0); -// U_ASSERT( csz01 == 3 ); +// U_ASSERT( csz01 == 3 ) // unsigned find(const char* s, unsigned pos = 0) const; csz01 = str01.find(str_lit01); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find(str_lit01, 3); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) // unsigned find(char c, unsigned pos = 0) const; csz01 = str01.find('z'); csz02 = str01.size() - 1; - U_ASSERT( csz01 == csz02 ); + U_ASSERT( csz01 == csz02 ) csz01 = str01.find('/'); U_ASSERT( csz01 == npos ); // unsigned find_first_of(const UString&, unsigned pos = 0) const; UString str05("xena rulez"); csz01 = str01.find_first_of(str01); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find_first_of(str01, 4); - U_ASSERT( csz01 == 4 ); + U_ASSERT( csz01 == 4 ) csz01 = str01.find_first_of(str02, 0); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find_first_of(str02, 3); - U_ASSERT( csz01 == 3 ); + U_ASSERT( csz01 == 3 ) csz01 = str01.find_first_of(str03, 0); - U_ASSERT( csz01 == 8 ); + U_ASSERT( csz01 == 8 ) csz01 = str01.find_first_of(str03, 3); - U_ASSERT( csz01 == 8 ); + U_ASSERT( csz01 == 8 ) csz01 = str01.find_first_of(str03, 12); - U_ASSERT( csz01 == 16 ); + U_ASSERT( csz01 == 16 ) csz01 = str01.find_first_of(str05, 0); - U_ASSERT( csz01 == 1 ); + U_ASSERT( csz01 == 1 ) csz01 = str01.find_first_of(str05, 4); - U_ASSERT( csz01 == 4 ); + U_ASSERT( csz01 == 4 ) // An empty UString consists of no characters // therefore it should be found at every point in a UString, @@ -594,27 +596,27 @@ static void test_find_01() // str1 (starting at pos) that exists in str2, which is none for empty str2 /* csz01 = str01.find_first_of(str04, 0); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) csz01 = str01.find_first_of(str04, 5); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) */ // unsigned find_first_of(const char* s, unsigned pos, unsigned n) const; csz01 = str01.find_first_of(str_lit01, 0, 3); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find_first_of(str_lit01, 3, 0); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) // unsigned find_first_of(const char* s, unsigned pos = 0) const; csz01 = str01.find_first_of(str_lit01); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.find_first_of(str_lit01, 3); - U_ASSERT( csz01 == 3 ); + U_ASSERT( csz01 == 3 ) // unsigned find_first_of(char c, unsigned pos = 0) const; csz01 = str01.find_first_of('z'); csz02 = str01.size() - 1; - U_ASSERT( csz01 == csz02 ); + U_ASSERT( csz01 == csz02 ) // unsigned find_last_of(const UString& str, unsigned pos = 0) const; // unsigned find_last_of(const char* s, unsigned pos, unsigned n) const; @@ -624,45 +626,45 @@ static void test_find_01() unsigned pos; UString x("X"); pos = x.find_last_not_of('X'); - U_ASSERT( pos == npos ); + U_ASSERT( pos == npos ) pos = x.find_last_not_of("XYZ"); - U_ASSERT( pos == npos ); + U_ASSERT( pos == npos ) UString y("a"); pos = y.find_last_not_of('X'); - U_ASSERT( pos == 0 ); + U_ASSERT( pos == 0 ) pos = y.find_last_not_of('a'); - U_ASSERT( pos == npos ); + U_ASSERT( pos == npos ) pos = y.find_last_not_of("XYZ"); - U_ASSERT( pos == 0 ); + U_ASSERT( pos == 0 ) pos = y.find_last_not_of("a"); - U_ASSERT( pos == npos ); + U_ASSERT( pos == npos ) UString z("ab"); pos = z.find_last_not_of('X'); - U_ASSERT( pos == 1 ); + U_ASSERT( pos == 1 ) pos = z.find_last_not_of("XYZ"); - U_ASSERT( pos == 1 ); + U_ASSERT( pos == 1 ) pos = z.find_last_not_of('b'); - U_ASSERT( pos == 0 ); + U_ASSERT( pos == 0 ) pos = z.find_last_not_of("Xb"); - U_ASSERT( pos == 0 ); + U_ASSERT( pos == 0 ) pos = z.find_last_not_of("Xa"); - U_ASSERT( pos == 1 ); + U_ASSERT( pos == 1 ) pos = z.find_last_of("ab"); - U_ASSERT( pos == 1 ); + U_ASSERT( pos == 1 ) pos = z.find_last_of("Xa"); - U_ASSERT( pos == 0 ); + U_ASSERT( pos == 0 ) pos = z.find_last_of("Xb"); - U_ASSERT( pos == 1 ); + U_ASSERT( pos == 1 ) pos = z.find_last_of("XYZ"); U_ASSERT( pos == npos ); pos = z.find_last_of('a'); - U_ASSERT( pos == 0 ); + U_ASSERT( pos == 0 ) pos = z.find_last_of('b'); - U_ASSERT( pos == 1 ); + U_ASSERT( pos == 1 ) pos = z.find_last_of('X'); - U_ASSERT( pos == npos ); + U_ASSERT( pos == npos ) } // UString rfind @@ -679,50 +681,50 @@ static void test_rfind_01() // unsigned rfind(const UString&, unsigned pos = 0) const; csz01 = str01.rfind(str01); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str01, 4); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str02,3); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str02); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str03); - U_ASSERT( csz01 == 8 ); + U_ASSERT( csz01 == 8 ) csz01 = str01.rfind(str03, 3); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) csz01 = str01.rfind(str03, 12); - U_ASSERT( csz01 == 8 ); + U_ASSERT( csz01 == 8 ) // An empty UString consists of no characters // therefore it should be found at every point in a UString, // except beyond the end csz01 = str01.rfind(str04, 0); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str04, 5); - U_ASSERT( csz01 == 5 ); + U_ASSERT( csz01 == 5 ) csz01 = str01.rfind(str04, str01.size()); - U_ASSERT( csz01 == str01.size() ); + U_ASSERT( csz01 == str01.size() ) csz01 = str01.rfind(str04, str01.size()+1); - U_ASSERT( csz01 == str01.size() ); + U_ASSERT( csz01 == str01.size() ) // unsigned rfind(const char* s, unsigned pos, unsigned n) const; csz01 = str01.rfind(str_lit01, 0, 3); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str_lit01, 3, 0); - U_ASSERT( csz01 == 3 ); + U_ASSERT( csz01 == 3 ) // unsigned rfind(const char* s, unsigned pos = 0) const; csz01 = str01.rfind(str_lit01); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) csz01 = str01.rfind(str_lit01, 3); - U_ASSERT( csz01 == 0 ); + U_ASSERT( csz01 == 0 ) // unsigned rfind(char c, unsigned pos = 0) const; csz01 = str01.rfind('z'); csz02 = str01.size() - 1; - U_ASSERT( csz01 == csz02 ); + U_ASSERT( csz01 == csz02 ) csz01 = str01.rfind('/'); - U_ASSERT( csz01 == npos ); + U_ASSERT( csz01 == npos ) } #endif @@ -754,19 +756,19 @@ static void test_insert_01() csz02 = str02.size(); str03.insert(13, str02, 0, 12); - U_ASSERT( str03 == "rodeo beach, baker beach,marin" ); + U_ASSERT( str03 == "rodeo beach, baker beach,marin" ) str03 = str01; csz01 = str03.size(); csz02 = str02.size(); - str03.insert(0, str02, 0, 12); - U_ASSERT( str03 == "baker beach,rodeo beach, marin" ); + str03.insert(0, str02, 0, 12); + U_ASSERT( str03 == "baker beach,rodeo beach, marin" ) str03 = str01; csz01 = str03.size(); csz02 = str02.size(); str03.insert(csz01, str02, 0, csz02); - U_ASSERT( str03 == "rodeo beach, marinbaker beach, san francisco" ); + U_ASSERT( str03 == "rodeo beach, marinbaker beach, san francisco" ) // UString& insert(unsigned p, const UString& str); // insert(p1, str, 0, npos) @@ -774,53 +776,53 @@ static void test_insert_01() csz01 = str03.size(); csz02 = str02.size(); str03.insert(csz01, str02); - U_ASSERT( str03 == "rodeo beach, marinbaker beach, san francisco" ); + U_ASSERT( str03 == "rodeo beach, marinbaker beach, san francisco" ) str03 = str01; csz01 = str03.size(); csz02 = str02.size(); str03.insert(0, str02); - U_ASSERT( str03 == "baker beach, san franciscorodeo beach, marin" ); + U_ASSERT( str03 == "baker beach, san franciscorodeo beach, marin" ) // UString& insert(unsigned p, const char* s, unsigned n); // insert(p1, UString(s,n)) str03 = str02; csz01 = str03.size(); str03.insert(0, "-break at the bridge", 20); - U_ASSERT( str03 == "-break at the bridgebaker beach, san francisco" ); + U_ASSERT( str03 == "-break at the bridgebaker beach, san francisco" ) // UString& insert(unsigned p, const char* s); // insert(p1, UString(s)) str03 = str02; str03.insert(0, "-break at the bridge"); - U_ASSERT( str03 == "-break at the bridgebaker beach, san francisco" ); + U_ASSERT( str03 == "-break at the bridgebaker beach, san francisco" ) // UString& insert(unsigned p, unsigned n, char c) // insert(p1, UString(n,c)) str03 = str02; csz01 = str03.size(); str03.insert(csz01, 5, 'z'); - U_ASSERT( str03 == "baker beach, san franciscozzzzz" ); + U_ASSERT( str03 == "baker beach, san franciscozzzzz" ) // iterator insert(unsigned p, unsigned n, char c) // inserts n copies of c before the character referred to by p str03 = str02; str03.insert(0, 1, 'u'); - U_ASSERT( str03 == "ubaker beach, san francisco" ); + U_ASSERT( str03 == "ubaker beach, san francisco" ) str03 = str02; str03.insert(0, 5, 'u'); - U_ASSERT( str03 == "uuuuubaker beach, san francisco" ); + U_ASSERT( str03 == "uuuuubaker beach, san francisco" ) str03 = str02; csz01 = str03.size(); str03.insert(0, str01); - U_ASSERT( str03 == "rodeo beach, marinbaker beach, san francisco" ); + U_ASSERT( str03 == "rodeo beach, marinbaker beach, san francisco" ) str03 = str02; csz01 = str03.size(); str03.insert(str03.size(), str01); - U_ASSERT( str03 == "baker beach, san franciscorodeo beach, marin" ); + U_ASSERT( str03 == "baker beach, san franciscorodeo beach, marin" ) } #endif @@ -848,21 +850,21 @@ static void test_replace_01() UString x = X; char ch = x[0]; - U_ASSERT( ch == 'H' ); + U_ASSERT( ch == 'H' ) UString z = x.substr(2U, 3U); - U_ASSERT( z == U_STRING_FROM_CONSTANT("llo") ); + U_ASSERT( z == U_STRING_FROM_CONSTANT("llo") ) x.replace(2, 2, "r"); - U_ASSERT( x == U_STRING_FROM_CONSTANT("Hero") ); + U_ASSERT( x == U_STRING_FROM_CONSTANT("Hero") ) x = X; x.replace(0, 1, "j"); - U_ASSERT( x == U_STRING_FROM_CONSTANT("jello") ); + U_ASSERT( x == U_STRING_FROM_CONSTANT("jello") ) const char ar[] = { 'H', 'e', 'l', 'l', 'o', '\0' }; x.replace(x.find('l'), 2, ar, (sizeof(ar) / sizeof(ar[0])) - 1); - U_ASSERT( x == U_STRING_FROM_CONSTANT("jeHelloo") ); + U_ASSERT( x == U_STRING_FROM_CONSTANT("jeHelloo") ) } #endif @@ -880,125 +882,125 @@ static void test_not_member_01() str_4 = str_0; //comparisons between UString objects - U_ASSERT( !(str_0 == str_1) ); - U_ASSERT( !(str_0 == str_2) ); - U_ASSERT( !(str_0 == str_3) ); - U_ASSERT( !(str_1 == str_0) ); - U_ASSERT( !(str_2 == str_0) ); - U_ASSERT( !(str_3 == str_0) ); - U_ASSERT( str_4 == str_0 ); - U_ASSERT( str_0 == str_4 ); - - U_ASSERT( str_0 != str_1 ); - U_ASSERT( str_0 != str_2 ); - U_ASSERT( str_0 != str_3 ); - U_ASSERT( str_1 != str_0 ); - U_ASSERT( str_2 != str_0 ); - U_ASSERT( str_3 != str_0 ); - U_ASSERT( !(str_0 != str_4) ); - U_ASSERT( !(str_4 != str_0) ); - - U_ASSERT( str_0 > str_1 ); //true cuz r>m - U_ASSERT( str_0 > str_2 ); - U_ASSERT( !(str_0 > str_3) ); - U_ASSERT( !(str_1 > str_0) ); //false cuz m str_0) ); - U_ASSERT( str_3 > str_0 ); - U_ASSERT( !(str_0 > str_4) ); - U_ASSERT( !(str_4 > str_0) ); - - U_ASSERT( !(str_0 < str_1) ); //false cuz r>m - U_ASSERT( !(str_0 < str_2) ); - U_ASSERT( str_0 < str_3 ); - U_ASSERT( str_1 < str_0 ); //true cuz m= str_1 ); //true cuz r>m - U_ASSERT( str_0 >= str_2 ); - U_ASSERT( !(str_0 >= str_3) ); - U_ASSERT( !(str_1 >= str_0) );//false cuz m= str_0) ); - U_ASSERT( str_3 >= str_0 ); - U_ASSERT( str_0 >= str_4 ); - U_ASSERT( str_4 >= str_0 ); - - U_ASSERT( !(str_0 <= str_1) );//false cuz r>m - U_ASSERT( !(str_0 <= str_2) ); - U_ASSERT( str_0 <= str_3 ); - U_ASSERT( str_1 <= str_0 );//true cuz m str_1 ) //true cuz r>m + U_ASSERT( str_0 > str_2 ) + U_ASSERT( !(str_0 > str_3) ) + U_ASSERT( !(str_1 > str_0) ) //false cuz m str_0) ) + U_ASSERT( str_3 > str_0 ) + U_ASSERT( !(str_0 > str_4) ) + U_ASSERT( !(str_4 > str_0) ) + + U_ASSERT( !(str_0 < str_1) ) //false cuz r>m + U_ASSERT( !(str_0 < str_2) ) + U_ASSERT( str_0 < str_3 ) + U_ASSERT( str_1 < str_0 ) //true cuz m= str_1 ) //true cuz r>m + U_ASSERT( str_0 >= str_2 ) + U_ASSERT( !(str_0 >= str_3) ) + U_ASSERT( !(str_1 >= str_0) ) //false cuz m= str_0) ) + U_ASSERT( str_3 >= str_0 ) + U_ASSERT( str_0 >= str_4 ) + U_ASSERT( str_4 >= str_0 ) + + U_ASSERT( !(str_0 <= str_1) ) //false cuz r>m + U_ASSERT( !(str_0 <= str_2) ) + U_ASSERT( str_0 <= str_3 ) + U_ASSERT( str_1 <= str_0 ) //true cuz m "costa marbella" ); //true cuz r>m - U_ASSERT( str_0 > "cost" ); - U_ASSERT( !(str_0 > "costa ricans") ); - U_ASSERT( !("costa marbella" > str_0) );//false cuz m str_0) ); - U_ASSERT( "costa ricans" > str_0 ); - U_ASSERT( !("costa rica" > str_0) ); - U_ASSERT( !(str_0 > "costa rica") ); - - U_ASSERT( !(str_0 < "costa marbella") );//false cuz r>m - U_ASSERT( !(str_0 < "cost") ); - U_ASSERT( str_0 < "costa ricans" ); - U_ASSERT( "costa marbella" < str_0 );//true cuz m= "costa marbella" );//true cuz r>m - U_ASSERT( str_0 >= "cost" ); - U_ASSERT( !(str_0 >= "costa ricans") ); - U_ASSERT( !("costa marbella" >= str_0) );//false cuz m= str_0) ); - U_ASSERT( "costa ricans" >= str_0 ); - U_ASSERT( "costa rica" >= str_0 ); - U_ASSERT( str_0 >= "costa rica" ); - - U_ASSERT( !(str_0 <= "costa marbella") );//false cuz r>m - U_ASSERT( !(str_0 <= "cost") ); - U_ASSERT( str_0 <= "costa ricans" ); - U_ASSERT( "costa marbella" <= str_0 );//true cuz m "costa marbella" ) //true cuz r>m + U_ASSERT( str_0 > "cost" ) + U_ASSERT( !(str_0 > "costa ricans") ) + U_ASSERT( !("costa marbella" > str_0) ) //false cuz m str_0) ) + U_ASSERT( "costa ricans" > str_0 ) + U_ASSERT( !("costa rica" > str_0) ) + U_ASSERT( !(str_0 > "costa rica") ) + + U_ASSERT( !(str_0 < "costa marbella") ) //false cuz r>m + U_ASSERT( !(str_0 < "cost") ) + U_ASSERT( str_0 < "costa ricans" ) + U_ASSERT( "costa marbella" < str_0 ) //true cuz m= "costa marbella" )//true cuz r>m + U_ASSERT( str_0 >= "cost" ) + U_ASSERT( !(str_0 >= "costa ricans") ) + U_ASSERT( !("costa marbella" >= str_0) )//false cuz m= str_0) ) + U_ASSERT( "costa ricans" >= str_0 ) + U_ASSERT( "costa rica" >= str_0 ) + U_ASSERT( str_0 >= "costa rica" ) + + U_ASSERT( !(str_0 <= "costa marbella") )//false cuz r>m + U_ASSERT( !(str_0 <= "cost") ) + U_ASSERT( str_0 <= "costa ricans" ) + U_ASSERT( "costa marbella" <= str_0 )//true cuz m>(istream&, UString&) istrstream istrs01(U_STRING_TO_PARAM(str01)); istrs01 >> str10; - U_ASSERT( str10 == str02 ); + U_ASSERT( str10 == str02 ) int i01 = istrs01.peek(); //a-boo - U_ASSERT( i01 == ' ' ); + U_ASSERT( i01 == ' ' ) istrs01 >> str10; - U_ASSERT( str10 == str03 ); + U_ASSERT( str10 == str03 ) istrs01 >> str10; - U_ASSERT( str10 == str04 ); // sentry picks out the white spaces. . + U_ASSERT( str10 == str04 ) // sentry picks out the white spaces. . #if __GNUC__ >= 3 istrstream istrs02(U_STRING_TO_PARAM(str05)); // empty istrs02 >> str10; - // U_ASSERT( str10 == str04 ); + // U_ASSERT( str10 == str04 ) #endif // istream& getline(istream&, UString&, char) @@ -1285,43 +1287,43 @@ static void test_stream_01() #endif getline(istrs01, str10, '\n'); - U_ASSERT( !istrs01.fail() ); - U_ASSERT( !istrs01.eof() ); - U_ASSERT( istrs01.good() ); - U_ASSERT( str10 == " bay" ); + U_ASSERT( !istrs01.fail() ) + U_ASSERT( !istrs01.eof() ) + U_ASSERT( istrs01.good() ) + U_ASSERT( str10 == " bay" ) istrs01.clear(); getline(istrs01, str10, '\t'); - U_ASSERT( !istrs01.fail() ); - U_ASSERT( !istrs01.eof() ); - U_ASSERT( istrs01.good() ); - U_ASSERT( str10 == str05 ); + U_ASSERT( !istrs01.fail() ) + U_ASSERT( !istrs01.eof() ) + U_ASSERT( istrs01.good() ) + U_ASSERT( str10 == str05 ) istrs01.clear(); getline(istrs01, str10, '\t'); - U_ASSERT( !istrs01.fail() ); - U_ASSERT( !istrs01.eof() ); - U_ASSERT( istrs01.good() ); - U_ASSERT( str10 == str05 ); + U_ASSERT( !istrs01.fail() ) + U_ASSERT( !istrs01.eof() ) + U_ASSERT( istrs01.good() ) + U_ASSERT( str10 == str05 ) istrs01.clear(); getline(istrs01, str10, '.'); - U_ASSERT( !istrs01.fail() ); - U_ASSERT( istrs01.eof() ); - U_ASSERT( !istrs01.good() ); - U_ASSERT( str10 == "\t from Elk Rapids to the point reminds me of miles" ); + U_ASSERT( !istrs01.fail() ) + U_ASSERT( istrs01.eof() ) + U_ASSERT( !istrs01.good() ) + U_ASSERT( str10 == "\t from Elk Rapids to the point reminds me of miles" ) #if __GNUC__ >= 3 getline(istrs02, str10, '\n'); - U_ASSERT( istrs02.fail() ); - U_ASSERT( istrs02.eof() ); - U_ASSERT( str10 == "\t from Elk Rapids to the point reminds me of miles" ); + U_ASSERT( istrs02.fail() ) + U_ASSERT( istrs02.eof() ) + U_ASSERT( str10 == "\t from Elk Rapids to the point reminds me of miles" ) #endif // ostream& operator<<(ostream&, const UString&) char buffer[1024]; ostrstream ostrs01(buffer, sizeof(buffer)); ostrs01 << str01 << '\0'; - U_ASSERT( str01 == ostrs01.str() ); + U_ASSERT( str01 == ostrs01.str() ) } // testing UStringbuf::xsputn via stress testing with large UStrings @@ -1336,20 +1338,20 @@ static void test_stream_04(unsigned size) ostrstream oss(buffer, sizeof(buffer)); // sanity checks - U_ASSERT( str.size() == size ); - U_ASSERT( oss.good() ); + U_ASSERT( str.size() == size ) + U_ASSERT( oss.good() ) // stress test oss << str << std::endl; - U_ASSERT( oss.good() ); + U_ASSERT( oss.good() ) oss << str << std::endl << '\0'; - U_ASSERT( oss.good() ); + U_ASSERT( oss.good() ) - U_ASSERT( str.size() == size ); - U_ASSERT( oss.good() ); + U_ASSERT( str.size() == size ) + U_ASSERT( oss.good() ) UString str_tmp = UString(oss.str()); - U_ASSERT( str_tmp.size() == expected_size ); + U_ASSERT( str_tmp.size() == expected_size ) } // testing filebuf::xsputn via stress testing with large UStrings @@ -1364,17 +1366,16 @@ static void test_stream_05(unsigned size) UString str(size, fillc); // sanity checks - U_ASSERT( str.size() == size ); - U_ASSERT( ofs.good() ); + U_ASSERT( str.size() == size ) + U_ASSERT( ofs.good() ) // stress test ofs << str << std::endl; - U_ASSERT( ofs.good() == true ); + U_ASSERT( ofs.good() ) ofs << str << std::endl; - U_ASSERT( ofs.good() == true ); - - U_ASSERT( str.size() == size ); + U_ASSERT( ofs.good() ) + U_ASSERT( str.size() == size ) ofs.close(); @@ -1394,7 +1395,7 @@ static void test_stream_05(unsigned size) break; } - U_ASSERT( count == 2 * size ); + U_ASSERT( count == (2 * size) ) unlink(filename); } @@ -1409,13 +1410,13 @@ static void test_stream_06() unsigned i01 = str01.size(); str01.erase(0, 1); unsigned i03 = str01.size(); - U_ASSERT( i01 - 1 == i03 ); + U_ASSERT( i01 - 1 == i03 ) istrstream is(U_STRING_TO_PARAM(str01)); UString str02; is >> str02; unsigned i05 = str02.size(); - U_ASSERT( i05 == i03 ); + U_ASSERT( i05 == i03 ) } // istream::operator>>(UString) @@ -1431,8 +1432,8 @@ static void test_stream_07() UString s; while (iss >> s) ++i; - U_ASSERT( i < 3 ); - U_ASSERT( static_cast(iss.rdstate() & ios::failbit) ); + U_ASSERT( i < 3 ) + U_ASSERT( static_cast(iss.rdstate() & ios::failbit) ) } static void test_stream_08() @@ -1462,7 +1463,7 @@ static void test_stream_09() char buffer[1024]; ostrstream oss1(buffer, sizeof(buffer)); oss1 << foo << '\0'; - U_ASSERT( foo == oss1.str() ); + U_ASSERT( foo == oss1.str() ) ostrstream oss2(buffer, sizeof(buffer)); oss2.width(20); diff --git a/tests/ulib/test_tokenizer.cpp b/tests/ulib/test_tokenizer.cpp index ac76db58d..69ab07280 100644 --- a/tests/ulib/test_tokenizer.cpp +++ b/tests/ulib/test_tokenizer.cpp @@ -123,15 +123,15 @@ U_EXPORT main (int argc, char* argv[]) t.setData(U_STRING_FROM_CONSTANT(" ( $QUERY_STRING = 'submitted' ) ")); - while (t.getTokenId(z) > 0); + while (t.getTokenId(0) > 0); - U_ASSERT( t.getTokenId(z) == 0 ) + U_ASSERT( t.getTokenId(0) == 0 ) t.setData(U_STRING_FROM_CONSTANT(" ( ${QUERY_STRING} != submitted ) ")); - while (t.getTokenId(z) > 0); + while (t.getTokenId(0) > 0); - U_ASSERT( t.getTokenId(z) == 0 ) + U_ASSERT( t.getTokenId(0) == 0 ) t.setData(U_STRING_FROM_CONSTANT("!!!.,;'?pippo.,;'?!!!"));