Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/lex/basicparse.cc File Reference

#include "basicparse.h"
#include <ctype.h>

Include dependency graph for basicparse.cc:

Include dependency graph

Go to the source code of this file.

Classes

struct  ParsedFloatValue
struct  ParsedIntegerValue
 Store parsed integer value. More...


Functions

template<typename T, typename UT> char * _ParseInt (T *rv, const char *str, SError &error, bool may_continue)
char * ParseInt (int8 *val, const char *str, SError &error, bool may_continue)
 Read in a signed 8bit integer value.

char * ParseInt (int16 *val, const char *str, SError &error, bool may_continue)
 Read in a signed 16bit integer value.

char * ParseInt (int32 *val, const char *str, SError &error, bool may_continue)
 Read in a signed 32bit integer value.

char * ParseInt (int64 *val, const char *str, SError &error, bool may_continue)
 Read in a signed 64bit integer value.

template<typename UT> char * _ParseUInt (UT *rv, const char *str, SError &error, bool may_continue)
char * ParseInt (uint8 *val, const char *str, SError &error, bool may_continue)
 Read in an unsigned 8bit integer value.

char * ParseInt (uint16 *val, const char *str, SError &error, bool may_continue)
 Read in an unsigned 16bit integer value.

char * ParseInt (uint32 *val, const char *str, SError &error, bool may_continue)
 Read in an unsigned 32bit integer value.

char * ParseInt (uint64 *val, const char *str, SError &error, bool may_continue)
 Read in an unsigned 64bit integer value.

int _Str2FP (dbl *rv, const char *str, char **end)
int _Str2FP (flt *rv, const char *str, char **end)
template<typename F> char * _ParseFloat (F *val, const char *str, SError &error, bool may_continue)
char * ParseFloat (flt *val, const char *str, SError &error, bool may_continue)
 Read in an flt (float) floating point value.

char * ParseFloat (dbl *val, const char *str, SError &error, bool may_continue)
 Read in a dbl (double) floating point value.

int ParseIntegerSpec (const char *str, ParsedIntegerValue *si, SError &error)
 Read in C-like integer specification.

char ParseCharacterSpec (const char *str, SError &error)
 Read in the C-like character specification.

int ParseFloatSpec (const char *str, ParsedFloatValue *sf, SError &error)
 Read in floating point value.


Function Documentation

template<typename F>
char* _ParseFloat F *  val,
const char *  str,
SError error,
bool  may_continue
 

Definition at line 306 of file basicparse.cc.

References _Str2FP(), and TLString::sprintf().

template<typename T, typename UT>
char* _ParseInt T *  rv,
const char *  str,
SError error,
bool  may_continue
[inline, static]
 

Definition at line 32 of file basicparse.cc.

References Assert, SError::clear(), SError::msg(), TLString::prepend(), and TLString::sprintf().

template<typename UT>
char* _ParseUInt UT *  rv,
const char *  str,
SError error,
bool  may_continue
[inline, static]
 

Definition at line 174 of file basicparse.cc.

References Assert, SError::clear(), SError::msg(), TLString::prepend(), and TLString::sprintf().

int _Str2FP flt rv,
const char *  str,
char **  end
 

Definition at line 299 of file basicparse.cc.

References flt.

Referenced by _ParseFloat().

int _Str2FP dbl rv,
const char *  str,
char **  end
 

Definition at line 297 of file basicparse.cc.

References dbl.

char ParseCharacterSpec const char *  str,
SError error
 

Read in the C-like character specification.

The input is a NUL-terminated string of the form 'CHAR' where CHAR is what a character can usually be, i.e.

  • the escape sequences \a, \b, \f, \n, \r, \t, \v, \\ \' \"
  • the NUL char \0
  • hexadecimal spec \0xVAL with 0<=VAL<=ff
  • octal spec \0VAL
Return value is the character value. The error details are stored in the passed SError object.

Todo:
ParseCharacterSpec() to be implemented.

Definition at line 412 of file basicparse.cc.

char* ParseFloat dbl val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in a dbl (double) floating point value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This function works much like the ParseInt() function but for floating point values. The format is just the standard floating point format (as also recognized via strtod()).

The input is a NUL-terminated string in str.

The parsed float is stored in *val (overloaded allowing the compiler to select the correct version itself).

Errors: Out of range or (in case may_continue is not set) if not the whole input was a valid floating point value.

Returns:
The first non-matching char (where parsing stopped) is returned.

Definition at line 327 of file basicparse.cc.

char* ParseFloat flt val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in an flt (float) floating point value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseFloat() for dbl (double) floats.

Definition at line 325 of file basicparse.cc.

int ParseFloatSpec const char *  str,
ParsedFloatValue sf,
SError error
 

Read in floating point value.

The passed NUL-terminated string is a floating point value of the usual form (i.e. with or without decimal point, optional exponent separated by "e" or "E", optional sign for either).

The floating point value can have the prefix "f" or "F" signalling 4-byte flt instead of standard 8-byte dbl.

The parsed value is stored in the passed *sf structure.

Errors (e.g. overflow) are stored in the passed SError object.
Returns 0 on success, !=0 on failure.

FIXME

Todo:
Should we use HUGE_VALF or FLT_MAX?

Definition at line 441 of file basicparse.cc.

References SError::AppendMsg(), dbl, ParsedFloatValue::dval, flt, ParsedFloatValue::fval, ParseFloat(), and ParsedFloatValue::size.

char* ParseInt uint64 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in an unsigned 64bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseInt() for 32bit (unsigned) integers.

Definition at line 290 of file basicparse.cc.

References uint64.

char* ParseInt uint32 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in an unsigned 32bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
Works pretty much like the ParseInt() for 32bit signed integers, however "underflow" cannot occur and the negative sign is (of course) not recognized.

For more information, see ParseInt() for signed 32bit integers.

Definition at line 287 of file basicparse.cc.

char* ParseInt uint16 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in an unsigned 16bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseInt() for 32bit (unsigned) integers.

Definition at line 284 of file basicparse.cc.

char* ParseInt uint8 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in an unsigned 8bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseInt() for 32bit (unsigned) integers.

Definition at line 281 of file basicparse.cc.

char* ParseInt int64 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in a signed 64bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseInt() for 32bit integers.

Definition at line 165 of file basicparse.cc.

char* ParseInt int32 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in a signed 32bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This function reads in a signed integer value and returns that value in the *val pointer. There are versions for 16, 32 and 64 bit integer values and the compiler can choose the correct one according to the first argument.

The passed string is a standard NUL-terminated string. The parsing is done as follows:

  • First, any number of whitespace is skipped.
  • Then, the sign (either '+' or '-') is read in.
  • Then, the prefix is interpreted to determine the base. As usual, a "0" is octal, a "0x" is hexadecimal. Additionally, "0b" is binary and the rest is considered decimal.
  • As many digits as possible are read in (keeps on reading digits on overfow).
The return value points to the first non-digit symbol in the input. If this is not end-of-string NUL, and may_continue is NOT set, then this is an error (returned in SError).

In case an over/underflow occurs, the largest/smallest value representable by the type is returned and the overflow error is set in the passed SError.

Definition at line 162 of file basicparse.cc.

char* ParseInt int16 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in a signed 16bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseInt() for 32bit integers.

Definition at line 159 of file basicparse.cc.

char* ParseInt int8 val,
const char *  str,
SError error,
bool  may_continue = 0
 

Read in a signed 8bit integer value.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
For more information, see ParseInt() for 32bit integers.

Definition at line 156 of file basicparse.cc.

int ParseIntegerSpec const char *  str,
ParsedIntegerValue si,
SError error
 

Read in C-like integer specification.

The passed string is a NUL-teminated string containing an integer spec consisting of an optional sign ("+" or "-"), the actual integer value and (any number of) the following optional postfixes:

  • "u", "U" for unsigned integers. In this case negative sign gives a warning.
  • "b", "B" for "byte" (8bit integer value)
  • "s", "S" for "short" 16bit integer value
  • "i", "I" for "int", 32bit value
  • "l", "L" for "long" 64bit integer value
"u"/"U" can be mixed with any of the size specifiers but size specifiers can obviously not be mixed.

The actual integer can be specified either decimal, or octal with "0" prefix, or hexadecimal with "0x" prefix. Hex digits a-f are case insensitive. [allow binary "0b" as well?]

In case a size postfix is specified (b,s,i or l), over- and underflow is handeled "correctly" for that size, i.e. -1US yields 65535 and 0x12345S is 0x2345.

In case a value without "u" postfix is larger than the domain but will fit into the unsigned domain of the same size, (e.g. 0x8000S), it is parsed like an unsigned value and then si->unsig is set to 1. For explicitly "u" specified unsigned values, si->unsig is set to 2; all other values are considered signed and have si->unsig=0.

In case a value is specified without size specification, the smallest size which fits the type is assumed:

  • For negative values without "u" postfix, this is the smallest signed 1,2,4 or 8-byte integer which can hold the value; an overflow (with warning) occurs at the 8byte domain. (si->unsig=0.)
  • For positive values without "u" postfix, the smallest size is a signed or unsigned value; si->unsig is set to 1 in case it was an unsigned value, 0 otherwise.
  • For positive values with "u" prefix, the smallest size is the unsigned 1,2,4 or 8-byte integer which can hold the value; an overflow (with warning) occurs at the 8byte domain. (si->unsig=2.)
  • Negative values with "u" postfix are parsed like positive values with "u" prefix (concerning the size) and after that, the "underflow computation" is performed.
The parsed integer value is stored in the passed *si structure. It is casted int an int64 for storage; values with si->unsig set (either 1 or 2) need to cast that back to uint64 to interprete the value correctly.

Return value is 0 on success, != on error. The error details are stored in the passed SError object.

Todo:
ParseIntegerSpec() to be implemented.

Definition at line 393 of file basicparse.cc.


Generated on Sat Feb 19 22:33:57 2005 for Ray by doxygen 1.3.5