The Battle for Wesnoth  1.15.0+dev
Classes | Macros | Typedefs | Functions | Variables
lparser.cpp File Reference
#include "lprefix.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)   new_localvarliteral_(ls, "" v, (sizeof(v)/sizeof(char))-1)
 
#define leavelevel(ls)   ((ls)->L->nCcalls--)
 
#define UNARY_PRIORITY   12 /* priority for unary operators */
 

Typedefs

typedef struct BlockCnt BlockCnt
 

Functions

static void statement (LexState *ls)
 
static void expr (LexState *ls, expdesc *v)
 
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 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 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)
 
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 118 of file lparser.cpp.

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

◆ eqstr

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

Definition at line 42 of file lparser.cpp.

Referenced by checkrepeated(), closegoto(), findgotos(), findlabel(), searchupvalue(), and searchvar().

◆ hasmultret

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

Definition at line 37 of file lparser.cpp.

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

◆ leavelevel

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

Definition at line 338 of file lparser.cpp.

Referenced by 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 34 of file lparser.cpp.

Referenced by new_localvar().

◆ new_localvarliteral

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

Definition at line 191 of file lparser.cpp.

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

◆ UNARY_PRIORITY

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

Definition at line 1041 of file lparser.cpp.

Referenced by subexpr().

Typedef Documentation

◆ BlockCnt

typedef struct BlockCnt BlockCnt

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

◆ assignment()

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

◆ block()

static void block ( LexState ls)
static

Definition at line 1093 of file lparser.cpp.

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

Referenced by forbody(), ifstat(), luaM_realloc_(), statement(), and whilestat().

◆ block_follow()

static int block_follow ( LexState ls,
int  withuntil 
)
static

Definition at line 587 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

◆ breaklabel()

static void breaklabel ( 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

◆ checklimit()

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

Definition at line 92 of file lparser.cpp.

References errorlimit().

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

◆ checkname()

static void checkname ( LexState ls,
expdesc e 
)
static

Definition at line 156 of file lparser.cpp.

References codestring(), and str_checkname().

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

◆ checknext()

static void checknext ( LexState ls,
int  c 
)
static

◆ checkrepeated()

static void checkrepeated ( FuncState fs,
Labellist ll,
TString label 
)
static

◆ close_func()

static void close_func ( LexState ls)
static

◆ closegoto()

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

◆ closelistfield()

static void closelistfield ( FuncState fs,
struct ConsControl cc 
)
static

◆ codeclosure()

static void codeclosure ( LexState ls,
expdesc v 
)
static

◆ codestring()

static void codestring ( LexState ls,
expdesc e,
TString s 
)
static

Definition at line 151 of file lparser.cpp.

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

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

◆ cond()

static int cond ( LexState ls)
static

◆ constructor()

static void constructor ( LexState ls,
expdesc t 
)
static

◆ enterblock()

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

◆ enterlevel()

static void enterlevel ( LexState ls)
static

Definition at line 331 of file lparser.cpp.

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

Referenced by statement(), and subexpr().

◆ error_expected()

static l_noret error_expected ( LexState ls,
int  token 
)
static

Definition at line 73 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 int exp1 ( LexState ls)
static

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

◆ explist()

static int explist ( LexState ls,
expdesc v 
)
static

Definition at line 804 of file lparser.cpp.

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

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

◆ expr()

static void expr ( LexState ls,
expdesc v 
)
static

◆ exprstat()

static void exprstat ( LexState ls)
static

◆ field()

static void field ( LexState ls,
struct ConsControl cc 
)
static

◆ fieldsel()

static void fieldsel ( LexState ls,
expdesc v 
)
static

Definition at line 610 of file lparser.cpp.

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

Referenced by funcname(), and suffixedexp().

◆ findgotos()

static void findgotos ( LexState ls,
Labeldesc lb 
)
static

◆ findlabel()

static int findlabel ( LexState ls,
int  g 
)
static

◆ forbody()

static void forbody ( LexState ls,
int  base,
int  line,
int  nvars,
int  isnum 
)
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 1462 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 1476 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

◆ getlocvar()

static LocVar* getlocvar ( FuncState fs,
int  i 
)
static

◆ getunopr()

static UnOpr getunopr ( int  op)
static

Definition at line 986 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,
int  pc 
)
static

◆ ifstat()

static void ifstat ( LexState ls,
int  line 
)
static

◆ init_exp()

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

◆ labelstat()

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

◆ lastlistfield()

static void lastlistfield ( FuncState fs,
struct ConsControl cc 
)
static

◆ leaveblock()

static void leaveblock ( FuncState fs)
static

◆ listfield()

static void listfield ( LexState ls,
struct ConsControl cc 
)
static

Definition at line 693 of file lparser.cpp.

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

Referenced by field().

◆ localfunc()

static void localfunc ( LexState ls)
static

◆ localstat()

static void localstat ( LexState ls)
static

◆ 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

Definition at line 258 of file lparser.cpp.

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

Referenced by singlevaraux().

◆ movegotosout()

static void movegotosout ( FuncState fs,
BlockCnt bl 
)
static

◆ new_localvar()

static void new_localvar ( LexState ls,
TString name 
)
static

◆ new_localvarliteral_()

static void new_localvarliteral_ ( LexState ls,
const char *  name,
size_t  sz 
)
static

Definition at line 187 of file lparser.cpp.

References luaX_newstring(), and new_localvar().

◆ 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,
struct ConsControl cc 
)
static

◆ registerlocalvar()

static int registerlocalvar ( LexState ls,
TString varname 
)
static

◆ removevars()

static void removevars ( FuncState fs,
int  tolevel 
)
static

◆ repeatstat()

static void repeatstat ( LexState ls,
int  line 
)
static

◆ retstat()

static void retstat ( LexState ls)
static

◆ searchupvalue()

static int searchupvalue ( FuncState fs,
TString name 
)
static

Definition at line 218 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 
)
static

Definition at line 244 of file lparser.cpp.

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

Referenced by singlevaraux().

◆ semerror()

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

Definition at line 67 of file lparser.cpp.

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

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

◆ 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

◆ skipnoopstat()

static void skipnoopstat ( LexState ls)
static

Definition at line 1217 of file lparser.cpp.

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

Referenced by labelstat().

◆ statement()

static void statement ( LexState ls)
static

◆ statlist()

static void statlist ( LexState ls)
static

Definition at line 598 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 621 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