Pol  Revision:cb584c9
Pol::Bscript::Compiler Class Reference

#include <compiler.h>

+ Inheritance diagram for Pol::Bscript::Compiler:

Public Member Functions

 Compiler ()
 ~Compiler ()
int _getStatement (CompilerContext &ctx, int level)
void addModule (FunctionalityModule *module)
void addToken (Token &tok)
int compile (CompilerContext &ctx)
int compileContext (CompilerContext &ctx)
int compileFile (const char *fname)
void dump (std::ostream &os)
int eatToken (CompilerContext &ctx, BTokenId tokenid)
int emit_function (UserFunction &uf)
int emit_functions ()
void emitFileLine (CompilerContext &ctx)
void emitFileLineIfFileChanged (CompilerContext &ctx)
int forward_read_function (CompilerContext &ctx)
virtual int getArrayElements (Expression &expr, CompilerContext &ctx) POL_OVERRIDE
virtual int getDictionaryMembers (Expression &expr, CompilerContext &ctx) POL_OVERRIDE
int getExpr (CompilerContext &ctx, unsigned expr_flags, size_t *exprlen=NULL, Expression *ex=NULL)
int getExpr2 (CompilerContext &ctx, unsigned expr_flags, Expression *ex=NULL)
int getExprInParens (CompilerContext &ctx, Expression *ex=NULL)
int getFileContents (const char *filename, char **contents)
virtual int getFunctionPArgument (Expression &expr, CompilerContext &ctx, Token *tok) POL_OVERRIDE
virtual int getMethodArguments (Expression &expr, CompilerContext &ctx, int &nargs) POL_OVERRIDE
virtual int getNewArrayElements (Expression &expr, CompilerContext &ctx) POL_OVERRIDE
int getSimpleExpr (CompilerContext &ctx)
int getStatement (CompilerContext &ctx, int level)
virtual int getStructMembers (Expression &expr, CompilerContext &ctx) POL_OVERRIDE
virtual int getUserArgs (Expression &ex, CompilerContext &ctx, bool inject_jsr) POL_OVERRIDE
int handleBlock (CompilerContext &ctx, int level)
int handleBracketedFor_basic (CompilerContext &ctx)
int handleBracketedFor_c (CompilerContext &ctx)
int handleBracketedFunction (CompilerContext &ctx)
int handleBracketedFunction2 (CompilerContext &ctx, int level, int tokentype)
int handleBracketedFunction3 (UserFunction &userfunc, CompilerContext &ctx)
int handleBracketedIf (CompilerContext &ctx, int level)
int handleBracketedWhile (CompilerContext &ctx, int level)
int handleBreak (CompilerContext &ctx)
int handleConstDeclare (CompilerContext &ctx)
int handleContinue (CompilerContext &ctx)
int handleDeclare (CompilerContext &ctx)
int handleDoClause (CompilerContext &ctx, int level)
int handleEnumDeclare (CompilerContext &ctx)
int handleExit (CompilerContext &ctx)
int handleFor (CompilerContext &ctx)
int handleFor_basic (CompilerContext &ctx)
int handleFor_c (CompilerContext &ctx)
int handleForEach (CompilerContext &ctx, int level)
int handleForEach (CompilerContext &ctx)
int handleFunction (CompilerContext &ctx)
int handleGotoGosub (CompilerContext &ctx, unsigned save_id)
int handleIf (CompilerContext &ctx, int level)
int handleInclude (CompilerContext &ctx)
int handleProgram (CompilerContext &ctx, int level)
int handleProgram2 (CompilerContext &ctx, int level)
int handleRepeatUntil (CompilerContext &ctx, int level)
int handleReturn (CompilerContext &ctx)
int handleSwitch (CompilerContext &ctx, int level)
int handleUse (CompilerContext &ctx)
int handleVarDeclare (CompilerContext &ctx, unsigned save_id)
int handleWhile (CompilerContext &ctx, int level)
int includeModule (const std::string &modulename)
bool inner_read_function_declarations (const CompilerContext &ctx)
virtual int isFunc (Token &tok, ModuleFunction **v) POL_OVERRIDE
virtual int isLegal (Token &tok) POL_OVERRIDE
virtual int isUserFunc (Token &tok, UserFunction **userfunc) POL_OVERRIDE
void patch_callers (UserFunction &uf)
void patchoffset (unsigned instruc, unsigned newoffset)
bool read_function_declarations (const CompilerContext &ctx)
bool read_function_declarations_in_included_file (const char *modulename)
void readCurLine (CompilerContext &ctx)
int readFunctionDeclaration (CompilerContext &ctx, UserFunction &userfunc)
void savesourceline ()
void setIncludeCompileMode ()
int useModule (const char *modulename)
int write (const char *fname)
int write_dbg (const char *fname, bool generate_txtfile)
void writeIncludedFilenames (const char *fname) const
- Public Member Functions inherited from Pol::Bscript::SmartParser
 SmartParser ()
virtual ~SmartParser ()
bool callingMethod (CompilerContext &ctx)
int getArgs (Expression &expr, CompilerContext &ctx)
virtual int getToken (CompilerContext &ctx, Token &token, Expression *expr=NULL) POL_OVERRIDE
int IIP (Expression &expr, CompilerContext &ctx, unsigned expr_flags)
int IP (Expression &expr, char *s)
int IP (Expression &expr, CompilerContext &ctx)
virtual int isOkay (const Token &token, BTokenType last_type)
SmartParseroperator= (const SmartParser &)
virtual int parseToken (CompilerContext &ctx, Expression &expr, Token *) POL_OVERRIDE
- Public Member Functions inherited from Pol::Bscript::Parser
 Parser ()
virtual ~Parser ()
int IP (Expression &expr, char *s)
Parseroperator= (const Parser &)
virtual int peekToken (const CompilerContext &ctx, Token &token, Expression *expr=NULL)
virtual int recognize (Token &tok, const char *buf, const char **s)
virtual int recognize_binary (Token &tok, const char *buf, const char **s)
virtual bool recognize_reserved_word (Token &tok, const char *buf)
virtual int recognize_unary (Token &tok, const char *buf)
void reinit (Expression &ex)
void setQuiet (int x)
virtual int tryBinaryOperator (Token &tok, CompilerContext &ctx)
virtual int tryNumeric (Token &tok, CompilerContext &ctx)
virtual int tryOperator (Token &tok, const char *buf, const char **s, Operator *opList, int n_ops, char *opbuf)
virtual int tryUnaryOperator (Token &tok, CompilerContext &ctx)

Static Public Member Functions

static void setCheckFileCase (bool check)
static void setVerbosityLevel (int vlev)
- Static Public Member Functions inherited from Pol::Bscript::Parser
static void write_words (std::ostream &os)

Static Public Attributes

static bool check_filecase_
static int verbosity_level_

Private Types

typedef std::map< std::string, TokenConstants
typedef std::set< std::string, Clib::ci_cmp_predINCLUDES
typedef std::map< std::string, UserFunction, Clib::ci_cmp_predUserFunctions

Private Member Functions

void convert_variables (Expression &expr) const
void emit_leaveblock ()
void enterblock (eb_label_ok eblabel, eb_break_ok ebbreak, eb_continue_ok ebcontinue)
void enterblock (eb_label_ok et)
int enterLabel (Token &tok)
int findLabel (Token &tok, unsigned &posn)
bool globalexists (const std::string &varname, unsigned &idx, CompilerContext *atctx=NULL) const
bool inGlobalScope () const
void inject (Expression &expr)
int insertBreak (const std::string &label)
void leaveblock (unsigned breakPC, unsigned continuePC)
void patchblock_breaks (unsigned breakPC)
void patchblock_continues (unsigned continuePC)
int readblock (CompilerContext &ctx, int level, BTokenId endtokenid, BTokenId *last_statement_id=NULL, Token *block_end=NULL)
int readexpr (Expression &expr, CompilerContext &ctx, unsigned flags)
void rollback (EScriptProgram &prog, const EScriptProgramCheckpoint &checkpoint)
bool substitute_constant (Token *tkn) const
void substitute_constants (Expression &expr) const
int validate (const Expression &expr, CompilerContext &ctx) const
bool varexists (const std::string &varname) const

Private Attributes

bool compiling_include
Constants constants
char curLine [80]
std::string current_file_path
int curSourceFile
std::vector< char * > delete_these_arrays
Variables globals_
bool haveProgram
INCLUDES included
int inExpr
int inFunction
std::string latest_label
Scope localscope
unsigned nProgramArgs
ref_ptr< EScriptProgramprogram
CompilerContext program_ctx
char * program_source
unsigned programPos
std::vector< std::string > referencedPathnames
UserFunctions userFunctions

Additional Inherited Members

- Public Attributes inherited from Pol::Bscript::Parser
char buffer [51]
bool contains_tabs
ParseError err
char ext_err [50]
int quiet
- Protected Member Functions inherited from Pol::Bscript::SmartParser
virtual int tryLiteral (Token &tok, CompilerContext &ctx) POL_OVERRIDE
- Protected Attributes inherited from Pol::Bscript::SmartParser
class ModuleFunctionmodfunc_

Detailed Description

Definition at line 120 of file compiler.h.

Member Typedef Documentation

typedef std::map<std::string, Token> Pol::Bscript::Compiler::Constants

Definition at line 157 of file compiler.h.

typedef std::set<std::string, Clib::ci_cmp_pred> Pol::Bscript::Compiler::INCLUDES

Definition at line 145 of file compiler.h.

typedef std::map<std::string, UserFunction, Clib::ci_cmp_pred> Pol::Bscript::Compiler::UserFunctions

Definition at line 151 of file compiler.h.

Constructor & Destructor Documentation

Pol::Bscript::Compiler::Compiler ( )
Pol::Bscript::Compiler::~Compiler ( )

Definition at line 861 of file compiler.cpp.

References delete_these_arrays.

Member Function Documentation

int Pol::Bscript::Compiler::_getStatement ( CompilerContext ctx,
int  level 

Definition at line 3987 of file compiler.cpp.

References Pol::Bscript::StoredTokenContainer::atGet1(), Pol::Bscript::compilercfg, Pol::Bscript::StoredTokenContainer::count(), Pol::Bscript::CTRL_JSR_USERFUNC, Pol::Bscript::CTRL_STATEMENTBEGIN, curLine, curSourceFile, Pol::Bscript::Token::deprecated, Pol::Bscript::CompilerConfig::DisplayWarnings, emitFileLineIfFileChanged(), Pol::Bscript::CompilerConfig::ErrorOnWarning, Pol::Bscript::EXPR_FLAG_CONSUME_RESULT, Pol::Bscript::EXPR_FLAG_SEMICOLON_TERM_ALLOWED, Pol::Bscript::CompilerContext::filename, getExpr(), Pol::Bscript::SmartParser::getToken(), handleBracketedFunction2(), handleBracketedIf(), handleBracketedWhile(), handleBreak(), handleConstDeclare(), handleContinue(), handleDeclare(), handleDoClause(), handleEnumDeclare(), handleExit(), handleFor(), handleForEach(), handleInclude(), handleProgram(), handleRepeatUntil(), handleReturn(), handleSwitch(), handleUse(), handleVarDeclare(), Pol::Bscript::StoredToken::id, Pol::Bscript::Token::id, INFO_PRINT, inGlobalScope(), Pol::Bscript::INS_ASSIGN_CONSUME, Pol::Bscript::INS_ASSIGN_GLOBALVAR, Pol::Bscript::INS_ASSIGN_LOCALVAR, Pol::Bscript::INS_CALL_METHOD, Pol::Bscript::INS_CALL_METHOD_ID, Pol::Bscript::INS_MULTISUBSCRIPT_ASSIGN, Pol::Bscript::INS_SET_MEMBER, Pol::Bscript::INS_SET_MEMBER_CONSUME, Pol::Bscript::INS_SET_MEMBER_ID, Pol::Bscript::INS_SET_MEMBER_ID_CONSUME, Pol::Bscript::INS_SET_MEMBER_ID_CONSUME_DIVIDEEQUAL, Pol::Bscript::INS_SET_MEMBER_ID_CONSUME_MINUSEQUAL, Pol::Bscript::INS_SET_MEMBER_ID_CONSUME_MODULUSEQUAL, Pol::Bscript::INS_SET_MEMBER_ID_CONSUME_PLUSEQUAL, Pol::Bscript::INS_SET_MEMBER_ID_CONSUME_TIMESEQUAL, Pol::Bscript::INS_SUBSCRIPT_ASSIGN, Pol::Bscript::INS_SUBSCRIPT_ASSIGN_CONSUME, latest_label, Pol::Bscript::CompilerContext::line, Pol::Bscript::Mod_Basic, Pol::Bscript::DebugToken::offset, Pol::Bscript::Parser::peekToken(), program, Pol::Bscript::Parser::quiet, readCurLine(), Pol::Bscript::RSV_BREAK, Pol::Bscript::RSV_CONST, Pol::Bscript::RSV_CONTINUE, Pol::Bscript::RSV_DECLARE, Pol::Bscript::RSV_DO, Pol::Bscript::RSV_ENUM, Pol::Bscript::RSV_EXIT, Pol::Bscript::RSV_EXPORTED, Pol::Bscript::RSV_FOR, Pol::Bscript::RSV_FOREACH, Pol::Bscript::RSV_FUNCTION, Pol::Bscript::RSV_GLOBAL, Pol::Bscript::RSV_INCLUDE_FILE, Pol::Bscript::RSV_LOCAL, Pol::Bscript::RSV_OPTION_BRACKETED, Pol::Bscript::RSV_PROGRAM, Pol::Bscript::RSV_REPEAT, Pol::Bscript::RSV_RETURN, Pol::Bscript::RSV_ST_IF, Pol::Bscript::RSV_SWITCH, Pol::Bscript::RSV_USE_MODULE, Pol::Bscript::RSV_VAR, Pol::Bscript::RSV_WHILE, Pol::Bscript::CompilerContext::s, Pol::Bscript::CompilerContext::s_begin, savesourceline(), Pol::Bscript::DebugToken::sourceFile, Pol::Bscript::DebugToken::strOffset, Pol::Bscript::TOK_ADDMEMBER, Pol::Bscript::TOK_ASSIGN, Pol::Bscript::TOK_CONSUMER, Pol::Bscript::TOK_DELMEMBER, Pol::Bscript::TOK_DIVIDEEQUAL, Pol::Bscript::TOK_EQUAL1, Pol::Bscript::TOK_FUNC, Pol::Bscript::TOK_MINUSEQUAL, Pol::Bscript::TOK_MODULUSEQUAL, Pol::Bscript::TOK_PLUSEQUAL, Pol::Bscript::TOK_TIMESEQUAL, Pol::Bscript::TOK_USERFUNC, Pol::Bscript::Token::tokval(), Pol::Bscript::TYP_CONTROL, Pol::Bscript::TYP_LABEL, Pol::Bscript::TYP_RESERVED, and Pol::Bscript::Token::type.

Referenced by getStatement().

void Pol::Bscript::Compiler::addModule ( FunctionalityModule module)

Definition at line 989 of file compiler.cpp.

References Pol::Bscript::FunctionalityModule::fillFunctionsByName(), and program.

Referenced by useModule().

void Pol::Bscript::Compiler::addToken ( Token tok)

Definition at line 1615 of file compiler.cpp.

References program.

Referenced by inject().

int Pol::Bscript::Compiler::compileFile ( const char *  in_file)

Here starts the real complation. Reads the given file and process it

in_filePath for the file to compile, no more validity checks are done
<0 on error

Definition at line 5369 of file compiler.cpp.

References compile(), current_file_path, emit_functions(), Pol::Clib::FullPath(), Pol::Bscript::getpathof(), INFO_PRINT, Pol::Bscript::is_web_script(), Pol::Bscript::preprocess_web_script(), program, read_function_declarations(), referencedPathnames, and verbosity_level_.

Referenced by Pol::ECompile::compile_file(), and Pol::ECompile::compile_inc().

void Pol::Bscript::Compiler::convert_variables ( Expression expr) const
void Pol::Bscript::Compiler::dump ( std::ostream &  os)

Definition at line 5445 of file compiler.cpp.

References program.

Referenced by Pol::ECompile::compile_file().

int Pol::Bscript::Compiler::eatToken ( CompilerContext ctx,
BTokenId  tokenid 
int Pol::Bscript::Compiler::emit_function ( UserFunction uf)
void Pol::Bscript::Compiler::emit_leaveblock ( )
void Pol::Bscript::Compiler::emitFileLineIfFileChanged ( CompilerContext ctx)

Definition at line 3969 of file compiler.cpp.

References emitFileLine(), Pol::Bscript::CompilerContext::filename, and program.

Referenced by _getStatement().

void Pol::Bscript::Compiler::enterblock ( eb_label_ok  et)
int Pol::Bscript::Compiler::enterLabel ( Token tok)
int Pol::Bscript::Compiler::findLabel ( Token tok,
unsigned &  posn 
int Pol::Bscript::Compiler::getExpr ( CompilerContext ctx,
unsigned  expr_flags,
size_t *  exprlen = NULL,
Expression ex = NULL 
int Pol::Bscript::Compiler::getExpr2 ( CompilerContext ctx,
unsigned  expr_flags,
Expression ex = NULL 

Definition at line 1787 of file compiler.cpp.

References getExpr(), and inExpr.

Referenced by getExprInParens(), getSimpleExpr(), handleBracketedFor_basic(), and handleReturn().

int Pol::Bscript::Compiler::getFileContents ( const char *  filename,
char **  contents 
int Pol::Bscript::Compiler::getFunctionPArgument ( Expression expr,
CompilerContext ctx,
Token tok 
bool Pol::Bscript::Compiler::globalexists ( const std::string &  varname,
unsigned &  idx,
CompilerContext atctx = NULL 
) const

Definition at line 872 of file compiler.cpp.

References globals_, name, and Pol::Clib::stringicmp().

Referenced by convert_variables(), handleVarDeclare(), and varexists().

int Pol::Bscript::Compiler::handleFor ( CompilerContext ctx)
int Pol::Bscript::Compiler::handleFor_basic ( CompilerContext ctx)
int Pol::Bscript::Compiler::handleForEach ( CompilerContext ctx)
int Pol::Bscript::Compiler::handleGotoGosub ( CompilerContext ctx,
unsigned  save_id 
int Pol::Bscript::Compiler::handleWhile ( CompilerContext ctx,
int  level 
bool Pol::Bscript::Compiler::inGlobalScope ( ) const

Definition at line 177 of file compiler.h.

References Pol::Bscript::Scope::inblock().

Referenced by _getStatement(), and handleVarDeclare().

void Pol::Bscript::Compiler::inject ( Expression expr)

Definition at line 1757 of file compiler.cpp.

References addToken(), and Pol::Bscript::Expression::tokens.

Referenced by getExpr(), handleBracketedFor_c(), and handleFor_c().

int Pol::Bscript::Compiler::isLegal ( Token tok)
void Pol::Bscript::Compiler::leaveblock ( unsigned  breakPC,
unsigned  continuePC 
void Pol::Bscript::Compiler::patch_callers ( UserFunction uf)
void Pol::Bscript::Compiler::patchblock_breaks ( unsigned  breakPC)
void Pol::Bscript::Compiler::patchblock_continues ( unsigned  continuePC)
void Pol::Bscript::Compiler::patchoffset ( unsigned  instruc,
unsigned  newoffset 
bool Pol::Bscript::Compiler::read_function_declarations ( const CompilerContext ctx)

Definition at line 5187 of file compiler.cpp.

References constants, included, inner_read_function_declarations(), and program.

Referenced by compileFile().

void Pol::Bscript::Compiler::savesourceline ( )

Definition at line 3981 of file compiler.cpp.

References curLine, and program.

Referenced by _getStatement(), and handleBracketedIf().

static void Pol::Bscript::Compiler::setCheckFileCase ( bool  check)

Definition at line 125 of file compiler.h.

void Pol::Bscript::Compiler::setIncludeCompileMode ( )

Definition at line 209 of file compiler.h.

References POL_OVERRIDE.

Referenced by Pol::ECompile::compile_inc().

static void Pol::Bscript::Compiler::setVerbosityLevel ( int  vlev)

Definition at line 126 of file compiler.h.

Referenced by Pol::ECompile::readargs().

bool Pol::Bscript::Compiler::substitute_constant ( Token tkn) const
void Pol::Bscript::Compiler::substitute_constants ( Expression expr) const

Definition at line 1721 of file compiler.cpp.

References substitute_constant(), Pol::Bscript::TOK_IDENT, and Pol::Bscript::Expression::tokens.

Referenced by readexpr().

bool Pol::Bscript::Compiler::varexists ( const std::string &  varname) const

Definition at line 887 of file compiler.cpp.

References globalexists(), localscope, and Pol::Bscript::Scope::varexists().

Referenced by validate().

int Pol::Bscript::Compiler::write ( const char *  fname)

Definition at line 5425 of file compiler.cpp.

References program.

Referenced by Pol::ECompile::compile_file().

int Pol::Bscript::Compiler::write_dbg ( const char *  fname,
bool  generate_txtfile 

Definition at line 5430 of file compiler.cpp.

References program.

Referenced by Pol::ECompile::compile_file().

void Pol::Bscript::Compiler::writeIncludedFilenames ( const char *  fname) const

Definition at line 5435 of file compiler.cpp.

References referencedPathnames.

Referenced by Pol::ECompile::compile_file().

Member Data Documentation

bool Pol::Bscript::Compiler::check_filecase_

Definition at line 123 of file compiler.h.

bool Pol::Bscript::Compiler::compiling_include

Definition at line 138 of file compiler.h.

Referenced by emit_functions().

Constants Pol::Bscript::Compiler::constants
char Pol::Bscript::Compiler::curLine[80]

Part of the content of the line being read, only for info/debug output, limited to 80 chars

Definition at line 134 of file compiler.h.

Referenced by _getStatement(), compileContext(), forward_read_function(), handleDeclare(), handleProgram(), handleSwitch(), isLegal(), readCurLine(), readFunctionDeclaration(), and savesourceline().

std::string Pol::Bscript::Compiler::current_file_path
int Pol::Bscript::Compiler::curSourceFile

Definition at line 132 of file compiler.h.

Referenced by _getStatement(), and compile().

std::vector<char*> Pol::Bscript::Compiler::delete_these_arrays

Definition at line 304 of file compiler.h.

Referenced by forward_read_function(), handleProgram(), and ~Compiler().

Variables Pol::Bscript::Compiler::globals_

Definition at line 168 of file compiler.h.

Referenced by globalexists(), and handleVarDeclare().

bool Pol::Bscript::Compiler::haveProgram

Definition at line 137 of file compiler.h.

Referenced by compile(), and handleProgram().

INCLUDES Pol::Bscript::Compiler::included
int Pol::Bscript::Compiler::inExpr

Definition at line 135 of file compiler.h.

Referenced by getExpr2(), and isLegal().

int Pol::Bscript::Compiler::inFunction
std::string Pol::Bscript::Compiler::latest_label

Definition at line 185 of file compiler.h.

Referenced by _getStatement().

unsigned Pol::Bscript::Compiler::nProgramArgs

Definition at line 140 of file compiler.h.

Referenced by handleProgram2().

CompilerContext Pol::Bscript::Compiler::program_ctx

Definition at line 142 of file compiler.h.

Referenced by compile(), and handleProgram().

char* Pol::Bscript::Compiler::program_source

Definition at line 143 of file compiler.h.

Referenced by handleProgram().

unsigned Pol::Bscript::Compiler::programPos

Definition at line 139 of file compiler.h.

std::vector<std::string> Pol::Bscript::Compiler::referencedPathnames

Definition at line 148 of file compiler.h.

Referenced by compileFile(), includeModule(), and writeIncludedFilenames().

UserFunctions Pol::Bscript::Compiler::userFunctions
int Pol::Bscript::Compiler::verbosity_level_

The documentation for this class was generated from the following files: