The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Macros | Typedefs | Functions | Variables
lparser.cpp File Reference
#include <string.h>
#include "lua.h"
#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "llex.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
Include dependency graph for lparser.cpp:

Go to the source code of this file.

Classes

struct  BlockCnt
 
struct  ConsControl
 
struct  LHS_assign
 

Macros

#define lparser_c
 
#define LUA_CORE
 
#define MAXVARS   200
 
#define hasmultret(k)   ((k) == VCALL || (k) == VVARARG)
 
#define check_condition(ls, c, msg)   { if (!(c)) luaX_syntaxerror(ls, msg); }
 
#define new_localvarliteral(ls, v)   new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)
 
#define leavelevel(ls)   ((ls)->L->nCcalls--)
 
#define UNARY_PRIORITY   8 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 

Functions

static void statement (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
static void anchor_token (LexState *ls)
 
static l_noret semerror (LexState *ls, const char *msg)
 
static l_noret error_expected (LexState *ls, int token)
 
static l_noret errorlimit (FuncState *fs, int limit, const char *what)
 
static void checklimit (FuncState *fs, int v, int l, const char *what)
 
static int testnext (LexState *ls, int c)
 
static void check (LexState *ls, int c)
 
static void checknext (LexState *ls, int c)
 
static void check_match (LexState *ls, int what, int who, int where)
 
static TStringstr_checkname (LexState *ls)
 
static void init_exp (expdesc *e, expkind k, int i)
 
static void codestring (LexState *ls, expdesc *e, TString *s)
 
static void checkname (LexState *ls, expdesc *e)
 
static int registerlocalvar (LexState *ls, TString *varname)
 
static void new_localvar (LexState *ls, TString *name)
 
static void new_localvarliteral_ (LexState *ls, const char *name, size_t sz)
 
static LocVargetlocvar (FuncState *fs, int i)
 
static void adjustlocalvars (LexState *ls, int nvars)
 
static void removevars (FuncState *fs, int tolevel)
 
static int searchupvalue (FuncState *fs, TString *name)
 
static int newupvalue (FuncState *fs, TString *name, expdesc *v)
 
static int searchvar (FuncState *fs, TString *n)
 
static void markupval (FuncState *fs, int level)
 
static int singlevaraux (FuncState *fs, TString *n, expdesc *var, int base)
 
static void singlevar (LexState *ls, expdesc *var)
 
static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e)
 
static void enterlevel (LexState *ls)
 
static void closegoto (LexState *ls, int g, Labeldesc *label)
 
static int findlabel (LexState *ls, int g)
 
static int newlabelentry (LexState *ls, Labellist *l, TString *name, int line, int pc)
 
static void findgotos (LexState *ls, Labeldesc *lb)
 
static void movegotosout (FuncState *fs, BlockCnt *bl)
 
static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop)
 
static void breaklabel (LexState *ls)
 
static l_noret undefgoto (LexState *ls, Labeldesc *gt)
 
static void leaveblock (FuncState *fs)
 
static Protoaddprototype (LexState *ls)
 
static void codeclosure (LexState *ls, expdesc *v)
 
static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl)
 
static void close_func (LexState *ls)
 
static int block_follow (LexState *ls, int withuntil)
 
static void statlist (LexState *ls)
 
static void fieldsel (LexState *ls, expdesc *v)
 
static void yindex (LexState *ls, expdesc *v)
 
static void recfield (LexState *ls, struct ConsControl *cc)
 
static void closelistfield (FuncState *fs, struct ConsControl *cc)
 
static void lastlistfield (FuncState *fs, struct ConsControl *cc)
 
static void listfield (LexState *ls, struct ConsControl *cc)
 
static void field (LexState *ls, struct ConsControl *cc)
 
static void constructor (LexState *ls, expdesc *t)
 
static void parlist (LexState *ls)
 
static void body (LexState *ls, expdesc *e, int ismethod, int line)
 
static int explist (LexState *ls, expdesc *v)
 
static void funcargs (LexState *ls, expdesc *f, int line)
 
static void primaryexp (LexState *ls, expdesc *v)
 
static void suffixedexp (LexState *ls, expdesc *v)
 
static void simpleexp (LexState *ls, expdesc *v)
 
static UnOpr getunopr (int op)
 
static BinOpr getbinopr (int op)
 
static BinOpr subexpr (LexState *ls, expdesc *v, int limit)
 
static void block (LexState *ls)
 
static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v)
 
static void assignment (LexState *ls, struct LHS_assign *lh, int nvars)
 
static int cond (LexState *ls)
 
static void gotostat (LexState *ls, int pc)
 
static void checkrepeated (FuncState *fs, Labellist *ll, TString *label)
 
static void skipnoopstat (LexState *ls)
 
static void labelstat (LexState *ls, TString *label, int line)
 
static void whilestat (LexState *ls, int line)
 
static void repeatstat (LexState *ls, int line)
 
static int exp1 (LexState *ls)
 
static void forbody (LexState *ls, int base, int line, int nvars, int isnum)
 
static void fornum (LexState *ls, TString *varname, int line)
 
static void forlist (LexState *ls, TString *indexname)
 
static void forstat (LexState *ls, int line)
 
static void test_then_block (LexState *ls, int *escapelist)
 
static void ifstat (LexState *ls, int line)
 
static void localfunc (LexState *ls)
 
static void localstat (LexState *ls)
 
static int funcname (LexState *ls, expdesc *v)
 
static void funcstat (LexState *ls, int line)
 
static void exprstat (LexState *ls)
 
static void retstat (LexState *ls)
 
static void mainfunc (LexState *ls, FuncState *fs)
 
ClosureluaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, Dyndata *dyd, const char *name, int firstchar)
 

Variables

struct {
   lu_byte   left
 
   lu_byte   right
 
priority []
 

Macro Definition Documentation

#define check_condition (   ls,
  c,
  msg 
)    { if (!(c)) luaX_syntaxerror(ls, msg); }

Definition at line 121 of file lparser.cpp.

Referenced by assignment(), exprstat(), and simpleexp().

#define hasmultret (   k)    ((k) == VCALL || (k) == VVARARG)

Definition at line 34 of file lparser.cpp.

Referenced by adjust_assign(), funcargs(), lastlistfield(), and retstat().

#define leavelevel (   ls)    ((ls)->L->nCcalls--)

Definition at line 336 of file lparser.cpp.

Referenced by statement(), and subexpr().

#define lparser_c

Definition at line 9 of file lparser.cpp.

#define LUA_CORE

Definition at line 10 of file lparser.cpp.

#define MAXVARS   200

Definition at line 31 of file lparser.cpp.

Referenced by new_localvar().

#define new_localvarliteral (   ls,
  v 
)    new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)

Definition at line 193 of file lparser.cpp.

Referenced by body(), forlist(), and fornum().

#define UNARY_PRIORITY   8 /* priority for unary operators */

Definition at line 1029 of file lparser.cpp.

Referenced by subexpr().

Typedef Documentation

typedef struct BlockCnt BlockCnt

Function Documentation

static Proto* addprototype ( LexState ls)
static
static void adjust_assign ( LexState ls,
int  nvars,
int  nexps,
expdesc e 
)
static
static void adjustlocalvars ( LexState ls,
int  nvars 
)
static
static void anchor_token ( LexState ls)
static
static void assignment ( LexState ls,
struct LHS_assign lh,
int  nvars 
)
static
static void block ( LexState ls)
static
static int block_follow ( LexState ls,
int  withuntil 
)
static

Definition at line 592 of file lparser.cpp.

References LexState::t, TK_ELSE, TK_ELSEIF, TK_END, TK_EOS, TK_UNTIL, and Token::token.

Referenced by labelstat(), retstat(), statlist(), and test_then_block().

static void body ( LexState ls,
expdesc e,
int  ismethod,
int  line 
)
static
static void breaklabel ( LexState ls)
static
static void check ( LexState ls,
int  c 
)
static
static void check_conflict ( LexState ls,
struct LHS_assign lh,
expdesc v 
)
static
static void check_match ( LexState ls,
int  what,
int  who,
int  where 
)
static
static void checklimit ( FuncState fs,
int  v,
int  l,
const char *  what 
)
static

Definition at line 95 of file lparser.cpp.

References errorlimit().

Referenced by assignment(), enterlevel(), listfield(), new_localvar(), newupvalue(), and recfield().

static void checkname ( LexState ls,
expdesc e 
)
static

Definition at line 159 of file lparser.cpp.

References codestring(), and str_checkname().

Referenced by fieldsel(), recfield(), and suffixedexp().

static void checknext ( LexState ls,
int  c 
)
static
static void checkrepeated ( FuncState fs,
Labellist ll,
TString label 
)
static
static void close_func ( LexState ls)
static
static void closegoto ( LexState ls,
int  g,
Labeldesc label 
)
static
static void closelistfield ( FuncState fs,
struct ConsControl cc 
)
static
static void codeclosure ( LexState ls,
expdesc v 
)
static
static void codestring ( LexState ls,
expdesc e,
TString s 
)
static

Definition at line 154 of file lparser.cpp.

References LexState::fs, init_exp(), luaK_stringK(), and VK.

Referenced by checkname(), funcargs(), simpleexp(), and singlevar().

static int cond ( LexState ls)
static
static void constructor ( LexState ls,
expdesc t 
)
static
static void enterblock ( FuncState fs,
BlockCnt bl,
lu_byte  isloop 
)
static
static void enterlevel ( LexState ls)
static

Definition at line 329 of file lparser.cpp.

References checklimit(), LexState::fs, LexState::L, LUAI_MAXCCALLS, and lua_State::nCcalls.

Referenced by statement(), and subexpr().

static l_noret error_expected ( LexState ls,
int  token 
)
static

Definition at line 76 of file lparser.cpp.

References LexState::L, luaO_pushfstring(), luaX_syntaxerror(), and luaX_token2str().

Referenced by check(), and check_match().

static l_noret errorlimit ( FuncState fs,
int  limit,
const char *  what 
)
static
static int exp1 ( LexState ls)
static

Definition at line 1271 of file lparser.cpp.

References e, expr(), LexState::fs, expdesc::info, expdesc::k, lua_assert, luaK_exp2nextreg(), expdesc::u, and VNONRELOC.

Referenced by fornum(), and lua_strx2number().

static int explist ( LexState ls,
expdesc v 
)
static

Definition at line 809 of file lparser.cpp.

References expr(), LexState::fs, luaK_exp2nextreg(), and testnext().

Referenced by assignment(), forlist(), funcargs(), localstat(), and retstat().

static void expr ( LexState ls,
expdesc v 
)
static

Definition at line 1066 of file lparser.cpp.

References subexpr().

Referenced by cond(), exp1(), explist(), listfield(), primaryexp(), recfield(), test_then_block(), and yindex().

static void exprstat ( LexState ls)
static
static void field ( LexState ls,
struct ConsControl cc 
)
static
static void fieldsel ( LexState ls,
expdesc v 
)
static

Definition at line 615 of file lparser.cpp.

References checkname(), LexState::fs, luaK_exp2anyregup(), luaK_indexed(), and luaX_next().

Referenced by funcname(), and suffixedexp().

static void findgotos ( LexState ls,
Labeldesc lb 
)
static
static int findlabel ( LexState ls,
int  g 
)
static
static void forbody ( LexState ls,
int  base,
int  line,
int  nvars,
int  isnum 
)
static
static void forlist ( LexState ls,
TString indexname 
)
static
static void fornum ( LexState ls,
TString varname,
int  line 
)
static
static void forstat ( LexState ls,
int  line 
)
static
static void funcargs ( LexState ls,
expdesc f,
int  line 
)
static
static int funcname ( LexState ls,
expdesc v 
)
static

Definition at line 1453 of file lparser.cpp.

References fieldsel(), singlevar(), LexState::t, and Token::token.

Referenced by funcstat(), and loadfunc().

static void funcstat ( LexState ls,
int  line 
)
static

Definition at line 1467 of file lparser.cpp.

References body(), LexState::fs, funcname(), luaK_fixline(), luaK_storevar(), and luaX_next().

Referenced by statement().

static BinOpr getbinopr ( int  op)
static
static LocVar* getlocvar ( FuncState fs,
int  i 
)
static
static UnOpr getunopr ( int  op)
static

Definition at line 986 of file lparser.cpp.

References OPR_LEN, OPR_MINUS, OPR_NOT, OPR_NOUNOPR, and TK_NOT.

Referenced by subexpr().

static void gotostat ( LexState ls,
int  pc 
)
static
static void ifstat ( LexState ls,
int  line 
)
static
static void init_exp ( expdesc e,
expkind  k,
int  i 
)
static
static void labelstat ( LexState ls,
TString label,
int  line 
)
static
static void lastlistfield ( FuncState fs,
struct ConsControl cc 
)
static
static void leaveblock ( FuncState fs)
static
static void listfield ( LexState ls,
struct ConsControl cc 
)
static

Definition at line 698 of file lparser.cpp.

References checklimit(), expr(), LexState::fs, MAX_INT, ConsControl::na, ConsControl::tostore, and ConsControl::v.

Referenced by field().

static void localfunc ( LexState ls)
static
static void localstat ( LexState ls)
static
Closure* luaY_parser ( lua_State L,
ZIO z,
Mbuffer buff,
Dyndata dyd,
const char *  name,
int  firstchar 
)
static void mainfunc ( LexState ls,
FuncState fs 
)
static
static void markupval ( FuncState fs,
int  level 
)
static

Definition at line 259 of file lparser.cpp.

References FuncState::bl, BlockCnt::nactvar, BlockCnt::previous, and BlockCnt::upval.

Referenced by singlevaraux().

static void movegotosout ( FuncState fs,
BlockCnt bl 
)
static
static void new_localvar ( LexState ls,
TString name 
)
static
static void new_localvarliteral_ ( LexState ls,
const char *  name,
size_t  sz 
)
static

Definition at line 189 of file lparser.cpp.

References luaX_newstring(), and new_localvar().

static int newlabelentry ( LexState ls,
Labellist l,
TString name,
int  line,
int  pc 
)
static
static int newupvalue ( FuncState fs,
TString name,
expdesc v 
)
static
static void open_func ( LexState ls,
FuncState fs,
BlockCnt bl 
)
static
static void parlist ( LexState ls)
static
static void primaryexp ( LexState ls,
expdesc v 
)
static
static void recfield ( LexState ls,
struct ConsControl cc 
)
static
static int registerlocalvar ( LexState ls,
TString varname 
)
static
static void removevars ( FuncState fs,
int  tolevel 
)
static
static void repeatstat ( LexState ls,
int  line 
)
static
static void retstat ( LexState ls)
static
static int searchupvalue ( FuncState fs,
TString name 
)
static

Definition at line 220 of file lparser.cpp.

References FuncState::f, i, luaS_eqstr(), FuncState::nups, and Proto::upvalues.

Referenced by singlevaraux().

static int searchvar ( FuncState fs,
TString n 
)
static

Definition at line 245 of file lparser.cpp.

References cast_int, getlocvar(), i, luaS_eqstr(), and FuncState::nactvar.

Referenced by singlevaraux().

static l_noret semerror ( LexState ls,
const char *  msg 
)
static

Definition at line 70 of file lparser.cpp.

References luaX_syntaxerror(), LexState::t, and Token::token.

Referenced by checkrepeated(), closegoto(), and undefgoto().

static void simpleexp ( LexState ls,
expdesc v 
)
static
static void singlevar ( LexState ls,
expdesc var 
)
static
static int singlevaraux ( FuncState fs,
TString n,
expdesc var,
int  base 
)
static

Definition at line 270 of file lparser.cpp.

References init_exp(), markupval(), newupvalue(), FuncState::prev, searchupvalue(), searchvar(), VLOCAL, VUPVAL, and VVOID.

Referenced by singlevar().

static void skipnoopstat ( LexState ls)
static

Definition at line 1208 of file lparser.cpp.

References statement(), LexState::t, TK_DBCOLON, and Token::token.

Referenced by labelstat(), and test_then_block().

static void statement ( LexState ls)
static
static void statlist ( LexState ls)
static

Definition at line 603 of file lparser.cpp.

References block_follow(), statement(), LexState::t, TK_RETURN, and Token::token.

Referenced by block(), body(), mainfunc(), repeatstat(), and test_then_block().

static TString* str_checkname ( LexState ls)
static
static BinOpr subexpr ( LexState ls,
expdesc v,
int  limit 
)
static
static void suffixedexp ( LexState ls,
expdesc v 
)
static
static void test_then_block ( LexState ls,
int escapelist 
)
static
static int testnext ( LexState ls,
int  c 
)
static
static l_noret undefgoto ( LexState ls,
Labeldesc gt 
)
static
static void whilestat ( LexState ls,
int  line 
)
static
static void yindex ( LexState ls,
expdesc v 
)
static

Definition at line 626 of file lparser.cpp.

References checknext(), expr(), LexState::fs, luaK_exp2val(), and luaX_next().

Referenced by recfield(), and suffixedexp().

Variable Documentation

Definition at line 1019 of file lparser.cpp.

const { ... } priority[]
Initial value:
= {
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7},
{10, 9}, {5, 4},
{3, 3}, {3, 3}, {3, 3},
{3, 3}, {3, 3}, {3, 3},
{2, 2}, {1, 1}
}

Referenced by ai::stage_unit_formulas::do_play_stage(), and subexpr().

lu_byte right