Skip to content

FileTokenizer

INCLUDE FILE
#include "FileTokenizer.h"

class FileTokenizer

This class gets tokens from a file.

DEFINITION
class FileTokenizer;

class MatcherNodeprivate

DEFINITION
class MatcherNode;

method add

DEFINITION
void  add ( const char * string,
Token::Type  type,
const std::unordered_set< char > & suffix_characters = {},
bool  match_in_word = false );
PARAMETERDESCRIPTION
string
type
suffix_characters
match_in_word

method conflictsconst private

DEFINITION
bool  conflicts ( const std::unordered_set< char > & new_suffix ) const;
PARAMETERDESCRIPTION
new_suffix
RETURNSDESCRIPTION
bool

method match

DEFINITION
std::optional< Token::Type >  match ( FileSource & source,
std::string & name );
PARAMETERDESCRIPTION
source
name
RETURNSDESCRIPTION
std::optional< Token::Type >

member match_in_word

DEFINITION
bool  match_in_word;

member match_type

DEFINITION
std::optional< Token::Type >  match_type;

member next

DEFINITION
std::unordered_map< char, std::unique_ptr< MatcherNode > >  next;

member suffix_characters

DEFINITION
std::unordered_set< char >  suffix_characters;

class PreStateprivate

DEFINITION
class PreState;

constructor PreState

DEFINITION
PreState ( bool  condition );
PARAMETERDESCRIPTION
condition

method operator boolconst

DEFINITION
operator bool ( ) const;

method process_else

DEFINITION
void  process_else ( );

method process_else_if

DEFINITION
void  process_else_if ( bool  condition );
PARAMETERDESCRIPTION
condition

method skipping_restconst

DEFINITION
bool  skipping_rest ( ) const;
RETURNSDESCRIPTION
bool

member else_seenprivate

DEFINITION
bool  else_seen;

member processingprivate

DEFINITION
bool  processing;

member skip_restprivate

DEFINITION
bool  skip_rest;

class PreprocessorDirectiveprivate

DEFINITION
class PreprocessorDirective;

constructor PreprocessorDirective

DEFINITION
PreprocessorDirective ( std::optional< size_t >  min_arguments,
std::optional< size_t >  max_arguments,
std::vector< TokenGroup >  argument_type,
void(FileTokenizer::*)(const Token &, const std::vector< Token > &)  handler );
PARAMETERDESCRIPTION
min_arguments
max_arguments
argument_type
handler

method operator()const

DEFINITION
void  operator() ( FileTokenizer & tokenizer,
const Token & directive,
const std::vector< Token > & arguments ) const;
PARAMETERDESCRIPTION
tokenizer
directive
arguments

member argument_typeprivate

DEFINITION
std::vector< TokenGroup >  argument_type;

member handlerprivate

DEFINITION
void(FileTokenizer::* handler;

member max_argumentsprivate

DEFINITION
std::optional< size_t >  max_arguments;

member min_argumentsprivate

DEFINITION
std::optional< size_t >  min_arguments;

class Sourceprivate

DEFINITION
class Source;

constructor Source

DEFINITION
Source ( Symbol  filename );
PARAMETERDESCRIPTION
filename

member pre_states

DEFINITION
std::vector< PreState >  pre_states;

constructor FileTokenizer

DEFINITION
FileTokenizer ( const SearchPath & search_path = SearchPath::empty_path,
const Target * target = {},
bool  use_preprocessor = true,
const std::unordered_set< Symbol > & defines = {} );
PARAMETERDESCRIPTION
search_path
target
use_preprocessor
defines

method add_literal

DEFINITION
void  add_literal ( Token::Type  match,
const std::string & name,
const std::string & suffix_characters = "" );
PARAMETERDESCRIPTION
match
name
suffix_characters

method add_literal

DEFINITION
void  add_literal ( const Token & token );
PARAMETERDESCRIPTION
token

method add_punctuations

DEFINITION
void  add_punctuations ( const std::unordered_set< std::string > & names );
PARAMETERDESCRIPTION
names

method convert_digitstatic private

DEFINITION
static int  convert_digit ( int  c );
PARAMETERDESCRIPTION
c
RETURNSDESCRIPTION
int

method current_fileconst

DEFINITION
Symbol  current_file ( ) const;
RETURNSDESCRIPTION
Symbol

method current_locationconst virtual

DEFINITION
virtual Location  current_location ( ) const;
RETURNSDESCRIPTION
Location

method define

DEFINITION
void  define ( const std::unordered_set< Symbol > & defines );
PARAMETERDESCRIPTION
defines

method define

DEFINITION
void  define ( Symbol  name );
PARAMETERDESCRIPTION
name

method find_file

DEFINITION
Symbol  find_file ( Symbol  file_name );
PARAMETERDESCRIPTION
file_name
RETURNSDESCRIPTION
Symbol

method get_definesconst

DEFINITION
const std::unordered_set< Symbol > & get_defines ( ) const;
RETURNSDESCRIPTION
const std::unordered_set< Symbol > &

method is_identifierstatic private

DEFINITION
static bool  is_identifier ( const std::string & s );
PARAMETERDESCRIPTION
s
RETURNSDESCRIPTION
bool

method is_identifier_continuationstatic private

DEFINITION
static bool  is_identifier_continuation ( int  c );
PARAMETERDESCRIPTION
c
RETURNSDESCRIPTION
bool

method is_identifier_startstatic private

DEFINITION
static bool  is_identifier_start ( int  c );
PARAMETERDESCRIPTION
c
RETURNSDESCRIPTION
bool

method next_rawprivate

DEFINITION
Token  next_raw ( );
RETURNSDESCRIPTION
Token

method parse_charprivate

DEFINITION
Token  parse_char ( Location  location );
PARAMETERDESCRIPTION
location
RETURNSDESCRIPTION
Token

method parse_hexprivate

DEFINITION
Token  parse_hex ( Location  location );
PARAMETERDESCRIPTION
location
RETURNSDESCRIPTION
Token

method parse_nameprivate

DEFINITION
Token  parse_name ( Token::Type  type,
Location  location );
PARAMETERDESCRIPTION
type
location
RETURNSDESCRIPTION
Token

method parse_numberprivate

DEFINITION
Token  parse_number ( unsigned int  base,
Location  location );
PARAMETERDESCRIPTION
base
location
RETURNSDESCRIPTION
Token

method parse_stringprivate

DEFINITION
Token  parse_string ( Location  location );
PARAMETERDESCRIPTION
location
RETURNSDESCRIPTION
Token

method parse_string_literalprivate

DEFINITION
std::string  parse_string_literal ( Location  location,
int  terminator );
PARAMETERDESCRIPTION
location
terminator
RETURNSDESCRIPTION
std::string

method pre_is_processingconst private

DEFINITION
bool  pre_is_processing ( ) const;
RETURNSDESCRIPTION
bool

method preprocessprivate

DEFINITION
void  preprocess ( const Token & directive,
const std::vector< Token > & tokens );
PARAMETERDESCRIPTION
directive
tokens

method preprocess_defineprivate

DEFINITION
void  preprocess_define ( const Token & directive,
const std::vector< Token > & tokens );
PARAMETERDESCRIPTION
directive
tokens

method preprocess_includeprivate

DEFINITION
void  preprocess_include ( const Token & directive,
const std::vector< Token > & tokens );
PARAMETERDESCRIPTION
directive
tokens

method preprocess_pre_elseprivate

DEFINITION
void  preprocess_pre_else ( const Token & directive,
const std::vector< Token > & tokens );
PARAMETERDESCRIPTION
directive
tokens

method preprocess_pre_endprivate

DEFINITION
void  preprocess_pre_end ( const Token & directive,
const std::vector< Token > & tokens );
PARAMETERDESCRIPTION
directive
tokens

method preprocess_pre_ifprivate

DEFINITION
void  preprocess_pre_if ( const Token & directive,
const std::vector< Token > & tokens );
PARAMETERDESCRIPTION
directive
tokens

method push

DEFINITION
void  push ( Symbol  filename );
PARAMETERDESCRIPTION
filename

method set_target

DEFINITION
void  set_target ( const Target * new_target );
PARAMETERDESCRIPTION
new_target

method sub_endedconst virtual protected

DEFINITION
virtual bool  sub_ended ( ) const;
RETURNSDESCRIPTION
bool

method sub_nextvirtual protected

DEFINITION
virtual Token  sub_next ( );
RETURNSDESCRIPTION
Token

method undefine

DEFINITION
void  undefine ( Symbol  name );
PARAMETERDESCRIPTION
name

member current_sourceprivate

DEFINITION
Source * current_source;

member eof_locationprivate

DEFINITION
Location  eof_location;

member last_was_newlineprivate

DEFINITION
bool  last_was_newline;

member matcherprivate

DEFINITION
MatcherNode  matcher;

member preprocessor_directivesstatic private

DEFINITION
static const std::unordered_map< Token, PreprocessorDirective >  preprocessor_directives;

member preprocessor_scopeprivate

DEFINITION
std::shared_ptr< Scope >  preprocessor_scope;

member search_pathprivate

DEFINITION
const SearchPath & search_path;

member sourcesprivate

DEFINITION
std::vector< Source >  sources;

member targetprivate

DEFINITION
const Target * target;

member token_definestatic private

DEFINITION
static const Token  token_define;

member token_includestatic private

DEFINITION
static const Token  token_include;

member token_pre_elsestatic private

DEFINITION
static const Token  token_pre_else;

member token_pre_else_ifstatic private

DEFINITION
static const Token  token_pre_else_if;

member token_pre_endstatic private

DEFINITION
static const Token  token_pre_end;

member token_pre_ifstatic private

DEFINITION
static const Token  token_pre_if;

member token_undefinestatic private

DEFINITION
static const Token  token_undefine;

member use_preprocessorprivate

DEFINITION
bool  use_preprocessor;

class MatcherNodeprivate

DEFINITION
class MatcherNode;

method add

DEFINITION
void  add ( const char * string,
Token::Type  type,
const std::unordered_set< char > & suffix_characters = {},
bool  match_in_word = false );
PARAMETERDESCRIPTION
string
type
suffix_characters
match_in_word

method conflictsconst private

DEFINITION
bool  conflicts ( const std::unordered_set< char > & new_suffix ) const;
PARAMETERDESCRIPTION
new_suffix
RETURNSDESCRIPTION
bool

method match

DEFINITION
std::optional< Token::Type >  match ( FileSource & source,
std::string & name );
PARAMETERDESCRIPTION
source
name
RETURNSDESCRIPTION
std::optional< Token::Type >

member match_in_word

DEFINITION
bool  match_in_word;

member match_type

DEFINITION
std::optional< Token::Type >  match_type;

member next

DEFINITION
std::unordered_map< char, std::unique_ptr< MatcherNode > >  next;

member suffix_characters

DEFINITION
std::unordered_set< char >  suffix_characters;

class PreStateprivate

DEFINITION
class PreState;

constructor PreState

DEFINITION
PreState ( bool  condition );
PARAMETERDESCRIPTION
condition

method operator boolconst

DEFINITION
operator bool ( ) const;

method process_else

DEFINITION
void  process_else ( );

method process_else_if

DEFINITION
void  process_else_if ( bool  condition );
PARAMETERDESCRIPTION
condition

method skipping_restconst

DEFINITION
bool  skipping_rest ( ) const;
RETURNSDESCRIPTION
bool

member else_seenprivate

DEFINITION
bool  else_seen;

member processingprivate

DEFINITION
bool  processing;

member skip_restprivate

DEFINITION
bool  skip_rest;

class PreprocessorDirectiveprivate

DEFINITION
class PreprocessorDirective;

constructor PreprocessorDirective

DEFINITION
PreprocessorDirective ( std::optional< size_t >  min_arguments,
std::optional< size_t >  max_arguments,
std::vector< TokenGroup >  argument_type,
void(FileTokenizer::*)(const Token &, const std::vector< Token > &)  handler );
PARAMETERDESCRIPTION
min_arguments
max_arguments
argument_type
handler

method operator()const

DEFINITION
void  operator() ( FileTokenizer & tokenizer,
const Token & directive,
const std::vector< Token > & arguments ) const;
PARAMETERDESCRIPTION
tokenizer
directive
arguments

member argument_typeprivate

DEFINITION
std::vector< TokenGroup >  argument_type;

member handlerprivate

DEFINITION
void(FileTokenizer::* handler;

member max_argumentsprivate

DEFINITION
std::optional< size_t >  max_arguments;

member min_argumentsprivate

DEFINITION
std::optional< size_t >  min_arguments;

class Sourceprivate

DEFINITION
class Source;

constructor Source

DEFINITION
Source ( Symbol  filename );
PARAMETERDESCRIPTION
filename

member pre_states

DEFINITION
std::vector< PreState >  pre_states;