The Battle for Wesnoth  1.17.0-dev
Classes | Macros | Typedefs | Functions | Variables
lparser.cpp File Reference
#include "lprefix.h"
#include <limits.h>
#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 eqstr(a, b)   ((a) == (b))
 
#define check_condition(ls, c, msg)   { if (!(c)) luaX_syntaxerror(ls, msg); }
 
#define new_localvarliteral(ls, v)
 
#define enterlevel(ls)   luaE_incCstack(ls->L)
 
#define leavelevel(ls)   ((ls)->L->nCcalls--)
 
#define UNARY_PRIORITY   12 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 
typedef struct ConsControl ConsControl
 

Functions

static void statement (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
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 (expdesc *e, TString *s)
 
static void codename (LexState *ls, expdesc *e)
 
static int registerlocalvar (LexState *ls, FuncState *fs, TString *varname)
 
static int new_localvar (LexState *ls, TString *name)
 
static Vardescgetlocalvardesc (FuncState *fs, int vidx)
 
static int stacklevel (FuncState *fs, int nvar)
 
int luaY_nvarstack (FuncState *fs)
 
static LocVarlocaldebuginfo (FuncState *fs, int vidx)
 
static void init_var (FuncState *fs, expdesc *e, int vidx)
 
static void check_readonly (LexState *ls, expdesc *e)
 
static void adjustlocalvars (LexState *ls, int nvars)
 
static void removevars (FuncState *fs, int tolevel)
 
static int searchupvalue (FuncState *fs, TString *name)
 
static Upvaldescallocupvalue (FuncState *fs)
 
static int newupvalue (FuncState *fs, TString *name, expdesc *v)
 
static int searchvar (FuncState *fs, TString *n, expdesc *var)
 
static void markupval (FuncState *fs, int level)
 
static void 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 l_noret jumpscopeerror (LexState *ls, Labeldesc *gt)
 
static void solvegoto (LexState *ls, int g, Labeldesc *label)
 
static Labeldescfindlabel (LexState *ls, TString *name)
 
static int newlabelentry (LexState *ls, Labellist *l, TString *name, int line, int pc)
 
static int newgotoentry (LexState *ls, TString *name, int line, int pc)
 
static int solvegotos (LexState *ls, Labeldesc *lb)
 
static int createlabel (LexState *ls, TString *name, int line, int last)
 
static void movegotosout (FuncState *fs, BlockCnt *bl)
 
static void enterblock (FuncState *fs, BlockCnt *bl, lu_byte isloop)
 
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, ConsControl *cc)
 
static void closelistfield (FuncState *fs, ConsControl *cc)
 
static void lastlistfield (FuncState *fs, ConsControl *cc)
 
static void listfield (LexState *ls, ConsControl *cc)
 
static void field (LexState *ls, ConsControl *cc)
 
static void constructor (LexState *ls, expdesc *t)
 
static void setvararg (FuncState *fs, int nparams)
 
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 restassign (LexState *ls, struct LHS_assign *lh, int nvars)
 
static int cond (LexState *ls)
 
static void gotostat (LexState *ls)
 
static void breakstat (LexState *ls)
 
static void checkrepeated (LexState *ls, TString *name)
 
static void labelstat (LexState *ls, TString *name, int line)
 
static void whilestat (LexState *ls, int line)
 
static void repeatstat (LexState *ls, int line)
 
static void exp1 (LexState *ls)
 
static void fixforjump (FuncState *fs, int pc, int dest, int back)
 
static void forbody (LexState *ls, int base, int line, int nvars, int isgen)
 
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 int getlocalattribute (LexState *ls)
 
static void checktoclose (LexState *ls, int level)
 
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)
 
LClosureluaY_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

◆ check_condition

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

Definition at line 122 of file lparser.cpp.

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

◆ enterlevel

#define enterlevel (   ls)    luaE_incCstack(ls->L)

Definition at line 492 of file lparser.cpp.

Referenced by restassign(), statement(), and subexpr().

◆ eqstr

#define eqstr (   a,
  b 
)    ((a) == (b))

◆ hasmultret

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

Definition at line 38 of file lparser.cpp.

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

◆ leavelevel

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

Definition at line 495 of file lparser.cpp.

Referenced by restassign(), statement(), and subexpr().

◆ lparser_c

#define lparser_c

Definition at line 7 of file lparser.cpp.

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lparser.cpp.

◆ MAXVARS

#define MAXVARS   200

Definition at line 35 of file lparser.cpp.

Referenced by new_localvar().

◆ new_localvarliteral

#define new_localvarliteral (   ls,
 
)
Value:
luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char)) - 1));
static int new_localvar(LexState *ls, TString *name)
Definition: lparser.cpp:193
TString * luaX_newstring(LexState *ls, const char *str, size_t l)
Definition: llex.cpp:129

Definition at line 208 of file lparser.cpp.

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

◆ UNARY_PRIORITY

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

Definition at line 1241 of file lparser.cpp.

Referenced by subexpr().

Typedef Documentation

◆ BlockCnt

typedef struct BlockCnt BlockCnt

◆ ConsControl

typedef struct ConsControl ConsControl

Function Documentation

◆ addprototype()

static Proto* addprototype ( LexState ls)
static

◆ adjust_assign()

static void adjust_assign ( LexState ls,
int  nvars,
int  nexps,
expdesc e 
)
static

◆ adjustlocalvars()

static void adjustlocalvars ( LexState ls,
int  nvars 
)
static

◆ allocupvalue()

static Upvaldesc* allocupvalue ( FuncState fs)
static

◆ block()

static void block ( LexState ls)
static

Definition at line 1293 of file lparser.cpp.

References enterblock(), LexState::fs, leaveblock(), and statlist().

Referenced by forbody(), ifstat(), luaM_growaux_(), statement(), tryagain(), and whilestat().

◆ block_follow()

static int block_follow ( LexState ls,
int  withuntil 
)
static

Definition at line 776 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().

◆ body()

static void body ( LexState ls,
expdesc e,
int  ismethod,
int  line 
)
static

◆ breakstat()

static void breakstat ( LexState ls)
static

◆ check()

static void check ( LexState ls,
int  c 
)
static

◆ check_conflict()

static void check_conflict ( LexState ls,
struct LHS_assign lh,
expdesc v 
)
static

◆ check_match()

static void check_match ( LexState ls,
int  what,
int  who,
int  where 
)
static

◆ check_readonly()

static void check_readonly ( LexState ls,
expdesc e 
)
static

◆ checklimit()

static void checklimit ( FuncState fs,
int  v,
int  l,
const char *  what 
)
static

Definition at line 87 of file lparser.cpp.

References errorlimit().

Referenced by allocupvalue(), new_localvar(), and recfield().

◆ checknext()

static void checknext ( LexState ls,
int  c 
)
static

◆ checkrepeated()

static void checkrepeated ( LexState ls,
TString name 
)
static

◆ checktoclose()

static void checktoclose ( LexState ls,
int  level 
)
static

Definition at line 1706 of file lparser.cpp.

References FuncState::bl, LexState::fs, BlockCnt::insidetbc, luaK_codeABC, markupval(), OP_TBC, and stacklevel().

Referenced by localstat().

◆ close_func()

static void close_func ( LexState ls)
static

◆ closelistfield()

static void closelistfield ( FuncState fs,
ConsControl cc 
)
static

◆ codeclosure()

static void codeclosure ( LexState ls,
expdesc v 
)
static

◆ codename()

static void codename ( LexState ls,
expdesc e 
)
static

Definition at line 166 of file lparser.cpp.

References codestring(), and str_checkname().

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

◆ codestring()

static void codestring ( expdesc e,
TString s 
)
static

Definition at line 159 of file lparser.cpp.

References expdesc::f, expdesc::k, NO_JUMP, s, expdesc::strval, expdesc::t, expdesc::u, and VKSTR.

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

◆ cond()

static int cond ( LexState ls)
static

◆ constructor()

static void constructor ( LexState ls,
expdesc t 
)
static

◆ createlabel()

static int createlabel ( LexState ls,
TString name,
int  line,
int  last 
)
static

◆ enterblock()

static void enterblock ( FuncState fs,
BlockCnt bl,
lu_byte  isloop 
)
static

◆ error_expected()

static l_noret error_expected ( LexState ls,
int  token 
)
static

Definition at line 68 of file lparser.cpp.

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

Referenced by check(), and check_match().

◆ errorlimit()

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

◆ exp1()

static void exp1 ( LexState ls)
static

Definition at line 1505 of file lparser.cpp.

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

Referenced by fornum(), and isneg().

◆ explist()

static int explist ( LexState ls,
expdesc v 
)
static

Definition at line 1000 of file lparser.cpp.

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

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

◆ expr()

static void expr ( LexState ls,
expdesc v 
)
static

◆ exprstat()

static void exprstat ( LexState ls)
static

◆ field()

static void field ( LexState ls,
ConsControl cc 
)
static

◆ fieldsel()

static void fieldsel ( LexState ls,
expdesc v 
)
static

Definition at line 799 of file lparser.cpp.

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

Referenced by funcname(), and suffixedexp().

◆ findlabel()

static Labeldesc* findlabel ( LexState ls,
TString name 
)
static

◆ fixforjump()

static void fixforjump ( FuncState fs,
int  pc,
int  dest,
int  back 
)
static

Definition at line 1518 of file lparser.cpp.

References Proto::code, FuncState::f, FuncState::ls, luaX_syntaxerror(), MAXARG_Bx, SETARG_Bx, and unlikely.

Referenced by forbody().

◆ forbody()

static void forbody ( LexState ls,
int  base,
int  line,
int  nvars,
int  isgen 
)
static

◆ forlist()

static void forlist ( LexState ls,
TString indexname 
)
static

◆ fornum()

static void fornum ( LexState ls,
TString varname,
int  line 
)
static

◆ forstat()

static void forstat ( LexState ls,
int  line 
)
static

◆ funcargs()

static void funcargs ( LexState ls,
expdesc f,
int  line 
)
static

◆ funcname()

static int funcname ( LexState ls,
expdesc v 
)
static

Definition at line 1758 of file lparser.cpp.

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

Referenced by funcstat().

◆ funcstat()

static void funcstat ( LexState ls,
int  line 
)
static

Definition at line 1772 of file lparser.cpp.

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

Referenced by statement().

◆ getbinopr()

static BinOpr getbinopr ( int  op)
static

◆ getlocalattribute()

static int getlocalattribute ( LexState ls)
static

◆ getlocalvardesc()

static Vardesc* getlocalvardesc ( FuncState fs,
int  vidx 
)
static

◆ getunopr()

static UnOpr getunopr ( int  op)
static

Definition at line 1183 of file lparser.cpp.

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

Referenced by subexpr().

◆ gotostat()

static void gotostat ( LexState ls)
static

◆ ifstat()

static void ifstat ( LexState ls,
int  line 
)
static

◆ init_exp()

static void init_exp ( expdesc e,
expkind  k,
int  i 
)
static

◆ init_var()

static void init_var ( FuncState fs,
expdesc e,
int  vidx 
)
static

◆ jumpscopeerror()

static l_noret jumpscopeerror ( LexState ls,
Labeldesc gt 
)
static

◆ labelstat()

static void labelstat ( LexState ls,
TString name,
int  line 
)
static

◆ lastlistfield()

static void lastlistfield ( FuncState fs,
ConsControl cc 
)
static

◆ leaveblock()

static void leaveblock ( FuncState fs)
static

◆ listfield()

static void listfield ( LexState ls,
ConsControl cc 
)
static

Definition at line 884 of file lparser.cpp.

References expr(), ConsControl::tostore, and ConsControl::v.

Referenced by field().

◆ localdebuginfo()

static LocVar* localdebuginfo ( FuncState fs,
int  vidx 
)
static

◆ localfunc()

static void localfunc ( LexState ls)
static

◆ localstat()

static void localstat ( LexState ls)
static

◆ luaY_nvarstack()

int luaY_nvarstack ( FuncState fs)

◆ luaY_parser()

LClosure* luaY_parser ( lua_State L,
ZIO z,
Mbuffer buff,
Dyndata dyd,
const char *  name,
int  firstchar 
)

◆ mainfunc()

static void mainfunc ( LexState ls,
FuncState fs 
)
static

◆ markupval()

static void markupval ( FuncState fs,
int  level 
)
static

◆ movegotosout()

static void movegotosout ( FuncState fs,
BlockCnt bl 
)
static

◆ new_localvar()

static int new_localvar ( LexState ls,
TString name 
)
static

◆ newgotoentry()

static int newgotoentry ( LexState ls,
TString name,
int  line,
int  pc 
)
static

Definition at line 563 of file lparser.cpp.

References LexState::dyd, Dyndata::gt, and newlabelentry().

Referenced by breakstat(), gotostat(), and test_then_block().

◆ newlabelentry()

static int newlabelentry ( LexState ls,
Labellist l,
TString name,
int  line,
int  pc 
)
static

◆ newupvalue()

static int newupvalue ( FuncState fs,
TString name,
expdesc v 
)
static

◆ open_func()

static void open_func ( LexState ls,
FuncState fs,
BlockCnt bl 
)
static

◆ parlist()

static void parlist ( LexState ls)
static

◆ primaryexp()

static void primaryexp ( LexState ls,
expdesc v 
)
static

◆ recfield()

static void recfield ( LexState ls,
ConsControl cc 
)
static

◆ registerlocalvar()

static int registerlocalvar ( LexState ls,
FuncState fs,
TString varname 
)
static

◆ removevars()

static void removevars ( FuncState fs,
int  tolevel 
)
static

◆ repeatstat()

static void repeatstat ( LexState ls,
int  line 
)
static

◆ restassign()

static void restassign ( LexState ls,
struct LHS_assign lh,
int  nvars 
)
static

◆ retstat()

static void retstat ( LexState ls)
static

◆ searchupvalue()

static int searchupvalue ( FuncState fs,
TString name 
)
static

Definition at line 342 of file lparser.cpp.

References eqstr, FuncState::f, i, FuncState::nups, and Proto::upvalues.

Referenced by singlevaraux().

◆ searchvar()

static int searchvar ( FuncState fs,
TString n,
expdesc var 
)
static

◆ setvararg()

static void setvararg ( FuncState fs,
int  nparams 
)
static

Definition at line 941 of file lparser.cpp.

References FuncState::f, Proto::is_vararg, luaK_codeABC, and OP_VARARGPREP.

Referenced by mainfunc(), and parlist().

◆ simpleexp()

static void simpleexp ( LexState ls,
expdesc v 
)
static

◆ singlevar()

static void singlevar ( LexState ls,
expdesc var 
)
static

◆ singlevaraux()

static void singlevaraux ( FuncState fs,
TString n,
expdesc var,
int  base 
)
static

◆ solvegoto()

static void solvegoto ( LexState ls,
int  g,
Labeldesc label 
)
static

◆ solvegotos()

static int solvegotos ( LexState ls,
Labeldesc lb 
)
static

◆ stacklevel()

static int stacklevel ( FuncState fs,
int  nvar 
)
static

◆ statement()

static void statement ( LexState ls)
static

◆ statlist()

static void statlist ( LexState ls)
static

Definition at line 787 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().

◆ str_checkname()

static TString* str_checkname ( LexState ls)
static

◆ subexpr()

static BinOpr subexpr ( LexState ls,
expdesc v,
int  limit 
)
static

◆ suffixedexp()

static void suffixedexp ( LexState ls,
expdesc v 
)
static

◆ test_then_block()

static void test_then_block ( LexState ls,
int *  escapelist 
)
static

◆ testnext()

static int testnext ( LexState ls,
int  c 
)
static

◆ undefgoto()

static l_noret undefgoto ( LexState ls,
Labeldesc gt 
)
static

◆ whilestat()

static void whilestat ( LexState ls,
int  line 
)
static

◆ yindex()

static void yindex ( LexState ls,
expdesc v 
)
static

Definition at line 810 of file lparser.cpp.

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

Referenced by recfield(), and suffixedexp().

Variable Documentation

◆ left

lu_byte left

◆ priority

const { ... } priority[]
Initial value:
= {
{10, 10}, {10, 10},
{11, 11}, {11, 11},
{14, 13},
{11, 11}, {11, 11},
{6, 6}, {4, 4}, {5, 5},
{7, 7}, {7, 7},
{9, 8},
{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().

◆ right

lu_byte right