Scanner for scanning YCP syntax. More...
#include <Scanner.h>
Public Member Functions | |
Scanner (FILE *inputfile, const char *filename) | |
Scanner (const char *inputbuffer) | |
Scanner (int input_fd, const char *filename) | |
~Scanner () | |
void | setBuffered () |
void | initTables (SymbolTable *globalTable, SymbolTable *localTable) |
SymbolTable * | globalTable () const |
SymbolTable * | localTable () const |
int | yylex () |
int | LexerInput (char *buf, int max_size) |
void | LexerError (const char *msg) |
tokenValue | scannedValue () const |
constTypePtr | scannedType () const |
int | lineNumber () const |
string | filename () const |
void | logError (const char *loginfo, int lineno,...) __attribute__((format(printf |
void void | logWarning (const char *loginfo, int lineno,...) __attribute__((format(printf |
void void const std::list < std::pair< std::string, Y2Namespace * > > & | autoimport_predefined () const |
void | closeInput () |
virtual void | error (string error) |
virtual void | warning (string warning) |
Static Public Member Functions | |
static char * | doStrdup (const char *s) |
Private Member Functions | |
void | setScannedToken (const tokenValue &value, constTypePtr type) |
char * | extend_scanbuffer (int size) |
Private Attributes | |
string | m_filename |
const char * | m_inputBuffer |
FILE * | m_inputFile |
int | m_inputFd |
tokenValue | m_scannedValue |
constTypePtr | m_scannedType |
int | m_lineNumber |
char * | m_scandataBufferPtr |
char * | m_scandataBuffer |
int | m_scandataBufferSize |
bool | m_buffered |
SymbolTable * | m_globalTable |
SymbolTable * | m_localTable |
bool | m_owningGlobal |
bool | m_owningLocal |
std::list< std::pair < std::string, Y2Namespace * > > | m_autoimport_predefined |
Static Private Attributes | |
static const int | STRING_HUNK = 1024 |
Scanner for scanning YCP syntax.
Scanner::Scanner | ( | FILE * | inputfile, | |
const char * | filename | |||
) |
Creates a new scanner that scans from an open clib-level file descriptor that has been opened with fopen(filename, "r"). You have to close the file yourself afterwards.
inputfile | the open file | |
filename | If you have the name of the file in hand here, tell it, it makes nicer error messages. Give 0 otherwise. |
References m_scannedValue, StaticDeclaration::symbolTable(), tokenValue::val, and y2debug.
Scanner::Scanner | ( | const char * | inputbuffer | ) |
Creates a new scanner that scans from a zero terminated constant C string. Your buffer is left untouched. We don't make a copy of it, so ist must be valid all the time this class is used.
inputbuffer | Pointer to the string. |
References m_scannedValue, StaticDeclaration::symbolTable(), tokenValue::val, and y2debug.
Scanner::Scanner | ( | int | input_fd, | |
const char * | filename | |||
) |
Creates a new scanner that scans from an open unix lowlevel file descriptor. You have to close the descriptor yourself afterwards
input_fd | the file descriptor | |
filename | If you have the name of the file in hand here, tell it, it makes nicer error messages. Give 0 otherwise. |
References m_scannedValue, tokenValue::sval, StaticDeclaration::symbolTable(), and y2debug.
Scanner::~Scanner | ( | ) |
Cleans up
References m_globalTable, m_localTable, m_owningGlobal, m_owningLocal, and m_scandataBuffer.
void void const std::list<std::pair<std::string, Y2Namespace *> >& Scanner::autoimport_predefined | ( | ) | const [inline] |
get list of predefined namespaces which have been autoloaded by the scanner
References m_autoimport_predefined.
void Scanner::closeInput | ( | ) |
References m_inputFd, and m_inputFile.
char * Scanner::doStrdup | ( | const char * | s | ) | [static] |
strdup via new, so delete [] can be used safely
void Scanner::error | ( | string | error | ) | [virtual] |
Implements Logger.
References logError(), and m_lineNumber.
char * Scanner::extend_scanbuffer | ( | int | size | ) | [private] |
Internal helper function that deals with strings of arbitrary length
References m_scandataBuffer, m_scandataBufferSize, STRING_HUNK, and y2error.
string Scanner::filename | ( | void | ) | const |
Gets the currently scanned file
References m_filename.
Referenced by logError(), logWarning(), and parsefile().
SymbolTable * Scanner::globalTable | ( | ) | const |
return current globalTable. used by parser.
References m_globalTable.
void Scanner::initTables | ( | SymbolTable * | globalTable, | |
SymbolTable * | localTable | |||
) |
Initialize tables for global and local symbols.
If gTable and lTable are set, they're used instead of local ones. This is used for include files using the symbol tables of the including block. see: Parser::parse()
References m_globalTable, m_localTable, m_owningGlobal, m_owningLocal, and y2debug.
Referenced by Parser::parse().
void Scanner::LexerError | ( | const char * | msg | ) |
Is called by the flex lexer, if a scan error occurs. Calls logError.
References logError().
int Scanner::LexerInput | ( | char * | buf, | |
int | max_size | |||
) |
Overriden from yyFlexLexer. The flex scanner uses this function to get the next input characters. Our implementation always returns just one character. Too much lookahead would result in blocking and deadlock in a protocol situation. FIXME: when reading from file read max_size characters
buf | Buffer where the input is to be stored in | |
max_size | size of this buffer |
References m_buffered, m_inputBuffer, m_inputFd, m_inputFile, and y2internal.
int Scanner::lineNumber | ( | ) | const |
Gets the line number of the latest scanned token.
References m_lineNumber.
Referenced by parsefile().
SymbolTable * Scanner::localTable | ( | ) | const |
return current localTable. used by parser.
References m_localTable.
void Scanner::logError | ( | const char * | loginfo, | |
int | lineno, | |||
... | ||||
) |
Is called by LexerError. Is also called by yyerror for error reporting. It reports the error via y2log and also reports the filename, if available and the linenumber.
msg | the plain error message |
References filename(), m_filename, and syn2error.
Referenced by error(), and LexerError().
void Scanner::logWarning | ( | const char * | loginfo, | |
int | lineno, | |||
... | ||||
) |
constTypePtr Scanner::scannedType | ( | ) | const |
Gets the value of the latest scanned token. Returns 0, if that token does not represent a proper value.
References m_scannedType.
tokenValue Scanner::scannedValue | ( | ) | const |
Gets the value of the latest scanned token. Returns 0, if that token does not represent a proper value.
References m_scannedValue.
void Scanner::setBuffered | ( | ) |
Makes the scanner use buffering, i.e. read more than one character at once.
References m_buffered.
Referenced by Parser::setBuffered(), and Parser::setInput().
void Scanner::setScannedToken | ( | const tokenValue & | value, | |
constTypePtr | type | |||
) | [private] |
Used in the rules of the scanner to define the value of a token.
References m_scannedType, and m_scannedValue.
void Scanner::warning | ( | string | warning | ) | [virtual] |
Implements Logger.
References logWarning(), and m_lineNumber.
int Scanner::yylex | ( | ) |
Scans and returns the next token. Return 0, in case of EOF. The value of the scanned token is saved in scanned_value and can be retrieved with scannedValue. The implementation of this function is generated by flex++.
Referenced by parsefile().
std::list<std::pair<std::string, Y2Namespace *> > Scanner::m_autoimport_predefined [private] |
list of predefined namespace which have been auto-imported Y2Namespace is non-const since the block might get evaluated (constructor)
Referenced by autoimport_predefined().
bool Scanner::m_buffered [private] |
Is true, if the input can be buffered, i.e. more than one character may be read at once in order to gain performance.
Referenced by LexerInput(), and setBuffered().
string Scanner::m_filename [private] |
The name of the file being parsed. It is used for generating nice error messages only. It is the empty string, if no filename is available (e.g. while scanning from stdin).
Referenced by filename(), logError(), and logWarning().
SymbolTable* Scanner::m_globalTable [private] |
Referenced by globalTable(), initTables(), and ~Scanner().
const char* Scanner::m_inputBuffer [private] |
If the YCP text source is given in form of a string buffer, this buffer is stored here. 0 otherwise.
Referenced by LexerInput().
int Scanner::m_inputFd [private] |
If the YCP text source is given in form of a unix lowlevel file descriptor, this variable holds the descriptor. Must be -1 otherwise, since 0 is a valid file descriptor (stdin).
Referenced by closeInput(), and LexerInput().
FILE* Scanner::m_inputFile [private] |
If the YCP text source is given in form of an open clib-level file pointer, this variable hold it. Must be 0 otherwise.
Referenced by closeInput(), and LexerInput().
int Scanner::m_lineNumber [private] |
Holds the line number of scanned_value
Referenced by error(), lineNumber(), and warning().
SymbolTable* Scanner::m_localTable [private] |
Referenced by initTables(), localTable(), and ~Scanner().
bool Scanner::m_owningGlobal [private] |
This is a kludge rather than proper memory management. Klaus, who owns the tables in various cases?
Referenced by initTables(), and ~Scanner().
bool Scanner::m_owningLocal [private] |
Referenced by initTables(), and ~Scanner().
char* Scanner::m_scandataBuffer [private] |
Used for string constant scanning
Referenced by extend_scanbuffer(), and ~Scanner().
char* Scanner::m_scandataBufferPtr [private] |
Used for string constant scanning
int Scanner::m_scandataBufferSize [private] |
Used for string constant scanning
Referenced by extend_scanbuffer().
constTypePtr Scanner::m_scannedType [private] |
Holds the type of the value being scanned lastly.
Referenced by scannedType(), and setScannedToken().
tokenValue Scanner::m_scannedValue [private] |
Holds the value being scanned lastly.
Referenced by scannedValue(), Scanner(), and setScannedToken().
const int Scanner::STRING_HUNK = 1024 [static, private] |
Allocate this many bytes for a string. If a larger string is encountered, the buffer size is at least doubled. I don't believe, that the value of STRING_HUNK has a great impact on speed. 1024 is probably a nice value for it.
Referenced by extend_scanbuffer().