Purple  0.1
Standard Language Specification
Classes | Macros | Typedefs | Enumerations | Functions | Variables
number.h File Reference

Definitions and function headers for the internal "Number" type. More...

#include <limits.h>
Include dependency graph for number.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Number
 Container for various kinds of number data. More...
 

Macros

#define NUMBER_BOOL(v)
 Generates a Number struct with type INT1. More...
 
#define NUMBER_CHAR(v)
 Generates a Number struct with type INT8. More...
 
#define NUMBER_SHORT(v)
 Generates a Number struct with type INT16. More...
 
#define NUMBER_INT(v)
 Generates a Number struct with type INT32. More...
 
#define NUMBER_LONG(v)
 Generates a Number struct with type INT64. More...
 
#define NUMBER_FROM_TYPE_VAL(t, v)
 Generates a Number struct given a NumberType and a value. More...
 
#define NUMBERS_TYPEQUIV(A, B)    (A.number_type == B.number_type && A.pointer_depth == B.pointer_depth)
 Determines if two Number structs have equivalent types. More...
 

Typedefs

typedef struct Number Number
 Container for various kinds of number data. More...
 

Enumerations

enum  NumberType {
  NT_INT1 , NT_INT8 , NT_INT16 , NT_INT32 ,
  NT_INT64
}
 Types of numbers supported by Purple. More...
 

Functions

NumberType token_type_to_number_type (int token_type)
 Convert a TokenType to a NumberType. More...
 
int number_to_token_type (Number number)
 
NumberType max_numbertype_for_val (long long int value)
 Finds the maximum NumberType possible for a given value. More...
 

Variables

static const int numberTypeByteSizes []
 Size of each NumberType. More...
 
static const int numberTypeBitSizes [] = {1, 8, 16, 32, 64}
 Bit size of each NumberType. More...
 
static const unsigned long long int numberTypeMaxValues []
 Max value of each NumberType. More...
 
static const char * numberTypeNames [] = {"bool", "char", "short", "int", "long"}
 Names of each NumberType. More...
 
static const char * numberTypeFormatStrings [] = {"%d", "%d", "%d", "%d", "%ld"}
 Format strings for each data type. More...
 

Detailed Description

Definitions and function headers for the internal "Number" type.

Author
Charles Averill
Date
12-Sep-2022

Macro Definition Documentation

◆ NUMBER_BOOL

#define NUMBER_BOOL (   v)
Value:
(Number) \
{ \
.number_type = NT_INT1, .value = v \
}
struct Number Number
Container for various kinds of number data.
@ NT_INT1
Definition: number.h:18

Generates a Number struct with type INT1.

◆ NUMBER_CHAR

#define NUMBER_CHAR (   v)
Value:
(Number) \
{ \
.number_type = NT_INT8, .value = v \
}
@ NT_INT8
Definition: number.h:19

Generates a Number struct with type INT8.

◆ NUMBER_FROM_TYPE_VAL

#define NUMBER_FROM_TYPE_VAL (   t,
 
)
Value:
(Number) \
{ \
.number_type = t, .value = v \
}

Generates a Number struct given a NumberType and a value.

◆ NUMBER_INT

#define NUMBER_INT (   v)
Value:
(Number) \
{ \
.number_type = NT_INT32, .value = v \
}
@ NT_INT32
Definition: number.h:21

Generates a Number struct with type INT32.

◆ NUMBER_LONG

#define NUMBER_LONG (   v)
Value:
(Number) \
{ \
.number_type = NT_INT64, .value = v \
}
@ NT_INT64
Definition: number.h:22

Generates a Number struct with type INT64.

◆ NUMBER_SHORT

#define NUMBER_SHORT (   v)
Value:
(Number) \
{ \
.number_type = NT_INT16, .value = v \
}
@ NT_INT16
Definition: number.h:20

Generates a Number struct with type INT16.

◆ NUMBERS_TYPEQUIV

#define NUMBERS_TYPEQUIV (   A,
 
)     (A.number_type == B.number_type && A.pointer_depth == B.pointer_depth)

Determines if two Number structs have equivalent types.

Typedef Documentation

◆ Number

typedef struct Number Number

Container for various kinds of number data.

Enumeration Type Documentation

◆ NumberType

enum NumberType

Types of numbers supported by Purple.

Enumerator
NT_INT1 
NT_INT8 
NT_INT16 
NT_INT32 
NT_INT64 

Function Documentation

◆ max_numbertype_for_val()

NumberType max_numbertype_for_val ( long long int  value)

Finds the maximum NumberType possible for a given value.

Parameters
valueValue to check
Returns
NumberType Corresponding NumberType, or -1 if none was found

◆ number_to_token_type()

int number_to_token_type ( Number  number)

◆ token_type_to_number_type()

NumberType token_type_to_number_type ( int  token_type)

Convert a TokenType to a NumberType.

Parameters
token_typeTokenType to convert
Returns
NumberType Converted TokenType

Variable Documentation

◆ numberTypeBitSizes

const int numberTypeBitSizes[] = {1, 8, 16, 32, 64}
static

Bit size of each NumberType.

◆ numberTypeByteSizes

const int numberTypeByteSizes[]
static
Initial value:
= {
1, 1, 2, 4, 8,
}

Size of each NumberType.

◆ numberTypeFormatStrings

const char* numberTypeFormatStrings[] = {"%d", "%d", "%d", "%d", "%ld"}
static

Format strings for each data type.

◆ numberTypeMaxValues

const unsigned long long int numberTypeMaxValues[]
static
Initial value:
= {1, CHAR_MAX, SHRT_MAX, INT_MAX,
LONG_MAX}

Max value of each NumberType.

◆ numberTypeNames

const char* numberTypeNames[] = {"bool", "char", "short", "int", "long"}
static

Names of each NumberType.