diff options
author | dgp <dgp@users.sourceforge.net> | 2016-04-19 20:35:49 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-04-19 20:35:49 (GMT) |
commit | 66032e8a327e0498b0d8970307452f66c69be25c (patch) | |
tree | 345b92b9d0c1be0f8ff45032a38884929744545e /generic | |
parent | 0a228666ae8b3189ae92ff7624263de1455c24ff (diff) | |
download | tcl-66032e8a327e0498b0d8970307452f66c69be25c.zip tcl-66032e8a327e0498b0d8970307452f66c69be25c.tar.gz tcl-66032e8a327e0498b0d8970307452f66c69be25c.tar.bz2 |
Fork of Tcl used in the "Little" project.
http://www.mcvoy.com/lm/little/index.html
Diffstat (limited to 'generic')
38 files changed, 28386 insertions, 329 deletions
diff --git a/generic/Last.c b/generic/Last.c new file mode 100644 index 0000000..0ce480a --- /dev/null +++ b/generic/Last.c @@ -0,0 +1,386 @@ +/* + * used to be: tclsh gen-l-ast2.tcl to regenerate + * As of Feb 2008 it is maintained by hand. + */ +#include "tclInt.h" +#include "Lcompile.h" + +private void +ast_init(void *node, Node_k type, YYLTYPE beg, YYLTYPE end) +{ + Ast *ast = (Ast *)node; + + ast->type = type; + ast->loc.beg = beg.beg; + ast->loc.end = end.end; + ast->loc.line = beg.line; + ast->loc.file = beg.file; + ast->next = L->ast_list; + L->ast_list = (void *)ast; +} + +Block * +ast_mkBlock(VarDecl *decls, Stmt *body, YYLTYPE beg, YYLTYPE end) +{ + Block *block = (Block *)ckalloc(sizeof(Block)); + memset(block, 0, sizeof(Block)); + block->body = body; + block->decls = decls; + ast_init(block, L_NODE_BLOCK, beg, end); + return (block); +} + +Expr * +ast_mkExpr(Expr_k kind, Op_k op, Expr *a, Expr *b, Expr *c, YYLTYPE beg, + YYLTYPE end) +{ + Expr *expr = (Expr *)ckalloc(sizeof(Expr)); + memset(expr, 0, sizeof(Expr)); + expr->a = a; + expr->b = b; + expr->c = c; + expr->kind = kind; + expr->op = op; + ast_init(expr, L_NODE_EXPR, beg, end); + return (expr); +} + +ForEach * +ast_mkForeach(Expr *expr, Expr *key, Expr *value, Stmt *body, + YYLTYPE beg, YYLTYPE end) +{ + ForEach *foreach = (ForEach *)ckalloc(sizeof(ForEach)); + memset(foreach, 0, sizeof(ForEach)); + foreach->expr = expr; + foreach->key = key; + foreach->value = value; + foreach->body = body; + ast_init(foreach, L_NODE_FOREACH_LOOP, beg, end); + return (foreach); +} + +FnDecl * +ast_mkFnDecl(VarDecl *decl, Block *body, YYLTYPE beg, YYLTYPE end) +{ + FnDecl *fndecl = (FnDecl *)ckalloc(sizeof(FnDecl)); + memset(fndecl, 0, sizeof(FnDecl)); + fndecl->body = body; + fndecl->decl = decl; + /* + * Propagate tracing attributes from L->options, which come + * from cmd-line options or #pragmas. Any attributes + * specified in the function declaration end up overwriting + * these. + */ + fndecl->attrs = Tcl_NewDictObj(); + hash_put(fndecl->attrs, "fntrace", hash_get(L->options, "fntrace")); + hash_put(fndecl->attrs, "fnhook", hash_get(L->options, "fnhook")); + hash_put(fndecl->attrs, "trace_depth", + hash_get(L->options, "trace_depth")); + ast_init(fndecl, L_NODE_FUNCTION_DECL, beg, end); + return (fndecl); +} + +Cond * +ast_mkIfUnless(Expr *expr, Stmt *if_body, Stmt *else_body, YYLTYPE beg, + YYLTYPE end) +{ + Cond *cond = (Cond *)ckalloc(sizeof(Cond)); + memset(cond, 0, sizeof(Cond)); + cond->cond = expr; + cond->else_body = else_body; + cond->if_body = if_body; + ast_init(cond, L_NODE_IF_UNLESS, beg, end); + return (cond); +} + +Loop * +ast_mkLoop(Loop_k kind, Expr *pre, Expr *cond, Expr *post, Stmt *body, + YYLTYPE beg, YYLTYPE end) +{ + Loop *loop = (Loop *)ckalloc(sizeof(Loop)); + memset(loop, 0, sizeof(Loop)); + loop->cond = cond; + loop->post = post; + loop->pre = pre; + loop->kind = kind; + loop->body = body; + ast_init(loop, L_NODE_LOOP, beg, end); + return (loop); +} + +Switch * +ast_mkSwitch(Expr *expr, Case *cases, YYLTYPE beg, YYLTYPE end) +{ + Switch *sw = (Switch *)ckalloc(sizeof(Switch)); + memset(sw, 0, sizeof(Switch)); + sw->expr = expr; + sw->cases = cases; + ast_init(sw, L_NODE_SWITCH, beg, end); + return (sw); +} + +Case * +ast_mkCase(Expr *expr, Stmt *body, YYLTYPE beg, YYLTYPE end) +{ + Case *c = (Case *)ckalloc(sizeof(Case)); + memset(c, 0, sizeof(Case)); + c->expr = expr; + c->body = body; + ast_init(c, L_NODE_CASE, beg, end); + return (c); +} + +Try * +ast_mkTry(Stmt *try, Expr *msg, Stmt *catch) +{ + Try *t = (Try *)ckalloc(sizeof(Try)); + memset(t, 0, sizeof(Try)); + t->try = try; + t->msg = msg; + t->catch = catch; + return (t); +} + +Stmt * +ast_mkStmt(Stmt_k kind, Stmt *next, YYLTYPE beg, YYLTYPE end) +{ + Stmt *stmt = (Stmt *)ckalloc(sizeof(Stmt)); + memset(stmt, 0, sizeof(Stmt)); + stmt->next = next; + stmt->kind = kind; + ast_init(stmt, L_NODE_STMT, beg, end); + return (stmt); +} + +TopLev * +ast_mkTopLevel(Toplv_k kind, TopLev *next, YYLTYPE beg, YYLTYPE end) +{ + TopLev *toplev = (TopLev *)ckalloc(sizeof(TopLev)); + memset(toplev, 0, sizeof(TopLev)); + toplev->next = next; + toplev->kind = kind; + ast_init(toplev, L_NODE_TOPLEVEL, beg, end); + return (toplev); +} + +VarDecl * +ast_mkVarDecl(Type *type, Expr *id, YYLTYPE beg, YYLTYPE end) +{ + VarDecl *vardecl = (VarDecl *)ckalloc(sizeof(VarDecl)); + memset(vardecl, 0, sizeof(VarDecl)); + vardecl->id = id; + vardecl->type = type; + ast_init(vardecl, L_NODE_VAR_DECL, beg, end); + return (vardecl); +} + +ClsDecl * +ast_mkClsDecl(VarDecl *decl, YYLTYPE beg, YYLTYPE end) +{ + ClsDecl *clsdecl = (ClsDecl *)ckalloc(sizeof(ClsDecl)); + memset(clsdecl, 0, sizeof(ClsDecl)); + clsdecl->decl = decl; + ast_init(clsdecl, L_NODE_CLASS_DECL, beg, end); + return (clsdecl); +} + +/* Build a default constructor if the user didn't provide one. */ +FnDecl * +ast_mkConstructor(ClsDecl *class) +{ + char *name; + Type *type; + Expr *id; + VarDecl *decl; + Block *block; + FnDecl *fn; + YYLTYPE loc = class->node.loc; + + type = type_mkFunc(class->decl->type, NULL); + name = cksprintf("%s_new", class->decl->id->str); + id = ast_mkId(name, loc, loc); + decl = ast_mkVarDecl(type, id, loc, loc); + decl->flags |= SCOPE_GLOBAL | DECL_CLASS_FN | DECL_PUBLIC | + DECL_CLASS_CONST; + decl->clsdecl = class; + block = ast_mkBlock(NULL, NULL, loc, loc); + fn = ast_mkFnDecl(decl, block, loc, loc); + + return (fn); +} + +/* Build a default destructor if the user didn't provide one. */ +FnDecl * +ast_mkDestructor(ClsDecl *class) +{ + char *name; + Type *type; + Expr *id, *self; + VarDecl *decl, *parm; + Block *block; + FnDecl *fn; + YYLTYPE loc = class->node.loc; + + self = ast_mkId("self", loc, loc); + parm = ast_mkVarDecl(class->decl->type, self, loc, loc); + parm->flags = SCOPE_LOCAL | DECL_LOCAL_VAR; + type = type_mkFunc(L_void, parm); + name = cksprintf("%s_delete", class->decl->id->str); + id = ast_mkId(name, loc, loc); + decl = ast_mkVarDecl(type, id, loc, loc); + decl->flags |= SCOPE_GLOBAL | DECL_CLASS_FN | DECL_PUBLIC | + DECL_CLASS_DESTR; + decl->clsdecl = class; + block = ast_mkBlock(NULL, NULL, loc, loc); + fn = ast_mkFnDecl(decl, block, loc, loc); + + return (fn); +} + +Expr * +ast_mkUnOp(Op_k op, Expr *e1, YYLTYPE beg, YYLTYPE end) +{ + return (ast_mkExpr(L_EXPR_UNOP, op, e1, NULL, NULL, beg, end)); +} + +Expr * +ast_mkBinOp(Op_k op, Expr *e1, Expr *e2, YYLTYPE beg, YYLTYPE end) +{ + return (ast_mkExpr(L_EXPR_BINOP, op, e1, e2, NULL, beg, end)); +} + +Expr * +ast_mkTrinOp(Op_k op, Expr *e1, Expr *e2, Expr *e3, YYLTYPE beg, + YYLTYPE end) +{ + return (ast_mkExpr(L_EXPR_TRINOP, op, e1, e2, e3, beg, end)); +} + +Expr * +ast_mkConst(Type *type, char *str, YYLTYPE beg, YYLTYPE end) +{ + Expr *e = ast_mkExpr(L_EXPR_CONST, L_OP_NONE, NULL, NULL, NULL, + beg, end); + e->type = type; + e->str = str; + return (e); +} + +Expr * +ast_mkRegexp(char *re, YYLTYPE beg, YYLTYPE end) +{ + Expr *e = ast_mkExpr(L_EXPR_RE, L_OP_NONE, NULL, NULL, NULL, beg, end); + e->str = re; + e->type = L_string; + return (e); +} + +Expr * +ast_mkFnCall(Expr *id, Expr *arg_list, YYLTYPE beg, YYLTYPE end) +{ + Expr *e = ast_mkExpr(L_EXPR_FUNCALL, L_OP_NONE, id, arg_list, NULL, + beg, end); + return (e); +} + +Expr * +ast_mkId(char *name, YYLTYPE beg, YYLTYPE end) +{ + Expr *e = ast_mkExpr(L_EXPR_ID, L_OP_NONE, NULL, NULL, NULL, beg, end); + e->str = ckstrdup(name); + return (e); +} + +private Type * +type_alloc(Type_k kind) +{ + Type *type = (Type *)ckalloc(sizeof(Type)); + memset(type, 0, sizeof(Type)); + type->kind = kind; + type->list = L->type_list; + L->type_list = type; + return (type); +} + +Type * +type_dup(Type *type) +{ + Type *dup = (Type *)ckalloc(sizeof(Type)); + *dup = *type; + if (type->name) { + dup->name = ckstrdup(type->name); + } + if ((type->kind == L_STRUCT) && type->u.struc.tag) { + dup->u.struc.tag = ckstrdup(type->u.struc.tag); + } + dup->list = L->type_list; + L->type_list = dup; + return (dup); +} + +Type * +type_mkScalar(Type_k kind) +{ + Type *type = type_alloc(kind); + return (type); +} + +Type * +type_mkArray(Expr *size, Type *base_type) +{ + Type *type = type_alloc(L_ARRAY); + type->u.array.size = size; + type->base_type = base_type; + return (type); +} + +Type * +type_mkHash(Type *index_type, Type *base_type) +{ + Type *type = type_alloc(L_HASH); + type->u.hash.idx_type = index_type; + type->base_type = base_type; + return (type); +} + +Type * +type_mkStruct(char *tag, VarDecl *members) +{ + Type *type = type_alloc(L_STRUCT); + type->u.struc.tag = ckstrdup(tag); + type->u.struc.members = members; + return (type); +} + +Type * +type_mkNameOf(Type *base_type) +{ + Type *type = type_alloc(L_NAMEOF); + type->base_type = base_type; + return (type); +} + +Type * +type_mkFunc(Type *ret_type, VarDecl *formals) +{ + Type *type = type_alloc(L_FUNCTION); + type->base_type = ret_type; + type->u.func.formals = formals; + return (type); +} + +Type * +type_mkList(Type *a) +{ + Type *type = type_alloc(L_LIST); + type->base_type = a; + return (type); +} + +Type * +type_mkClass(void) +{ + Type *type = type_alloc(L_CLASS); + return (type); +} diff --git a/generic/Last.h b/generic/Last.h new file mode 100644 index 0000000..74246f5 --- /dev/null +++ b/generic/Last.h @@ -0,0 +1,490 @@ +/* + * used to be: tclsh gen-l-ast2.tcl to regenerate + * As of Feb 2008 it is maintained by hand. + */ +#ifndef L_AST_H +#define L_AST_H + +#define unless(p) if (!(p)) +#define private static + +typedef struct Ast Ast; +typedef struct Block Block; +typedef struct VarDecl VarDecl; +typedef struct FnDecl FnDecl; +typedef struct ClsDecl ClsDecl; +typedef struct Stmt Stmt; +typedef struct TopLev TopLev; +typedef struct ClsLev ClsLev; +typedef struct Cond Cond; +typedef struct Loop Loop; +typedef struct ForEach ForEach; +typedef struct Switch Switch; +typedef struct Case Case; +typedef struct Expr Expr; +typedef struct Type Type; +typedef struct Try Try; +typedef struct Sym Sym; + +/* + * Source-file offset and line # of an AST node, token, or + * nonterminal. Set by the scanner and parser. + */ +typedef struct { + int beg; // source offset of first char + int end; // source offset of last char + 1 + int line; // line # of first char adjusted for any #include's + char *file; // file name +} YYLTYPE; +#define YYLTYPE YYLTYPE + +typedef enum { + L_LOOP_DO, + L_LOOP_FOR, + L_LOOP_WHILE, +} Loop_k; + +typedef enum { + L_STMT_BLOCK, + L_STMT_BREAK, + L_STMT_COND, + L_STMT_CONTINUE, + L_STMT_DECL, + L_STMT_EXPR, + L_STMT_FOREACH, + L_STMT_SWITCH, + L_STMT_LOOP, + L_STMT_RETURN, + L_STMT_GOTO, + L_STMT_LABEL, + L_STMT_PRAGMA, + L_STMT_TRY, +} Stmt_k; + +typedef enum { + L_TOPLEVEL_CLASS, + L_TOPLEVEL_FUN, + L_TOPLEVEL_GLOBAL, + L_TOPLEVEL_STMT, +} Toplv_k; + +typedef enum { + L_NODE_BLOCK, + L_NODE_EXPR, + L_NODE_FOREACH_LOOP, + L_NODE_FUNCTION_DECL, + L_NODE_IF_UNLESS, + L_NODE_SWITCH, + L_NODE_CASE, + L_NODE_LOOP, + L_NODE_STMT, + L_NODE_TOPLEVEL, + L_NODE_CLSLEVEL, + L_NODE_VAR_DECL, + L_NODE_CLASS_DECL, +} Node_k; + +/* + * A compiler temp. + */ +typedef struct Tmp Tmp; +struct Tmp { + int free; + int idx; // local variable slot # + char *name; + Tmp *next; +}; + +/* + * An L type name is represented with exactly one instance of a + * Type structure. All references to the type name point to that + * structure, so pointer comparison can be used to check for name + * equivalence of types. + * + * L_int, L_float, etc are the global Type pointers for the + * pre-defined types. L_INT, L_FLOAT, etc are the type kinds + * (enum) used in the type structure. + * + * L_NAMEOF is like an address in other languages. An expression + * of this type holds the name of an lvalue (e.g., &p has the value + * "p"). The base_type is the type of the name. + */ + +typedef enum { + L_INT = 0x0001, + L_FLOAT = 0x0002, + L_STRING = 0x0004, + L_ARRAY = 0x0008, + L_HASH = 0x0010, + L_STRUCT = 0x0020, + L_LIST = 0x0040, + L_VOID = 0x0080, + L_POLY = 0x0100, + L_NAMEOF = 0x0200, + L_FUNCTION = 0x0400, + L_CLASS = 0x0800, + L_WIDGET = 0x1000, +} Type_k; + +struct Type { + Type_k kind; + Type *base_type; // for array, hash, list, nameof, etc + Type *next; // for linking list types + char *name; // if a typedef, the type name being declared + union { + struct { + Expr *size; + } array; + struct { + Type *idx_type; + } hash; + struct { + char *tag; + VarDecl *members; + } struc; + struct { + VarDecl *formals; + } func; + struct { + ClsDecl *clsdecl; + } class; + } u; + Type *list; // links all type structures ever allocated +}; + +struct Ast { + Node_k type; + Ast *next; // links all nodes in an AST + YYLTYPE loc; +}; + +struct Block { + Ast node; + Stmt *body; + VarDecl *decls; +}; + +typedef enum { + L_EXPR_ID, + L_EXPR_CONST, + L_EXPR_FUNCALL, + L_EXPR_UNOP, + L_EXPR_BINOP, + L_EXPR_TRINOP, + L_EXPR_RE, +} Expr_k; + +typedef enum { + L_OP_NONE, + L_OP_CAST, + L_OP_BANG, + L_OP_ADDROF, + L_OP_MINUS, + L_OP_UMINUS, + L_OP_PLUS, + L_OP_UPLUS, + L_OP_PLUSPLUS_PRE, + L_OP_PLUSPLUS_POST, + L_OP_MINUSMINUS_PRE, + L_OP_MINUSMINUS_POST, + L_OP_EQUALS, + L_OP_EQPLUS, + L_OP_EQMINUS, + L_OP_EQSTAR, + L_OP_EQSLASH, + L_OP_EQPERC, + L_OP_EQBITAND, + L_OP_EQBITOR, + L_OP_EQBITXOR, + L_OP_EQLSHIFT, + L_OP_EQRSHIFT, + L_OP_EQTWID, + L_OP_BANGTWID, + L_OP_EQDOT, + L_OP_STAR, + L_OP_SLASH, + L_OP_PERC, + L_OP_STR_EQ, + L_OP_STR_NE, + L_OP_STR_GT, + L_OP_STR_LT, + L_OP_STR_GE, + L_OP_STR_LE, + L_OP_EQUALEQUAL, + L_OP_NOTEQUAL, + L_OP_GREATER, + L_OP_LESSTHAN, + L_OP_GREATEREQ, + L_OP_LESSTHANEQ, + L_OP_ANDAND, + L_OP_OROR, + L_OP_LSHIFT, + L_OP_RSHIFT, + L_OP_BITOR, + L_OP_BITAND, + L_OP_BITXOR, + L_OP_BITNOT, + L_OP_DEFINED, + L_OP_ARRAY_INDEX, + L_OP_HASH_INDEX, + L_OP_DOT, + L_OP_POINTS, + L_OP_CLASS_INDEX, + L_OP_INTERP_STRING, + L_OP_INTERP_RE, + L_OP_LIST, + L_OP_KV, + L_OP_COMMA, + L_OP_ARRAY_SLICE, + L_OP_EXPAND, + L_OP_CONCAT, + L_OP_CMDSUBST, + L_OP_TERNARY_COND, + L_OP_FILE, +} Op_k; + +/* + * Flags for L expression compilation. Bits are used for simplicity + * even though some of these are mutually exclusive. These are used + * in various places such as calls to compile_expr() and in the AST. + */ +typedef enum { + L_EXPR_RE_I = 0x00000001, // expr is an re with "i" qualifier + L_EXPR_RE_G = 0x00000002, // expr is an re with "g" qualifier + L_EXPR_RE_T = 0x00000004, // expr is an re with "t" qualifier + L_EXPR_DEEP = 0x00000008, // expr is the result of a deep dive + L_IDX_ARRAY = 0x00000010, // what kind of thing we're indexing + L_IDX_HASH = 0x00000020, + L_IDX_STRING = 0x00000040, + L_LVALUE = 0x00000080, // if we will be writing the obj + L_DELETE = 0x00000100, // delete from parent hash/array/string + L_PUSH_VAL = 0x00000200, // what we want INST_L_INDEX to leave on + L_PUSH_PTR = 0x00000400, // the stack + L_PUSH_VALPTR = 0x00000800, + L_PUSH_PTRVAL = 0x00001000, + L_DISCARD = 0x00002000, // have compile_expr push nothing + L_PUSH_NAME = 0x00004000, // have compile_expr push name not val + L_PUSH_NEW = 0x00008000, // whether INST_L_DEEP_WRITE should push + L_PUSH_OLD = 0x00010000, // the new or old value + L_SAVE_IDX = 0x00020000, // save idx to a tmp var (for copy in/out) + L_REUSE_IDX = 0x00040000, // get idx from tmp var instead of expr + L_NOTUSED = 0x00080000, // do not update used_p in symtab entry + L_NOWARN = 0x00100000, // issue no err if symbol undefined + L_SPLIT_RE = 0x00200000, // split on a regexp + L_SPLIT_STR = 0x00400000, // split on a string + L_SPLIT_LIM = 0x00800000, // enforce split limit + L_INSERT_ELT = 0x01000000, // insert a single elt into a list + L_INSERT_LIST = 0x02000000, // insert a list into a list + L_NEG_OK = 0x04000000, // indexing element -1 is OK + L_EXPR_RE_L = 0x08000000, // expr is an re with "l" qualifier +} Expr_f; + +struct Expr { + Ast node; + Expr_k kind; + Op_k op; + Type *type; + Expr *a; + Expr *b; + Expr *c; + Expr_f flags; + Sym *sym; // for id, ptr to symbol table entry + char *str; // for constants/id/re/struct-index + union { + struct { + Tmp *idx; + Tmp *val; + } deepdive; + } u; + Expr *next; +}; + +struct ForEach { + Ast node; + Expr *expr; + Expr *key; + Expr *value; + Stmt *body; +}; + +struct FnDecl { + Ast node; + Block *body; + VarDecl *decl; + FnDecl *next; + Tcl_Obj *attrs; // hash of function attributes, if any +}; + +struct ClsDecl { + Ast node; + VarDecl *decl; + VarDecl *clsvars; + VarDecl *instvars; + FnDecl *fns; + FnDecl *constructors; + FnDecl *destructors; + Tcl_HashTable *symtab; +}; + +struct Cond { + Ast node; + Expr *cond; + Stmt *else_body; + Stmt *if_body; +}; + +struct Loop { + Ast node; + Expr *cond; + Expr *post; + Expr *pre; + Loop_k kind; + Stmt *body; +}; + +struct Switch { + Ast node; + Expr *expr; + Case *cases; +}; + +struct Case { + Ast node; + Expr *expr; + Stmt *body; + Case *next; +}; + +struct Try { + Ast node; + Stmt *try; + Stmt *catch; + Expr *msg; +}; + +struct Stmt { + Ast node; + Stmt *next; + Stmt_k kind; + union { + Block *block; + Expr *expr; + ForEach *foreach; + Cond *cond; + Loop *loop; + Switch *swich; // not a typo -- illegal to call it "switch" + VarDecl *decl; + char *label; + Try *try; + } u; +}; + +struct TopLev { + Ast node; + TopLev *next; + Toplv_k kind; + union { + ClsDecl *class; + FnDecl *fun; + Stmt *stmt; + VarDecl *global; + } u; +}; + +/* + * These encode both scope information and the kind of declaration. + * Some flags are redundant but were chosen for clarity. + */ +typedef enum { + SCOPE_LOCAL = 0x00000001, // scope the symbol should go in + SCOPE_SCRIPT = 0x00000002, // visible in current script + SCOPE_GLOBAL = 0x00000004, // visible across scripts + SCOPE_CLASS = 0x00000008, // visible in a class + DECL_GLOBAL_VAR = 0x00000010, // the kind of declaration + DECL_LOCAL_VAR = 0x00000020, + DECL_ERR = 0x00000040, // added on undeclared var + DECL_FN = 0x00000080, // regular function + DECL_CLASS_VAR = 0x00000100, // class variable + DECL_CLASS_INST_VAR = 0x00000200, // class instance variable + DECL_CLASS_FN = 0x00000400, // class member fn + DECL_CLASS_CONST = 0x00000800, // class constructor + DECL_CLASS_DESTR = 0x00001000, // class destructor + DECL_REST_ARG = 0x00002000, // ...arg formal parameter + DECL_EXTERN = 0x00004000, // decl has extern qualifier + DECL_PRIVATE = 0x00008000, // decl has private qualifier + DECL_PUBLIC = 0x00010000, // decl has public qualifier + DECL_REF = 0x00020000, // decl has & qualifier + DECL_ARGUSED = 0x00040000, // decl has _argused qualifier + DECL_OPTIONAL = 0x00080000, // decl has _optional qualifier + DECL_NAME_EQUIV = 0x00100000, // decl has _mustbetype qualifier + DECL_FORWARD = 0x00200000, // a forward decl + DECL_DONE = 0x00400000, // decl already processed + FN_PROTO_ONLY = 0x00800000, // compile fn proto only + FN_PROTO_AND_BODY = 0x01000000, // compile entire fn decl +} Decl_f; + +struct VarDecl { + Ast node; + Expr *id; + char *tclprefix; // prepend to L var name to create Tcl var name + Expr *initializer; + Expr *attrs; // optional _attributes(...) + Type *type; + ClsDecl *clsdecl; // for class member fns, class & instance vars + Sym *refsym; // for a call-by-ref parm x, ptr to &x sym + VarDecl *next; + Decl_f flags; +}; + +extern Expr *ast_mkBinOp(Op_k op, Expr *e1, Expr *e2, YYLTYPE beg, + YYLTYPE end); +extern Block *ast_mkBlock(VarDecl *decls,Stmt *body, YYLTYPE beg, + YYLTYPE end); +extern Case *ast_mkCase(Expr *expr, Stmt *body, YYLTYPE beg, + YYLTYPE end); +extern ClsDecl *ast_mkClsDecl(VarDecl *decl, YYLTYPE beg, YYLTYPE end); +extern Expr *ast_mkConst(Type *type, char *str, YYLTYPE beg, + YYLTYPE end); +extern FnDecl *ast_mkConstructor(ClsDecl *class); +extern FnDecl *ast_mkDestructor(ClsDecl *class); +extern Expr *ast_mkExpr(Expr_k kind, Op_k op, Expr *a, Expr *b, Expr *c, + YYLTYPE beg, YYLTYPE end); +extern Expr *ast_mkFnCall(Expr *id, Expr *arg_list, YYLTYPE beg, + YYLTYPE end); +extern FnDecl *ast_mkFnDecl(VarDecl *decl, Block *body, YYLTYPE beg, + YYLTYPE end); +extern ForEach *ast_mkForeach(Expr *hash, Expr *key, Expr *value, + Stmt *body, YYLTYPE beg, YYLTYPE end); +extern Expr *ast_mkId(char *name, YYLTYPE beg, YYLTYPE end); +extern Cond *ast_mkIfUnless(Expr *expr, Stmt *if_body, Stmt *else_body, + YYLTYPE beg, YYLTYPE end); +extern Loop *ast_mkLoop(Loop_k kind, Expr *pre, Expr *cond, Expr *post, + Stmt *body, YYLTYPE beg, YYLTYPE end); +extern Expr *ast_mkRegexp(char *re, YYLTYPE beg, YYLTYPE end); +extern Stmt *ast_mkStmt(Stmt_k kind, Stmt *next, YYLTYPE beg, + YYLTYPE end); +extern Switch *ast_mkSwitch(Expr *expr, Case *cases, YYLTYPE beg, + YYLTYPE end); +extern TopLev *ast_mkTopLevel(Toplv_k kind, TopLev *next, YYLTYPE beg, + YYLTYPE end); +extern Expr *ast_mkTrinOp(Op_k op, Expr *e1, Expr *e2, Expr *e3, + YYLTYPE beg, YYLTYPE end); +extern Try *ast_mkTry(Stmt *try, Expr *msg, Stmt *catch); +extern Expr *ast_mkUnOp(Op_k op, Expr *e1, YYLTYPE beg, YYLTYPE end); +extern VarDecl *ast_mkVarDecl(Type *type, Expr *name, YYLTYPE beg, + YYLTYPE end); +extern void hash_dump(Tcl_Obj *hash); +extern char *hash_get(Tcl_Obj *hash, char *key); +extern void hash_put(Tcl_Obj *hash, char *key, char *val); +extern void hash_rm(Tcl_Obj *hash, char *key); +extern Type *type_dup(Type *type); +extern Type *type_mkArray(Expr *size, Type *base_type); +extern Type *type_mkClass(void); +extern Type *type_mkFunc(Type *base_type, VarDecl *formals); +extern Type *type_mkHash(Type *index_type, Type *base_type); +extern Type *type_mkList(Type *a); +extern Type *type_mkNameOf(Type *base_type); +extern Type *type_mkScalar(Type_k kind); +extern Type *type_mkStruct(char *tag, VarDecl *members); + +#endif /* L_AST_H */ diff --git a/generic/Lcompile.c b/generic/Lcompile.c new file mode 100644 index 0000000..38fb447 --- /dev/null +++ b/generic/Lcompile.c @@ -0,0 +1,8167 @@ +/* + * Copyright (c) 2006-2009 BitMover, Inc. + */ +#include <stdio.h> +#include <stdarg.h> +#include <setjmp.h> +#include "tclInt.h" +#include "tclIO.h" +#include "tclCompile.h" +#include "tclRegexp.h" +#include "Lcompile.h" +#include "Lgrammar.h" + +/* Used by compile_spawn_system(). */ +enum { + SYSTEM_ARGV = 0x00000001, + SYSTEM_IN_STRING = 0x00000002, + SYSTEM_IN_ARRAY = 0x00000004, + SYSTEM_IN_FILENAME = 0x00000008, + SYSTEM_IN_HANDLE = 0x00000010, + SYSTEM_OUT_STRING = 0x00000020, + SYSTEM_OUT_ARRAY = 0x00000040, + SYSTEM_OUT_FILENAME = 0x00000080, + SYSTEM_OUT_HANDLE = 0x00000100, + SYSTEM_ERR_STRING = 0x00000200, + SYSTEM_ERR_ARRAY = 0x00000400, + SYSTEM_ERR_FILENAME = 0x00000800, + SYSTEM_ERR_HANDLE = 0x00001000, + SYSTEM_BACKGROUND = 0x00002000, +}; + +/* + * As of March 2009, we use a bit in the Tcl_Obj structure to + * represent when an object has the L undefined value. This avoids + * the problems we had when Tcl would shimmer undef away into another + * type, making it look defined. But we also need an undef object, as + * the value of array, hash, and struct members when they dynamically + * are brought into life. This is also the value of the "undef" + * pre-defined constant. We create one object of this type and dup it + * whenever undef is requested. + */ + +private void +undef_freeInternalRep(Tcl_Obj *o) +{ +} + +/* + * Return an error if someone tries to convert something to undef + * type. + */ +private int +undef_setFromAny(Tcl_Interp *interp, Tcl_Obj *o) +{ + Tcl_SetObjResult(interp, + Tcl_NewStringObj("cannot convert to undefined value", + -1)); + return (TCL_ERROR); +} + +/* + * Get a pointer to the "undefined" object pointer, allocating it the + * first time it is needed. Keep the refCount high because we want + * the one-and-only undef object to never be freed. + */ +Tcl_Obj ** +L_undefObjPtrPtr() +{ + static Tcl_Obj *undef_obj = NULL; + + unless (undef_obj) { + undef_obj = Tcl_NewObj(); + undef_obj->bytes = tclEmptyStringRep; + undef_obj->typePtr = &L_undefType; + undef_obj->undef = 1; + undef_obj->refCount = 1234; // arbitrary; to be recognizable + } + ASSERT(undef_obj->undef); + return (&undef_obj); +} + +int +L_isUndef(Tcl_Obj *o) +{ + return (o->undef); +} + +Tcl_ObjType L_undefType = { + "undef", + undef_freeInternalRep, + NULL, + NULL, + undef_setFromAny +}; + +/* Returned by re_kind. */ +typedef enum { + RE_NOT_AN_RE = 0x0001, + RE_CONST = 0x0002, + RE_GLOB = 0x0004, + RE_SIMPLE = 0x0008, + RE_COMPLEX = 0x0010, + RE_NEEDS_EVAL = 0x0020, +} ReKind; + +/* Used by tmp_* API. */ +typedef enum { + TMP_REUSE, + TMP_UNSET, +} TmpKind; + +/* + * Lists of allowable attributes in #pragma, _attribute, and cmd-line + * options. Each array must end with a NULL. + */ +char *L_attrs_attribute[] = { + "dis", + "fnhook", + "fntrace", + "trace_depth", + NULL +}; +char *L_attrs_cmdLine[] = { + "L", + "dis", + "fnhook", + "fntrace", + "line", + "lineadj", + "norun", + "nowarn", + "poly", + "trace_depth", + "trace_files", + "trace_funcs", + "trace_out", + "trace_script", + "warn_undefined_fns", + "version", + NULL +}; +char *L_attrs_pragma[] = { + "dis", + "fnhook", + "fntrace", + "line", + "lineadj", + "norun", + "nowarn", + "poly", + "trace_depth", + "warn_undefined_fns", + NULL +}; +char *L_attrs_Lhtml[] = { + "line", + "lineadj", +}; + +/* The next two functions are generated by flex. */ +extern void *L__scan_bytes (const char *bytes, int len); +extern void L__delete_buffer(void *buf); + +private int ast_compile(void *ast); +private void ast_free(Ast *ast_list); +private char *basenm(char *s); +private int compile_abs(Expr *expr); +private int compile_assert(Expr *expr); +private void compile_assign(Expr *expr); +private void compile_assignComposite(Expr *expr); +private void compile_assignFromStack(Expr *lhs, Type *rhs_type, Expr *expr, + int flags); +private int compile_binOp(Expr *expr, Expr_f flags); +private void compile_block(Block *block); +private void compile_break(Stmt *stmt); +private int compile_cast(Expr *expr, Expr_f flags); +private int compile_catch(Expr *expr); +private void compile_clsDecl(ClsDecl *class); +private int compile_clsDeref(Expr *expr, Expr_f flags); +private int compile_clsInstDeref(Expr *expr, Expr_f flags); +private void compile_condition(Expr *cond); +private void compile_continue(Stmt *stmt); +private void compile_defined(Expr *expr); +private int compile_die(Expr *expr); +private void compile_do(Loop *loop); +private void compile_eq_stack(Expr *expr, Type *type); +private void compile_for_while(Loop *loop); +private int compile_idxOp(Expr *expr, Expr_f flags); +private int compile_idxOp2(Expr *expr, Expr_f flags); +private int compile_expr(Expr *expr, Expr_f flags); +private int compile_exprs(Expr *expr, Expr_f flags); +private int compile_fnCall(Expr *expr); +private void compile_fnDecl(FnDecl *fun, Decl_f flags); +private void compile_fnDecls(FnDecl *fun, Decl_f flags); +private void compile_foreach(ForEach *loop); +private void compile_foreachAngle(ForEach *loop); +private void compile_foreachArray(ForEach *loop); +private void compile_foreachHash(ForEach *loop); +private void compile_foreachString(ForEach *loop); +private void compile_goto(Stmt *stmt); +private int compile_here(Expr *expr); +private void compile_ifUnless(Cond *cond); +private void compile_incdec(Expr *expr); +private int compile_insert_unshift(Expr *expr); +private int compile_join(Expr *expr); +private int compile_keys(Expr *expr); +private void compile_label(Stmt *stmt); +private int compile_length(Expr *expr); +private void compile_loop(Loop *loop); +private int compile_min_max(Expr *expr); +private int compile_fnParms(VarDecl *decl); +private int compile_popen(Expr *expr); +private int compile_pop_shift(Expr *expr); +private int compile_push(Expr *expr); +private void compile_reMatch(Expr *re); +private int compile_read(Expr *expr); +private int compile_rename(Expr *expr); +private void compile_return(Stmt *stmt); +private int compile_script(Tcl_Obj *scriptObj, Tcl_Obj *nameObj); +private void compile_shortCircuit(Expr *expr); +private int compile_sort(Expr *expr); +private int compile_spawn_system(Expr *expr); +private int compile_split(Expr *expr); +private void compile_stmt(Stmt *stmt); +private void compile_stmts(Stmt *stmt); +private void compile_switch(Switch *sw); +private void compile_switch_fast(Switch *sw); +private void compile_switch_slow(Switch *sw); +private int compile_trinOp(Expr *expr); +private int compile_trace_script(char *script); +private void compile_trycatch(Stmt *stmt); +private void compile_twiddle(Expr *expr); +private void compile_twiddleSubst(Expr *expr); +private int compile_typeof(Expr *expr); +private int compile_undef(Expr *expr); +private int compile_unOp(Expr *expr); +private int compile_var(Expr *expr, Expr_f flags); +private void compile_varDecl(VarDecl *decl); +private void compile_varDecls(VarDecl *decls); +private int compile_warn(Expr *expr); +private int compile_write(Expr *expr); +private void copyout_parms(Expr *actuals); +private Tcl_Obj *do_getline(Tcl_Interp *interp, Tcl_Channel chan); +private void emit_globalUpvar(Sym *sym); +private void emit_instrForLOp(Expr *expr, Type *type); +private void emit_jmp_back(TclJumpType jmp_type, int offset); +private Jmp *emit_jmp_fwd(int op, Jmp *next); +private void fixup_jmps(Jmp **jumps); +private int fnCallBegin(); +private void fnCallEnd(int lev); +private int fnInArgList(); +private Frame *frame_find(Frame_f flags); +private char *frame_name(void); +private void frame_pop(void); +private void frame_push(void *node, char *name, Frame_f flags); +private void frame_resumeBody(); +private void frame_resumePrologue(); +private char *get_text(Expr *expr); +private int has_END(Expr *expr); +private void init_predefined(); +private Type *iscallbyname(VarDecl *formal); +private int ispatternfn(char *name, Expr **foo, Expr **Foo_star, + Expr **opts, int *nopts); +private Label *label_lookup(Stmt *stmt, Label_f flags); +private Expr *mkId(char *name); +private int parse_options(int objc, Tcl_Obj **objv, char *allowed[]); +private int parse_script(char *str, Ast **L_ast, Tcl_Obj *nameObj); +private void proc_mkArg(Proc *proc, VarDecl *decl); +private int push_index(Expr *expr, int flags); +private int push_parms(Expr *actuals, VarDecl *formals); +private int push_regexpModifiers(Expr *regexp); +private ReKind re_kind(Expr *re, Tcl_DString *ds); +private int re_submatchCnt(Expr *re); +private VarDecl *struct_lookupMember(Type *t, Expr *idx, int *offset); +private Sym *sym_mk(char *name, Type *t, Decl_f flags); +private Sym *sym_lookup(Expr *id, Expr_f flags); +private Sym *sym_store(VarDecl *decl); +private Tmp *tmp_get(TmpKind kind); +private void tmp_free(Tmp *tmp); +private void tmp_freeAll(Tmp *tmp); +private void track_cmd(int codeOffset, void *node); +private void type_free(Type *type_list); +private int typeck_spawn(Expr *in, Expr *out, Expr *err); +private int typeck_system(Expr *in, Expr *out, Expr *err); + +Linterp *L; // per-interp L state +Type *L_int; // pre-defined types +Type *L_float; +Type *L_string; +Type *L_void; +Type *L_var; +Type *L_poly; +Type *L_widget; + +/* + * L built-in functions. + */ +static struct { + char *name; + int (*fn)(Expr *); +} builtins[] = { + { "abs", compile_abs }, + { "assert", compile_assert }, + { "catch", compile_catch }, + { "die", compile_die }, + { "here", compile_here }, + { "insert", compile_insert_unshift }, + { "join", compile_join }, + { "keys", compile_keys }, + { "length", compile_length }, + { "max", compile_min_max }, + { "min", compile_min_max }, + { "popen", compile_popen }, + { "pop", compile_pop_shift }, + { "push", compile_push }, + { "read", compile_read }, + { "rename", compile_rename }, + { "shift", compile_pop_shift }, + { "sort", compile_sort }, + { "split", compile_split }, + { "spawn", compile_spawn_system }, + { "system", compile_spawn_system }, + { "typeof", compile_typeof }, + { "undef", compile_undef }, + { "unshift", compile_insert_unshift }, + { "warn", compile_warn }, + { "write", compile_write }, +}; + +/* + * L compiler entry point. + */ +int +Tcl_LObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[]) +{ + char *s; + int argc, ret; + Tcl_Obj **argvList; + + /* Extract the L state from the interp. */ + L = Tcl_GetAssocData(interp, "L", NULL); + + /* + * Verify that lib L was loaded. L fails badly if lib L isn't + * there, and this catches cases where the user overrides the + * Tcl library path. + */ + unless (Tcl_GetVar(L->interp, "::L_libl_initted", 0)) { + Tcl_SetResult(L->interp, "fatal -- libl.tcl not found", 0); + return (TCL_ERROR); + } + + if (objc < 2) { + Tcl_WrongNumArgs(interp, 1, objv, "?options? l-program"); + return (TCL_ERROR); + } + + /* Parse options from both the Tcl L command and the tclsh cmd line. */ + L->errs = NULL; + L->options = Tcl_NewDictObj(); + ret = parse_options(objc-1, (Tcl_Obj **)(objv+1), L_attrs_cmdLine); + unless (ret == TCL_OK) { + Tcl_SetObjResult(interp, L->errs); + return (ret); + } + if (L->global->tclsh_argv && + Tcl_ListObjGetElements(L->interp, L->global->tclsh_argv, &argc, + &argvList) == TCL_OK) { + ret = parse_options(argc-1, argvList+1, L_attrs_cmdLine); + unless (ret == TCL_OK) { + Tcl_SetObjResult(interp, L->errs); + return (ret); + } + } + + /* L_synerr() longjmps back here on a parser syntax error. */ + if (setjmp(L->jmp)) { + Tcl_SetObjResult(interp, L->errs); + return (TCL_ERROR); + } + + /* + * If a function-tracing script was specified in + * --trace_script or L_TRACE_SCRIPT (takes precedence), + * compile that (once) but only after libL has been compiled. + */ + unless (hash_get(L->options, "trace_script_compiled")) { + if ((s = getenv("L_TRACE_SCRIPT"))) { + hash_put(L->options, "trace_script", s); + } + if ((s = hash_get(L->options, "trace_script")) && + Tcl_GetVar(L->interp, "::L_libl_done", 0)) { + hash_put(L->options, "trace_script_compiled", "yes"); + s = ckstrdup(s); + ret = compile_trace_script(s); + if (ret != TCL_OK) return (ret); + } + } + + /* + * Propagate some cmd-line options to env variables for lib L. + * Pre-existing env variables take precedence. + */ + if ((s = hash_get(L->options, "trace_funcs"))) { + unless (getenv("L_TRACE_FUNCS")) { + s = cksprintf("L_TRACE_FUNCS=%s", s); + putenv(s); + } + } + if ((s = hash_get(L->options, "trace_files"))) { + unless (getenv("L_TRACE_FILES")) { + s = cksprintf("L_TRACE_FILES=%s", s); + putenv(s); + } + } + if ((s = hash_get(L->options, "trace_out"))) { + unless (getenv("L_TRACE_OUT")) { + s = cksprintf("L_TRACE_OUT=%s", s); + putenv(s); + } + } + if ((s = hash_get(L->options, "fnhook"))) { + unless (getenv("L_TRACE_HOOK")) { + s = cksprintf("L_TRACE_HOOK=%s", s); + putenv(s); + } + } + if ((s = hash_get(L->options, "fntrace"))) { + unless (getenv("L_TRACE_ALL")) { + s = cksprintf("L_TRACE_ALL=%s", s); + putenv(s); + } + } + if ((s = hash_get(L->options, "dis"))) { + unless (getenv("L_DISASSEMBLE")) { + s = cksprintf("L_DISASSEMBLE=%s", s); + putenv(s); + } + } + + /* This allows the old comparison-op syntax (eq ne lt le gt ge). */ + if (getenv("_L_ALLOW_EQ_OPS")) { + hash_put(L->options, "allow_eq_ops", "yes"); + } + + return (compile_script(objv[objc-1], ((Interp *)L->interp)->scriptFile)); +} + +private int +compile_trace_script(char *script) +{ + int len, ret; + Tcl_Channel chan; + Tcl_Obj *nameObj, *scriptObj; + + len = strlen(script); + if ((len > 3) && (script[len-2] == '.') && (script[len-1] == 'l')) { + nameObj = Tcl_NewStringObj(script, -1); + Tcl_IncrRefCount(nameObj); + chan = Tcl_FSOpenFileChannel(L->interp, nameObj, "r", 0644); + unless (chan) return (TCL_ERROR); + scriptObj = Tcl_NewObj(); + Tcl_IncrRefCount(scriptObj); + ret = Tcl_ReadChars(chan, scriptObj, -1, 0); + Tcl_Close(L->interp, chan); + if (ret < 0) { + Tcl_DecrRefCount(scriptObj); + return (TCL_ERROR); + } + } else { + nameObj = Tcl_NewStringObj("L_TRACE_SCRIPT", -1); + scriptObj = Tcl_ObjPrintf( + "void L_fn_hook(_argused int pre, _argused poly av[], " + "_argused poly ret) { %s ;}", + script); + hash_put(L->options, "fnhook", "L_fn_hook"); + Tcl_IncrRefCount(nameObj); + } + ret = compile_script(scriptObj, nameObj); + Tcl_DecrRefCount(nameObj); + return (ret); +} + +private int +compile_script(Tcl_Obj *scriptObj, Tcl_Obj *nameObj) +{ + int ret; + Ast *ast; +#ifdef TCL_COMPILE_DEBUG + char *s; +#endif + + L->script = Tcl_NewObj(); + Tcl_IncrRefCount(L->script); + L->script_len = 0; + + ret = parse_script(TclGetString(scriptObj), &ast, nameObj); + + if ((ret == TCL_OK) && ast) { + ret = ast_compile(ast); + } + +#ifdef TCL_COMPILE_DEBUG + if ((s = getenv("L_TRACE_BYTECODES"))) { + extern int tclTraceExec; + tclTraceExec = atoi(s); + } +#endif + return (ret); +} + +/* + * Parse key=val (where =val is optional and is replaced by "yes" if + * omitted) and add to the L->options hash. Strip any leading -'s from + * key so that -key and --key both work. Replace all other -'s with _'s + * so that --trace-files becomes trace_files. + */ +private int +parse_options(int objc, Tcl_Obj **objv, char *allowed[]) +{ + int i, ret = TCL_OK; + char *key, *newkey, *p, *val; + char **q; + + for (i = 0; i < objc; ++i) { + key = Tcl_GetString(objv[i]); + unless (key[0] == '-') break; + /* Look for key=val */ + val = strchr(key, '='); + if (val) { + *val = 0; + } + newkey = ckalloc(strlen(key)+1); + /* Skip past all leading -'s in the key */ + while (*key == '-') ++key; + /* Now copy except replace all other -'s with _ */ + for (p = newkey; *key; ++key, ++p) { + *p = *key; + if (*p == '-') *p = '_'; + } + *p = 0; + key = newkey; + for (q = allowed; *q; ++q) { + if (!strcmp(key, *q)) break; + } + unless (*q) { + L_errf(NULL, "illegal option '%s'", + Tcl_GetString(objv[i])); + ret = TCL_ERROR; + } + if (val) { + hash_put(L->options, key, val+1); + *val = '='; + } else { + hash_put(L->options, key, "yes"); + } + } + return (ret); +} + +/* + * Parse an L script into an AST. Parsing and compiling are broken into two + * stages in order to support an interactive mode that parses many times + * before finally compiling. + */ +private int +parse_script(char *str, Ast **ast_p, Tcl_Obj *nameObj) +{ + char *prepend, *s; + void *lex_buffer; + + L_typeck_init(); + + if (nameObj) { + L->file = ckstrdup(Tcl_GetString(nameObj)); + L->dir = L_dirname(L->file); + } else { + char *cwd = getcwd(NULL, 0); + L->file = ckstrdup("<stdin>"); + L->dir = ckstrdup(cwd); + free(cwd); + } + + /* + * Calculate the starting line # from the --line and --lineadj + * cmd-line options and inject a #line directive at the start + * of the source code. This communicates the file-relative + * line # to code elsewhere that prints run-time error + * messages. + */ + if ((s = getenv("_L_LINE"))) { + L->line = strtoul(s, NULL, 10); + } else { + if ((s = hash_get(L->options, "line"))) { + L->line = atoi(s); + } else { + L->line = 1; + } + if ((s = hash_get(L->options, "lineadj"))) { + L->line += atoi(s); + } + } + prepend = cksprintf("#line %d\n", L->line); + str = cksprintf("%s%s", prepend, str); + + L->token_off = 0; + L->prev_token_off = 0; + L->prev_token_len = 0; + L->errs = NULL; + L_lex_start(); + lex_buffer = (void *)L__scan_bytes(str, strlen(str)); + + L_parse(); + ASSERT(ast_p); + *ast_p = L->ast; + + L__delete_buffer(lex_buffer); + ckfree(str); + ckfree(prepend); + + if (L->errs) { + Tcl_SetObjResult(L->interp, L->errs); + return (TCL_ERROR); + } + return (TCL_OK); +} + +/* Compile an L AST into Tcl ByteCodes. The envPtr may be NULL. */ +private int +ast_compile(void *ast) +{ + int ret = TCL_OK; + TopLev *toplev; + static int ctr = 0; + + ASSERT(((Ast *)ast)->type == L_NODE_TOPLEVEL); + + L->toplev = cksprintf("%d%%l_toplevel", ctr++); + + init_predefined(); // set the L pre-defined identifiers + + /* + * Two frames get pushed, one for private globals that exist + * at file scope, and one for the top-level code. See the + * comment in sym_store(). + */ + frame_push(NULL, NULL, SCRIPT|SEARCH); + frame_push(NULL, L->toplev, FUNC|TOPLEV|SKIP); + + /* + * Before compiling, enter prototypes for all functions into + * the global symbol table. + */ + for (toplev = (TopLev *)ast; toplev; toplev = toplev->next) { + switch (toplev->kind) { + case L_TOPLEVEL_FUN: + compile_fnDecl(toplev->u.fun, FN_PROTO_ONLY); + break; + default: + break; + } + } + + for (toplev = (TopLev *)ast; toplev; toplev = toplev->next) { + switch (toplev->kind) { + case L_TOPLEVEL_CLASS: + compile_clsDecl(toplev->u.class); + break; + case L_TOPLEVEL_FUN: + compile_fnDecl(toplev->u.fun, FN_PROTO_AND_BODY); + break; + case L_TOPLEVEL_GLOBAL: + compile_varDecls(toplev->u.global); + break; + case L_TOPLEVEL_STMT: + compile_stmts(toplev->u.stmt); + break; + default: + L_bomb("Unexpected toplevel stmt type %d", toplev->kind); + } + } + + /* If main() was defined, emit a %%call_main_if_defined call. */ + if (sym_lookup(mkId("main"), L_NOWARN)) { + if (hash_get(L->options, "warn_undefined_fns")) { + push_lit("%%check_L_fns"); + emit_invoke(1); + } + push_lit("%%call_main_if_defined"); + emit_invoke(1); + } + + push_lit(""); + TclEmitOpcode(INST_DONE, L->frame->envPtr); + frame_pop(); + frame_pop(); + + if (L->errs) { + Tcl_SetObjResult(L->interp, L->errs); + return (TCL_ERROR); + } + + if (hash_get(L->options, "norun") || (L->err && !getenv("_L_TEST"))) { + /* Still check for undefined functions if requested. */ + if (hash_get(L->options, "warn_undefined_fns") && + sym_lookup(mkId("main"), L_NOWARN)) { + if (L->frame->envPtr) { + push_lit("%%check_L_fns"); + emit_invoke(1); + } else { + Tcl_Eval(L->interp, "%%check_L_fns"); + } + } + return (TCL_OK); + } + + /* Invoke the top-level code that was just compiled. */ + if (L->frame->envPtr) { + push_lit("LtraceInit"); + emit_invoke(1); + push_lit(L->toplev); + emit_invoke(1); + } else { + if (Tcl_GetVar(L->interp, "::L_libl_done", 0)) { + ret = Tcl_Eval(L->interp, "LtraceInit"); + } + if (ret == TCL_OK) ret = Tcl_Eval(L->interp, L->toplev); + } + return (ret); +} + +private void +init_predefined() +{ +#define SET_INT(name, val) \ + Tcl_SetVar2Ex(L->interp, (name), NULL, Tcl_NewIntObj(val), \ + TCL_GLOBAL_ONLY) + + /* + * These are flags used by compile_spawn_system() when + * compiling calls to libl.tcl's system_(). Pre-define them as L + * variables so that system_() in lib L can see their values. + */ + SET_INT("SYSTEM_ARGV__", SYSTEM_ARGV); + SET_INT("SYSTEM_IN_STRING__", SYSTEM_IN_STRING); + SET_INT("SYSTEM_IN_ARRAY__", SYSTEM_IN_ARRAY); + SET_INT("SYSTEM_IN_FILENAME__", SYSTEM_IN_FILENAME); + SET_INT("SYSTEM_IN_HANDLE__", SYSTEM_IN_HANDLE); + SET_INT("SYSTEM_OUT_STRING__", SYSTEM_OUT_STRING); + SET_INT("SYSTEM_OUT_ARRAY__", SYSTEM_OUT_ARRAY); + SET_INT("SYSTEM_OUT_FILENAME__", SYSTEM_OUT_FILENAME); + SET_INT("SYSTEM_OUT_HANDLE__", SYSTEM_OUT_HANDLE); + SET_INT("SYSTEM_ERR_STRING__", SYSTEM_ERR_STRING); + SET_INT("SYSTEM_ERR_ARRAY__", SYSTEM_ERR_ARRAY); + SET_INT("SYSTEM_ERR_FILENAME__", SYSTEM_ERR_FILENAME); + SET_INT("SYSTEM_ERR_HANDLE__", SYSTEM_ERR_HANDLE); + SET_INT("SYSTEM_BACKGROUND__", SYSTEM_BACKGROUND); + +#undef SET_INT +} + +private void +compile_clsDecl(ClsDecl *clsdecl) +{ + ASSERT(clsdecl->constructors); + ASSERT(clsdecl->destructors); + + /* + * A class creates two scopes, one for the class symbols and + * the other for its top-level code (class variable + * initializers). See the comments in sym_store(). The class + * symtab is persisted so it can be later retrieved from the + * class type to support obj->var or classname->var lookups. + */ + frame_push(NULL, NULL, CLS_OUTER|SEARCH|KEEPSYMS); + clsdecl->symtab = L->frame->symtab; + frame_push(NULL, NULL, CLS_TOPLEV|SKIP); + L->frame->clsdecl = clsdecl; + + frame_resumePrologue(); + push_lit("::namespace"); + push_lit("eval"); + push_litf("::L::_class_%s", clsdecl->decl->id->str); + push_lit("variable __num 0"); + emit_invoke(4); + emit_pop(); + frame_resumeBody(); + + compile_varDecls(clsdecl->clsvars); + /* Process function decls first, then compile the bodies. */ + compile_fnDecls(clsdecl->fns, FN_PROTO_ONLY); + compile_fnDecls(clsdecl->constructors, FN_PROTO_ONLY); + compile_fnDecls(clsdecl->destructors, FN_PROTO_ONLY); + compile_fnDecls(clsdecl->constructors, FN_PROTO_AND_BODY); + compile_fnDecls(clsdecl->destructors, FN_PROTO_AND_BODY); + compile_fnDecls(clsdecl->fns, FN_PROTO_AND_BODY); + + frame_pop(); + frame_pop(); +} + +/* + * Take an expr list consisting of + * + * id like the arg to "#pragma fntrace" + * id=constant like the arg to "#pragma fnhook=myhook" + * + * and add hash entries to the given hash. The id's here aren't taken + * as variables, but the name of the id itself is used, to avoid + * making the programmer put everything inside quotes. This is used + * for #pragmas and function attributes. + */ +void +L_compile_attributes(Tcl_Obj *hash, Expr *expr, char *allowed[]) +{ + Expr *arg; + char *key, *val; + char **p; + + ASSERT(hash); + for (arg = expr; arg; arg = arg->next) { + if (arg->kind == L_EXPR_ID) { + key = arg->str; + val = "yes"; + } else if ((arg->kind == L_EXPR_BINOP) && + (arg->op == L_OP_EQUALS)) { + key = arg->a->str; + val = arg->b->str; + unless (isconst(arg->b) || (arg->b->kind == L_EXPR_ID)) { + L_errf(arg, + "non-constant value for attribute %s", + key); + } + } else { + L_errf(arg, "illegal attribute; not id or id=constant"); + continue; + } + for (p = allowed; *p; ++p) { + if (!strcmp(key, *p)) break; + } + unless (*p) { + L_errf(expr, "illegal attribute '%s'", key); + } else { + hash_put(hash, key, val); + } + } +} + +private void +compile_fnDecls(FnDecl *fun, Decl_f flags) +{ + for (; fun; fun = fun->next) { + compile_fnDecl(fun, flags); + } +} + +private void +compile_fnDecl(FnDecl *fun, Decl_f flags) +{ + int i; + VarDecl *decl = fun->decl; + char *name = decl->id->str; + char *clsname = NULL; + ClsDecl *clsdecl = NULL; + Sym *self_sym = NULL; + Sym *sym; + + flags |= decl->flags; + + ASSERT(fun && decl); + ASSERT(!(flags & SCOPE_LOCAL)); + ASSERT(flags & (SCOPE_CLASS | SCOPE_GLOBAL | SCOPE_SCRIPT)); + ASSERT(flags & (DECL_FN | DECL_CLASS_FN)); + // DECL_CLASS_FN ==> DECL_PUBLIC | DECL_PRIVATE + ASSERT(!(flags & DECL_CLASS_FN) || + (flags & (DECL_PUBLIC | DECL_PRIVATE))); + ASSERT(flags & (FN_PROTO_ONLY | FN_PROTO_AND_BODY)); + + /* + * Sort out the possible error cases: + * + * - main() declared with wrong types for formals + * - name illegal + * - name already declared as a variable + * - proto already declared and doesn't match this decl + * - this decl declares function body but body already declared + */ + if (!strcmp(name, "main")) L_typeck_main(decl); + if (name[0] == '_') { + L_errf(decl->id, "function names cannot begin with _"); + } + if (!strcmp(name, "END")) { + L_errf(decl->id, "cannot use END for function name"); + } else if (!strcmp(name, "undef")) { + L_errf(decl->id, "cannot use undef for function name"); + } + for (i = 0; i < sizeof(builtins)/sizeof(builtins[0]); ++i) { + if (!strcmp(builtins[i].name, name)) { + L_errf(decl->id, + "function '%s' conflicts with built-in", + name); + return; + } + } + sym = sym_lookup(decl->id, L_NOWARN|L_NOTUSED); + if (sym) { + unless (sym->kind & L_SYM_FN) { + L_errf(fun, "%s already declared as a variable",name); + return; + } else if ((sym->kind & L_SYM_FNBODY) && fun->body) { + L_errf(fun, "function %s already declared", name); + return; + } else unless (L_typeck_same(decl->type, sym->type)) { + L_errf(fun, "does not match other declaration of %s", + name); + return; + } + } else { + sym = sym_store(decl); + unless (sym) return; + } + + /* Check arg and return types for legality. */ + L_typeck_declType(decl); + + if (!fun->body || (flags & FN_PROTO_ONLY)) return; + + /* + * Add this function's attributes to the hash of all declared + * functions in L->fn_decls which is put into the Tcl global + * variable L_fnsDeclared, for use by the function-tracing + * subsystem code in libl.tcl when tracing is enabled. + */ + L_compile_attributes(fun->attrs, decl->attrs, L_attrs_attribute); + if (flags & FN_PROTO_AND_BODY) { + Tcl_Obj *key; + Var *arrayPtr, *varPtr; + + /* + * L->fn_decls can get out of date when the L code in + * lib L writes to L_fnsDeclared, so grab the latest. + */ + varPtr = TclLookupVar(L->interp, + "L_fnsDeclared", + NULL, + TCL_GLOBAL_ONLY, + NULL, + 0, + 0, + &arrayPtr); + if (L->fn_decls != varPtr->value.objPtr) { + L->fn_decls = varPtr->value.objPtr; + } + + hash_put(fun->attrs, "name", name); + hash_put(fun->attrs, "file", basenm(fun->node.loc.file)); + if (Tcl_IsShared(L->fn_decls)) { + L->fn_decls = Tcl_DuplicateObj(L->fn_decls); + Tcl_SetVar2Ex(L->interp, "L_fnsDeclared", NULL, + L->fn_decls, TCL_GLOBAL_ONLY); + } + key = Tcl_NewStringObj(sym->tclname, -1); + Tcl_IncrRefCount(key); + Tcl_DictObjPut(L->interp, L->fn_decls, key, fun->attrs); + Tcl_DecrRefCount(key); + } + + frame_push(fun, sym->tclname, FUNC|SEARCH); + sym->kind |= L_SYM_FNBODY; + L->frame->block = (Ast *)fun; + + compile_fnParms(decl); + + /* Gather class decl and name, for class member functions. */ + clsdecl = fun->decl->clsdecl; + if (clsdecl) clsname = clsdecl->decl->id->str; + + /* + * For private class member fns and the constructor, declare + * the local variable "self". For public member fns, lookup + * "self" which is required to be the first parameter (and is + * added by compile_fnParms if not present). + */ + if (isClsConstructor(decl) || isClsFnPrivate(decl)) { + self_sym = sym_mk("self", + clsdecl->decl->type, + SCOPE_LOCAL | DECL_LOCAL_VAR); + ASSERT(self_sym && self_sym->idx >= 0); + self_sym->used_p = TRUE; + } else if (isClsFnPublic(decl)) { + self_sym = sym_lookup(mkId("self"), L_NOWARN); + ASSERT(self_sym && self_sym->idx >= 0); + } + + /* + * For a constructor, before compiling the user's + * constructor body, emit code to increment the class instance + * #, set "self" to the namespace name of the class instance, + * create the namespace, then compile the instance-variable + * initializers. Basically this: + * + * incrStkImm ::L::_class_<cls_name>::__num + * set self ::L::_instance_<cls_name>${__num} + * namespace eval $self {} + * ...instance variable initializers... + * ...user's constructor body... + */ + if (isClsConstructor(decl)) { + frame_resumePrologue(); + ASSERT(clsdecl && clsname && self_sym); + push_litf("::L::_class_%s::__num", clsname); + TclEmitInstInt1(INST_INCR_STK_IMM, 1, L->frame->envPtr); + emit_pop(); + push_lit("::namespace"); + push_lit("eval"); + push_litf("::L::_instance_%s", clsname); + push_litf("::L::_class_%s::__num", clsname); + TclEmitOpcode(INST_LOAD_STK, L->frame->envPtr); + TclEmitInstInt1(INST_STR_CONCAT1, 2, L->frame->envPtr); + emit_store_scalar(self_sym->idx); + push_lit(""); + emit_invoke(4); + emit_pop(); + frame_resumeBody(); + compile_varDecls(clsdecl->instvars); + } + + /* + * For private member functions, upvar "self" to the "self" in + * the calling frame. This works because only other class member + * functions can call private member functions, and they have "self". + */ + if (isClsFnPrivate(decl)) { + frame_resumePrologue(); + push_lit("1"); + push_lit("self"); + TclEmitInstInt4(INST_UPVAR, self_sym->idx, L->frame->envPtr); + emit_pop(); + frame_resumeBody(); + } + + L->enclosing_func = fun; + L->enclosing_func_frame = L->frame; + compile_block(fun->body); + L->enclosing_func = NULL; + L->enclosing_func_frame = NULL; + + /* + * Emit a "fall off the end" implicit return for void + * functions. Class constructors return the value of "self". + * Non-void functions throw an exception if you fall + * off the end. + */ + if (isClsConstructor(decl)) { + emit_load_scalar(self_sym->idx); + } else if (isvoidtype(decl->type->base_type)) { + push_lit(""); + } else { + push_lit("::throw"); + push_lit("{FUNCTION NO-RETURN-VALUE " + "{no value returned from function}}"); + push_lit("no value returned from function"); + emit_invoke(3); + } + + /* + * Fix-up the return jmps so that all return stmts jump to here. + * The return value will already be on the run-time stack. + */ + fixup_jmps(&L->frame->ret_jmps); + + /* + * For class destructor, delete the instance namespace. + */ + if (isClsDestructor(decl)) { + ASSERT(self_sym); + push_lit("::namespace"); + push_lit("delete"); + emit_load_scalar(self_sym->idx); + emit_invoke(3); + emit_pop(); + } + + TclEmitOpcode(INST_DONE, L->frame->envPtr); + + frame_pop(); +} + +/* + * Push a semantic-stack frame. If flags & FUNC, start a new proc + * too. To support the delayed generation of proc prologue code, we + * allocate two CompileEnv's, one for the proc body and one for its + * prologue. You switch between the two with frame_resumePrologue() + * and frame_resumeBody(). A jump is emitted at the head of the proc + * that jumps to the end, and when the proc is done being compiled, + * the prologue code is emitted at the end along with a jump back. + * This provides a way to lazily output proc initialization code, such + * as the upvars for accessing globals and class variables. + */ +private void +frame_push(void *node, char *name, Frame_f flags) +{ + Frame *frame; + Proc *proc; + CompileEnv *bodyEnvPtr, *prologueEnvPtr; + + frame = (Frame *)ckalloc(sizeof(Frame)); + memset(frame, 0, sizeof(*frame)); + frame->flags = flags; + frame->symtab = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(frame->symtab, TCL_STRING_KEYS); + frame->labeltab = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(frame->labeltab, TCL_STRING_KEYS); + frame->prevFrame = L->frame; + L->frame = frame; + + unless (frame->flags & FUNC) { + frame->block = node; + if (frame->prevFrame) { + frame->envPtr = frame->prevFrame->envPtr; + frame->bodyEnvPtr = frame->prevFrame->bodyEnvPtr; + frame->prologueEnvPtr = frame->prevFrame->prologueEnvPtr; + } + return; + } + + bodyEnvPtr = (CompileEnv *)ckalloc(sizeof(CompileEnv)); + prologueEnvPtr = (CompileEnv *)ckalloc(sizeof(CompileEnv)); + frame->bodyEnvPtr = bodyEnvPtr; + frame->prologueEnvPtr = prologueEnvPtr; + frame->envPtr = bodyEnvPtr; + + proc = (Proc *)ckalloc(sizeof(Proc)); + proc->iPtr = (struct Interp *)L->interp; + proc->refCount = 1; + proc->numArgs = 0; + proc->numCompiledLocals = 0; + proc->firstLocalPtr = NULL; + proc->lastLocalPtr = NULL; + proc->bodyPtr = Tcl_NewObj(); + Tcl_IncrRefCount(proc->bodyPtr); + TclInitCompileEnv(L->interp, bodyEnvPtr, TclGetString(L->script), + L->script_len, NULL, 0); + bodyEnvPtr->procPtr = proc; + + TclInitCompileEnv(L->interp, prologueEnvPtr, NULL, 0, NULL, 0); + + frame->proc = proc; + frame->name = name; + + /* + * Emit a jump to what will eventually be the prologue code + * (output by frame_pop()). + */ + frame->end_jmp = emit_jmp_fwd(INST_JUMP4, NULL); + frame->proc_top = currOffset(frame->envPtr); +} + +private void +frame_resumePrologue() +{ + L->frame->envPtr = L->frame->prologueEnvPtr; +} + +private void +frame_resumeBody() +{ + L->frame->envPtr = L->frame->bodyEnvPtr; +} + +private void +frame_pop() +{ + int off; + Frame *frame = L->frame; + Proc *proc = frame->proc; + Sym *sym; + Label *label; + ByteCode *codePtr; + Tcl_HashEntry *hPtr; + Tcl_HashSearch hSearch; + + /* + * Emit proc prologue code and the jump back to the head of + * the proc. Splice in any code in the frame->prologueEnvPtr + * CompileEnv. This is dependent on CompileEnv details. + */ + if (frame->flags & FUNC) { + CompileEnv *body = frame->bodyEnvPtr; + CompileEnv *prologue = frame->prologueEnvPtr; + int len = prologue->codeNext - prologue->codeStart; + + ASSERT(frame->envPtr == frame->bodyEnvPtr); + + fixup_jmps(&frame->end_jmp); + while ((body->codeNext + len) >= body->codeEnd) { + TclExpandCodeArray(body); + } + memcpy(body->codeNext, prologue->codeStart, len); + body->codeNext += len; + if (prologue->maxStackDepth > body->maxStackDepth) { + body->maxStackDepth = prologue->maxStackDepth; + } + off = currOffset(frame->envPtr); + TclEmitInstInt4(INST_JUMP4, frame->proc_top-off, frame->envPtr); + } + + /* + * Check for unused local symbols, and free the frame's symbol table. + */ + for (hPtr = Tcl_FirstHashEntry(frame->symtab, &hSearch); + hPtr != NULL; + hPtr = Tcl_NextHashEntry(&hSearch)) { + sym = (Sym *)Tcl_GetHashValue(hPtr); + unless (sym->used_p || !(sym->kind & L_SYM_LVAR) || + (sym->decl->flags & DECL_ARGUSED)) { + L_warnf(sym->decl, "%s unused", sym->name); + } + unless (frame->flags & KEEPSYMS) { + ckfree(sym->name); + ckfree(sym->tclname); + ckfree((char *)sym); + } + } + unless (frame->flags & KEEPSYMS) { + Tcl_DeleteHashTable(frame->symtab); + ckfree((char *)frame->symtab); + } + + /* + * Check for unresolved labels, and free the frame's label table. + */ + for (hPtr = Tcl_FirstHashEntry(frame->labeltab, &hSearch); + hPtr != NULL; + hPtr = Tcl_NextHashEntry(&hSearch)) { + label = (Label *)Tcl_GetHashValue(hPtr); + unless (label->offset >= 0) { + L_err("label %s referenced but not defined", + label->name); + } + ckfree((char *)label); + } + Tcl_DeleteHashTable(frame->labeltab); + ckfree((char *)frame->labeltab); + + /* + * Create the Tcl command and free the old frame. + */ + if (frame->flags & FUNC) { + TclInitByteCodeObj(proc->bodyPtr, frame->envPtr); + proc->cmdPtr = (Command *)Tcl_CreateObjCommand(L->interp, + frame->name, + TclObjInterpProc, + (ClientData)proc, + TclProcDeleteProc); + // Don't recompile on compileEpoch changes. + codePtr = (ByteCode *)proc->bodyPtr->internalRep.twoPtrValue.ptr1; + codePtr->flags |= TCL_BYTECODE_PRECOMPILED; + TclFreeCompileEnv(frame->bodyEnvPtr); + TclFreeCompileEnv(frame->prologueEnvPtr); + ckfree((char *)frame->bodyEnvPtr); + ckfree((char *)frame->prologueEnvPtr); + } + + L->frame = frame->prevFrame; + tmp_freeAll(frame->tmps); + ckfree((char *)frame); +} + +private Frame * +frame_find(Frame_f flags) +{ + Frame *f = L->frame; + + ASSERT(f); + while (f && !(f->flags & flags)) f = f->prevFrame; + return (f); +} + +private char * +frame_name() +{ + if (L->enclosing_func) { + return(L->enclosing_func->decl->id->str); + } else { + return(L->toplev); + } +} + +private void +compile_varInitializer(VarDecl *decl) +{ + int start_off = currOffset(L->frame->envPtr); + + unless (decl->initializer) { + decl->initializer = ast_mkBinOp(L_OP_EQUALS, + decl->id, + mkId("undef"), + decl->node.loc, + decl->node.loc); + } + compile_expr(decl->initializer, L_DISCARD); + track_cmd(start_off, decl); +} + +private void +compile_varDecl(VarDecl *decl) +{ + char *name; + Sym *sym; + + /* + * Process any declaration only once, but generate code for + * its initializers each time through here. This is for class + * constructors where the class instance variables get + * compiled once for each constructor. + */ + if (decl->flags & DECL_DONE) { + compile_varInitializer(decl); + return; + } + decl->flags |= DECL_DONE; + + ASSERT(decl->id && decl->type); + + name = decl->id->str; + + unless (L_typeck_declType(decl)) return; + + if (decl->flags & DECL_LOCAL_VAR) { + if (name[0] == '_') { + L_errf(decl, + "local variable names cannot begin with _"); + } + if (decl->flags & (DECL_PRIVATE | DECL_PUBLIC)) { + L_errf(decl, + "public/private qualifiers illegal for locals"); + decl->flags &= ~(DECL_PRIVATE | DECL_PUBLIC); + } + } + if (!strcmp(name, "END")) { + L_errf(decl, "cannot use END for variable name"); + return; + } else if (!strcmp(name, "undef")) { + L_errf(decl, "cannot use undef for variable name"); + return; + } + if ((decl->type->kind == L_CLASS) && + !strcmp(name, decl->type->u.class.clsdecl->decl->id->str)) { + L_errf(decl, "cannot declare object with same name as class"); + } + + sym = sym_store(decl); + unless (sym) return; // bail if multiply declared + + if (decl->flags & DECL_EXTERN) { + if (decl->initializer) { + L_errf(decl, "extern initializers illegal"); + } + unless (L->frame->flags & TOPLEV) { + L_errf(decl, "externs legal only at global scope"); + } + sym->used_p = TRUE; // to suppress extraneous warning + return; + } + + compile_varInitializer(decl); + + /* Mark var as unused even though it was just initialized. */ + sym->used_p = FALSE; +} + +private void +compile_varDecls(VarDecl *decls) +{ + for (; decls; decls = decls->next) { + compile_varDecl(decls); + } +} + +private void +compile_stmt(Stmt *stmt) +{ + int start_off = currOffset(L->frame->envPtr); + + unless (stmt) return; + switch (stmt->kind) { + case L_STMT_BLOCK: + frame_push(stmt, NULL, SEARCH); + compile_block(stmt->u.block); + frame_pop(); + break; + case L_STMT_EXPR: + compile_exprs(stmt->u.expr, L_DISCARD); + break; + case L_STMT_COND: + compile_ifUnless(stmt->u.cond); + break; + case L_STMT_LOOP: + compile_loop(stmt->u.loop); + break; + case L_STMT_SWITCH: + compile_switch(stmt->u.swich); + break; + case L_STMT_FOREACH: + compile_foreach(stmt->u.foreach); + break; + case L_STMT_RETURN: + compile_return(stmt); + break; + case L_STMT_BREAK: + compile_break(stmt); + break; + case L_STMT_CONTINUE: + compile_continue(stmt); + break; + case L_STMT_LABEL: + compile_label(stmt); + break; + case L_STMT_GOTO: + compile_goto(stmt); + break; + case L_STMT_TRY: + compile_trycatch(stmt); + break; + default: + L_bomb("Malformed AST in compile_stmt"); + } + switch (stmt->kind) { + case L_STMT_BLOCK: + case L_STMT_COND: + case L_STMT_EXPR: + case L_STMT_TRY: + break; + default: + track_cmd(start_off, stmt); + break; + } +} + +private void +compile_stmts(Stmt *stmts) +{ + for (; stmts; stmts = stmts->next) { + compile_stmt(stmts); + } +} + +private void +compile_trycatch(Stmt *stmt) +{ + int range; + int msg_idx = -1; + Jmp *jmp; + Try *try = stmt->u.try; + Expr *msg = try->msg; + + if (msg) { + unless (msg->op == L_OP_ADDROF) { + L_errf(msg, "expected catch(&variable)"); + return; + } + compile_expr(msg, L_DISCARD); + if (msg->a->sym) { + msg_idx = msg->a->sym->idx; + } else { + L_errf(msg->a, "illegal operand to &"); + } + } + + range = TclCreateExceptRange(CATCH_EXCEPTION_RANGE, L->frame->envPtr); + TclEmitInstInt4(INST_BEGIN_CATCH4, range, L->frame->envPtr); + + /* + * Emit separate INST_END_CATCH's for the non-error and error + * paths so that a return can be done inside of a catch() + * clause -- the "try" is done when the body finishes without + * error or by the time the catch() is entered. + */ + + /* body */ + ExceptionRangeStarts(L->frame->envPtr, range); + compile_stmts(try->try); + ExceptionRangeEnds(L->frame->envPtr, range); + TclEmitOpcode(INST_END_CATCH, L->frame->envPtr); + jmp = emit_jmp_fwd(INST_JUMP4, 0); + + /* error case */ + ExceptionRangeTarget(L->frame->envPtr, range, catchOffset); + if (msg_idx != -1) { + TclEmitOpcode(INST_PUSH_RESULT, L->frame->envPtr); + TclEmitInstInt4(INST_STORE_SCALAR4, msg_idx, L->frame->envPtr); + TclEmitOpcode(INST_POP, L->frame->envPtr); + } + TclEmitOpcode(INST_END_CATCH, L->frame->envPtr); + compile_stmts(try->catch); + + /* out */ + fixup_jmps(&jmp); +} + +private void +compile_block(Block *block) +{ + compile_varDecls(block->decls); + compile_stmts(block->body); +} + +private void +compile_return(Stmt *stmt) +{ + VarDecl *decl; + Type *ret_type; + + /* Handle return from the top level. */ + unless (L->enclosing_func) { + if (stmt->u.expr) { + compile_expr(stmt->u.expr, L_PUSH_VAL); + } else { + push_lit(""); + } + TclEmitOpcode(INST_DONE, L->frame->envPtr); + return; + } + + decl = L->enclosing_func->decl; + ret_type = decl->type->base_type; + + if (isvoidtype(ret_type) && (stmt->u.expr)) { + L_errf(stmt, "void function cannot return value"); + compile_expr(stmt->u.expr, L_DISCARD); + } else if (stmt->u.expr) { + compile_expr(stmt->u.expr, L_PUSH_VAL); // return value + unless (L_typeck_compat(ret_type, stmt->u.expr->type)) { + L_errf(stmt, "incompatible return type"); + } + } else unless (isvoidtype(ret_type)) { + L_errf(stmt, "must specify return value"); + } else { + push_lit(""); // no return value -- push a "" + } + + /* Jmp to the function end where any necessary clean-up code is. */ + ASSERT(L->enclosing_func_frame); + L->enclosing_func_frame->ret_jmps = + emit_jmp_fwd(INST_JUMP4, L->enclosing_func_frame->ret_jmps); +} + +private void +proc_mkArg(Proc *proc, VarDecl *decl) +{ + int argnum; + char *name = decl->id->str; + CompiledLocal *local; + + argnum = proc->numArgs++; + ++proc->numCompiledLocals; + local = (CompiledLocal *)ckalloc(sizeof(CompiledLocal) - + sizeof(local->name) + + strlen(name) + 1); + if (proc->firstLocalPtr == NULL) { + proc->firstLocalPtr = local; + proc->lastLocalPtr = local; + } else { + proc->lastLocalPtr->nextPtr = local; + proc->lastLocalPtr = local; + } + local->nextPtr = NULL; + local->resolveInfo = NULL; + local->defValuePtr = NULL; + local->frameIndex = argnum; + local->nameLength = strlen(name); + strcpy(local->name, name); + + local->flags = VAR_ARGUMENT; + if (decl->flags & DECL_REST_ARG) local->flags |= VAR_IS_ARGS; + if (decl->flags & DECL_OPTIONAL) { + if (isnameoftype(decl->type)) { + local->defValuePtr = + Tcl_NewStringObj("::L_undef_ref_parm_", -1); + local->defValuePtr->undef = 1; + } else { + local->defValuePtr = *L_undefObjPtrPtr(); + } + Tcl_IncrRefCount(local->defValuePtr); + } +} + +/* + * Determine whether the parameter-passing mode for a formal parameter + * declaration is call-by-reference. Return NULL or the base type of + * the parameter (without the name-of). You get call-by-reference if + * the parameter was declared with & and is not a function pointer. + */ +private Type * +iscallbyname(VarDecl *formal) +{ + unless (formal) return (NULL); + if (formal->flags & DECL_REF) { + if (isfntype(formal->type->base_type)) { + return (NULL); + } else { + return (formal->type->base_type); + } + } + return (NULL); +} + +private int +compile_fnParms(VarDecl *decl) +{ + int n; + int name_parms = 0; + char *name; + Proc *proc = L->frame->envPtr->procPtr; + Expr *varId; + VarDecl *p, *varDecl; + Sym *parmSym, *varSym; + Type *type; + VarDecl *param = decl->type->u.func.formals; + + proc->numArgs = 0; + proc->numCompiledLocals = 0; + + /* + * Public class member fns (except constructor) must have "self" + * as the first arg and it must be of the class type. + */ + if (isClsFnPublic(decl) && !isClsConstructor(decl)) { + Type *clstype = decl->clsdecl->decl->type; + Expr *self_id; + VarDecl *self_decl; + unless (param && param->id && isid(param->id, "self")) { + L_errf(decl->id, "class public member function lacks " + "'self' as first arg"); + /* Add it so we can keep compiling. */ + self_id = mkId("self"); + self_decl = ast_mkVarDecl(clstype, self_id, + decl->node.loc, + decl->node.loc); + self_decl->flags = SCOPE_LOCAL | DECL_LOCAL_VAR; + self_decl->next = param; + param = self_decl; + } else unless (L_typeck_same(param->type, clstype)) { + L_errf(param, "'self' parameter must be of class type"); + } + } + + /* + * To handle call-by-name formals, make two passes through the + * formals list. In the first pass, mangle any formal name to + * "&name". In the second pass, for formals only, create a + * local "name" as an upvar to the variable one frame up whose + * name is passed in the arg. Note that the formal will have + * type "name-of <t>" and the local gets type <t>. This is + * needed since Tcl requires the locals to follow the args. + */ + for (p = param, n = 0; p; p = p->next, n++) { + unless (p->id) { + L_errf(p, "formal parameter #%d lacks a name", n+1); + name = cksprintf("unnamed-arg-%d", n+1); + p->id = mkId(name); + ckfree(name); + } + if (isClsConstructor(decl) && isid(p->id, "self")) { + L_errf(p, + "'self' parameter illegal in class constructor"); + continue; + } + if (isClsFnPrivate(decl) && isid(p->id, "self")) { + L_errf(p, + "'self' parameter illegal in private function"); + continue; + } + if ((p->flags & DECL_REST_ARG) && (p->next)) { + L_errf(p, "Rest parameter must be last"); + } + if ((p->flags & DECL_OPTIONAL) && (p->next)) { + L_errf(p, "_optional parameter must be last"); + } + if (typeis(p->type, "FMT") && + (!p->next || !(p->next->flags & DECL_REST_ARG))) { + L_errf(p, "rest argument must follow FMT"); + } + if (iscallbyname(p)) { + name = cksprintf("&%s", p->id->str); + ckfree(p->id->str); + p->id->str = name; + ++name_parms; + } + proc_mkArg(proc, p); + parmSym = sym_store(p); + unless (parmSym) continue; // multiple declaration + parmSym->idx = n; + /* Suppress unused warning for obj arg to class member fns. */ + if ((p == param) && + isClsFnPublic(decl) && !isClsConstructor(decl)) { + parmSym->used_p = TRUE; + } + } + /* For call by name, push a 1 the first time (arg to INST_UPVAR). */ + if (name_parms) push_lit("1"); + /* + * For each call-by-reference formal, we have + * "&var" - a fn parm that gets the name of the caller's actual parm + * "var" - a local upvar'd to this name, becomes alias for the actual + * The first was created above. Create the second one now. + */ + for (p = param; p; p = p->next) { + unless (type = iscallbyname(p)) continue; + + /* Lookup "&var". */ + parmSym = sym_lookup(p->id, L_NOWARN); + ASSERT(parmSym && (p->id->str[0] == '&')); + + /* Create "var". */ + varId = ast_mkId(p->id->str + 1, // point past the & + p->id->node.loc, + p->id->node.loc); + varDecl = ast_mkVarDecl(type, varId, p->node.loc, p->node.loc); + varDecl->flags = SCOPE_LOCAL | DECL_LOCAL_VAR | p->flags; + varDecl->node.loc.line = p->node.loc.line; + unless (varSym = sym_store(varDecl)) continue; // multiple decl + varSym->decl->refsym = parmSym; + emit_load_scalar(parmSym->idx); + TclEmitInstInt4(INST_UPVAR, varSym->idx, L->frame->envPtr); + } + /* Pop the 1 pushed for INST_UPVAR. */ + if (name_parms) emit_pop(); + return (n); +} + +private int +compile_rename(Expr *expr) +{ + int n; + + push_lit("frename_"); + n = compile_exprs(expr->b, L_PUSH_VAL); + unless (n == 2) { + L_errf(expr, "incorrect # args for rename"); + } + emit_invoke(3); + expr->type = L_int; + return (1); // stack effect +} + +private int +compile_split(Expr *expr) +{ + int n; + Expr *str = NULL, *lim = NULL, *sep = NULL; + Expr_f flags = 0; + + expr->type = L_poly; // for err return path + n = compile_exprs(expr->b, L_PUSH_VAL); + ASSERT(n > 0); // grammar ensures this + if (n > 3) { + L_errf(expr, "too many args to split"); + return (0); + } + switch (n) { + case 1: // split(<str>) + str = expr->b; + break; + case 2: // split(/re/, <str>) + sep = expr->b; + str = sep->next; + break; + case 3: // split(/re/, <str>, <lim>) + sep = expr->b; + str = sep->next; + lim = str->next; + break; + } + unless (istype(str, L_STRING|L_WIDGET|L_POLY)) { + L_errf(str, "expression to split must be string"); + } + if (sep) { + unless (isregexp(sep)) { + L_errf(sep, "split delimiter must be a " + "regular expression"); + } + if (sep->flags & ~(L_EXPR_RE_T | L_EXPR_RE_I)) { + L_errf(sep, "illegal regular expression modifier"); + } + flags |= L_SPLIT_RE | sep->flags; + } + if (lim) { + flags |= L_SPLIT_LIM; + unless (isint(lim)) { + L_errf(expr, "third arg to split must be integer"); + return (0); + } + } + TclEmitInstInt4(INST_L_SPLIT, flags, L->frame->envPtr); + TclAdjustStackDepth(n-1, L->frame->envPtr); + expr->type = type_mkArray(0, L_string); + return (1); // stack effect +} + +private int +compile_push(Expr *expr) +{ + int flags = 0, i, idx; + Expr *arg, *array; + Type *base_type; + Tmp *tmp; + + expr->type = L_void; + unless (expr->b && expr->b->next) { + L_errf(expr, "too few arguments to push"); + return (0); + } + unless (isaddrof(expr->b)) { + L_errf(expr, "first arg to push not an array reference (&)"); + return (0); + } + ASSERT(expr->b->a); + array = expr->b->a; + arg = expr->b->next; + compile_expr(array, L_PUSH_PTR | L_LVALUE); + unless (isarray(array) || ispoly(array)) { + L_errf(expr, + "first arg to push not an array reference (&)"); + return (0); + } + unless (array->sym) { + L_errf(expr, "invalid l-value in push"); + return (0); + } + idx = array->sym->idx; // local slot # for array + if (isarray(array)) { + base_type = array->type->base_type; + } else { + base_type = L_poly; + } + if (arg->next) { + /* Build up a list of the args to push. */ + tmp = tmp_get(TMP_REUSE); + push_lit(""); + emit_store_scalar(tmp->idx); + emit_pop(); + for (i = 2; arg; arg = arg->next, ++i) { + compile_expr(arg, L_PUSH_VAL); + /* We allow base_type or an array of base_type. */ + if (L_typeck_compat(base_type, arg->type)) { + flags = L_INSERT_ELT; + } else if (L_typeck_compat(array->type, arg->type)) { + flags = L_INSERT_LIST; + } else { + L_errf(expr, "arg #%d to push has type " + "incompatible with array", i); + } + push_lit("-1"); // -1 means append + TclEmitInstInt4(INST_L_LIST_INSERT, tmp->idx, + L->frame->envPtr); + TclEmitInt4(flags, L->frame->envPtr); + } + emit_load_scalar(tmp->idx); + tmp_free(tmp); + flags = L_INSERT_LIST; + } else { + compile_expr(arg, L_PUSH_VAL); + /* We allow base_type or an array of base_type. */ + if (L_typeck_compat(base_type, arg->type)) { + flags = L_INSERT_ELT; + } else if (L_typeck_compat(array->type, arg->type)) { + flags = L_INSERT_LIST; + } else { + L_errf(expr, "arg #2 to push has type " + "incompatible with array"); + } + } + if (array->flags & L_EXPR_DEEP) { + // deep-ptr rval + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + // rval deep-ptr + push_lit("-1"); // -1 means append + TclEmitInstInt4(INST_L_DEEP_WRITE, idx, + L->frame->envPtr); + TclEmitInt4(flags | L_DISCARD, L->frame->envPtr); + } else { + push_lit("-1"); // -1 means append + TclEmitInstInt4(INST_L_LIST_INSERT, idx, + L->frame->envPtr); + TclEmitInt4(flags, L->frame->envPtr); + } + return (0); // stack effect +} + +private int +compile_pop_shift(Expr *expr) +{ + int idx; + Expr *arg = NULL; + char *opNm = expr->a->str; + Expr *toDelete; + YYLTYPE loc; + + expr->type = L_poly; + unless (expr->b && !expr->b->next) { + L_errf(expr, "incorrect # arguments to %s", opNm); + return (0); + } + unless (isaddrof(expr->b)) { + L_errf(expr, "arg to %s not an array reference (&)", opNm); + return (0); + } + /* + * For pop, change arg from &arr to &arr[END] and then delete + * that element. For shift, use &arr[0]. + */ + ASSERT(expr->b->a); + loc = expr->b->a->node.loc; + if (!strcmp(opNm, "pop")) { + toDelete = mkId("END"); + } else { + toDelete = ast_mkConst(L_int, ckstrdup("0"), loc, loc); + } + arg = ast_mkBinOp(L_OP_ARRAY_INDEX, + expr->b->a, + toDelete, + loc, + loc); + expr->b->a = arg; + /* L_NEG_OK here permits indexing element -1 (array already empty). */ + compile_expr(arg, L_PUSH_PTR | L_DELETE | L_NEG_OK | L_LVALUE); + unless (isarray(arg->a) || ispoly(arg->a)) { + L_errf(expr, "arg to %s not an array reference (&)", opNm); + return (0); + } + unless (arg->sym) { + L_errf(expr, "invalid l-value in %s", opNm); + return (0); + } + idx = arg->sym->idx; // local slot # for array + TclEmitInstInt4(INST_L_DEEP_WRITE, idx, L->frame->envPtr); + TclEmitInt4(L_DELETE | L_PUSH_OLD, L->frame->envPtr); + TclAdjustStackDepth(1, L->frame->envPtr); + expr->type = arg->type; + return (1); // stack effect +} + +private int +compile_insert_unshift(Expr *expr) +{ + int flags, i, idx; + Expr *arg, *array, *index; + Type *base_type; + Tmp *argTmp = NULL, *idxTmp = NULL; + char *opNm = expr->a->str; + + /* + * Make unshift(arg1, arg2, ...) look like insert(arg1, "0", arg2, ...) + */ + if (!strcmp(opNm, "unshift")) { + if (expr->b) { + arg = ast_mkConst(L_int, ckstrdup("0"), expr->node.loc, + expr->node.loc); + arg->next = expr->b->next; + expr->b->next = arg; + } + i = 2; // where data args start + } else { + i = 3; // where data args start + } + + expr->type = L_void; + unless (expr->b && expr->b->next && expr->b->next->next) { + L_errf(expr, "too few arguments to %s", opNm); + return (0); + } + ASSERT(expr->b->a); + array = expr->b->a; + index = expr->b->next; + arg = expr->b->next->next; + unless (isaddrof(expr->b)) { + L_errf(expr, "first arg to %s not an array reference (&)", opNm); + return (0); + } + compile_expr(array, L_PUSH_PTR | L_LVALUE); + unless (isarray(array) || ispoly(array)) { + L_errf(expr, + "first arg to %s not an array reference (&)", opNm); + return (0); + } + unless (array->sym) { + L_errf(expr, "invalid l-value in %s", opNm); + return (0); + } + idx = array->sym->idx; // local slot # for array + if (isarray(array)) { + base_type = array->type->base_type; + } else { + base_type = L_poly; + } + + /* + * If >1 arg, concat them all into a temp and insert that. We + * can't just insert them one by one like we do in + * compile_push(), since that would insert them backwards. + * We could reverse the arg list, but building the temp is + * about as fast as re-indexing into the array for each element. + */ + if (arg->next) { + idxTmp = tmp_get(TMP_REUSE); + compile_expr(index, L_PUSH_VAL); + emit_store_scalar(idxTmp->idx); + emit_pop(); + unless (isint(index)) { + L_errf(expr, "second arg to %s not an int", opNm); + return (0); + } + argTmp = tmp_get(TMP_REUSE); + push_lit(""); + emit_store_scalar(argTmp->idx); + emit_pop(); + for (; arg; arg = arg->next, ++i) { + compile_expr(arg, L_PUSH_VAL); + /* For an arg, allow base_type or array of base_type. */ + unless (L_typeck_compat(base_type, arg->type) || + L_typeck_compat(array->type, arg->type)) { + L_errf(expr, "arg #%d to %s has type " + "incompatible with array", i, opNm); + } + if (isarray(arg) || islist(arg)) { + flags = L_INSERT_LIST; + } else { + flags = L_INSERT_ELT; + } + push_lit("-1"); // -1 means append + TclEmitInstInt4(INST_L_LIST_INSERT, argTmp->idx, + L->frame->envPtr); + TclEmitInt4(flags, L->frame->envPtr); + } + if (array->flags & L_EXPR_DEEP) { + emit_load_scalar(argTmp->idx); + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + emit_load_scalar(idxTmp->idx); + TclEmitInstInt4(INST_L_DEEP_WRITE, idx, + L->frame->envPtr); + TclEmitInt4(L_INSERT_LIST | L_DISCARD, + L->frame->envPtr); + } else { + emit_load_scalar(argTmp->idx); + emit_load_scalar(idxTmp->idx); + TclEmitInstInt4(INST_L_LIST_INSERT, idx, + L->frame->envPtr); + TclEmitInt4(L_INSERT_LIST, L->frame->envPtr); + } + } else { + compile_expr(arg, L_PUSH_VAL); + /* For the arg, we allow base_type or an array of base_type. */ + unless (L_typeck_compat(base_type, arg->type) || + L_typeck_compat(array->type, arg->type)) { + L_errf(expr, "arg #%d to %s has type incompatible " + "with array", i, opNm); + } + if (isarray(arg) || islist(arg)) { + flags = L_INSERT_LIST; + } else { + flags = L_INSERT_ELT; + } + if (array->flags & L_EXPR_DEEP) { + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + } + compile_expr(index, L_PUSH_VAL); + unless (isint(index)) { + L_errf(expr, "second arg to %s not an int", opNm); + return (0); + } + if (array->flags & L_EXPR_DEEP) { + TclEmitInstInt4(INST_L_DEEP_WRITE, idx, + L->frame->envPtr); + TclEmitInt4(flags | L_DISCARD, L->frame->envPtr); + } else { + TclEmitInstInt4(INST_L_LIST_INSERT, idx, + L->frame->envPtr); + TclEmitInt4(flags, L->frame->envPtr); + } + } + tmp_free(idxTmp); + tmp_free(argTmp); + return (0); // stack effect +} + +private void +compile_eq_stack(Expr *expr, Type *type) +{ + int i, top_off; + Tmp *itmp, *ltmp, *rtmp; + Jmp *out = NULL; + Jmp *out_false = NULL, *out_false2 = NULL, *out_true = NULL; + VarDecl *v; + + unless (type->kind & (L_ARRAY|L_STRUCT|L_HASH)) { + /* Scalar -- just need a single bytecode. */ + emit_instrForLOp(expr, type); + return; + } + + /* Put lhs and rhs into temps. */ + ltmp = tmp_get(TMP_REUSE); + rtmp = tmp_get(TMP_REUSE); + emit_store_scalar(rtmp->idx); + emit_pop(); + emit_store_scalar(ltmp->idx); + emit_pop(); + + switch (type->kind) { + case L_ARRAY: + itmp = tmp_get(TMP_UNSET); + /* + * if (length(lhs) != length(rhs)) goto out_false + * itmp = length(rhs) + * top_off: + * if (itmp == 0) goto out_true + * --itmp + * if (lhs[itmp] != rhs[itmp]) goto out_false + * goto top_off + * out_true: + * push 1 + * goto out + * out_false: + * push 0 + * out: + */ + emit_load_scalar(ltmp->idx); + TclEmitOpcode(INST_LIST_LENGTH, L->frame->envPtr); + emit_load_scalar(rtmp->idx); + TclEmitOpcode(INST_LIST_LENGTH, L->frame->envPtr); + emit_store_scalar(itmp->idx); + TclEmitOpcode(INST_EQ, L->frame->envPtr); + out_false = emit_jmp_fwd(INST_JUMP_FALSE4, out_false); + top_off = currOffset(L->frame->envPtr); + emit_load_scalar(itmp->idx); + out_true = emit_jmp_fwd(INST_JUMP_FALSE4, out_true); + TclEmitInstInt1(INST_INCR_SCALAR1_IMM, itmp->idx, + L->frame->envPtr); + TclEmitInt1(-1, L->frame->envPtr); + emit_pop(); + emit_load_scalar(ltmp->idx); + emit_load_scalar(itmp->idx); + TclEmitOpcode(INST_LIST_INDEX, L->frame->envPtr); + emit_load_scalar(rtmp->idx); + emit_load_scalar(itmp->idx); + TclEmitOpcode(INST_LIST_INDEX, L->frame->envPtr); + compile_eq_stack(expr, type->base_type); + out_false = emit_jmp_fwd(INST_JUMP_FALSE4, out_false); + emit_jmp_back(TCL_UNCONDITIONAL_JUMP, top_off); + fixup_jmps(&out_true); + push_lit("1"); + out = emit_jmp_fwd(INST_JUMP1, out); + fixup_jmps(&out_false); + push_lit("0"); + fixup_jmps(&out); + tmp_free(itmp); + break; + case L_STRUCT: + /* + * The structs are of compatible types, so we know + * they have the same number of members. Compare + * them one by one. + */ + i = 0; + for (v = type->u.struc.members; v; v = v->next) { + emit_load_scalar(ltmp->idx); + TclEmitInstInt4(INST_LIST_INDEX_IMM, i, + L->frame->envPtr); + emit_load_scalar(rtmp->idx); + TclEmitInstInt4(INST_LIST_INDEX_IMM, i, + L->frame->envPtr); + ++i; + compile_eq_stack(expr, v->type); + out_false = emit_jmp_fwd(INST_JUMP_FALSE4, out_false); + } + push_lit("1"); + out = emit_jmp_fwd(INST_JUMP1, out); + fixup_jmps(&out_false); + push_lit("0"); + fixup_jmps(&out); + break; + case L_HASH: + /* + * if (length(lhs) != length(rhs)) goto out_false2 + * if [dict first lhs] goto out_true + * top_off: + * // stack: val key (key is on top) + * unless [::dict exists rhs key] goto out_false + * unless [::dict get rhs key] == val goto out_false2 + * unless [dict next] goto top_off + * out_true: + * pop // pop key + * pop // pop val + * push 1 + * goto out + * out_false: + * pop // pop key + * pop // pop val + * out_false2: + * push 0 + * out: + */ + itmp = tmp_get(TMP_UNSET); + push_lit("::dict"); + push_lit("size"); + emit_load_scalar(ltmp->idx); + // ::dict size lhs + emit_invoke(3); + // <lhs-size> + push_lit("::dict"); + push_lit("size"); + emit_load_scalar(rtmp->idx); + // <lhs-size> ::dict size rhs + emit_invoke(3); + // <lhs-size> <rhs-size> + TclEmitOpcode(INST_EQ, L->frame->envPtr); + // <true/false> + out_false2 = emit_jmp_fwd(INST_JUMP_FALSE4, out_false2); + emit_load_scalar(ltmp->idx); + // lhs + TclEmitInstInt4(INST_DICT_FIRST, itmp->idx, L->frame->envPtr); + // <lhs-val> <lhs-key> <done-flag> + out_true = emit_jmp_fwd(INST_JUMP_TRUE4, out_true); + top_off = currOffset(L->frame->envPtr); + // <lhs-val> <lhs-key> + TclEmitOpcode(INST_DUP, L->frame->envPtr); + // <lhs-val> <lhs-key> <lhs-key> + push_lit("::dict"); + push_lit("exists"); + emit_load_scalar(rtmp->idx); + // <lhs-val> <lhs-key> <lhs-key> ::dict exists rhs + TclEmitInstInt1(INST_ROT, 3, L->frame->envPtr); + // <lhs-val> <lhs-key> ::dict exists rhs <lhs-key> + emit_invoke(4); + // <lhs-val> <lhs-key> <rhs-exists-flag> + out_false = emit_jmp_fwd(INST_JUMP_FALSE4, out_false); + // <lhs-val> <lhs-key> + push_lit("::dict"); + push_lit("get"); + emit_load_scalar(rtmp->idx); + // <lhs-val> <lhs-key> ::dict get rhs + TclEmitInstInt1(INST_ROT, 3, L->frame->envPtr); + // <lhs-val> ::dict get rhs <lhs-key> + emit_invoke(4); + // <lhs-val> <rhs-val> + compile_eq_stack(expr, type->base_type); + // <equals-flag> + out_false2 = emit_jmp_fwd(INST_JUMP_FALSE4, out_false2); + TclEmitInstInt4(INST_DICT_NEXT, itmp->idx, L->frame->envPtr); + // <lhs-val> <lhs-key> <done-flag> + emit_jmp_back(TCL_FALSE_JUMP, top_off); + fixup_jmps(&out_true); + // <lhs-val> <lhs-key> + emit_pop(); + emit_pop(); + push_lit("1"); + out = emit_jmp_fwd(INST_JUMP1, out); + // <lhs-val> <lhs-key> + fixup_jmps(&out_false); + emit_pop(); + emit_pop(); + fixup_jmps(&out_false2); + push_lit("0"); + fixup_jmps(&out); + tmp_free(itmp); + break; + default: ASSERT(0); + } + tmp_free(ltmp); + tmp_free(rtmp); +} + +private int +compile_keys(Expr *expr) +{ + int n; + + push_lit("::dict"); + push_lit("keys"); + n = compile_exprs(expr->b, L_PUSH_VAL); + unless (n == 1) { + L_errf(expr, "incorrect # args to keys"); + expr->type = L_poly; + return (0); // stack effect + } + unless (ishash(expr->b) || ispoly(expr->b)) { + L_errf(expr, "arg to keys is not a hash"); + expr->type = L_poly; + return (0); // stack effect + } + emit_invoke(3); + if (ispoly(expr->b)) { + expr->type = L_poly; + } else { + expr->type = type_mkArray(0, expr->b->type->u.hash.idx_type); + } + return (1); // stack effect +} + +private int +compile_length(Expr *expr) +{ + int n; + Jmp *jmp1, *jmp2; + + expr->type = L_int; + + n = compile_exprs(expr->b, L_PUSH_VAL); + unless (n == 1) { + L_errf(expr, "incorrect # args to length"); + return (0); // stack effect + } + if (isstring(expr->b) || iswidget(expr->b)) { + TclEmitOpcode(INST_STR_LEN, L->frame->envPtr); + } else if (isarray(expr->b) || islist(expr->b) || ispoly(expr->b)) { + TclEmitOpcode(INST_LIST_LENGTH, L->frame->envPtr); + } else if (ishash(expr->b)) { + /* + * <arg is on stack from above compile_exprs> + * dup + * l_defined + * jmpFalse 1 + * ::dict size (rot arg into place before the invoke) + * jmp 2 + * 1: pop + * push 0 + * 2: + */ + TclEmitOpcode(INST_DUP, L->frame->envPtr); + TclEmitOpcode(INST_L_DEFINED, L->frame->envPtr); + jmp1 = emit_jmp_fwd(INST_JUMP_FALSE1, NULL); + push_lit("::dict"); + push_lit("size"); + TclEmitInstInt1(INST_ROT, 2, L->frame->envPtr); + emit_invoke(3); + jmp2 = emit_jmp_fwd(INST_JUMP1, NULL); + fixup_jmps(&jmp1); + emit_pop(); + push_lit("0"); + fixup_jmps(&jmp2); + } else { + L_errf(expr, "arg to length has illegal type"); + } + return (1); // stack effect +} + +private int +compile_min_max(Expr *expr) +{ + push_litf("::tcl::mathfunc::%s", expr->a->str); + unless (compile_exprs(expr->b, L_PUSH_VAL) == 2) { + L_errf(expr, "incorrect # args to %s", expr->a->str); + expr->type = L_poly; + return (0); + } + L_typeck_expect(L_INT|L_FLOAT, expr->b, "in min/max"); + L_typeck_expect(L_INT|L_FLOAT, expr->b->next, "in min/max"); + emit_invoke(3); + if (isfloat(expr->b) || isfloat(expr->b->next)) { + expr->type = L_float; + } else { + expr->type = L_int; + } + return (1); // stack effect +} + +private int +compile_sort(Expr *expr) +{ + int custom_compar = 0, i, n; + Expr *e, *l; + Type *t; + + /* + * Do some gymnastics to get this on the run-time stack: + * ::lsort + * <all args except last one> + * -integer, -real, or -ascii depending on list type, unless + * the -compare option was given + * <last arg (the thing to be sorted)> + */ + + push_lit("::lsort"); + n = compile_exprs(expr->b, L_PUSH_VAL); + unless (n >= 1) { + L_errf(expr, "incorrect # args to sort"); + expr->type = L_poly; + return (0); // stack effect + } + /* See if there's a "-command" argument. */ + for (i = 0, l = expr->b; i < (n-1); ++i, l = l->next) { + unless (isconst(l) && l->str && !strcmp(l->str, "-command")) { + continue; + } + /* Type check the arg to -command. */ + e = l->next; + unless (e && (e->type->kind == L_NAMEOF) && + (e->type->base_type->kind == L_FUNCTION)) { + L_errf(e, "'command:' arg to sort must be &function"); + } + custom_compar = 1; + } + /* The last argument to sort must be an array, list, or poly. */ + if (isarray(l) || islist(l)) { + t = l->type->base_type; + } else if (ispoly(l)) { + t = L_poly; + } else { + L_errf(expr, "last arg to sort not an array or list"); + expr->type = L_poly; + return (0); // stack effect + } + unless (custom_compar) { + switch (t->kind) { + case L_INT: + push_lit("-integer"); + break; + case L_FLOAT: + push_lit("-real"); + break; + default: + push_lit("-ascii"); + break; + } + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + ++n; + } + if (n > 255) L_errf(expr, "sort cannot have >255 args"); + emit_invoke(n+1); + expr->type = type_mkArray(0, t); + return (1); // stack effect +} + +private int +compile_join(Expr *expr) +{ + Expr *array, *sep; + + expr->type = L_string; + push_lit("::join"); + unless ((sep=expr->b) && (array=sep->next) && !array->next) { + L_errf(expr, "incorrect # args to join"); + return (0); // stack effect + } + compile_expr(array, L_PUSH_VAL); + unless (isarray(array) || islist(array) || ispoly(array)) { + L_errf(expr, "second arg to join not an array or list"); + return (0); // stack effect + } + compile_expr(sep, L_PUSH_VAL); + unless (isstring(sep) || iswidget(sep) || ispoly(sep)) { + L_errf(expr, "first arg to join not a string"); + return (0); // stack effect + } + emit_invoke(3); + return (1); // stack effect +} + +private int +compile_abs(Expr *expr) +{ + int n; + + push_lit("::tcl::mathfunc::abs"); + n = compile_exprs(expr->b, L_PUSH_VAL); + unless (n == 1) { + L_errf(expr, "incorrect # args to abs"); + expr->type = L_poly; + return (0); + } + unless (isint(expr->b) || isfloat(expr->b) || ispoly(expr->b)) { + L_errf(expr, "must pass int or float to abs"); + } + emit_invoke(2); + expr->type = expr->b->type; + return (1); // stack effect +} + +private int +compile_assert(Expr *expr) +{ + Jmp *jmp; + char *cond_txt; + + expr->type = L_void; + unless (expr->b && !expr->b->next) { + L_errf(expr, "incorrect # args to assert"); + return (0); // stack effect + } + compile_condition(expr->b); + jmp = emit_jmp_fwd(INST_JUMP_TRUE4, NULL); + cond_txt = get_text(expr->b); + push_lit("die_"); + push_lit(frame_name()); + push_litf("%d", expr->node.loc.line); + push_litf("ASSERTION FAILED %s:%d: %s\n", expr->node.loc.file, + expr->node.loc.line, cond_txt); + emit_invoke(4); + emit_pop(); + ckfree(cond_txt); + fixup_jmps(&jmp); + return (0); // stack effect +} + +private int +compile_catch(Expr *expr) +{ + L_errf(expr, "catch() is reserved for try/catch; " + "use ::catch() for Tcl's catch"); + return (0); +} + +/* + * Change die(fmt, ...args) into die_(__FILE__, __LINE__, fmt, ...args) + */ +private int +compile_die(Expr *expr) +{ + Expr *arg; + + ckfree(expr->a->str); + expr->a->str = ckstrdup("die_"); + arg = ast_mkId("__FILE__", expr->node.loc, expr->node.loc); + arg->next = ast_mkId("__LINE__", expr->node.loc, expr->node.loc); + arg->next->next = expr->b; + expr->b = arg; + return (compile_expr(expr, L_PUSH_VAL)); +} + +/* + * Change warn(fmt, ...args) into warn_(__FILE__, __LINE__, fmt, ...args) + */ +private int +compile_warn(Expr *expr) +{ + Expr *arg; + + ckfree(expr->a->str); + expr->a->str = ckstrdup("warn_"); + arg = ast_mkId("__FILE__", expr->node.loc, expr->node.loc); + arg->next = ast_mkId("__LINE__", expr->node.loc, expr->node.loc); + arg->next->next = expr->b; + expr->b = arg; + return (compile_expr(expr, L_PUSH_VAL)); +} + +/* + * Change here() into here_(__FILE__, __LINE__, __FUNC__) + */ +private int +compile_here(Expr *expr) +{ + Expr *arg; + + if (expr->b) { + L_errf(expr, "here() takes no arguments"); + } + ckfree(expr->a->str); + expr->a->str = ckstrdup("here_"); + arg = ast_mkId("__FILE__", expr->node.loc, expr->node.loc); + arg->next = ast_mkId("__LINE__", expr->node.loc, expr->node.loc); + arg->next->next = ast_mkId("__FUNC__", expr->node.loc, expr->node.loc); + expr->b = arg; + return (compile_expr(expr, L_PUSH_VAL)); +} + +private int +compile_undef(Expr *expr) +{ + int n; + Expr *arg = expr->b; + + n = compile_exprs(arg, L_PUSH_PTR | L_DELETE | L_LVALUE); + unless (n == 1) { + L_errf(expr, "incorrect # args to undef"); + goto done; + } + unless (arg->sym) { + L_errf(expr, "illegal l-value in undef()"); + goto done; + } + if (((arg->op == L_OP_DOT) || (arg->op == L_OP_POINTS)) && + isstruct(arg->a)) { + L_errf(expr, "cannot undef() a struct field"); + goto done; + } + /* + * If arg is a deep dive, delete the hash or array element. + * If arg is a variable, treat undef(var) like var=undef. + */ + if (arg->flags & L_EXPR_DEEP) { + TclEmitInstInt4(INST_L_DEEP_WRITE, + arg->sym->idx, + L->frame->envPtr); + TclEmitInt4(L_DELETE | L_DISCARD, L->frame->envPtr); + } else { + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + emit_store_scalar(arg->sym->idx); + emit_pop(); + } + done: + expr->type = L_void; + return (0); // stack effect +} + +private int +compile_typeof(Expr *expr) +{ + Sym *sym; + + expr->type = L_string; + unless (expr->b->kind == L_EXPR_ID) { + L_errf(expr, "argument to typeof() not a variable"); + return (0); + } + sym = sym_lookup(expr->b, 0); + if (sym) { + if (sym->type->name) { + push_lit(sym->type->name); + } else { + push_lit(L_type_str(sym->type->kind)); + } + } + return (1); // stack effect +} + +private int +compile_read(Expr *expr) +{ + int n; + Expr *buf, *fd, *nbytes; + + expr->type = L_int; + push_lit("Lread_"); + n = compile_exprs(expr->b, L_PUSH_VAL); + unless ((n == 2) || (n == 3)) { + L_errf(expr, "incorrect # args to read()"); + return (0); + } + fd = expr->b; + unless (typeisf(fd, "FILE") || ispoly(fd)) { + L_errf(expr, "first arg to read() must have type FILE"); + return (0); + } + buf = fd->next; + unless (isaddrof(buf) && (isstring(buf->a) || ispoly(buf->a))) { + L_errf(expr, "second arg to read() must have type string&"); + return (0); + } + nbytes = buf->next; + if (nbytes) { + unless (isint(nbytes) || ispoly(nbytes)) { + L_errf(expr, "third arg to read() must have type int"); + return (0); + } + } + emit_invoke(n+1); + return (1); // stack effect +} + +private int +compile_write(Expr *expr) +{ + int n; + Expr *buf, *fd, *nbytes; + + expr->type = L_int; + push_lit("Lwrite_"); + n = compile_exprs(expr->b, L_PUSH_VAL); + unless (n == 3) { + L_errf(expr, "incorrect # args to write()"); + return (0); + } + fd = expr->b; + unless (typeisf(fd, "FILE") || ispoly(fd)) { + L_errf(expr, "first arg to write() must have type FILE"); + return (0); + } + buf = fd->next; + unless (isstring(buf) || iswidget(buf) || ispoly(buf)) { + L_errf(expr, "second arg to write() must have type string"); + return (0); + } + nbytes = buf->next; + unless (isint(nbytes) || ispoly(nbytes)) { + L_errf(expr, "third arg to write() must have type int"); + return (0); + } + emit_invoke(4); + return (1); // stack effect +} + +/* + * Allowable forms of system(): + * + * int system(string cmd) + * int system(string cmd, STATUS &s) + * int system(string argv[]) + * int system(string argv[], STATUS &s) + * int system(cmd | argv[], string in, string &out, string &err) + * int system(cmd | argv[], string in, string &out, string &err, STATUS &) + * int system(cmd | argv[], string[] in, string[] &out, string[] &err) + * int system(cmd | argv[], string[] in, string[] &out, string[] &err,STATUS &) + * int system(cmd | argv[], "input", "${outf}", "errors") + * int system(cmd | argv[], "input", "${outf}", "errors", STATUS &s) + * int system(cmd | argv[], FILE in, FILE out, FILE err); + * int system(cmd | argv[], FILE in, FILE out, FILE err, STATUS &s); + * + * and spawn(): + * + * int spawn(string cmd) + * int spawn(string cmd, STATUS &s) + * int spawn(string argv[]) + * int spawn(string argv[], STATUS &s) + * int spawn(cmd | argv[], string in, FILE out, FILE err) + * int spawn(cmd | argv[], string in, FILE out, FILE err, STATUS &s) + * int spawn(cmd | argv[], string[] in, FILE out, FILE err) + * int spawn(cmd | argv[], string[] in, FILE out, FILE err, STATUS &s) + * int spawn(cmd | argv[], "input", "${outf}", "errors") + * int spawn(cmd | argv[], "input", "${outf}", "errors", STATUS &s) + * int spawn(cmd | argv[], FILE in, FILE out, FILE err) + * int spawn(cmd | argv[], FILE in, FILE out, FILE err, STATUS &s) + * + * Convert these into a call to system_ or spawn_ that has exactly + * seven args, the last being flags indicating the number and type of + * what the user supplied. + */ + +private int +compile_spawn_system(Expr *expr) +{ + int flags = 0, n; + Expr *cmd; + Expr *err = NULL, *in = NULL, *out = NULL, *status = NULL; + enum { SYSTEM, SPAWN } kind; + + kind = isid(expr->a, "system") ? SYSTEM : SPAWN; + + push_lit("system_"); + n = compile_exprs(expr->b, L_PUSH_VAL); + + expr->type = L_poly; + cmd = expr->b; + switch (n) { + case 1: + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + break; + case 2: + status = cmd->next; + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + TclEmitInstInt1(INST_ROT, 3, L->frame->envPtr); + break; + case 4: + in = cmd->next; + out = in->next; + err = out->next; + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + break; + case 5: + in = cmd->next; + out = in->next; + err = out->next; + status = err->next; + break; + default: + L_errf(expr, "incorrect # args"); + return (0); + } + if (isstring(cmd) || ispoly(cmd)) { + } else if (isarrayof(cmd, L_STRING | L_POLY) || islist(cmd)) { + flags |= SYSTEM_ARGV; + } else { + L_errf(expr, "first arg must be string or string array"); + } + switch (kind) { + case SYSTEM: flags |= typeck_system(in, out, err); break; + case SPAWN: flags |= typeck_spawn(in, out, err); break; + } + if (status) { + Type *base_type = status->type->base_type; + unless (isid(status, "undef") || + (isnameoftype(status->type) && + (ispolytype(base_type) || typeis(base_type, "STATUS")))) { + L_errf(expr, "last arg must be of type STATUS &"); + return (0); + } + } + push_litf("0x%x", flags); + emit_invoke(7); + expr->type = L_int; + return (1); +} + +private int +typeck_spawn(Expr *in, Expr *out, Expr *err) +{ + int flags = 0; + + if (!in || isid(in, "undef")) { + } else if (typeisf(in, "FILE")) { + flags |= SYSTEM_IN_HANDLE; + } else if (isstring(in) && (isconst(in) || isinterp(in))) { + flags |= SYSTEM_IN_FILENAME; + } else if (isstring(in) || ispoly(in)) { + flags |= SYSTEM_IN_STRING; + } else if (isarrayof(in, L_STRING | L_POLY) || islist(in)) { + flags |= SYSTEM_IN_ARRAY; + } else { + L_errf(in, "second arg must be FILE, or " + "string constant/variable/array"); + } + if (!out || isid(out, "undef")) { + } else if (typeisf(out, "FILE")) { + flags |= SYSTEM_OUT_HANDLE; + } else if (isstring(out) && (isconst(out) || isinterp(out))) { + flags |= SYSTEM_OUT_FILENAME; + } else { + L_errf(out, "third arg must be FILE, or string constant"); + } + if (!err || isid(err, "undef")) { + } else if (typeisf(err, "FILE")) { + flags |= SYSTEM_ERR_HANDLE; + } else if (isstring(err) && (isconst(err) || isinterp(err))) { + flags |= SYSTEM_ERR_FILENAME; + } else { + L_errf(err, "fourth arg must be FILE, or string constant"); + } + + return (flags | SYSTEM_BACKGROUND); +} + +private int +typeck_system(Expr *in, Expr *out, Expr *err) +{ + int flags = 0; + + if (!in || isid(in, "undef")) { + } else if (typeisf(in, "FILE")) { + flags |= SYSTEM_IN_HANDLE; + } else if (isstring(in) && (isconst(in) || isinterp(in))) { + flags |= SYSTEM_IN_FILENAME; + } else if (isstring(in) || ispoly(in)) { + flags |= SYSTEM_IN_STRING; + } else if (isarrayof(in, L_STRING | L_POLY) || islist(in)) { + flags |= SYSTEM_IN_ARRAY; + } else { + L_errf(in, "second arg must be FILE, or " + "string constant/variable/array"); + } + if (!out || isid(out, "undef")) { + } else if (typeisf(out, "FILE")) { + flags |= SYSTEM_OUT_HANDLE; + } else if (isstring(out) && (isconst(out) || isinterp(out))) { + flags |= SYSTEM_OUT_FILENAME; + } else if (isaddrof(out) && (isstring(out->a) || ispoly(out->a))) { + flags |= SYSTEM_OUT_STRING; + } else if (isaddrof(out) && isarrayof(out->a, L_STRING | L_POLY)) { + flags |= SYSTEM_OUT_ARRAY; + } else { + L_errf(out, "third arg must be FILE, string " + "constant, or reference to string or string array"); + } + if (!err || isid(err, "undef")) { + } else if (typeisf(err, "FILE")) { + flags |= SYSTEM_ERR_HANDLE; + } else if (isstring(err) && (isconst(err) || isinterp(err))) { + flags |= SYSTEM_ERR_FILENAME; + } else if (isaddrof(err) && (isstring(err->a) || ispoly(err->a))) { + flags |= SYSTEM_ERR_STRING; + } else if (isaddrof(err) && isarrayof(err->a, L_STRING | L_POLY)) { + flags |= SYSTEM_ERR_ARRAY; + } else { + L_errf(err, "fourth arg must be FILE, string " + "constant, or reference to string or string array"); + } + + return (flags); +} + +private int +compile_popen(Expr *expr) +{ + int flags = 0, n; + Expr *cb, *cmd, *mode; + VarDecl *args; + Type *want; + YYLTYPE loc = { 0 }; + + push_lit("popen_"); + expr->type = L_poly; + + n = compile_exprs(expr->b, L_PUSH_VAL); + unless ((n == 2) || (n == 3)) { + L_errf(expr, "incorrect # args to popen"); + return (0); + } + cmd = expr->b; + mode = cmd->next; + cb = mode->next; + + if (isarrayof(cmd, L_STRING | L_POLY) || islist(cmd)) { + flags |= SYSTEM_ARGV; + } else unless (isstring(cmd) || ispoly(cmd)) { + L_errf(cmd, "first arg to popen must be string or string array"); + } + + L_typeck_expect(L_STRING, mode, "in second arg to popen"); + + // To typecheck the optional stderr-callback arg, build a + // type descriptor and let L_typeck_same() do the work. + if (cb) { + args = ast_mkVarDecl(L_string, NULL, loc, loc); + args->next = ast_mkVarDecl(L_string, NULL, loc, loc); + want = type_mkNameOf(type_mkFunc(L_void, args)); + unless (L_typeck_same(want, cb->type)) { + L_errf(cb, "illegal type for stderr callback"); + } + flags |= SYSTEM_OUT_HANDLE; + } else { + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + } + + push_litf("0x%x", flags); + emit_invoke(5); + expr->type = L_typedef_lookup("FILE"); + ASSERT(expr->type); + return (1); +} + +/* + * Return a copy of the source text for the given expression. Caller + * must free. + */ +private char * +get_text(Expr *expr) +{ + int beg = expr->node.loc.beg; + int end = expr->node.loc.end; + int len = end - beg; + char *s; + + s = ckalloc(len + 1); + strncpy(s, Tcl_GetString(L->script)+beg, len); + s[len] = 0; + return (s); +} + +/* + * Emit code to compute the value of the given expression. The flags + * say in what form the generated code should produce the value. The + * caller chooses these flags based on whether + * 1. expr will be read, written, or both; and whether + * 2. expr is a deep dive or something else (an object dereference, + * a variable, or an expression). + * The flags are bit-masks (see below) and can be combined. + * + * Passing in one of the pointer flags means that IF the expr is a + * deep dive, leave a deep-ptr to it and possibly also its value on + * the run-time stack. If the expr is not, evaluate it (so that + * expr->sym etc is valid) but don't push anything. You use this when + * expr is an l-value. + * + * Passing in L_PUSH_VAL and none of the pointer flags means that + * the expr's value is left on the stack. + * + * Passing in both L_PUSH_VAL and one of the pointer flags is done + * when the caller needs a deep-ptr if expr is a deep dive but + * just wants the value otherwise. You use this when expr is + * an l-value but you also need the r-value, such as when + * compiling ++/-- or =~. + * + * Passing in L_PUSH_NAME means the fully qualified name of the + * variable is left on the stack and is valid only for certain + * kinds of variables (globals, locals, class variables, or class + * instance variables). + * + * L_PUSH_VAL push value onto stack, unless deep dive and + * you also request a deep-ptr + * L_PUSH_PTR if deep dive, push deep-ptr onto stack + * L_PUSH_PTRVAL if deep dive, push deep-ptr then value onto stack + * L_PUSH_VALPTR if deep dive, push value then deep-ptr onto stack + * L_LVALUE if deep dive, create an un-shared copy for writing + * L_DISCARD evaluate expr then discard its value + * L_PUSH_NAME push fully qualified name of variable, not the value + */ +private int +compile_expr(Expr *expr, Expr_f flags) +{ + int n = 0; + int start_off = currOffset(L->frame->envPtr); + + ++L->expr_level; + + /* The compile_xxx returns indicate whether they pushed anything. */ + unless (expr) return (0); + switch (expr->kind) { + case L_EXPR_FUNCALL: + n = compile_fnCall(expr); + break; + case L_EXPR_CONST: + case L_EXPR_RE: + push_lit(expr->str); + n = 1; + break; + case L_EXPR_ID: + n = compile_var(expr, flags); + break; + case L_EXPR_UNOP: + n = compile_unOp(expr); + break; + case L_EXPR_BINOP: + n = compile_binOp(expr, flags); + break; + case L_EXPR_TRINOP: + n = compile_trinOp(expr); + break; + default: + L_bomb("Unknown expression type %d", expr->kind); + } + + /* + * Throw away the value if requested by the caller. This is done + * for expressions that are statements, in for-loop pre and + * post expressions, etc. + */ + if (flags & L_DISCARD) { + while (n--) emit_pop(); + } + + track_cmd(start_off, expr); + + --L->expr_level; + return (n); +} + +/* + * If a function-call name begins with a cap and has an _ inside, it + * looks like a pattern call. From a name like "Foo_barBazBlech" + * create Expr const nodes "foo", "Foo_*" and a linked list of Expr + * const nodes for "bar", "baz", and "blech". Note that the returned + * Expr's need not be freed explicitly since all AST nodes are + * deallocated by the compiler. + */ +private int +ispatternfn(char *name, Expr **foo, Expr **Foo_star, Expr **opts, int *nopts) +{ + int i; + char *buf, *p, *under; + Expr *e; + + unless ((name[0] >= 'A') && (name[0] <= 'Z') && + (p = strchr(name, '_')) && p[1]) { // _ cannot be last + return (FALSE); + } + + under = p; + *under = '\0'; + + /* Build foo from Foo_bar. */ + buf = cksprintf("%s", name); + buf[0] = tolower(buf[0]); + *foo = mkId(buf); + ckfree(buf); + + /* Build Foo_* from Foo_bar. */ + buf = cksprintf("%s_*", name); + *Foo_star = mkId(buf); + ckfree(buf); + + /* Build a list of bar,baz,blech nodes from barBazBlech. */ + ++p; + *opts = NULL; + *nopts = 0; + while (*p) { + YYLTYPE loc = { 0 }; + *p = tolower(*p); + buf = ckalloc(strlen(p) + 1); + for (i = 0; *p && !isupper(*p); ++p, ++i) { + buf[i] = *p; + } + buf[i] = 0; + e = ast_mkConst(L_string, buf, loc, loc); + APPEND_OR_SET(Expr, next, *opts, e); + ++(*nopts); + } + + *under = '_'; + + return (TRUE); +} + +/* + * Rules for compiling a function call like "foo(arg)": + * + * - If foo is a variable of type name-of function, assume it contains + * the name of the function to call. + * + * - Otherwise call foo. If foo isn't declared, that's OK, we just + * won't have a prototype to type-check against. + * + * For a function call like "Foo_bar(a,b,c)" or "Foo_barBazBlech(a,b,c)", + * where the name starts with [A-Z] and has an _ in it (except at the + * end), we have what's called a "pattern function". The "bar", "baz", + * and "blech" are the "options", and "a", "b", and "c" are the "arguments". + * + * - If Foo_bar happens to be a declared function, handle as above. + * + * - If the function Foo_* is defined, change the call to + * Foo_*(bar,baz,blech,a,b,c). + * + * - If "a" is not of widget type, change the call to + * foo(bar,baz,blech,a,b,c). + * + * - If "a" is a widget type, change the call to *a(bar,baz,blech,b,c) + * where *a means that the value of the argument "a" becomes the + * function name. + */ +private int +compile_fnCall(Expr *expr) +{ + int expand, i, level, nopts; + int num_parms = 0, typchk = FALSE; + char *name; + char *defchk = NULL; // name for definedness chk before main() runs + Expr *foo, *Foo_star, *opts, *p; + Sym *sym; + VarDecl *formals = NULL; + + ASSERT(expr->a->kind == L_EXPR_ID); + name = expr->a->str; + + /* Check for an (expand) in the arg list. */ + expand = 0; + for (p = expr->b; p; p = p->next) { + if (isexpand(p)) { + TclEmitOpcode(INST_EXPAND_START, L->frame->envPtr); + expand = 1; + break; + } + } + + /* + * Check for an L built-in function. XXX change the array to + * a hash if the number of built-ins grows much more. + */ + for (i = 0; i < sizeof(builtins)/sizeof(builtins[0]); ++i) { + if (!strcmp(builtins[i].name, name)) { + if (expand) { + L_errf(expr, "(expand) illegal with " + "this function"); + } + i = builtins[i].fn(expr); + /* Copy out hash/array elements passed by reference. */ + copyout_parms(expr->b); + return (i); + } + } + + level = fnCallBegin(); + sym = sym_lookup(expr->a, L_NOWARN); + + if (sym && isfntype(sym->type)) { + /* A regular call -- the name is the fn name. */ + push_lit(sym->tclname); + formals = sym->type->u.func.formals; + typchk = TRUE; + defchk = name; + expr->type = sym->type->base_type; + } else if (sym && (sym->type->kind == L_NAMEOF) && + (sym->type->base_type->kind == L_FUNCTION)) { + /* + * Name is a function "pointer". It holds the function + * name and its type is the function proto. + */ + emit_load_scalar(sym->idx); + formals = sym->type->base_type->u.func.formals; + typchk = TRUE; + expr->type = sym->type->base_type->base_type; + } else if (sym) { + /* Name is declared but isn't a function or fn pointer. */ + L_errf(expr, "'%s' is declared but not as a function", name); + expr->type = L_poly; + } else if (ispatternfn(name, &foo, &Foo_star, &opts, &nopts)) { + /* Pattern function. Figure out which kind. */ + if ((sym = sym_lookup(Foo_star, L_NOWARN))) { + /* Foo_* is defined -- compile Foo_*(opts,a,b,c). */ + push_lit(Foo_star->str); + APPEND(Expr, next, opts, expr->b); + expr->b = opts; + formals = sym->type->u.func.formals; + typchk = TRUE; + defchk = Foo_star->str; + expr->type = sym->type->base_type; + } else { + /* Push first arg, then check its type. */ + compile_expr(expr->b, L_PUSH_VAL); + if (!expr->b) { + /* No args, compile as foo(opts). */ + push_lit(foo->str); + num_parms = push_parms(opts, NULL); + defchk = foo->str; + } else if (iswidget(expr->b)) { + /* Compile as *a(opts,b,c). */ + APPEND(Expr, next, opts, expr->b->next); + expr->b = opts; + } else { + /* Compile as foo(opts,a,b,c). */ + // a + push_lit(foo->str); + num_parms = push_parms(opts, NULL); + ASSERT(num_parms == nopts); + // a foo <opts> + TclEmitInstInt1(isexpand(expr->b)? + INST_EXPAND_ROT : INST_ROT, + nopts + 1, + L->frame->envPtr); + // foo <opts> a + expr->b = expr->b->next; + ++num_parms; + defchk = foo->str; + } + expr->type = L_poly; + } + } else { + /* Call to an undeclared function. */ + push_lit(name); + expr->type = L_poly; + defchk = name; + } + num_parms += push_parms(expr->b, formals); + if (expand) { + emit_invoke_expanded(); + } else { + emit_invoke(num_parms+1); + } + + /* + * Handle the copy-out part of copy in/out parameters. + * These are any deep-dive expressions that are passed by reference. + */ + copyout_parms(expr->b); + + if (typchk) L_typeck_fncall(formals, expr); + fnCallEnd(level); + /* + * If the call is to a function name that is known now (e.g., + * not a function pointer), add it to the L->fn_calls list + * which is walked before main() is called to verify that the + * function exists. + */ + if (defchk) { + Tcl_Obj *nm = Tcl_NewStringObj(defchk, -1); + Tcl_Obj *val = Tcl_NewObj(); + Tcl_DictObjPut(L->interp, L->fn_calls, nm, val); + Tcl_SetVar2Ex(L->interp, "%%L_fnsCalled", NULL, L->fn_calls, + TCL_GLOBAL_ONLY); + } + return (1); // stack effect +} + +private void +copyout_parms(Expr *actuals) +{ + Expr *actual, *arg; + + /* + * Copy out any deep-dive expressions that were passed with &. + * For these, the actual's value was copied into a temp var + * and its name passed. Copy that temp back out. + */ + for (actual = actuals; actual; actual = actual->next) { + arg = actual->a; + unless (isaddrof(actual) && (arg->flags & L_SAVE_IDX)) { + continue; + } + emit_load_scalar(arg->u.deepdive.val->idx); + compile_assignFromStack(arg, arg->type, NULL, L_REUSE_IDX); + emit_pop(); + tmp_free(arg->u.deepdive.val); + arg->u.deepdive.val = NULL; + } +} + +private int +compile_var(Expr *expr, Expr_f flags) +{ + Sym *self, *sym; + + ASSERT(expr->kind == L_EXPR_ID); + + /* Check for pre-defined identifiers first. */ + if (isid(expr, "END")) { + TclEmitOpcode(INST_L_READ_SIZE, L->frame->envPtr); + unless ((L->idx_op == L_OP_ARRAY_INDEX) | + (L->idx_op == L_OP_ARRAY_SLICE)) { + L_errf(expr, + "END illegal outside of a string or array index"); + } + expr->type = L_int; + return (1); + } else if (isid(expr, "undef")) { + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + expr->type = L_poly; + return (1); + } else if (isid(expr, "__FILE__")) { + push_lit(expr->node.loc.file); + expr->type = L_string; + return (1); + } else if (isid(expr, "__LINE__")) { + push_litf("%d", expr->node.loc.line); + expr->type = L_int; + return (1); + } else if (isid(expr, "__FUNC__")) { + push_lit(frame_name()); + expr->type = L_string; + return (1); + } + + unless ((sym = sym_lookup(expr, flags))) { + // Undeclared variable. + expr->type = L_poly; + return (1); + } + expr->type = sym->type; + if (flags & L_PUSH_VAL) { + if (sym->kind & L_SYM_FN) { + L_errf(expr, "cannot use a function name as a value"); + } else { + emit_load_scalar(sym->idx); + } + return (1); + } else if (flags & L_PUSH_NAME) { + switch (canDeref(sym)) { + case DECL_GLOBAL_VAR: + if (sym->decl->flags & DECL_PRIVATE) { + push_litf("::_%s_%s", L->toplev, sym->name); + } else { + push_litf("::%s", sym->name); + } + break; + case DECL_LOCAL_VAR: + push_lit(sym->tclname); + break; + case DECL_FN: + push_lit(sym->tclname); + break; + case DECL_CLASS_VAR: + push_litf("::L::_class_%s::%s", + sym->decl->clsdecl->decl->id->str, + sym->name); + break; + case DECL_CLASS_INST_VAR: + self = sym_lookup(mkId("self"), L_NOWARN); + ASSERT(self); + emit_load_scalar(self->idx); + push_litf("::%s", sym->name); + TclEmitInstInt1(INST_STR_CONCAT1, 2, L->frame->envPtr); + break; + default: + ASSERT(0); + } + return (1); + } else { + /* Push nothing. */ + return (0); + } + /* Not reached. */ + ASSERT(0); + return (1); +} + +private int +compile_exprs(Expr *expr, Expr_f flags) +{ + int num_exprs; + + for (num_exprs = 0; expr; expr = expr->next, ++num_exprs) { + compile_expr(expr, flags); + } + return (num_exprs); +} + +/* + * Emit code to push the parameters to a function call and return the + * # pushed. Rules: + * + * - For two consecutive parms like "-foovariable, &foo", push "-foovariable" + * and then the name of "foo". This is legal only for globals, class + * variables, and class instance variables. + * + * - If undef is passed as a reference parameter, pass the name of the + * special variable L_undef_ref_parm_. Code in lib L sets read and + * write traces on this variable as a way to cause a run-time error + * upon access to it. + * + * - For everything else, push the value or name as indicated by whether + * the parm has the & operator; compile_expr() handles that. The type + * checker sorts out any mis-matches with the declared formals. + */ +private int +push_parms(Expr *actuals, VarDecl *formals) +{ + int i; + int widget_flag = FALSE; + int strlen_of_variable = strlen("variable"); + char *s; + Expr *a, *v; + Sym *sym; + + for (i = 0, a = actuals; a; a = a->next, ++i) { + if (isaddrof(a) && (a->a->kind == L_EXPR_ID) && + (sym = sym_lookup(a->a, L_NOWARN)) && + (sym->decl->flags & DECL_REF)) { + push_lit(sym->tclname); + a->type = type_mkNameOf(a->a->type); + } else if (isid(a, "undef") && + formals && isnameoftype(formals->type) && + !isfntype(formals->type->base_type)) { + push_lit("::L_undef_ref_parm_"); + a->type = L_poly; + } else { + compile_expr(a, L_PUSH_VAL); + } + if (widget_flag && isaddrof(a)) { + a->type = L_poly; + v = a->a; + /* can't use local vars or functions from a widget */ + if (v->sym && + ((v->sym->decl->flags & (DECL_LOCAL_VAR|DECL_FN)) || + !canDeref(v->sym))) { + L_errf(a, "illegal operand to &"); + } + } + s = a->str; + widget_flag = ((a->kind == L_EXPR_CONST) && + isstring(a) && + /* has at least the minimum length */ + (strlen(s) > strlen_of_variable) && + /* starts with '-' */ + (s[0] == '-') && + /* ends with "variable" */ + !strcmp("variable", s + (strlen(s) - strlen_of_variable))); + if (formals) formals = formals->next; + } + return (i); +} + +private int +compile_unOp(Expr *expr) +{ + switch (expr->op) { + case L_OP_BANG: + case L_OP_BITNOT: + if (expr->op == L_OP_BANG) { + compile_condition(expr->a); + } else { + compile_expr(expr->a, L_PUSH_VAL); + } + L_typeck_expect(L_INT, expr->a, "in unary ! or ~"); + emit_instrForLOp(expr, expr->type); + expr->type = expr->a->type; + break; + case L_OP_UPLUS: + case L_OP_UMINUS: + compile_expr(expr->a, L_PUSH_VAL); + L_typeck_expect(L_INT|L_FLOAT, expr->a, "in unary +/-"); + emit_instrForLOp(expr, expr->type); + expr->type = expr->a->type; + break; + case L_OP_DEFINED: + compile_defined(expr->a); + expr->type = L_int; + break; + case L_OP_ADDROF: + /* + * Compile &<expr>. For function names, regular + * variables, and class variables (&x, + * &classname->var, &obj->var), this is just the name + * of the Tcl variable. For a deep-dive expr, + * it's the name of a temp var that holds the value. + */ + compile_expr(expr->a, L_PUSH_NAME); + expr->type = type_mkNameOf(expr->a->type); + unless (expr->a->sym) { + L_errf(expr->a, "illegal operand to &"); + expr->type = L_poly; + } + break; + case L_OP_PLUSPLUS_PRE: + case L_OP_PLUSPLUS_POST: + case L_OP_MINUSMINUS_PRE: + case L_OP_MINUSMINUS_POST: + compile_incdec(expr); + expr->type = expr->a->type; + break; + case L_OP_EXPAND: + unless (fnInArgList()) { + L_errf(expr, "(expand) illegal in this context"); + } + compile_expr(expr->a, L_PUSH_VAL); + TclEmitInstInt4(INST_EXPAND_STKTOP, + L->frame->envPtr->currStackDepth, + L->frame->envPtr); + expr->type = L_poly; + break; + case L_OP_CMDSUBST: + push_lit("::backtick_"); + if (expr->a) { + compile_expr(expr->a, L_PUSH_VAL); + push_lit(expr->str); + TclEmitInstInt1(INST_STR_CONCAT1, 2, L->frame->envPtr); + } else { + push_lit(expr->str); + } + emit_invoke(2); + expr->type = L_string; + break; + case L_OP_FILE: + if (expr->a) { + push_lit("fgetline"); + compile_expr(expr->a, L_PUSH_VAL); + if (typeisf(expr->a, "FILE")) { + emit_invoke(2); + } else { + L_errf(expr->a, "expect FILE in <>"); + } + } else { + push_lit("angle_read_"); + emit_invoke(1); + } + expr->type = L_string; + break; + default: + L_bomb("Unknown unary operator %d", expr->op); + break; + } + return (1); // stack effect +} + +private int +compile_binOp(Expr *expr, Expr_f flags) +{ + int expand, level, n; + Type *type; + Expr *e; + + /* Return the net run-time stack effect (i.e., how much was pushed). */ + + switch (expr->op) { + case L_OP_EQUALS: + compile_assign(expr); + expr->type = expr->a->type; + return (1); + case L_OP_EQPLUS: + case L_OP_EQMINUS: + case L_OP_EQSTAR: + case L_OP_EQSLASH: + compile_assign(expr); + L_typeck_expect(L_INT|L_FLOAT, expr->a, + "in arithmetic assignment"); + expr->type = expr->a->type; + return (1); + case L_OP_EQPERC: + case L_OP_EQBITAND: + case L_OP_EQBITOR: + case L_OP_EQBITXOR: + case L_OP_EQLSHIFT: + case L_OP_EQRSHIFT: + compile_assign(expr); + L_typeck_expect(L_INT, expr->a, "in arithmetic assignment"); + expr->type = expr->a->type; + return (1); + case L_OP_EQDOT: + compile_assign(expr); + L_typeck_expect(L_STRING|L_WIDGET, expr->a, "in .="); + expr->type = expr->a->type; + return (1); + case L_OP_ANDAND: + case L_OP_OROR: + compile_shortCircuit(expr); + expr->type = L_int; + return (1); + case L_OP_STR_EQ: + case L_OP_STR_NE: + case L_OP_STR_GT: + case L_OP_STR_GE: + case L_OP_STR_LT: + case L_OP_STR_LE: + unless (hash_get(L->options, "allow_eq_ops")) { + L_errf(expr, "illegal comparison operator"); + } + /* Warn on things like "s eq undef". */ + if (isid(e=expr->a, "undef") || isid(e=expr->b, "undef")) { + L_errf(e, "undef illegal in comparison"); + } + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + L_typeck_expect(L_STRING|L_WIDGET, expr->a, + "in string comparison"); + L_typeck_expect(L_STRING|L_WIDGET, expr->b, + "in string comparison"); + emit_instrForLOp(expr, expr->type); + expr->type = L_int; + return (1); + case L_OP_EQUALEQUAL: + case L_OP_NOTEQUAL: + case L_OP_GREATER: + case L_OP_GREATEREQ: + case L_OP_LESSTHAN: + case L_OP_LESSTHANEQ: + expr->type = L_int; + /* Warn on things like "i == undef". */ + if (isid(e=expr->a, "undef") || isid(e=expr->b, "undef")) { + L_errf(e, "undef illegal in comparison"); + } + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + L_typeck_deny(L_VOID, expr->a); + L_typeck_deny(L_VOID, expr->b); + unless (L_typeck_compat(expr->a->type, expr->b->type) || + L_typeck_compat(expr->b->type, expr->a->type)) { + L_errf(expr, "incompatible types in comparison"); + return (0); + } + if (!isscalar(expr->a) && (expr->op != L_OP_EQUALEQUAL)) { + L_errf(expr, "only eq() allowed on non-scalar types"); + return (0); + } + compile_eq_stack(expr, expr->a->type); + return (1); // stack effect + case L_OP_PLUS: + case L_OP_MINUS: + case L_OP_STAR: + case L_OP_SLASH: + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + L_typeck_expect(L_INT|L_FLOAT, expr->a, + "in arithmetic operator"); + L_typeck_expect(L_INT|L_FLOAT, expr->b, + "in arithmetic operator"); + emit_instrForLOp(expr, expr->type); + if (isfloat(expr->a) || isfloat(expr->b)) { + expr->type = L_float; + } else { + expr->type = L_int; + } + return (1); + case L_OP_PERC: + case L_OP_BITAND: + case L_OP_BITOR: + case L_OP_BITXOR: + case L_OP_LSHIFT: + case L_OP_RSHIFT: + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + L_typeck_expect(L_INT, expr->a, "in arithmetic operator"); + L_typeck_expect(L_INT, expr->b, "in arithmetic operator"); + emit_instrForLOp(expr, expr->type); + expr->type = L_int; + return (1); + case L_OP_ARRAY_INDEX: + case L_OP_HASH_INDEX: + case L_OP_DOT: + case L_OP_POINTS: + return (compile_idxOp(expr, flags)); + case L_OP_CLASS_INDEX: + return (compile_clsDeref(expr, flags)); + case L_OP_INTERP_STRING: + case L_OP_INTERP_RE: + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + TclEmitInstInt1(INST_STR_CONCAT1, 2, L->frame->envPtr); + expr->type = L_string; + return (1); + case L_OP_LIST: + level = fnCallBegin(); + for (e = expr, expand = 0; e; e = e->b) { + if (e->a && isexpand(e->a)) { + TclEmitOpcode(INST_EXPAND_START, + L->frame->envPtr); + expand = 1; + break; + } + } + push_lit("::list"); + n = compile_expr(expr->a, L_PUSH_VAL); + if (n == 0) { // empty list {} + ASSERT(!expr->a && !expr->b); + type = L_poly; + } else if (iskv(expr->a)) { + ASSERT((n == 2) && ishash(expr->a)); + type = expr->a->type; + } else { + type = type_mkList(expr->a->type); + } + for (e = expr->b; e; e = e->b) { + ASSERT(e->op == L_OP_LIST); + n += compile_expr(e->a, L_PUSH_VAL); + if (ishashtype(type) && iskv(e->a)) { + } else if (islisttype(type) && !iskv(e->a)) { + /* + * The list type is literally a list of all the + * individual element types linked together. + */ + Type *t = type_mkList(e->a->type); + APPEND(Type, next, type, t); + } else unless (ispolytype(type)) { + L_errf(expr, "cannot mix hash and " + "non-hash elements"); + type = L_poly; + } + } + if (expand) { + emit_invoke_expanded(); + } else { + emit_invoke(n+1); + } + expr->type = type; + fnCallEnd(level); + return (1); + case L_OP_KV: + n = compile_expr(expr->a, L_PUSH_VAL); + n += compile_expr(expr->b, L_PUSH_VAL); + ASSERT(n == 2); + unless (isscalar(expr->a)) { + L_errf(expr->a, "hash keys must be scalar"); + } + expr->type = type_mkHash(expr->a->type, expr->b->type); + return (n); + case L_OP_EQTWID: + case L_OP_BANGTWID: + compile_twiddle(expr); + expr->type = L_int; + return (1); + case L_OP_COMMA: + compile_expr(expr->a, L_DISCARD); + compile_expr(expr->b, L_PUSH_VAL); + expr->type = expr->b->type; + return (1); + case L_OP_CAST: + return (compile_cast(expr, flags)); + case L_OP_CONCAT: + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + L_typeck_expect(L_STRING|L_WIDGET, expr->a, + "in lhs of . operator"); + L_typeck_expect(L_STRING|L_WIDGET, expr->b, + "in rhs of . operator"); + TclEmitInstInt1(INST_STR_CONCAT1, 2, L->frame->envPtr); + expr->type = L_string; + return (1); + default: + L_bomb("compile_binOp: malformed AST"); + return (1); + } +} + +private int +compile_cast(Expr *expr, Expr_f flags) +{ + int range; + Jmp *jmp; + Type *type = (Type *)expr->a; + + flags &= ~L_DISCARD; + if (flags & L_LVALUE) { + compile_expr(expr->b, flags); + } else if ((type->kind == L_INT) || (type->kind == L_FLOAT)) { + range = TclCreateExceptRange(CATCH_EXCEPTION_RANGE, + L->frame->envPtr); + TclEmitInstInt4(INST_BEGIN_CATCH4, range, L->frame->envPtr); + ExceptionRangeStarts(L->frame->envPtr, range); + if (type->kind == L_INT) { + push_lit("::tcl::mathfunc::int"); + compile_expr(expr->b, flags); + emit_invoke(2); + } else if (type->kind == L_FLOAT) { + push_lit("::tcl::mathfunc::double"); + compile_expr(expr->b, flags); + emit_invoke(2); + } + ExceptionRangeEnds(L->frame->envPtr, range); + jmp = emit_jmp_fwd(INST_JUMP4, 0); + /* error case */ + ExceptionRangeTarget(L->frame->envPtr, range, catchOffset); + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + /* out */ + fixup_jmps(&jmp); + TclEmitOpcode(INST_END_CATCH, L->frame->envPtr); + } else { + compile_expr(expr->b, flags); + } + L_typeck_deny(L_VOID|L_FUNCTION, expr->b); + expr->sym = expr->b->sym; + expr->flags = expr->b->flags; + expr->type = type; + return (1); +} + +private int +compile_trinOp(Expr *expr) +{ + int save, start_off; + int i = 0, n = 0; + Jmp *end_jmp, *false_jmp; + + switch (expr->op) { + case L_OP_EQTWID: + compile_twiddleSubst(expr); + expr->type = L_int; + n = 1; + break; + case L_OP_INTERP_STRING: + case L_OP_INTERP_RE: + compile_expr(expr->a, L_PUSH_VAL); + compile_expr(expr->b, L_PUSH_VAL); + compile_expr(expr->c, L_PUSH_VAL); + TclEmitInstInt1(INST_STR_CONCAT1, 3, L->frame->envPtr); + expr->type = L_string; + n = 1; + break; + case L_OP_ARRAY_SLICE: + compile_expr(expr->a, L_PUSH_VAL); + if (isstring(expr->a) || iswidget(expr->a)) { + push_lit("::string"); + push_lit("range"); + TclEmitInstInt1(INST_ROT, 2, L->frame->envPtr); + expr->type = L_string; + i = 5; + } else if (isarray(expr->a) || islist(expr->a)) { + push_lit("::lrange"); + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + expr->type = expr->a->type; + i = 4; + } else { + L_errf(expr->a, "illegal type for slice"); + expr->type = L_poly; + } + if (has_END(expr->b) || has_END(expr->c)) { + if (isstring(expr->a) || iswidget(expr->a)) { + TclEmitOpcode(INST_L_PUSH_STR_SIZE, + L->frame->envPtr); + } else { + TclEmitOpcode(INST_L_PUSH_LIST_SIZE, + L->frame->envPtr); + } + } + save = L->idx_op; + L->idx_op = L_OP_ARRAY_SLICE; + compile_expr(expr->b, L_PUSH_VAL); + unless (isint(expr->b)) { + L_errf(expr->b, "first slice index not an int"); + } + compile_expr(expr->c, L_PUSH_VAL); + unless (isint(expr->c)) { + L_errf(expr->c, "second slice index not an int"); + } + L->idx_op = save; + if (has_END(expr->b) || has_END(expr->c)) { + TclEmitOpcode(INST_L_POP_SIZE, L->frame->envPtr); + } + emit_invoke(i); + n = 1; + break; + case L_OP_TERNARY_COND: + compile_condition(expr->a); + false_jmp = emit_jmp_fwd(INST_JUMP_FALSE4, NULL); + start_off = currOffset(L->frame->envPtr); + n = compile_expr(expr->b, L_PUSH_VAL); + end_jmp = emit_jmp_fwd(INST_JUMP4, NULL); + track_cmd(start_off, expr->b); + fixup_jmps(&false_jmp); + start_off = currOffset(L->frame->envPtr); + compile_expr(expr->c, L_PUSH_VAL); + track_cmd(start_off, expr->c); + fixup_jmps(&end_jmp); + if (ispoly(expr->b) || ispoly(expr->c)) { + expr->type = L_poly; + } else if (L_typeck_same(expr->b->type, expr->c->type)) { + expr->type = expr->b->type; + } else if ((expr->b->type->kind & (L_INT|L_FLOAT)) && + (expr->c->type->kind & (L_INT|L_FLOAT))) { + expr->type = L_float; + } else { + L_errf(expr, "incompatible types in ? : expressions"); + expr->type = L_poly; + } + break; + default: + L_bomb("compile_trinOp: malformed AST"); + } + return (n); // stack effect +} + + +/* + * There are two kinds of defined(): + * defined(&var) - var is a call-by-reference formal + * defined(expr) - otherwise + */ +private void +compile_defined(Expr *expr) +{ + Sym *sym; + + if (isaddrof(expr)) { + unless (expr->a->kind == L_EXPR_ID) { + L_errf(expr, "arg to & not a call-by-reference parm"); + return; + } + sym = sym_lookup(expr->a, L_NOWARN); + unless (sym && (sym->decl->flags & DECL_REF)) { + L_errf(expr, "%s undeclared or not a " + "call-by-reference parm", expr->a->str); + return; + } + push_lit("::L_undef_ref_parm_"); + TclEmitInstInt4(INST_DIFFERENT_OBJ, sym->idx, L->frame->envPtr); + } else { + compile_expr(expr, L_PUSH_VAL); + L_typeck_deny(L_VOID, expr); + TclEmitOpcode(INST_L_DEFINED, L->frame->envPtr); + } +} + +/* + * Estimate how many submatches are in the given regexp. These are + * the sub-expressions within parens. If the regexp includes an + * interpolated string, we can't get this exact, so just assume + * the maximum (9) in that case. + */ +private int +re_submatchCnt(Expr *re) +{ + int n = 9; + Tcl_Obj *const_regexp; + Tcl_RegExp compiled; + + if (re->kind == L_EXPR_RE) { + const_regexp = Tcl_NewStringObj(re->str, -1); + Tcl_IncrRefCount(const_regexp); + compiled = Tcl_GetRegExpFromObj(L->interp, const_regexp, + TCL_REG_ADVANCED); + Tcl_DecrRefCount(const_regexp); + if (compiled) n = ((TclRegexp *)compiled)->re.re_nsub; + } + return (n); +} + +/* + * Determine whether a regexp is a constant (which can be matched with + * a string comparison), a glob (use string-match bytecode), a simpler + * regexp (no submatches, use the regexp bytecode), or a more complex + * regexp which requires the ::regexp command. If the regexp is + * interpolated, we can't tell for sure, so assume the worst. Also + * return flags indicating whether the re expr needs to be compiled. + * + * If ds is non-NULL return the equivalent glob in *ds; this becomes + * an operand to INST_STR_EQ or INST_STR_MATCH. + */ +private ReKind +re_kind(Expr *re, Tcl_DString *ds) +{ + Tcl_DString myds; + int exact, ret = 0; + + unless ((re->kind == L_EXPR_RE) || (re->op == L_OP_INTERP_RE)) { + return (RE_NOT_AN_RE); + } + unless (ds) ds = &myds; // to accommodate passing in ds==NULL + + if (re->op == L_OP_INTERP_RE) { + ret |= RE_NEEDS_EVAL; + } + if (re->flags & L_EXPR_RE_L) { + ret |= RE_NEEDS_EVAL | RE_GLOB; + } else if (re_submatchCnt(re) || (re->flags & L_EXPR_RE_G)) { + ret |= RE_NEEDS_EVAL | RE_COMPLEX; + } else if (isstring(re) && + (TclReToGlob(NULL, re->str, strlen(re->str), + ds, &exact, NULL) == TCL_OK) && + exact) { + if (ds == &myds) Tcl_DStringFree(&myds); + ret |= RE_CONST; + } else { + ret |= RE_NEEDS_EVAL | RE_SIMPLE; + } + return (ret); +} + +private void +compile_twiddle(Expr *expr) +{ + compile_expr(expr->a, L_PUSH_VAL); + compile_reMatch(expr->b); + if (expr->op == L_OP_BANGTWID) { + TclEmitOpcode(INST_LNOT, L->frame->envPtr); + L_typeck_expect(L_STRING|L_WIDGET, expr->a, "in !~"); + } else { + L_typeck_expect(L_STRING|L_WIDGET, expr->a, "in =~"); + } +} + +/* + * Compile a regexp match. It is assumed that the value to compare + * the regexp against will already be on the run-time stack. Code to + * push the regexp is generated here. When run, these are replaced + * with the match Boolean. + */ +private void +compile_reMatch(Expr *re) +{ + int i, cflags, mod_cnt, submatch_cnt; + int nocase = (re->flags & L_EXPR_RE_I); + Sym *s; + Expr *id; + ReKind kind; + Tcl_DString ds; + + kind = re_kind(re, &ds); + /* First push the regexp. */ + if (kind & RE_NEEDS_EVAL) { + compile_expr(re, L_PUSH_VAL); + } else { + push_lit(Tcl_DStringValue(&ds)); + Tcl_DStringFree(&ds); + } + /* Now emit the appropriate match instruction. */ + switch (kind & (RE_CONST|RE_GLOB|RE_SIMPLE|RE_COMPLEX)) { + case RE_CONST: + TclEmitOpcode(INST_STR_EQ, L->frame->envPtr); + break; + case RE_GLOB: + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + TclEmitInstInt1(INST_STR_MATCH, nocase, L->frame->envPtr); + break; + case RE_SIMPLE: + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + cflags = TCL_REG_ADVANCED | TCL_REG_NLSTOP | + (nocase ? TCL_REG_NOCASE : 0); + TclEmitInstInt1(INST_REGEXP, cflags, L->frame->envPtr); + break; + case RE_COMPLEX: + // val re + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + // re val + push_lit("::regexp"); + mod_cnt = push_regexpModifiers(re); + push_lit("--"); + // re val ::regexp <mods> -- + TclEmitInstInt1(INST_ROT, mod_cnt+3, L->frame->envPtr); + // val ::regexp <mods> -- re + TclEmitInstInt1(INST_ROT, mod_cnt+3, L->frame->envPtr); + // ::regexp <mods> -- re val + /* Submatch vars. This loop always iterates at least once. */ + submatch_cnt = re_submatchCnt(re); + for (i = 0; i <= submatch_cnt; i++) { + char buf[32]; + snprintf(buf, sizeof(buf), "$%d", i); + id = mkId(buf); + unless (sym_lookup(id, L_NOWARN)) { + s = sym_mk(buf, L_string, + SCOPE_LOCAL | DECL_LOCAL_VAR); + s->used_p = TRUE; // suppress unused var warning + } + push_lit(buf); + } + emit_invoke(5 + submatch_cnt + mod_cnt); + break; + default: ASSERT(0); + } +} + +private void +compile_twiddleSubst(Expr *expr) +{ + Expr *id, *lhs = expr->a; + int i, modCount, submatchCount; + Sym *s; + Tmp *tmp = NULL; + Tcl_Obj *varList; + + push_lit("::regsub"); + modCount = push_regexpModifiers(expr->b); + /* Submatch vars. This loop always iterates at least once. */ + push_lit("-submatches"); + submatchCount = re_submatchCnt(expr->b); + varList = Tcl_NewObj(); + Tcl_IncrRefCount(varList); + for (i = 0; i <= submatchCount; i++) { + char buf[32]; + snprintf(buf, sizeof(buf), "$%d", i); + id = mkId(buf); + unless (sym_lookup(id, L_NOWARN)) { + s = sym_mk(buf, L_string, + SCOPE_LOCAL | DECL_LOCAL_VAR); + s->used_p = TRUE; // suppress unused var warning + } + Tcl_AppendPrintfToObj(varList, "$%d ", i); + } + push_lit(Tcl_GetString(varList)); + Tcl_DecrRefCount(varList); + push_lit("-line"); + push_lit("--"); + compile_expr(expr->b, L_PUSH_VAL); + // ::regsub <mods> -submatches <varlist> -line -- <re> + compile_expr(expr->c, L_PUSH_VAL); + // ::regsub <mods> -submatches <varlist> -line -- <re> <subst> + compile_expr(lhs, L_PUSH_VALPTR | L_PUSH_VAL | L_LVALUE); + unless (lhs->sym) { + L_errf(expr, "invalid l-value in =~"); + return; + } + if (isdeepdive(lhs)) { + tmp = tmp_get(TMP_REUSE); + // ::regsub <mods> -submatches <varlist> + // -line -- <re> <subst> <lhs-val> <lhs-ptr> + TclEmitInstInt1(INST_ROT, -(8+modCount), L->frame->envPtr); + // <lhs-ptr> ::regsub <mods> -submatches <varlist> + // -line -- <re> <subst> <lhs-val> + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + // <lhs-ptr> ::regsub <mods> -submatches <varlist> + // -line -- <re> <lhs-val> <subst> + push_lit(tmp->name); + // <lhs-ptr> ::regsub <mods> -submatches <varlits> + // -line -- <re> <lhs-val> <subst> <tmp-name> + } else { + // ::regsub <mods> -submatches <varlist> + // -line -- <re> <subst> <lhs-val> + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + // ::regsub <mods> -submatches <varlist> + // -line -- <re> <lhs-val> <subst> + push_lit(lhs->sym->tclname); + // ::regsub <mods> -submatches <varlist> + // -line -- <re> <lhs-val> <subst> <lhs-name> + } + emit_invoke(modCount + 9); + if (isdeepdive(lhs)) { + // <lhs-ptr> <match> + emit_load_scalar(tmp->idx); + tmp_free(tmp); + // <lhs-ptr> <match> <new-val> + TclEmitInstInt1(INST_ROT, 2, L->frame->envPtr); + // <match> <new-val> <lhs-ptr> + TclEmitInstInt4(INST_L_DEEP_WRITE, + lhs->sym->idx, + L->frame->envPtr); + TclEmitInt4(L_PUSH_NEW, L->frame->envPtr); + // <match> <new-val> + emit_pop(); + } + L_typeck_expect(L_STRING|L_WIDGET, lhs, "in =~"); + // <match> +} + +private void +compile_shortCircuit(Expr *expr) +{ + Jmp *jmp; + unsigned char op; + + /* + * In case the operator "a op b" short-circuits, we need one + * value of "a" on the stack for the test and one for the value of + * the expression. If the operator doesn't short-circuit, we + * pop one of these off and move on to evaluating "b". + */ + ASSERT((expr->op == L_OP_ANDAND) || (expr->op == L_OP_OROR)); + op = (expr->op == L_OP_ANDAND) ? INST_JUMP_FALSE4 : INST_JUMP_TRUE4; + compile_condition(expr->a); + // <a-val> + TclEmitOpcode(INST_DUP, L->frame->envPtr); + // <a-val> <a-val> + jmp = emit_jmp_fwd(op, NULL); + // <a-val> if short-circuit and we jumped out + // <a-val> if did not short-circuit and we're still going + emit_pop(); + compile_condition(expr->b); + fixup_jmps(&jmp); + // <a-val> if short-circuit + // <b-val> if did not short-circuit +} + +/* + * Compile an expression that is used as a conditional test. + * This is compiled like a normal expression except that if it's + * of string type the expression is tested for defined. + */ +private void +compile_condition(Expr *cond) +{ + unless (cond) { + push_lit("1"); + return; + } + if (isaddrof(cond)) { + compile_defined(cond); + } else { + compile_expr(cond, L_PUSH_VAL); + if (isvoid(cond)) { + L_errf(cond, "void type illegal in predicate"); + } + unless (isint(cond) || isfloat(cond) || ispoly(cond)) { + TclEmitOpcode(INST_L_DEFINED, L->frame->envPtr); + } + } + cond->type = L_int; +} + +/* + * Compile if-unless as follows. + * + * No "else" leg: "Else" leg present: + * <eval cond> <eval cond> + * jmpFalse 1 jmpFalse 1 + * <if leg> <if leg> + * 1: jmp 2 + * 1: <else leg> + * 2: + */ +private void +compile_ifUnless(Cond *cond) +{ + Jmp *endjmp, *falsejmp; + + /* Test the condition and jmp if false. */ + compile_condition(cond->cond); + falsejmp = emit_jmp_fwd(INST_JUMP_FALSE4, NULL); + + /* Compile the "if" leg. */ + frame_push(cond, NULL, SEARCH); + compile_stmts(cond->if_body); + + if (cond->else_body) { + /* "Else" leg present. */ + frame_pop(); + frame_push(cond, NULL, SEARCH); + endjmp = emit_jmp_fwd(INST_JUMP4, NULL); + fixup_jmps(&falsejmp); + compile_stmts(cond->else_body); + fixup_jmps(&endjmp); + } else { + /* No "else" leg. */ + fixup_jmps(&falsejmp); + } + frame_pop(); +} + +private void +compile_loop(Loop *loop) +{ + switch (loop->kind) { + case L_LOOP_DO: + compile_do(loop); + break; + case L_LOOP_FOR: + case L_LOOP_WHILE: + compile_for_while(loop); + break; + default: + L_bomb("bad loop type"); + break; + } +} + +/* + * Do loop: + * + * 1: <body> + * <cond> + * jmpTrue 1 + */ +private void +compile_do(Loop *loop) +{ + int body_off; + Jmp *break_jmps, *continue_jmps; + + body_off = currOffset(L->frame->envPtr); + frame_push(loop, NULL, LOOP|SEARCH); + compile_stmts(loop->body); + break_jmps = L->frame->break_jumps; + continue_jmps = L->frame->continue_jumps; + frame_pop(); + fixup_jmps(&continue_jmps); + + compile_condition(loop->cond); + emit_jmp_back(TCL_TRUE_JUMP, body_off); + fixup_jmps(&break_jmps); +} + +/* + * While loop: For loop: + * + * <pre> + * 1: <cond> 1: <cond> + * jmpFalse 2 jmpFalse 2 + * <body> <body> + * <post> + * jmp 1 jmp 1 + * 2: 2: + */ +private void +compile_for_while(Loop *loop) +{ + int cond_off; + Jmp *break_jmps, *continue_jmps, *out_jmp; + + if (loop->kind == L_LOOP_FOR) compile_exprs(loop->pre, L_DISCARD); + + cond_off = currOffset(L->frame->envPtr); + compile_condition(loop->cond); + out_jmp = emit_jmp_fwd(INST_JUMP_FALSE4, NULL); + + frame_push(loop, NULL, LOOP|SEARCH); + compile_stmts(loop->body); + break_jmps = L->frame->break_jumps; + continue_jmps = L->frame->continue_jumps; + frame_pop(); + fixup_jmps(&continue_jmps); + + if (loop->kind == L_LOOP_FOR) compile_exprs(loop->post, L_DISCARD); + + emit_jmp_back(TCL_UNCONDITIONAL_JUMP, cond_off); + fixup_jmps(&out_jmp); + fixup_jmps(&break_jmps); +} + +/* + * Emit a jump instruction to a backwards target. jmp_type is one of + * TCL_UNCONDITIONAL, TCL_TRUE_JUMP, or TCL_FALSE_JUMP. The jump + * opcope is appropriately selected for the jump distance. + */ +private void +emit_jmp_back(TclJumpType jmp_type, int offset) +{ + int op = 0; + int dist = currOffset(L->frame->envPtr) - offset; + + if (dist > 127) { + switch (jmp_type) { + case TCL_UNCONDITIONAL_JUMP: + op = INST_JUMP4; + break; + case TCL_TRUE_JUMP: + op = INST_JUMP_TRUE4; + break; + case TCL_FALSE_JUMP: + op = INST_JUMP_FALSE4; + break; + default: + L_bomb("bad jmp type"); + break; + } + TclEmitInstInt4(op, -dist, L->frame->envPtr); + } else { + switch (jmp_type) { + case TCL_UNCONDITIONAL_JUMP: + op = INST_JUMP1; + break; + case TCL_TRUE_JUMP: + op = INST_JUMP_TRUE1; + break; + case TCL_FALSE_JUMP: + op = INST_JUMP_FALSE1; + break; + default: + L_bomb("bad jmp type"); + break; + } + TclEmitInstInt1(op, -dist, L->frame->envPtr); + } +} + +/* + * Emit a jump instruction with an unknown target offset and return a + * structure that can be passed in to fixup_jmps() to later fix-up the + * target to any desired bytecode offset. Caller must free the + * returned structure. + */ +private Jmp * +emit_jmp_fwd(int op, Jmp *next) +{ + Jmp *ret = (Jmp *)ckalloc(sizeof(Jmp)); + + ret->op = op; + ret->offset = currOffset(L->frame->envPtr); + ret->next = next; + switch (op) { + case INST_JUMP1: + case INST_JUMP_TRUE1: + case INST_JUMP_FALSE1: + ret->size = 1; + TclEmitInstInt1(op, 0, L->frame->envPtr); + break; + case INST_JUMP4: + case INST_JUMP_TRUE4: + case INST_JUMP_FALSE4: + ret->size = 4; + TclEmitInstInt4(op, 0, L->frame->envPtr); + break; + default: + L_bomb("unexpected jump instruction"); + break; + } + return (ret); +} + +/* + * Fix up jump targets to point to the current PC, free the + * passed-in fix-ups list and then set it to NULL. + */ +private void +fixup_jmps(Jmp **p) +{ + int target; + Jmp *t; + Jmp *j = *p; + unsigned char *jmp_pc; + + while (j) { + target = currOffset(L->frame->envPtr) - j->offset; + jmp_pc = L->frame->envPtr->codeStart + j->offset; + switch (j->size) { + case 1: + ASSERT(*jmp_pc == j->op); + TclUpdateInstInt1AtPc(j->op, target, jmp_pc); + break; + case 4: + ASSERT(*jmp_pc == j->op); + TclUpdateInstInt4AtPc(j->op, target, jmp_pc); + break; + default: + L_bomb("unexpected jump fixup"); + break; + } + t = j->next; + ckfree((char *)j); + j = t; + } + *p = NULL; +} + +private void +compile_foreach(ForEach *loop) +{ + /* + * Handle foreach(s in <expr>). + */ + if (loop->expr->op == L_OP_FILE) { + compile_foreachAngle(loop); + return; + } + + compile_expr(loop->expr, L_PUSH_VAL); + + switch (loop->expr->type->kind) { + case L_ARRAY: + case L_LIST: + compile_foreachArray(loop); + break; + case L_HASH: + compile_foreachHash(loop); + break; + case L_STRING: + compile_foreachString(loop); + break; + default: + L_errf(loop->expr, "foreach expression must be" + " array, hash, or string"); + break; + } +} + +/* + * Most of the following function came from tclCompCmds.c + * TclCompileForEachCmd(), modified in various ways for L. + */ +private void +compile_foreachArray(ForEach *loop) +{ + int i, continue_off, num_vars; + Expr *var; + ForeachInfo *info; + ForeachVarList *varlist; + Jmp *break_jumps, *continue_jumps, *false_jump; + int jumpBackDist, jumpBackOffset, infoIndex; + Tmp *loopctrTmp, *valTmp; + + /* The foreach(k=>v in expr) form is illegal in array iteration. */ + if (loop->value) { + L_errf(loop, "=> illegal in foreach over arrays"); + } + + /* + * Type-check the value variables. In "foreach (v1,v2,v3 in + * a)", v* are the value variables or variable list, and a is + * the value list, in tcl terminology. + */ + for (var = loop->key, num_vars = 0; var; var = var->next, ++num_vars) { + unless (sym_lookup(var, 0)) return; // undeclared var + unless (L_typeck_arrElt(var->type, loop->expr->type)) { + L_errf(var, "loop index type incompatible with" + " array element type"); + } + } + + /* Temps for value list value and loop counter. */ + valTmp = tmp_get(TMP_UNSET); + loopctrTmp = tmp_get(TMP_UNSET); + + /* + * ForeachInfo and ForeachVarList are structures required by + * the bytecode interpreter for foreach bytecodes. In our + * case, we have only one value and one variable list + * consisting of num_vars variables. + */ + info = (ForeachInfo *)ckalloc(sizeof(ForeachInfo) + + sizeof(ForeachVarList *)); + info->numLists = 1; + info->firstValueTemp = valTmp->idx; + info->loopCtTemp = loopctrTmp->idx; + varlist = (ForeachVarList *)ckalloc(sizeof(ForeachVarList) + + num_vars * sizeof(int)); + varlist->numVars = num_vars; + for (i = 0, var = loop->key; var; var = var->next, ++i) { + Sym *s = sym_lookup(var, 0); + varlist->varIndexes[i] = s->idx; + } + info->varLists[0] = varlist; + infoIndex = TclCreateAuxData(info, &tclForeachInfoType, + L->frame->envPtr); + + /* The values to iterate through are already on the stack (the + * caller evaluated loop->expr). Assign to the value temp. */ + emit_store_scalar(valTmp->idx); + emit_pop(); + + /* Initialize the loop state. */ + TclEmitInstInt4(INST_FOREACH_START4, infoIndex, L->frame->envPtr); + + /* Top of the loop. Step, and jump out if done. */ + continue_off = currOffset(L->frame->envPtr); + TclEmitInstInt4(INST_FOREACH_STEP4, infoIndex, L->frame->envPtr); + false_jump = emit_jmp_fwd(INST_JUMP_FALSE4, NULL); + + /* Loop body. */ + frame_push(loop, NULL, LOOP|SEARCH); + compile_stmts(loop->body); + break_jumps = L->frame->break_jumps; + continue_jumps = L->frame->continue_jumps; + frame_pop(); + fixup_jmps(&continue_jumps); + + /* End of loop -- jump back to top. */ + jumpBackOffset = currOffset(L->frame->envPtr); + jumpBackDist = jumpBackOffset - continue_off; + if (jumpBackDist > 120) { + TclEmitInstInt4(INST_JUMP4, -jumpBackDist, L->frame->envPtr); + } else { + TclEmitInstInt1(INST_JUMP1, -jumpBackDist, L->frame->envPtr); + } + + fixup_jmps(&false_jump); + + /* Set the value variables to undef. */ + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + for (var = loop->key; var; var = var->next) { + Sym *s = sym_lookup(var, 0); + ASSERT(s); + emit_store_scalar(s->idx); + } + emit_pop(); + + fixup_jmps(&break_jumps); + tmp_free(valTmp); + tmp_free(loopctrTmp); +} + +private void +compile_foreachHash(ForEach *loop) +{ + Sym *key; + Sym *val = NULL; + int body_off, disp; + Jmp *break_jumps, *continue_jumps, *out_jmp; + Tmp *itTmp; + + /* Check types and ensure variables are declared etc. */ + unless ((key = sym_lookup(loop->key, 0))) return; + if (loop->value) { + unless ((val = sym_lookup(loop->value, 0))) return; + unless (L_typeck_compat(val->type, + loop->expr->type->base_type)) { + L_errf(loop->value, "loop index value type " + "incompatible with hash element type"); + } + } + unless (L_typeck_compat(key->type, loop->expr->type->u.hash.idx_type)) { + L_errf(loop->key, + "loop index key type incompatible with hash index type"); + } + if (loop->key->next) { + L_errf(loop, "multiple variables illegal in foreach over hash"); + } + + /* A temp to hold the iterator state.*/ + itTmp = tmp_get(TMP_UNSET); + + /* + * Both DICT_FIRST and DICT_NEXT leave value, key, and done-p + * on the stack. Check done-p and jump out of the loop if + * it's true. (We fixup the jump target once we know the size + * of the loop body.) + */ + TclEmitInstInt4(INST_DICT_FIRST, itTmp->idx, L->frame->envPtr); + out_jmp = emit_jmp_fwd(INST_JUMP_TRUE4, NULL); + + /* + * Update the key and value variables. We save the offset of + * this code so we can jump back to it after DICT_NEXT. + * Note: the caller already pushed loop->expr. + */ + body_off = currOffset(L->frame->envPtr); + emit_store_scalar(key->idx); + emit_pop(); + if (loop->value) emit_store_scalar(val->idx); + emit_pop(); + + /* + * Compile loop body. Note that we must grab the jump fix-ups + * out of the frame before popping it. + */ + frame_push(loop, NULL, LOOP|SEARCH); + compile_stmts(loop->body); + break_jumps = L->frame->break_jumps; + continue_jumps = L->frame->continue_jumps; + frame_pop(); + fixup_jmps(&continue_jumps); + + /* If there's another entry in the hash, go around again. */ + TclEmitInstInt4(INST_DICT_NEXT, itTmp->idx, L->frame->envPtr); + disp = body_off - currOffset(L->frame->envPtr); + TclEmitInstInt4(INST_JUMP_FALSE4, disp, L->frame->envPtr); + + /* End of the loop. Point the jump after the DICT_FIRST to here. */ + fixup_jmps(&out_jmp); + + /* All done. Cleanup the values that DICT_FIRST/DICT_NEXT left. */ + emit_pop(); + emit_pop(); + + /* Set key and/or value counters to undef. */ + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + emit_store_scalar(key->idx); + if (val) emit_store_scalar(val->idx); + emit_pop(); + + fixup_jmps(&break_jumps); + /* XXX We need to ensure that DICT_DONE happens in the face of + exceptions, so that the refcount on the dict will be + decremented, and the iterator freed. See the + implementation of "dict for" in tclCompCmds.c. --timjr + 2006.11.3 */ + TclEmitInstInt4(INST_DICT_DONE, itTmp->idx, L->frame->envPtr); + tmp_free(itTmp); +} + +/* + * Foreach over a string uses three temp variables (str_idx, len_idx, + * and it_idx) and compiles to this: + * + * str_idx = string value already on stack + * len_idx = [::string length $str_idx] + * it_idx = 0 + * jmp 2 + * 1: loopvar1 = str_idx[it_idx++] + * loopvar2 = str_idx[it_idx++] + * ... + * loopvarn = str_idx[it_idx++] + * <loop body> + * 2: test it_idx < len_idx + * jmp if true to 1 + */ +private void +compile_foreachString(ForEach *loop) +{ + int body_off, jmp_dist; + Jmp *break_jmps, *continue_jmps; + Jmp *cond_jmp = 0; + Expr *id; + Tmp *itTmp, *lenTmp, *strTmp; + + /* The foreach(k=>v in expr) form is illegal in string iteration. */ + if (loop->value) { + L_errf(loop, "=> illegal in foreach over strings"); + } + + /* Temps for the loop index, string value, and string length. */ + itTmp = tmp_get(TMP_REUSE); + lenTmp = tmp_get(TMP_REUSE); + strTmp = tmp_get(TMP_REUSE); + + emit_store_scalar(strTmp->idx); + + push_lit("::string"); + push_lit("length"); + TclEmitInstInt1(INST_ROT, 2, L->frame->envPtr); + emit_invoke(3); + emit_store_scalar(lenTmp->idx); + emit_pop(); + + push_lit("0"); + emit_store_scalar(itTmp->idx); + emit_pop(); + + cond_jmp = emit_jmp_fwd(INST_JUMP4, NULL); + body_off = currOffset(L->frame->envPtr); + + for (id = loop->key; id; id = id->next) { + unless (sym_lookup(id, 0)) return; // undeclared var + unless (L_typeck_compat(id->type, L_string)) { + L_errf(id, "loop index not of string type"); + } + emit_load_scalar(strTmp->idx); + emit_load_scalar(itTmp->idx); + TclEmitInstInt4(INST_L_INDEX, L_IDX_STRING | L_PUSH_VAL, + L->frame->envPtr); + emit_store_scalar(id->sym->idx); + emit_pop(); + TclEmitInstInt1(INST_INCR_SCALAR1_IMM, itTmp->idx, + L->frame->envPtr); + TclEmitInt1(1, L->frame->envPtr); + emit_pop(); + } + + frame_push(loop, NULL, LOOP|SEARCH); + compile_stmts(loop->body); + break_jmps = L->frame->break_jumps; + continue_jmps = L->frame->continue_jumps; + frame_pop(); + fixup_jmps(&continue_jmps); + + fixup_jmps(&cond_jmp); + emit_load_scalar(itTmp->idx); + emit_load_scalar(lenTmp->idx); + TclEmitOpcode(INST_LT, L->frame->envPtr); + jmp_dist = currOffset(L->frame->envPtr) - body_off; + TclEmitInstInt4(INST_JUMP_TRUE4, -jmp_dist, L->frame->envPtr); + + /* Set the loop counters to undef. */ + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); + for (id = loop->key; id; id = id->next) { + emit_store_scalar(id->sym->idx); + } + emit_pop(); + + fixup_jmps(&break_jmps); + tmp_free(itTmp); + tmp_free(lenTmp); + tmp_free(strTmp); +} + +private void +compile_foreachAngle(ForEach *loop) +{ + Expr *expr = loop->expr->a; + Expr *id; + Tmp *tmp; + Jmp *break_jmps, *continue_jmps, *out_jmp; + int top_off; + + /* Outlaw foreach(s in <>). */ + unless (expr) { + L_errf(loop, "this form is disallowed; did you mean " + "while (buf = <>)?"); + return; + } + + /* The foreach(k=>v in expr) form is illegal in string iteration. */ + if (loop->value) { + L_errf(loop, "=> illegal in foreach over strings"); + } + + push_lit("LgetNextLineInit_"); + compile_expr(expr, L_PUSH_VAL); + + /* Outlaw foreach(s in <a_FILE>). */ + if (typeisf(expr, "FILE")) { + L_errf(loop->expr, + "this form is disallowed; did you mean " + "while (buf = <F>)?"); + return; + } + unless (isstring(expr)) { + L_errf(expr, "in foreach, arg to <> must be a string"); + return; + } + + for (id = loop->key; id; id = id->next) { + unless (sym_lookup(id, 0)) return; // undeclared var + unless (L_typeck_compat(id->type, L_string)) { + L_errf(id, "loop index %s not of string type", id->str); + } + } + + /* + * tmp = LgetNextLineInit_(expr) + * 1: s1 = LgetNextLine_(tmp) + * s2 = LgetNextLine_(tmp) + * ... + * s<n> = LgetNextLine_(tmp) + * if (s1 is undef) jmp 2 + * <loop body> + * jmp 1 + * 2: + */ + + tmp = tmp_get(TMP_REUSE); + emit_invoke(2); + emit_store_scalar(tmp->idx); + emit_pop(); + top_off = currOffset(L->frame->envPtr); + for (id = loop->key; id; id = id->next) { + push_lit("LgetNextLine_"); + emit_load_scalar(tmp->idx); + emit_invoke(2); + emit_store_scalar(id->sym->idx); + emit_pop(); + } + emit_load_scalar(loop->key->sym->idx); + TclEmitOpcode(INST_L_DEFINED, L->frame->envPtr); + out_jmp = emit_jmp_fwd(INST_JUMP_FALSE4, NULL); + frame_push(loop, NULL, LOOP|SEARCH); + compile_stmts(loop->body); + break_jmps = L->frame->break_jumps; + continue_jmps = L->frame->continue_jumps; + frame_pop(); + fixup_jmps(&continue_jmps); + emit_jmp_back(TCL_UNCONDITIONAL_JUMP, top_off); + fixup_jmps(&break_jmps); + fixup_jmps(&out_jmp); +} + +private void +compile_switch(Switch *sw) +{ + Case *c; + + /* + * If all cases are constant, compile a jump table (fast), + * otherwise compile if-then-else code (slower). + */ + for (c = sw->cases; c; c = c->next) { + if (c->expr && !isconst(c->expr)) break; + } + if (c) { + compile_switch_slow(sw); + } else { + compile_switch_fast(sw); + } +} + +/* + * Generate if-then-else code like the following for a switch statement. + * + * local_tmp = <switch expression> + * # The following is generated for each case except the default case. + * # All jmps are forward jmps. + * next-test: + * load local_tmp + * <case expression> + * <appropriate compare opcode> + * jmp-false next-test + * next-body: + * <case body> + * jmp next-body + * # The following is generated for the default case. + * jmp next-test + * next-body: + * default: + * <case body> + * jmp next-body + * # Statement prologue. + * next-test: + * jmp default # backward jmp, only if default case present + * next-body: + * break-label: # where break stmts jmp to + * pop + */ +private void +compile_switch_slow(Switch *sw) +{ + Expr *e = sw->expr; + Case *c; + int def_off = -1; + int start_off; + Jmp *break_jmps; + Jmp *next_body_jmp = NULL, *next_test_jmp = NULL, *undef_jmp = NULL; + Tmp *tmp; + + compile_expr(e, L_PUSH_VAL); + tmp = tmp_get(TMP_REUSE); + emit_store_scalar(tmp->idx); + emit_pop(); + unless (istype(e, L_INT|L_STRING|L_WIDGET|L_POLY)) { + L_errf(e, "switch expression must be int or string"); + return; + } + + frame_push(sw, NULL, SWITCH|SEARCH); + /* + * If there's a case undef, check that first, because if the + * switch expr is undef, Tcl will still let us get its value + * and it would match a "" case and we don't want that. + */ + for (c = sw->cases; c; c = c->next) { + if (c->expr && isid(c->expr, "undef")) { + start_off = currOffset(L->frame->envPtr); + emit_load_scalar(tmp->idx); + TclEmitOpcode(INST_L_DEFINED, L->frame->envPtr); + undef_jmp = emit_jmp_fwd(INST_JUMP_FALSE4, NULL); + track_cmd(start_off, c->expr); + break; + } + } + for (c = sw->cases; c; c = c->next) { + start_off = currOffset(L->frame->envPtr); + if (c->expr && isid(c->expr, "undef")) { + next_test_jmp = emit_jmp_fwd(INST_JUMP4, next_test_jmp); + fixup_jmps(&undef_jmp); + } else if (c->expr) { + fixup_jmps(&next_test_jmp); + emit_load_scalar(tmp->idx); + if (isregexp(c->expr)) { + compile_reMatch(c->expr); + } else if (isint(e)) { + compile_expr(c->expr, L_PUSH_VAL); + TclEmitOpcode(INST_EQ, L->frame->envPtr); + } else { + compile_expr(c->expr, L_PUSH_VAL); + TclEmitOpcode(INST_STR_EQ, L->frame->envPtr); + } + unless (L_typeck_compat(e->type, c->expr->type)) { + L_errf(c, "case type incompatible" + " with switch expression"); + } + next_test_jmp = emit_jmp_fwd(INST_JUMP_FALSE4, + next_test_jmp); + track_cmd(start_off, c->expr); + } else { // default case (grammar ensures there's at most one) + next_test_jmp = emit_jmp_fwd(INST_JUMP4, next_test_jmp); + ASSERT(def_off == -1); + def_off = currOffset(L->frame->envPtr); + track_cmd(start_off, c); + } + fixup_jmps(&next_body_jmp); + compile_stmts(c->body); + next_body_jmp = emit_jmp_fwd(INST_JUMP4, NULL); + } + fixup_jmps(&next_test_jmp); + if (def_off != -1) { + emit_jmp_back(TCL_UNCONDITIONAL_JUMP, def_off); + } + fixup_jmps(&next_body_jmp); + break_jmps = L->frame->break_jumps; + frame_pop(); + fixup_jmps(&break_jmps); + tmp_free(tmp); +} + +/* + * Generate jump-table code like the following for a switch statement. + * + * <switch expression> + * INST_JUMP_TABLE + * jmp default + * # The following is generated for each case except the default case. + * # All jmps are forward jmps. + * next-body: + * <case body> + * jmp next-body + * # The following is the default case. + * default: + * next-body: + * <case body> (only if default case present) + * jmp next-body (only if default case present) + * # Statement prologue. + * next-body: + * break-label: # where break stmts jmp to + */ +private void +compile_switch_fast(Switch *sw) +{ + Expr *e = sw->expr; + Case *c; + int jt_idx, new, start_off; + Jmp *break_jmps; + Jmp *default_jmp; + Jmp *next_body_jmp = NULL; + Tcl_HashEntry *hPtr; + JumptableInfo *jt; + + jt = (JumptableInfo *)ckalloc(sizeof(JumptableInfo)); + Tcl_InitHashTable(&jt->hashTable, TCL_STRING_KEYS); + jt_idx = TclCreateAuxData(jt, &tclJumptableInfoType, L->frame->envPtr); + + compile_expr(e, L_PUSH_VAL); + unless (istype(e, L_INT|L_STRING|L_WIDGET|L_POLY)) { + L_errf(e, "switch expression must be int or string"); + return; + } + if (isint(e)) { + /* + * Since the jump table keys are strings, add 0 to + * guarantee a canonicalized string rep of an int. + */ + push_lit("0"); + TclEmitOpcode(INST_ADD, L->frame->envPtr); + } + + frame_push(sw, NULL, SWITCH|SEARCH); + + start_off = currOffset(L->frame->envPtr); + TclEmitInstInt4(INST_JUMP_TABLE, jt_idx, L->frame->envPtr); + default_jmp = emit_jmp_fwd(INST_JUMP4, NULL); + + for (c = sw->cases; c; c = c->next) { + if (c->expr) { + ASSERT(isconst(c->expr)); + hPtr = Tcl_CreateHashEntry(&jt->hashTable, + c->expr->str, + &new); + if (new) { + Tcl_SetHashValue(hPtr, + INT2PTR(currOffset(L->frame->envPtr) - + start_off)); + } else { + L_errf(c, "duplicate case value"); + } + unless (L_typeck_compat(e->type, c->expr->type)) { + L_errf(c, + "case type incompatible with switch expression"); + } + } else { // default case (grammar ensures there's at most one) + fixup_jmps(&default_jmp); + } + fixup_jmps(&next_body_jmp); + compile_stmts(c->body); + next_body_jmp = emit_jmp_fwd(INST_JUMP4, NULL); + } + fixup_jmps(&default_jmp); // no-op if default exists (already fixed up) + fixup_jmps(&next_body_jmp); + break_jmps = L->frame->break_jumps; + frame_pop(); + fixup_jmps(&break_jmps); +} + +private VarDecl * +struct_lookupMember(Type *t, Expr *idx, int *offset) +{ + VarDecl *m; + + ASSERT((idx->op == L_OP_DOT) || (idx->op == L_OP_POINTS)); + + unless (t->u.struc.members) { + L_errf(idx, "incomplete struct type %s", t->u.struc.tag); + return (NULL); + } + for (*offset = 0, m = t->u.struc.members; m; m = m->next, ++*offset) { + if (!strcmp(idx->str, m->id->str)) { + return (m); + } + } + return (NULL); +} + +/* + * Determine whether an array index expression contains a reference to + * the array's END index. + */ +private int +has_END(Expr *expr) +{ + Expr *p; + + unless (expr) return (0); + switch (expr->kind) { + case L_EXPR_FUNCALL: + for (p = expr->b; p; p = p->next) { + if (has_END(p)) return (1); + } + return (0); + case L_EXPR_CONST: + case L_EXPR_RE: + return (0); + case L_EXPR_ID: + return (isid(expr, "END")); + case L_EXPR_UNOP: + return (has_END(expr->a)); + case L_EXPR_BINOP: + switch (expr->op) { + case L_OP_ARRAY_INDEX: + /* END in a nested index refers to another array. */ + return (has_END(expr->a)); + case L_OP_CAST: + /* A cast is special: expr->a is a type not an expr. */ + return (has_END(expr->b)); + default: + return (has_END(expr->a) || has_END(expr->b)); + } + case L_EXPR_TRINOP: + if (expr->op == L_OP_ARRAY_SLICE) { + /* END in a nested index refers to another array. */ + return (has_END(expr->a)); + } else { + return (has_END(expr->a) || has_END(expr->b) || + has_END(expr->c)); + } + default: ASSERT(0); + } + /*NOTREACHED*/ + return (0); +} + +/* + * Generate code to push an array/hash/struct/string index onto the stack. + * Return flags suitable for the INST_L_INDEX instruction which indicate + * whether the operator is an array, hash, struct, or string index. + */ +private int +push_index(Expr *expr, int flags) +{ + int ret; + int reuse = flags & L_REUSE_IDX; + int save = flags & L_SAVE_IDX; + Type *type; + VarDecl *member; + Tmp *idxTmp; + int offset; + + /* Error-path return values. */ + ret = 0; + type = L_poly; + + ASSERT(type); + switch (expr->op) { + case L_OP_DOT: + case L_OP_POINTS: + unless (isstruct(expr->a)) { + L_errf(expr, "not a struct"); + goto out; + } + member = struct_lookupMember(expr->a->type, + expr, + &offset); + if (member) { + unless (reuse) push_litf("%i", offset); + type = member->type; + } else { + L_errf(expr, "struct field %s not found", expr->str); + } + ret = L_IDX_ARRAY; + break; + case L_OP_ARRAY_INDEX: + unless (reuse) { + compile_expr(expr->b, L_PUSH_VAL); + if (isid(expr->b, "undef")) { + L_errf(expr->b, "cannot use undef as an " + "array/string index"); + } + } + L_typeck_expect(L_INT, expr->b, "in array/string index"); + if (isarray(expr->a) || islist(expr->a)) { + type = expr->a->type->base_type; + ret = L_IDX_ARRAY; + } else if (isstring(expr->a) || iswidget(expr->a)) { + /* + * Disallow stringvar[0][0] = "x". It doesn't make much + * sense and INST_L_DEEP_WRITE can't handle it anyway. + */ + if ((expr->a->op == L_OP_ARRAY_INDEX) && + expr->a->sym && + isstring(expr->a->a) && + (expr->a->flags & L_LVALUE)) { + L_errf(expr, "cannot index a string index"); + } + type = L_string; + ret = L_IDX_STRING; + } else if (ispoly(expr->a)) { + type = L_poly; + ret = L_IDX_ARRAY; + } else { + L_errf(expr, "not an array or string"); + } + break; + case L_OP_HASH_INDEX: { + unless (reuse) { + compile_expr(expr->b, L_PUSH_VAL); + if (isid(expr->b, "undef")) { + L_errf(expr->b, "cannot use undef as a " + "hash index"); + } + } + if (ishash(expr->a)) { + L_typeck_expect(expr->a->type->u.hash.idx_type->kind, + expr->b, + "in hash index"); + type = expr->a->type->base_type; + } else if (ispoly(expr->a)) { + type = L_poly; + } else { + L_errf(expr, "not a hash"); + } + ret = L_IDX_HASH; + break; + } + default: + L_bomb("Invalid index op, %d", expr->op); + break; + } + out: + if (save) { + // save copy of index to a temp + idxTmp = tmp_get(TMP_REUSE); + expr->u.deepdive.idx = idxTmp; + emit_store_scalar(idxTmp->idx); + } else if (reuse) { + // get index value from temp + idxTmp = expr->u.deepdive.idx; + ASSERT(idxTmp); + emit_load_scalar(idxTmp->idx); + tmp_free(idxTmp); + expr->u.deepdive.idx = NULL; + } + expr->type = type; + return (ret); +} + +/* + * Compile a hash/array/struct/class or string index. These are the + * L_OP_HASH_INDEX, L_OP_ARRAY_INDEX, L_OP_DOT, and L_OP_POINTS nodes. + * + * The resulting stack depends on the flags which specify whether the + * indexed element's value, pointer, or both (and in what order) are + * wanted. We get one of + * + * <elem-obj> if flags & L_PUSH_VAL + * <deep-ptr> if flags & L_PUSH_PTR + * <elem-obj> <deep-ptr> if flags & L_PUSH_VAL_PTR + * <deep-ptr> <elem-obj> if flags & L_PUSH_PTR_VAL + * <tmp-name> if flags & L_PUSH_NAME + * + * For L_PUSH_NAME, we evaluate the indexed expression and store its + * value and all the indices in local temp variables, then use the + * value temp's name as the value of the expression. The expr nodes + * store information about the temps so they can be accessed later, + * such as for the copy-out part of copy in/out parameters. + */ +private int +compile_idxOp(Expr *expr, Expr_f flags) +{ + int ret; + Tmp *valTmp; + + if ((flags & L_PUSH_NAME) && !(flags & L_SAVE_IDX)) { + /* First time through for L_PUSH_NAME. */ + ret = compile_idxOp2(expr, flags | L_PUSH_VAL | L_SAVE_IDX); + /* + * Check whether this was really an object index (we + * don't know until now). + */ + if (isclass(expr->a)) return (ret); + valTmp = tmp_get(TMP_REUSE); + expr->u.deepdive.val = valTmp; + emit_store_scalar(valTmp->idx); + emit_pop(); + push_lit(valTmp->name); + } else { + ret = compile_idxOp2(expr, flags); + } + return (ret); +} + +private int +compile_idxOp2(Expr *expr, Expr_f flags) +{ + int save; + + /* + * Eval the thing being indexed. The flags magic here is + * because we always want its value if it's a variable, or a + * deep-pointer if it's the result of another deep-dive index, + * regardless of in what form we want expr. + */ + compile_expr(expr->a, L_PUSH_PTR | L_PUSH_VAL | + (flags & ~(L_PUSH_VALPTR | + L_PUSH_PTRVAL | + L_DISCARD | + L_PUSH_NAME))); + + /* + * Require "->" for all objects and call-by-reference structures. + * Require "." for all call-by-value and non-parameter structures. + */ + if (isclass(expr->a)) { + unless (expr->op == L_OP_POINTS) { + L_errf(expr, "must access object only with ->"); + } + } else if (expr->a->sym && + (expr->a->sym->decl->flags & DECL_REF) && + !(expr->a->flags & L_EXPR_DEEP)) { + if (expr->op == L_OP_DOT) { + L_errf(expr, ". illegal on call-by-reference " + "parms; use -> instead"); + } + } else { + if (expr->op == L_OP_POINTS) { + L_errf(expr, "-> illegal except on call-by-reference " + "parms; use . instead"); + } + } + + /* + * Handle obj->var. We check here because, in general, we + * don't know until now whether expr->a has type class. + */ + if (isclass(expr->a) && ((expr->op == L_OP_DOT) || + (expr->op == L_OP_POINTS))) { + return (compile_clsInstDeref(expr, flags)); + } + + if (has_END(expr->b)) { + if (flags & L_REUSE_IDX) { + } else if (isstring(expr->a) || iswidget(expr->a)) { + TclEmitOpcode(INST_L_PUSH_STR_SIZE, L->frame->envPtr); + } else { + TclEmitOpcode(INST_L_PUSH_LIST_SIZE, L->frame->envPtr); + } + } + + save = L->idx_op; + L->idx_op = expr->op; + flags |= push_index(expr, flags); + L->idx_op = save; + + if (has_END(expr->b)) { + TclEmitOpcode(INST_L_POP_SIZE, L->frame->envPtr); + } + + /* + * Perform an optimization and don't create a deep pointer if + * the caller won't be doing a deep dive into the expression + * being evaluated but instead just needs its value. This + * happens when the deep dive we're doing now results in + * something of type class and the caller requested a value. + * See the comments in compile_expr(). + * + * This wart is here because the caller can't know in general + * whether expr is a deep dive or a class deref. Their + * expressions look identical but are evaluated in drastically + * different ways. + */ + if (isclass(expr) && (flags & (L_PUSH_VAL | L_DISCARD))) { + flags &= ~(L_PUSH_PTR | L_PUSH_VALPTR | L_PUSH_PTRVAL | + L_LVALUE); + } else if (flags & (L_PUSH_PTR | L_PUSH_VALPTR | L_PUSH_PTRVAL)) { + flags &= ~L_PUSH_VAL; + } + + TclEmitInstInt4(INST_L_INDEX, flags, L->frame->envPtr); + + /* + * Adjust the stack depth that Tcl tracks (debug build) to + * reflect when two objs are left on the stack instead of one + * as indicated by the entry in the tclInstructionTable in + * tclCompile.c + */ + if (flags & (L_PUSH_PTRVAL | L_PUSH_VALPTR)) { + TclAdjustStackDepth(1, L->frame->envPtr); + } + + expr->sym = expr->a->sym; // propagate sym table ptr up the tree + expr->flags = flags | L_EXPR_DEEP; + return ((flags & L_DISCARD) ? 0 : 1); +} + +/* Compile classname->var. */ +private int +compile_clsDeref(Expr *expr, Expr_f flags) +{ + int in_class = 0; + char *clsnm, *varnm; + Sym *sym, *tmpsym; + Tmp *tmp; + Type *type = (Type *)expr->a; + ClsDecl *clsdecl = type->u.class.clsdecl; + Tcl_HashEntry *hPtr; + + expr->type = L_poly; + unless (isclasstype(type)) { + L_errf(expr, "can dereference only class types"); + return (0); + } + + ASSERT(type && clsdecl); + + clsnm = clsdecl->decl->id->str; + varnm = expr->str; + if (L->enclosing_func) { + in_class = L->enclosing_func->decl->flags & DECL_CLASS_FN; + } + + hPtr = Tcl_FindHashEntry(clsdecl->symtab, varnm); + unless (hPtr) { + L_errf(expr, "%s is not a member of class %s", varnm, clsnm); + return (0); + } + sym = (Sym *)Tcl_GetHashValue(hPtr); + unless (in_class || (sym->decl->flags & DECL_PUBLIC)) { + L_errf(expr, "%s is not a public variable of class %s", + varnm, clsnm); + } + unless (sym->decl->flags & DECL_CLASS_VAR) { + L_errf(expr, "%s is not a class variable of class %s", + varnm, clsnm); + } + + if (flags & L_PUSH_NAME) { + push_litf("::L::_class_%s::%s", clsnm, sym->name); + expr->sym = sym; + expr->type = sym->type; + return (1); // stack effect + } + + tmp = tmp_get(TMP_UNSET); + tmpsym = sym_mk(tmp->name, sym->type, SCOPE_LOCAL | DECL_LOCAL_VAR); + ASSERT(tmpsym); // cannot be multiply declared + tmpsym->used_p = TRUE; + + push_litf("::L::_class_%s", clsnm); + push_lit(sym->name); + TclEmitInstInt4(INST_NSUPVAR, tmp->idx, L->frame->envPtr); + emit_pop(); + + expr->sym = tmpsym; + expr->type = sym->type; + + if (flags & L_PUSH_VAL) { + emit_load_scalar(tmp->idx); + return (1); // stack effect + } else { + return (0); // stack effect + } +} + +/* + * Compile obj->var. Code to push the value of obj on the run-time + * stack already has been generated by compile_idxOp(). + */ +private int +compile_clsInstDeref(Expr *expr, Expr_f flags) +{ + int in_class = 0; + char *clsnm, *varnm; + Tmp *tmp; + Sym *sym, *tmpsym; + ClsDecl *clsdecl = expr->a->type->u.class.clsdecl; + Tcl_HashEntry *hPtr; + + ASSERT(isclass(expr->a) && clsdecl); + ASSERT(clsdecl->symtab); + + clsnm = clsdecl->decl->id->str; + varnm = expr->str; + if (L->enclosing_func) { + in_class = L->enclosing_func->decl->flags & DECL_CLASS_FN; + } + + hPtr = Tcl_FindHashEntry(clsdecl->symtab, varnm); + unless (hPtr) { + L_errf(expr, "%s is not a member of class %s", varnm, clsnm); + expr->type = L_poly; + return (0); // stack effect + } + sym = (Sym *)Tcl_GetHashValue(hPtr); + unless (in_class || (sym->decl->flags & DECL_PUBLIC)) { + L_errf(expr, "%s is not a public variable of class %s", + varnm, clsnm); + } + unless (sym->decl->flags & DECL_CLASS_INST_VAR) { + L_errf(expr, "%s is not an instance variable of class %s", + varnm, clsnm); + } + + if (flags & L_PUSH_NAME) { + // Caller already pushed obj value, so concat var name to it. + push_litf("::%s", sym->name); + TclEmitInstInt1(INST_STR_CONCAT1, 2, L->frame->envPtr); + expr->sym = sym; + expr->type = sym->type; + return (1); // stack effect + } + + tmp = tmp_get(TMP_UNSET); + tmpsym = sym_mk(tmp->name, sym->type, SCOPE_LOCAL | DECL_LOCAL_VAR); + ASSERT(tmpsym); // cannot be multiply declared + tmpsym->used_p = TRUE; + + push_lit(sym->name); + TclEmitInstInt4(INST_NSUPVAR, tmp->idx, L->frame->envPtr); + emit_pop(); + + expr->sym = tmpsym; + expr->type = sym->type; + + if (flags & L_PUSH_VAL) { + emit_load_scalar(tmp->idx); + return (1); // stack effect + } else { + return (0); // stack effect + } +} + +private void +compile_assign(Expr *expr) +{ + Expr *lhs = expr->a; + Expr *rhs = expr->b; + + if (lhs->op == L_OP_LIST) { + /* Handle {a,b,c} = ... */ + compile_assignComposite(expr); + } else { + /* Handle regular assignment. */ + compile_expr(rhs, L_PUSH_VAL); + compile_assignFromStack(lhs, rhs->type, expr, 0); + } +} + +private void +compile_assignFromStack(Expr *lhs, Type *rhs_type, Expr *expr, int flags) +{ + /* Whether it's an arithmetic assignment (lhs op= rhs). */ + int arith = (expr && (expr->op != L_OP_EQUALS)); + + compile_expr(lhs, (arith?L_PUSH_VALPTR:L_PUSH_PTR) | L_LVALUE | flags); + unless (lhs->sym) { + L_errf(lhs, "invalid l-value in assignment"); + return; + } + L_typeck_assign(lhs, rhs_type); + + if (isdeepdive(lhs)) { + // <rval> <lhs-ptr> if !arith + // <rval> <lhs-val> <lhs-ptr> if arith + if (arith) { + // <rval> <lhs-val> <lhs-ptr> + TclEmitInstInt4(INST_REVERSE, 3, L->frame->envPtr); + // <lhs-ptr> <lhs-val> <rval> + emit_instrForLOp(expr, expr->type); + // <lhs-ptr> <new-val> + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + } + // <rval> <lhs-ptr> or <new-val> <lhs-ptr> + TclEmitInstInt4(INST_L_DEEP_WRITE, + lhs->sym->idx, + L->frame->envPtr); + TclEmitInt4(L_PUSH_NEW, L->frame->envPtr); + } else { + // <rval> + if (arith) { + emit_load_scalar(lhs->sym->idx); + // <rval> <old-val> + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + // <old-val> <rval> + emit_instrForLOp(expr, expr->type); + // <new-val> + } + // <rval> or <new-val> + emit_store_scalar(lhs->sym->idx); + } + // <rval> +} + +private void +compile_assignComposite(Expr *expr) +{ + int i; + Expr *lhs = expr->a; + Expr *rhs = expr->b; + Type *list = NULL, *rhs_elt_type; + VarDecl *member = NULL; + + expr->type = L_poly; + unless (expr->op == L_OP_EQUALS) { + L_errf(expr, "arithmetic assignment illegal"); + lhs->type = L_poly; + rhs->type = L_poly; + return; + } + ASSERT(lhs->op == L_OP_LIST); + + compile_expr(rhs, L_PUSH_VAL); + + /* rhs_elt_type stores the current rhs type as we walk the elts. */ + switch (rhs->type->kind) { + case L_POLY: + rhs_elt_type = L_poly; + break; + case L_ARRAY: + rhs_elt_type = rhs->type->base_type; + break; + case L_STRUCT: + member = rhs->type->u.struc.members; + ASSERT(member); + rhs_elt_type = member->type; + break; + case L_LIST: + list = rhs->type; + rhs_elt_type = list->base_type; + break; + default: + L_errf(expr, + "right-hand side incompatible with composite assign"); + return; + } + /* Assign lhs <- rhs elements (left to right). */ + for (i = 0, lhs = expr->a; lhs; ++i, lhs = lhs->b) { + ASSERT(lhs->op == L_OP_LIST); + /* A lhs undef means skip the corresponding rhs element. */ + unless (isid(lhs->a, "undef")) { + TclEmitInstInt1(INST_L_LINDEX_STK, i, L->frame->envPtr); + compile_assignFromStack(lhs->a, rhs_elt_type, expr, 0); + emit_pop(); + } + /* Advance rhs_elt_type to type of next elt, if known. */ + if (member) { + member = member->next; + rhs_elt_type = member? member->type: NULL; + } else if (list) { + list = list->next; + rhs_elt_type = list? list->base_type: NULL; + } + } + /* Pop rhs. */ + emit_pop(); + /* The value of the assignment is undef. */ + TclEmitOpcode(INST_L_PUSH_UNDEF, L->frame->envPtr); +} + +private void +compile_incdec(Expr *expr) +{ + Expr *lhs = expr->a; + /* Whether expr is a postfix operator. */ + int post = ((expr->op == L_OP_PLUSPLUS_POST) || + (expr->op == L_OP_MINUSMINUS_POST)); + /* Whether expr is a ++ operator. */ + int inc = ((expr->op == L_OP_PLUSPLUS_PRE) || + (expr->op == L_OP_PLUSPLUS_POST)); + + compile_expr(lhs, L_PUSH_PTRVAL | (post?L_PUSH_VAL:0) | L_LVALUE); + unless (lhs->sym) { + L_errf(expr, "invalid l-value in inc/dec"); + return; + } + L_typeck_expect(L_INT|L_FLOAT, lhs, "in ++/--"); + + if (isdeepdive(lhs)) { + // <lhs-ptr> <lhs-val> + push_lit("1"); + // <hs-ptr> <lhs-val> 1 + TclEmitOpcode(inc?INST_ADD:INST_SUB, L->frame->envPtr); + // <lhs-ptr> <new-val> + TclEmitInstInt1(INST_ROT, 1, L->frame->envPtr); + // <new-val> <lhs-ptr> + TclEmitInstInt4(INST_L_DEEP_WRITE, + lhs->sym->idx, + L->frame->envPtr); + TclEmitInt4(post?L_PUSH_OLD:L_PUSH_NEW, L->frame->envPtr); + } else { + // <old-val> if post + TclEmitInstInt1(INST_INCR_SCALAR1_IMM, lhs->sym->idx, + L->frame->envPtr); + TclEmitInt1(inc? 1 : -1, L->frame->envPtr); + // <old-val> <new-val> if post + // <new-val> if !post + if (post) emit_pop(); + } + // <old-val> if post + // <new-val> if !post +} + +private int +push_regexpModifiers(Expr *regexp) +{ + int n = 0; + + push_lit("-linestop"); + n++; + if (regexp->flags & L_EXPR_RE_I) { + push_lit("-nocase"); + n++; + } + if (regexp->flags & L_EXPR_RE_G) { + push_lit("-all"); + n++; + } + return (n); +} + +private void +emit_instrForLOp(Expr *expr, Type *type) +{ + int arg = 0; + int op = 0; + + switch (expr->op) { + case L_OP_EQUALEQUAL: + case L_OP_NOTEQUAL: + case L_OP_GREATER: + case L_OP_GREATEREQ: + case L_OP_LESSTHAN: + case L_OP_LESSTHANEQ: + switch (type->kind) { + case L_INT: + case L_FLOAT: + case L_POLY: + switch (expr->op) { + case L_OP_EQUALEQUAL: + op = INST_EQ; + break; + case L_OP_NOTEQUAL: + op = INST_NEQ; + break; + case L_OP_GREATER: + op = INST_GT; + break; + case L_OP_GREATEREQ: + op = INST_GE; + break; + case L_OP_LESSTHAN: + op = INST_LT; + break; + case L_OP_LESSTHANEQ: + op = INST_LE; + break; + default: ASSERT(0); + } + break; + case L_STRING: + case L_WIDGET: + switch (expr->op) { + case L_OP_EQUALEQUAL: + op = INST_STR_EQ; + break; + case L_OP_NOTEQUAL: + op = INST_STR_NEQ; + break; + default: + TclEmitOpcode(INST_STR_CMP, L->frame->envPtr); + switch (expr->op) { + case L_OP_GREATER: + push_lit("1"); + op = INST_EQ; + break; + case L_OP_LESSTHAN: + push_lit("-1"); + op = INST_EQ; + break; + case L_OP_GREATEREQ: + push_lit("0"); + op = INST_GE; + break; + case L_OP_LESSTHANEQ: + push_lit("0"); + op = INST_LE; + break; + default: ASSERT(0); + } + break; + } + break; + default: + // We get here only for eq() of a composite type + // w/no numerics. + op = INST_STR_EQ; + break; + } + break; + case L_OP_STR_EQ: + op = INST_STR_EQ; + break; + case L_OP_STR_NE: + op = INST_STR_NEQ; + break; + case L_OP_STR_GT: + case L_OP_STR_GE: + case L_OP_STR_LT: + case L_OP_STR_LE: + TclEmitOpcode(INST_STR_CMP, L->frame->envPtr); + switch (expr->op) { + case L_OP_STR_GT: + push_lit("1"); + op = INST_EQ; + break; + case L_OP_STR_LT: + push_lit("-1"); + op = INST_EQ; + break; + case L_OP_STR_GE: + push_lit("0"); + op = INST_GE; + break; + case L_OP_STR_LE: + push_lit("0"); + op = INST_LE; + break; + default: ASSERT(0); + } + break; + case L_OP_PLUS: + case L_OP_EQPLUS: + op = INST_ADD; + break; + case L_OP_MINUS: + case L_OP_EQMINUS: + op = INST_SUB; + break; + case L_OP_STAR: + case L_OP_EQSTAR: + op = INST_MULT; + break; + case L_OP_SLASH: + case L_OP_EQSLASH: + op = INST_DIV; + break; + case L_OP_PERC: + case L_OP_EQPERC: + op = INST_MOD; + break; + case L_OP_BITAND: + case L_OP_EQBITAND: + op = INST_BITAND; + break; + case L_OP_BITOR: + case L_OP_EQBITOR: + op = INST_BITOR; + break; + case L_OP_BITXOR: + case L_OP_EQBITXOR: + op = INST_BITXOR; + break; + case L_OP_LSHIFT: + case L_OP_EQLSHIFT: + op = INST_LSHIFT; + break; + case L_OP_RSHIFT: + case L_OP_EQRSHIFT: + op = INST_RSHIFT; + break; + case L_OP_UMINUS: + op = INST_UMINUS; + break; + case L_OP_UPLUS: + op = INST_UPLUS; + break; + case L_OP_BANG: + op = INST_LNOT; + break; + case L_OP_BITNOT: + op = INST_BITNOT; + break; + default: + break; + } + if (op) { + TclEmitOpcode(op, L->frame->envPtr); + return; + } + switch (expr->op) { + case L_OP_EQDOT: + op = INST_STR_CONCAT1; + arg = 2; + break; + default: + L_bomb("Unable to map operator %d to an instruction", expr->op); + break; + } + if (op) { + TclEmitInstInt1(op, arg, L->frame->envPtr); + } +} + +private void +compile_continue(Stmt *stmt) +{ + Frame *loop_frame = frame_find(LOOP); + + unless (loop_frame) { + L_errf(stmt, "continue allowed only inside loops"); + return; + } + loop_frame->continue_jumps = emit_jmp_fwd(INST_JUMP4, + loop_frame->continue_jumps); +} + +private void +compile_break(Stmt *stmt) +{ + Frame *loop_frame = frame_find(LOOP|SWITCH); + + unless (loop_frame) { + L_errf(stmt, + "break allowed only inside switch and loop statements"); + return; + } + loop_frame->break_jumps = emit_jmp_fwd(INST_JUMP4, + loop_frame->break_jumps); +} + +private void +compile_label(Stmt *stmt) +{ + Label *label; + + if (!strcmp(stmt->u.label, "break")) { + L_errf(stmt, "break is not a legal label"); + } + label = label_lookup(stmt, LABEL_DEF); + fixup_jmps(&label->fixups); + label->fixups = NULL; + label->offset = currOffset(L->frame->envPtr); +} + +private void +compile_goto(Stmt *stmt) +{ + Label *label; + + label = label_lookup(stmt, LABEL_USE); + if (label->offset >= 0) { + emit_jmp_back(TCL_UNCONDITIONAL_JUMP, label->offset); + } else { + label->fixups = emit_jmp_fwd(INST_JUMP4, label->fixups); + } +} + +private Label * +label_lookup(Stmt *stmt, Label_f flags) +{ + int new; + char *name = stmt->u.label; + Label *label = NULL; + Frame *frame; + Tcl_HashEntry *hPtr = NULL; + + /* Labels are restricted to the enclosing proc's labeltab. */ + frame = frame_find(FUNC); + ASSERT(frame); + + hPtr = Tcl_FindHashEntry(frame->labeltab, name); + if (hPtr) { + label = (Label *)Tcl_GetHashValue(hPtr); + } else { + label = (Label *)ckalloc(sizeof(Label)); + memset(label, 0, sizeof(Label)); + label->name = name; + label->offset = -1; + hPtr = Tcl_CreateHashEntry(frame->labeltab, name, &new); + ASSERT(new); + Tcl_SetHashValue(hPtr, label); + } + if ((flags & LABEL_DEF) && (label->offset >= 0)) { + L_errf(stmt, "label %s already defined", name); + } + return (label); +} + +private void +emit_globalUpvar(Sym *sym) +{ + VarDecl *decl = sym->decl; + char *id = sym->name; + + /* + * Tim comment: We attempt to detect whether L global + * variables should be true globals, or should be shared with + * the calling proc, by checking if the current variable frame + * pointer in interp is the same as the global frame pointer. + * (Sharing variables with the calling proc is useful if you + * want to use L as an expr replacement). + */ + if (((Interp *)L->interp)->rootFramePtr != + ((Interp *)L->interp)->varFramePtr) { + ASSERT(!(decl->flags & (DECL_CLASS_VAR | DECL_CLASS_INST_VAR))); + frame_resumePrologue(); + push_lit("#0"); + push_lit(id); + TclEmitInstInt4(INST_UPVAR, sym->idx, L->frame->envPtr); + emit_pop(); + frame_resumeBody(); + return; + } + + /* + * The namespace of the var we're creating an upvar alias to is + * either ::, an L class namespace, or an L class instance namespace + * where the local "self" holds the namespace name. + */ + frame_resumePrologue(); + switch (decl->flags & + (DECL_GLOBAL_VAR | DECL_CLASS_VAR | DECL_CLASS_INST_VAR)) { + case DECL_GLOBAL_VAR: + push_lit("::"); + /* Private globals get mangled to avoid clashes. */ + if (decl->flags & DECL_PRIVATE) { + push_litf("_%s_%s", L->toplev, id); + } else { + push_lit(id); + } + break; + case DECL_CLASS_VAR: + push_litf("::L::_class_%s", decl->clsdecl->decl->id->str); + push_lit(id); + break; + case DECL_CLASS_INST_VAR: { + Sym *self = sym_lookup(mkId("self"), L_NOWARN); + ASSERT(self); + emit_load_scalar(self->idx); + push_lit(id); + break; + } + } + TclEmitInstInt4(INST_NSUPVAR, sym->idx, L->frame->envPtr); + emit_pop(); + frame_resumeBody(); +} + +/* + * Add a variable or function name to the symbol table. If it's a + * local variable, allocate a slot for it in the current proc. + * + * Print an error if the symbol is already defined. The rules are + * + * - Multiply defined globals are illegal, with the exception that + * main() can be re-defined. + * - A local cannot shadow any other local in the proc. + * - A local can shadow a global. + * - A local can shadow a global upvar shadow (which is a local + * with special status). + * + * Scopes are created as follows. The complexity stems from Tcl + * requiring local upvar shadows as the only way to access globals. + * So we have a scope in which the global symbol is stored and a + * nested scope for the proc in which the local upvar shadow is + * stored. + * + * There is one scope hierarchy per Tcl Interp in which L code + * appears, as illustrated next. OUTER,SCRIPT,TOPLEV,SKIP etc are frame + * flags (Frame_f); SKIP means that the scope is skipped when + * searching enclosing scopes. + * + * [ outer-most scope (OUTER): public globals go in this frame's symtab + * [ file scope (SCRIPT): private globals go in this frame's symtab + * [ * (%%n_toplevel proc) (TOPLEV|SKIP) + * global initializers get compiled in this scope, causing the + * local upvar shadows to go in this scope's symtab + * [ class outer-most (CLS_OUTER): class/instance vars & private + * member fns go in this frame's symtab + * [ * class top-level (CLS_TOPLEV|SKIP) + * class variable initializers get compiled in this scope + * (note that this is still in the %%n_toplevel proc) + * [ (constructor proc) + * instance var initializers get compiled here + * ] + * [ (destructor proc) + * ] + * [ (member fn proc): public fn names go in outer-most + * scope's, symtable, private fn names go in class + * outer-most scope, fn locals go in this frame's + * symtab + * [ block + * [ nested blocks... + * ] + * ] + * ] + * ] + * ] + * [ regular function (proc): public fn name goes in outer-most + * scope's symtab, private fn name goes in file scope's symtab, + * fn locals go in this frame's symtab + * [ block + * [ nested blocks... + * ] + * ] + * ] + * ] + * ] + * ] + */ +private Sym * +sym_store(VarDecl *decl) +{ + int new; + char *name = decl->id->str; + Sym *sym = NULL; + Sym *sym2; + Frame *frame = NULL; + Tcl_HashEntry *hPtr; + + /* Check for multiple declaration. */ + switch (decl->flags & + (SCOPE_LOCAL | SCOPE_GLOBAL | SCOPE_SCRIPT | SCOPE_CLASS)) { + case SCOPE_GLOBAL: + case SCOPE_SCRIPT: + /* Declaring a global -- search outer-most and file frames. */ + frame = frame_find(OUTER); + hPtr = Tcl_FindHashEntry(frame->symtab, name); + unless (hPtr) { + frame = frame_find(SCRIPT); + hPtr = Tcl_FindHashEntry(frame->symtab, name); + } + if (hPtr) { + sym2 = (Sym *)Tcl_GetHashValue(hPtr); + if (decl->flags & DECL_EXTERN) { + sym = (Sym *)Tcl_GetHashValue(hPtr); + if (L_typeck_same(decl->type, sym->type)) { + return (sym); + } + L_errf(decl, + "extern re-declaration type does not " + "match other declaration"); + return (NULL); + } else if (sym2->decl->flags & DECL_ERR) { + Tcl_DeleteHashEntry(hPtr); + } else { + L_errf(decl, + "multiple declaration of global %s", name); + return (NULL); + } + } + break; + case SCOPE_CLASS: + /* Declaring class var -- search up thru class outer scope. */ + for (frame = L->frame; frame; frame = frame->prevFrame) { + hPtr = Tcl_FindHashEntry(frame->symtab, name); + if (hPtr) { + sym2 = (Sym *)Tcl_GetHashValue(hPtr); + if (sym2->decl->flags & DECL_ERR) { + Tcl_DeleteHashEntry(hPtr); + } else { + L_errf(decl, "multiple declaration of %s", + name); + return (NULL); + } + } + if (frame->flags & CLS_OUTER) break; + } + break; + case SCOPE_LOCAL: + /* + * Declaring a local -- search current proc's local + * scopes, then the global scope so we can issue a warning + * if this is a local that shadows a class or global var. + */ + for (frame = L->frame; frame; frame = frame->prevFrame) { + unless (frame->envPtr == L->frame->envPtr) break; + hPtr = Tcl_FindHashEntry(frame->symtab, name); + if (hPtr) { + sym = (Sym *)Tcl_GetHashValue(hPtr); + ASSERT(sym->kind & L_SYM_LVAR); + unless (sym->kind & L_SYM_LSHADOW) { + L_errf(decl, "multiple declaration " + "of local %s", name); + return (NULL); + } + } + } + for (; frame; frame = frame->prevFrame) { + hPtr = Tcl_FindHashEntry(frame->symtab, name); + unless (hPtr && (frame->flags & SEARCH)) continue; + sym2 = (Sym *)Tcl_GetHashValue(hPtr); + if (sym2->decl->flags & DECL_GLOBAL_VAR) { + L_warnf(decl, "local variable %s shadows " + "a global declared at %s:%d", + name, sym2->decl->node.loc.file, + sym2->decl->node.loc.line); + } else if (sym2->decl->flags & DECL_CLASS_VAR) { + L_warnf(decl, "local variable %s shadows " + "a class variable declared at %s:%d", + name, sym2->decl->node.loc.file, + sym2->decl->node.loc.line); + } else if (sym2->decl->flags & DECL_CLASS_INST_VAR) { + L_warnf(decl, "local variable %s shadows a " + "class instance variable declared " + "at %s:%d", name, + sym2->decl->node.loc.file, + sym2->decl->node.loc.line); + } + } + break; + default: + ASSERT(0); + break; + } + + /* Select the frame to add the symbol to. */ + switch (decl->flags & + (SCOPE_LOCAL | SCOPE_GLOBAL | SCOPE_SCRIPT | SCOPE_CLASS)) { + case SCOPE_GLOBAL: + frame = frame_find(OUTER); + break; + case SCOPE_SCRIPT: + frame = frame_find(SCRIPT); + break; + case SCOPE_CLASS: + frame = frame_find(CLS_OUTER); + break; + case SCOPE_LOCAL: + frame = L->frame; + break; + default: + ASSERT(0); + break; + } + hPtr = Tcl_CreateHashEntry(frame->symtab, name, &new); + /* If it's not new, it must be shadowing a global. */ + ASSERT(new || (sym && (sym->kind & L_SYM_LSHADOW) && + (decl->flags & (DECL_LOCAL_VAR | DECL_CLASS_INST_VAR)))); + sym = (Sym *)ckalloc(sizeof(Sym)); + memset(sym, 0, sizeof(*sym)); + sym->name = ckstrdup(name); + sym->type = decl->type; + sym->decl = decl; + + /* + * Set the name of the tcl variable, mangling it to avoid + * clashes. + */ + if (isfntype(decl->type)) { + ASSERT(decl->flags & (DECL_FN | DECL_CLASS_FN)); + sym->kind = L_SYM_FN; + if (decl->tclprefix) { + sym->tclname = cksprintf("%s%s", decl->tclprefix, name); + } else { + sym->tclname = ckstrdup(name); + } + } else if (decl->flags & DECL_GLOBAL_VAR) { + sym->kind = L_SYM_GVAR; + sym->tclname = cksprintf("_%s", name); + } else if (decl->flags & (DECL_CLASS_VAR | DECL_CLASS_INST_VAR)) { + sym->kind = L_SYM_GVAR; + sym->tclname = cksprintf("_%s_%s", + decl->clsdecl->decl->id->str, + name); + } else { + ASSERT(decl->flags & DECL_LOCAL_VAR); + sym->kind = L_SYM_LVAR; + sym->tclname = ckstrdup(name); + } + + /* If a local, allocate a slot for it. */ + if (sym->kind & L_SYM_LVAR) { + sym->idx = TclFindCompiledLocal(name, strlen(name), + 1, L->frame->envPtr); + } else { + sym->idx = -1; + } + + decl->id->sym = sym; + decl->id->type = decl->type; + Tcl_SetHashValue(hPtr, sym); + + return (sym); +} + +/* + * Lookup id in the symbol table. + * + * flags & L_NOTUSED ==> don't mark the id as having been referenced + * (used for warning which variables are unused). + * + * flags & L_NOWARN ==> don't print error message if id not found. + * + * The first time a global is referenced within a scope, an upvar is + * created for it. + */ +private Sym * +sym_lookup(Expr *id, Expr_f flags) +{ + int new; + char *name; + Sym *shw; + Sym *sym = NULL; + Frame *frame; + Tcl_HashEntry *hPtr = NULL; + + unless (id->kind == L_EXPR_ID) return (NULL); + name = id->str; + + for (frame = L->frame; frame; frame = frame->prevFrame) { + if ((frame->envPtr == L->frame->envPtr) || + (frame->flags & SEARCH)) { + hPtr = Tcl_FindHashEntry(frame->symtab, name); + if (hPtr) break; + } + } + if (hPtr) sym = (Sym *)Tcl_GetHashValue(hPtr); + if (sym) { + /* + * If a global is being referenced for the first time + * in this scope, create a local upvar to shadow it + * in the symtab of the enclosing proc or top-level. + */ + if ((sym->kind & L_SYM_GVAR) && (sym->idx == -1)) { + Frame *proc_frame; + // assert global => in outer-most or file frame + ASSERT(!(sym->decl->flags & DECL_GLOBAL_VAR) || + (frame->flags & (OUTER|SCRIPT))); + // assert class var => in class outer-most frame + ASSERT(!(sym->decl->flags & DECL_CLASS_VAR) || + (frame->flags & CLS_OUTER)); + // assert class instance var => class outer-most frame + ASSERT(!(sym->decl->flags & DECL_CLASS_INST_VAR) || + (frame->flags & CLS_OUTER)); + proc_frame = frame_find(TOPLEV|CLS_TOPLEV|FUNC); + ASSERT(proc_frame); + hPtr = Tcl_CreateHashEntry(proc_frame->symtab, name, + &new); + ASSERT(new); + shw = (Sym *)ckalloc(sizeof(Sym)); + memset(shw, 0, sizeof(*shw)); + shw->kind = L_SYM_LVAR | L_SYM_LSHADOW; + shw->name = ckstrdup(name); + shw->tclname = ckstrdup(sym->tclname); + shw->type = sym->decl->type; + shw->decl = sym->decl; + shw->used_p = TRUE; + shw->idx = TclFindCompiledLocal(shw->tclname, + strlen(shw->tclname), + 1, + L->frame->envPtr); + emit_globalUpvar(shw); + Tcl_SetHashValue(hPtr, shw); + sym = shw; + } + unless (flags & L_NOTUSED) sym->used_p = TRUE; + id->sym = sym; + id->type = sym->type; + return (sym); + } else { + ASSERT(id->sym == NULL); + unless (flags & L_NOWARN) { + /* + * Add the undeclared variable to the symtab to avoid + * cascading errors. + */ + YYLTYPE loc = id->node.loc; + VarDecl *decl = ast_mkVarDecl(L_poly, id, loc, loc); + decl->flags = DECL_ERR | DECL_ARGUSED; + switch (L->frame->flags & (FUNC|CLS_TOPLEV|TOPLEV)) { + case TOPLEV | FUNC: + decl->flags |= SCOPE_GLOBAL | DECL_GLOBAL_VAR; + break; + case CLS_TOPLEV: + decl->flags |= SCOPE_CLASS | DECL_CLASS_VAR; + ASSERT(L->frame->clsdecl); + decl->clsdecl = L->frame->clsdecl; + break; + case FUNC: + case 0: // stmt block + decl->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + break; + default: ASSERT(0); + } + L_errf(id, "undeclared variable: %s", name); + id->sym = sym_store(decl); + } + id->type = L_poly; + return (NULL); + } +} + +private Sym * +sym_mk(char *name, Type *t, Decl_f flags) +{ + YYLTYPE loc = { 0 }; + Expr *id = mkId(name); + VarDecl *decl = ast_mkVarDecl(t, id, loc, loc); + + decl->flags = flags; + return (sym_store(decl)); +} + +private Tmp * +tmp_get(TmpKind kind) +{ + Tmp *tmp; + + for (tmp = L->frame->tmps; tmp; tmp = tmp->next) { + if (tmp->free) break; + } + unless (tmp) { + tmp = (Tmp *)ckalloc(sizeof(*tmp)); + tmp->next = L->frame->tmps; + L->frame->tmps = tmp; + tmp->name = cksprintf("=temp%d", L->tmpnum++); + tmp->idx = TclFindCompiledLocal(tmp->name, strlen(tmp->name), + 1, L->frame->envPtr); + } + tmp->free = 0; + /* + * Sometimes we need a tmp var that is not set to anything. + * For example, to create an upvar or to use the INST_DICT_* + * bytecodes. + */ + if (kind == TMP_UNSET) { + TclEmitInstInt4(INST_UNSET_LOCAL, tmp->idx, L->frame->envPtr); + } + return (tmp); +} + +private void +tmp_free(Tmp *tmp) +{ + if (tmp) tmp->free = 1; +} + +private void +tmp_freeAll(Tmp *tmp) +{ + while (tmp) { + Tmp *next = tmp->next; + ckfree((char *)tmp); + tmp = next; + } +} + +void +L_bomb(const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + fprintf(stderr, "L Internal Error: "); + vfprintf(stderr, format, ap); + va_end(ap); + fprintf(stderr, "\n"); + exit(1); +} + +/* + * L_synerr is Bison's yyerror and is called by the parser for syntax + * errors. Bail out by longjumping back to Tcl_LObjCmd, as a way + * to work-around a possible compiler bug in our Windows build where + * the Bison-generated parser's own internal longjmp causes a crash. + */ +void +L_synerr(const char *s) +{ + int i, off; + char *beg = Tcl_GetString(L->script); + char *end = beg + L->script_len; + char *line, *stop; + + unless (L->errs) { + L->errs = Tcl_NewObj(); + L->err = 1; + } + Tcl_AppendPrintfToObj(L->errs, "%s:%d: L Error: %s\n", + L->file, L->line, s); + + /* Search backwards to find the start of the offending line. */ + off = L_lloc.beg; + ASSERT(off >= 0); + ASSERT(beg); + for (line = beg+off; (line > beg) && (line[-1] != '\n'); --line) ; + off = beg+off - line; // is now offset from start of offending line + + /* Print the offending line with a ^ pointing to the current token. */ + stop = line + off; + for (i = 1; (*line != '\n') && (line < end); ++i) { + // adjust for tab printing >1 char + if ((*line == '\t') && (line <= stop)) { + off += 8 - i%8; + i += 7; + } + Tcl_AppendToObj(L->errs, line++, 1); + } + Tcl_AppendToObj(L->errs, "\n", 1); + ASSERT(off >= 0); + while (off--) Tcl_AppendToObj(L->errs, " ", 1); + Tcl_AppendToObj(L->errs, "^\n", 2); + + longjmp(L->jmp, 0); +} + +/* + * Like L_synerr() above but take the offset of the offending token + * instead of using the current token. + */ +void +L_synerr2(const char *s, int offset) +{ + L_lloc.beg = offset; + L_synerr(s); +} + +void +L_warnf(void *node, const char *format, ...) +{ + va_list ap; + int len = 64; + char *buf, *fmt; + + if (hash_get(L->options, "nowarn")) return; + + fmt = cksprintf("%s:%d: L Warning: %s\n", + ((Ast *)node)->loc.file, ((Ast *)node)->loc.line, + format); + va_start(ap, format); + while (!(buf = ckvsprintf(fmt, ap, len))) { + va_end(ap); + va_start(ap, format); + len *= 2; + } + va_end(ap); + unless (L->errs) { + L->errs = Tcl_NewObj(); + L->err = 1; + } + Tcl_AppendToObj(L->errs, buf, -1); + ckfree(fmt); + ckfree(buf); +} + +void +L_err(const char *format, ...) +{ + va_list ap; + int len = 64; + char *buf, *fmt; + + fmt = cksprintf("%s:%d: L Error: %s\n", L->file, L->line, format); + va_start(ap, format); + while (!(buf = ckvsprintf(fmt, ap, len))) { + va_end(ap); + va_start(ap, format); + len *= 2; + } + va_end(ap); + unless (L->errs) { + L->errs = Tcl_NewObj(); + L->err = 1; + } + Tcl_AppendToObj(L->errs, buf, -1); + ckfree(fmt); + ckfree(buf); +} + +void +L_errf(void *node, const char *format, ...) +{ + va_list ap; + int len = 64; + char *buf, *fmt; + + if (node) { + fmt = cksprintf("%s:%d: L Error: %s\n", + ((Ast *)node)->loc.file, + ((Ast *)node)->loc.line, + format); + } else { + fmt = cksprintf("L Error: %s\n", format); + } + va_start(ap, format); + while (!(buf = ckvsprintf(fmt, ap, len))) { + va_end(ap); + va_start(ap, format); + len *= 2; + } + va_end(ap); + unless (L->errs) { + L->errs = Tcl_NewObj(); + L->err = 1; + } + Tcl_AppendToObj(L->errs, buf, -1); + ckfree(fmt); +} + +private void +ast_free(Ast *ast_list) +{ + while (ast_list) { + Ast *node = ast_list; + ast_list = ast_list->next; + switch (node->type) { + case L_NODE_STMT: { + Stmt *s = (Stmt *)node; + if ((s->kind == L_STMT_LABEL) || + (s->kind == L_STMT_GOTO)) { + ckfree(s->u.label); + } + break; + } + case L_NODE_EXPR: + ckfree(((Expr *)node)->str); + break; + case L_NODE_VAR_DECL: + ckfree(((VarDecl *)node)->tclprefix); + break; + default: + break; + } + ckfree((char *)node); + } +} + +private void +type_free(Type *type_list) +{ + while (type_list) { + Type *type = type_list; + type_list = type_list->list; + if (type->kind == L_STRUCT) ckfree(type->u.struc.tag); + ckfree(type->name); + ckfree((char *)type); + } +} + +/* + * This is basically a whacked version of EnterCmdStartData and + * EnterCmdWordData from tclCompile.c. + */ +private void +track_cmd(int codeOffset, void *node) +{ + int cmdIndex = L->frame->envPtr->numCommands++; + Ast *ast = (Ast *)node; + int len = ast->loc.end - ast->loc.beg; + int srcOffset = ast->loc.beg; + ECL *ePtr; + CmdLocation *cmdLocPtr; + CompileEnv *envPtr = L->frame->envPtr; + ExtCmdLoc *eclPtr = envPtr->extCmdMapPtr; + + if ((cmdIndex < 0) || (cmdIndex >= envPtr->numCommands)) { + Tcl_Panic("track_cmd: bad command index %d", cmdIndex); + } + if (cmdIndex >= envPtr->cmdMapEnd) { + /* + * Expand the command location array by allocating + * more storage from the heap. The currently allocated + * CmdLocation entries are stored from cmdMapPtr[0] up + * to cmdMapPtr[envPtr->cmdMapEnd] (inclusive). + */ + size_t currElems = envPtr->cmdMapEnd; + size_t newElems = 2*currElems; + size_t currBytes = currElems * sizeof(CmdLocation); + size_t newBytes = newElems * sizeof(CmdLocation); + CmdLocation *newPtr = (CmdLocation *)ckalloc((int)newBytes); + + /* + * Copy from old command location array to new, free + * old command location array if needed, and mark new + * array as malloced. + */ + memcpy(newPtr, envPtr->cmdMapPtr, currBytes); + if (envPtr->mallocedCmdMap) ckfree((char *)envPtr->cmdMapPtr); + envPtr->cmdMapPtr = (CmdLocation *)newPtr; + envPtr->cmdMapEnd = newElems; + envPtr->mallocedCmdMap = 1; + } + + cmdLocPtr = &(envPtr->cmdMapPtr[cmdIndex]); + cmdLocPtr->codeOffset = codeOffset; + cmdLocPtr->srcOffset = srcOffset; + cmdLocPtr->numSrcBytes = len; + cmdLocPtr->numCodeBytes = currOffset(envPtr) - codeOffset; + + /* + * The command locations have to be sorted in ascending order + * by codeOffset. (Or Tcl panics in GetCmdLocEncodingSize(), + * if nothing else). However, when L compiles nested function + * calls, the outer one will get tracked second, even though + * it begins first. So we walk the new CmdLocation entry back + * from the end until it lands where it belongs. + */ + while ((cmdIndex > 0) && (envPtr->cmdMapPtr[cmdIndex-1].codeOffset > + envPtr->cmdMapPtr[cmdIndex].codeOffset)) { + CmdLocation cmdLoc = envPtr->cmdMapPtr[cmdIndex]; + envPtr->cmdMapPtr[cmdIndex] = envPtr->cmdMapPtr[cmdIndex-1]; + envPtr->cmdMapPtr[cmdIndex-1] = cmdLoc; + cmdIndex--; + } + + if (eclPtr->nuloc >= eclPtr->nloc) { + /* + * Expand the ECL array by allocating more storage + * from the heap. The currently allocated ECL entries + * are stored from eclPtr->loc[0] up to + * eclPtr->loc[eclPtr->nuloc-1] (inclusive). + */ + size_t currElems = eclPtr->nloc; + size_t newElems = (currElems ? 2*currElems : 1); + size_t newBytes = newElems * sizeof(ECL); + eclPtr->loc = (ECL *) ckrealloc((char *) eclPtr->loc, newBytes); + eclPtr->nloc = newElems; + } + + /* We enter only one word for the L command. */ + ePtr = &eclPtr->loc[eclPtr->nuloc]; + ePtr->srcOffset = srcOffset; + ePtr->line = (int *) ckalloc(sizeof(int)); + ePtr->nline = 1; + eclPtr->nuloc ++; +} + +/* + * API for tracking when we are compiling a function argument. This is + * used to check whether an (expand) operator is being used as a + * function argument (OK) or as something else (error). + * + * fnCallBegin: call just before compiling a fn call + * fnCallEnd: call just after compiling a fn call + * fnInArgList: returns 1 if we are just starting to compile a + * fn call arg; returns 0 if we're either outside of a + * fn call or nested within an expression inside of + * an arg: + * foo(x) -- true + * foo(x+y) -- false + */ +private int +fnCallBegin() +{ + int old = L->call_level; + L->call_level = L->expr_level; + return (old); +} +private void +fnCallEnd(int lev) +{ + L->call_level = lev; +} +private int +fnInArgList() +{ + return (L->expr_level == (L->call_level + 1)); +} + +private Expr * +mkId(char *name) +{ + YYLTYPE loc = { 0 }; + + return (ast_mkId(name, loc, loc)); +} + +char * +ckstrdup(const char *str) +{ + if (str) { + return (ckstrndup(str, strlen(str))); + } else { + return (NULL); + } +} + +char * +ckstrndup(const char *str, int len) +{ + char *newStr = ckalloc(len+1); + + strncpy(newStr, str, len); + newStr[len] = '\0'; + return (newStr); +} + +char * +cksprintf(const char *fmt, ...) +{ + va_list ap; + int len = 64; + char *buf; + + va_start(ap, fmt); + while (!(buf = ckvsprintf(fmt, ap, len))) { + va_end(ap); + va_start(ap, fmt); + len *= 2; + } + va_end(ap); + return (buf); +} + +/* + * Allocate a buffer of len bytes and attempt a vsnprintf and fail + * (return NULL) if len isn't enough. The caller should double len + * and re-try. We require the caller to re-try instead of re-trying + * here because on some platforms "ap" is changed by the vsnprintf + * call and there is no portable way to save and restore it. + */ +char * +ckvsprintf(const char *fmt, va_list ap, int len) +{ + char *buf = ckalloc(len); + int ret = vsnprintf(buf, len, fmt, ap); + /* + * The meaning of the return value depends on the platform. + * Some return the needed length (minus 1), some return -1, + * some truncate the buffer. For the latter, ret will be + * len-1 and we won't know whether it barely fit or wasn't + * enough, so just fail on that case. + */ + if ((ret >= (len-1)) || (ret < 0)) { + ckfree(buf); + return (NULL); + } + return (buf); +} + +/* + * Since we have C-like variable declarations in L, when hashes and + * arrays are declared, the base type is parsed separately from the + * array sizes or hash-element types. The next two functions put them + * back together. E.g., in + * + * string h{int}; + * + * the main type passed in to these functions is a hash type + * (w/index type of "int") but the hash type doesn't yet have its + * base type set, which in this example is "string". + * + * For simple declarations (like "string s") where there is no + * explicit array or hash, decl->type won't be set by the parser, so + * the base type goes there. For arrays/hashes, decl->type points to + * the first level of array or hash, and the base type must go onto + * the last nested hash or array type. + */ + +void +L_set_baseType(Type *type, Type *base_type) +{ + while (type->base_type) { + ASSERT((type->kind == L_ARRAY) || + (type->kind == L_HASH) || + (type->kind == L_NAMEOF)); + type = type->base_type; + } + type->base_type = base_type; +} + +void +L_set_declBaseType(VarDecl *decl, Type *base_type) +{ + if (decl->type) { + L_set_baseType(decl->type, base_type); + } else { + decl->type = base_type; + } + if (isnameoftype(base_type)) decl->flags |= DECL_REF; +} + +/* + * These are called before each Tcl interp is created (see + * tclInterp.c) and after it is deleted. Set up a top-level scope and + * call frame in order to persist typedefs, struct types, and globals + * across all the L programs compiled inside the interp. + */ +void +TclLInitCompiler(Tcl_Interp *interp) +{ + static Lglobal global; // L global state + +// putenv("MallocStackLogging=1"); + + /* Associate the L interp state with this interp. */ + L = (Linterp *)ckalloc(sizeof(Linterp)); + memset(L, 0, sizeof(Linterp)); + Tcl_SetAssocData(interp, "L", TclLCleanupCompiler, L); + + L->global = &global; + L->interp = interp; + frame_push(NULL, NULL, OUTER|SEARCH); + L_scope_enter(); + L->fn_calls = Tcl_NewObj(); + Tcl_SetVar2Ex(L->interp, "%%L_fnsCalled", NULL, L->fn_calls, + TCL_GLOBAL_ONLY); + L->fn_decls = Tcl_NewObj(); + Tcl_SetVar2Ex(L->interp, "L_fnsDeclared", NULL, L->fn_decls, + TCL_GLOBAL_ONLY); +} + +void +TclLCleanupCompiler(ClientData clientData, Tcl_Interp *interp) +{ + char buf[32]; + + L = (Linterp *)clientData; + L_scope_leave(); + frame_pop(); + ast_free(L->ast_list); + type_free(L->type_list); + if (L->include_table) { + Tcl_DeleteHashTable(L->include_table); + ckfree((char *)L->include_table); + } + ckfree(L->file); + ckfree(L->toplev); + if (L->script) Tcl_DecrRefCount(L->script); + ckfree((char *)L); + L = NULL; + + snprintf(buf, sizeof(buf), "/usr/bin/leaks %u", getpid()); +// system(buf); +} + +void +L_scope_enter() +{ + Scope *new_scope = (Scope *)ckalloc(sizeof(*new_scope)); + + new_scope->structs = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(new_scope->structs, TCL_STRING_KEYS); + + new_scope->typedefs = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(new_scope->typedefs, TCL_STRING_KEYS); + + new_scope->prev = L->curr_scope; + L->curr_scope = new_scope; +} + +void +L_scope_leave() +{ + Scope *prev = L->curr_scope->prev; + + Tcl_DeleteHashTable(L->curr_scope->structs); + ckfree((char *)L->curr_scope->structs); + + Tcl_DeleteHashTable(L->curr_scope->typedefs); + ckfree((char *)L->curr_scope->typedefs); + + ckfree((char *)L->curr_scope); + + L->curr_scope = prev; +} + +/* + * Called by parser to look up a reference to "struct tag". If + * "local" is true, check only the current scope. If the struct + * hasn't yet been declared, add an incomplete type to the current + * scope's struct table whose members will get filled up later when + * the struct is fully declared. + */ +Type * +L_struct_lookup(char *tag, int local) +{ + int new; + Type *type; + Tcl_HashEntry *hPtr = NULL; + Scope *scope; + + for (scope = L->curr_scope; !hPtr && scope; scope = scope->prev) { + hPtr = Tcl_FindHashEntry(scope->structs, tag); + if (local) break; + } + if (hPtr) { + type = (Type *)Tcl_GetHashValue(hPtr); + } else { + hPtr = Tcl_CreateHashEntry(L->curr_scope->structs, tag, &new); + type = type_mkStruct(tag, NULL); + Tcl_SetHashValue(hPtr, type); + } + return (type); +} + +/* + * Called by parser to declare a new struct type. If the struct + * already has been declared but without any members, fill them in + * now and return the existing type pointer. If tag is NULL, just + * sanity check the members' types (checking for void etc). + */ +Type * +L_struct_store(char *tag, VarDecl *m) +{ + Type *type = NULL; + + ASSERT(m); + + if (tag) { + type = L_struct_lookup(tag, TRUE); + if (type->u.struc.members) { + L_errf(m, "multiple declaration of struct %s", tag); + } else { + type->u.struc.members = m; + } + } + + /* Check member types for legality. */ + for (; m; m = m->next) { + L_typeck_declType(m); + } + + return (type); +} + +/* + * Called by parser to look up an ID in the typedef table to see if + * it's been previously declared as a type name. + */ +Type * +L_typedef_lookup(char *name) +{ + Tcl_HashEntry *hPtr = NULL; + Scope *scope; + + for (scope = L->curr_scope; !hPtr && scope; scope = scope->prev) { + hPtr = Tcl_FindHashEntry(scope->typedefs, name); + } + if (hPtr) { + return ((Type *)Tcl_GetHashValue(hPtr)); + } else { + return (NULL); + } +} + +/* + * Called by parser to define a new type name. + */ +void +L_typedef_store(VarDecl *decl) +{ + int new; + Tcl_HashEntry *hPtr; + Type *new_type; + char *name = decl->id->str; + + hPtr = Tcl_CreateHashEntry(L->curr_scope->typedefs, name, &new); + if (new) { + new_type = type_dup(decl->type); + if (new_type->name) ckfree(new_type->name); + new_type->name = ckstrdup(name); + Tcl_SetHashValue(hPtr, new_type); + } else { + Type *t = Tcl_GetHashValue(hPtr); + unless (L_typeck_same(decl->type, t)) { + L_errf(decl, "Cannot redefine type %s", name); + } + } +} + +void +hash_put(Tcl_Obj *hash, char *key, char *val) +{ + Tcl_Obj *keyObj, *valObj; + + ASSERT(hash && key); + keyObj = Tcl_NewStringObj(key, -1); + Tcl_IncrRefCount(keyObj); + if (val) { + valObj = Tcl_NewStringObj(val, -1); + } else { + valObj = *L_undefObjPtrPtr(); + } + Tcl_DictObjPut(L->interp, hash, keyObj, valObj); + Tcl_DecrRefCount(keyObj); +} + +void +hash_rm(Tcl_Obj *hash, char *key) +{ + Tcl_Obj *keyObj; + + ASSERT(hash && key); + keyObj = Tcl_NewStringObj(key, -1); + Tcl_IncrRefCount(keyObj); + Tcl_DictObjRemove(L->interp, hash, keyObj); + Tcl_DecrRefCount(keyObj); +} + +char * +hash_get(Tcl_Obj *hash, char *key) +{ + int ret; + Tcl_Obj *keyObj = Tcl_NewStringObj(key, -1); + Tcl_Obj *valObj; + + ASSERT(hash); + Tcl_IncrRefCount(keyObj); + ret = Tcl_DictObjGet(L->interp, hash, keyObj, &valObj); + unless (ret == TCL_OK) return (NULL); + Tcl_DecrRefCount(keyObj); + if (valObj) { + return (Tcl_GetString(valObj)); + } else { + return (NULL); + } +} + +/* For debugging. */ +void +hash_dump(Tcl_Obj *hash) +{ + int done, ret; + Tcl_Obj *key, *val; + Tcl_DictSearch ctxt; + + ret = Tcl_DictObjFirst(L->interp, hash, &ctxt, &key, &val, &done); + if ((ret != TCL_OK) || done) return; + do { + printf("%s -> %s\n", Tcl_GetString(key), + val->undef ? "<undef>" : Tcl_GetString(val)); + Tcl_DictObjNext(&ctxt, &key, &val, &done); + } while (!done); +} + +private char * +basenm(char *s) +{ + char *t; + + for (t = s; *t; t++); + do { + t--; + } while (*t != '/' && t > s); + if (*t == '/') t++; + return (t); +} + +/* + * Return the dirname of a path. The caller must ckfree() it. + */ +char * +L_dirname(char *path) +{ + Tcl_Obj *pathObj = Tcl_NewStringObj(path, -1); + Tcl_Obj *dirObj, *tmpObj; + char *ret = NULL; + + Tcl_IncrRefCount(pathObj); + tmpObj = Tcl_FSGetNormalizedPath(NULL, pathObj); + if (tmpObj == NULL) goto err; + dirObj = TclPathPart(L->interp, tmpObj, TCL_PATH_DIRNAME); + if (dirObj == NULL) goto err; + ret = ckstrdup(Tcl_GetString(dirObj)); + Tcl_DecrRefCount(dirObj); + err: Tcl_DecrRefCount(pathObj); + return (ret); +} + +/* + * This function executes the INST_L_SPLIT bytecode and is based on + * pieces from tclCmdMZ.c. + * + * For edge cases, some of Perl's "split" semantics are obeyed: + * + * - A limit <= 0 means no limit. + * + * - Trailing null fields in the result are always suppressed. + * + * - If there is no delim, split on white space and trim any leading + * null fields from the result. + * + * - If the delim is /regexp/t, trim any leading null fields. + * + * - If all result fields are null, they are considered to be trailing + * and are all suppressed. + */ +Tcl_Obj * +L_split(Tcl_Interp *interp, Tcl_Obj *strobj, Tcl_Obj *delimobj, + Tcl_Obj *limobj, Expr_f flags) +{ + int chlen, i, leading, len, lim, matches, nocase, off, ret; + int trim = (flags & L_EXPR_RE_T); + int start = 0, end = 0; + Tcl_RegExp regExpr = NULL; + Tcl_RegExpInfo info; + Tcl_Obj **elems, *resultPtr, *objPtr, *listPtr; + Tcl_UniChar ch; + char *str; + + if (limobj) { + Tcl_GetIntFromObj(interp, limobj, &lim); + if (lim <= 0) { + lim = INT_MAX; + } else { + /* The lim is the max # fields to return, + * which is one less than the max # matches to + * allow. */ + --lim; + } + } else { + lim = INT_MAX; + } + + /* + * Make sure to avoid problems where the objects are shared. This can + * cause RegExpObj <> UnicodeObj shimmering that causes data corruption. + * [Bug #461322] + */ + if (strobj == delimobj) { + objPtr = Tcl_DuplicateObj(strobj); + } else { + objPtr = strobj; + } + if (objPtr->typePtr == &tclByteArrayType) { + str = (char *)Tcl_GetByteArrayFromObj(objPtr, &len); + } else { + str = Tcl_GetStringFromObj(objPtr, &len); + } + + listPtr = Tcl_NewObj(); + matches = 0; + leading = 1; + off = 0; + + /* + * Split on white space if no delim was specified. + */ + unless (delimobj) { + int skip = 0; + for (start = 0; (off < len) && (matches < lim); off += chlen) { + chlen = TclUtfToUniChar(str+off, &ch); + if (skip) { + unless (Tcl_UniCharIsSpace(ch)) { + start = off; + skip = 0; + ++matches; + } + } else { + if (Tcl_UniCharIsSpace(ch)) { + /* Suppress leading null field + * in result. */ + if (off || start) { + resultPtr = Tcl_NewStringObj( + str+start, + off-start); + Tcl_ListObjAppendElement( + NULL, listPtr, + resultPtr); + } + skip = 1; + } + } + } + unless (skip) { + resultPtr = Tcl_NewStringObj(str+start, len-start); + Tcl_ListObjAppendElement(NULL, listPtr, resultPtr); + } + goto done; + } + + /* + * Split on a regular expression. + */ + nocase = (flags & L_EXPR_RE_I) ? TCL_REG_NOCASE : 0; + regExpr = Tcl_GetRegExpFromObj(interp, delimobj, + TCL_REG_ADVANCED | TCL_REG_PCRE | nocase); + unless (regExpr) { // bad regexp + listPtr = NULL; + goto done; + } + while ((off < len) && (matches < lim)) { + int flags = TCL_REG_BYTEOFFSET; + + if ((off > 0) && (str[off-1] != '\n')) flags |= TCL_REG_NOTBOL; + ret = Tcl_RegExpExecObj(interp, regExpr, objPtr, off, 1, flags); + if (ret < 0) goto done; + if (ret == 0) break; + Tcl_RegExpGetInfo(regExpr, &info); + start = info.matches[0].start; + end = info.matches[0].end; + matches++; + + /* + * Copy to the result list the portion of the source + * string before the match. If we matched the empty + * string, split after the current char. Don't add + * leading null fields if specified. + */ + if (leading && trim && (start == 0)) { + if (start == end) ++off; + off += end; + continue; + } + if (start == end) { + ASSERT(start == 0); + resultPtr = Tcl_NewStringObj(str+off, 1); + ++off; + } else { + resultPtr = Tcl_NewStringObj(str+off, start); + } + leading = 0; + Tcl_ListObjAppendElement(NULL, listPtr, resultPtr); + off += end; + } + /* + * Copy to the result list the portion of the source string after + * the last match, unless we matched the last char. + */ + if (off < len) { + resultPtr = Tcl_NewStringObj(str+off, len-off); + Tcl_ListObjAppendElement(NULL, listPtr, resultPtr); + } + + done: + if (objPtr && (strobj == delimobj)) { + Tcl_DecrRefCount(objPtr); + } + unless (listPtr) return (NULL); + + /* + * Strip any trailing empty fields in the result. This is + * to be consistent with Perl's split semantics. + */ + TclListObjGetElements(NULL, listPtr, &len, &elems); + for (i = len-1; i >= 0; --i) { + if (Tcl_GetCharLength(elems[i])) break; + Tcl_ListObjReplace(interp, listPtr, i, 1, 0, NULL); + } + return (listPtr); +} + +/* + * This command splits the given arguments according to bash-style + * quoting, returning a string[] array. + * + * xyz -- all escapes are processed except \<newline> ignored + * 'xyz' -- no single quotes allowed inside, no escapes processed + * "xyz" -- only \\ and \" are processed, \<newline> ignored + */ +int +Tcl_ShSplitObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + char *cmd; + int i, j, len; + Tcl_Obj *arg = NULL, *argv; + enum { LOOKING, ARG, SINGLE, DOUBLE } state; + + unless (objc >= 2) { + Tcl_WrongNumArgs(interp, 1, objv, "string ?string ...?"); + return (TCL_ERROR); + } + argv = Tcl_NewObj(); + for (i = 1; i < objc; ++i) { + cmd = TclGetStringFromObj(objv[i], &len); + state = LOOKING; + for (j = 0; j < len; ++j) { + char c = cmd[j]; + switch (state) { + case LOOKING: + if (isspace(c)) { + continue; + } else { + arg = Tcl_NewObj(); + state = ARG; + /*FALLTHRU*/ + } + case ARG: + if (isspace(c)) { + Tcl_ListObjAppendElement(interp, + argv, arg); + state = LOOKING; + } else if (c == '\\') { + char e = 0; + if ((j+1) < len) e = cmd[j+1]; + // escape anything but ignore \<newline> + if (!e) { + Tcl_AppendResult(interp, + "trailing \\", + NULL); + return (TCL_ERROR); + } else if (e == '\n') { + ++j; + } else { + Tcl_AppendToObj(arg, &e, 1); + ++j; + } + } else if (c == '\'') { + state = SINGLE; + } else if (c == '"') { + state = DOUBLE; + } else { + Tcl_AppendToObj(arg, &c, 1); + } + break; + case SINGLE: + if (c == '\'') { + state = ARG; + } else { + Tcl_AppendToObj(arg, &c, 1); + } + break; + case DOUBLE: + if (c == '\\') { + char e = 0; + if ((j+1) < len) e = cmd[j+1]; + // escape \ and " but ignore \<newline> + if ((e == '\\') || (e == '"')) { + Tcl_AppendToObj(arg, &e, 1); + ++j; + } else if (e == '\n') { + ++j; + } else { + Tcl_AppendToObj(arg, &c, 1); + } + } else if (c == '"') { + state = ARG; + } else { + Tcl_AppendToObj(arg, &c, 1); + } + break; + } + } + switch (state) { + case LOOKING: + break; + case ARG: + Tcl_ListObjAppendElement(interp, argv, arg); + break; + case SINGLE: + Tcl_AppendResult(interp, "unterminated \'", NULL); + return (TCL_ERROR); + case DOUBLE: + Tcl_AppendResult(interp, "unterminated \"", NULL); + return (TCL_ERROR); + } + } + Tcl_SetObjResult(interp, argv); + return (TCL_OK); +} + +int +Tcl_GetOptObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int ac, i, n, ret = TCL_OK; + char **av, *opts, *s; + longopt *lopts = NULL; + Tcl_Obj **objs; + + /* + * This is all about converting the L args to C args for the + * getopt() call and then mapping back for the return value. + */ + + unless (objc == 4) { + Tcl_WrongNumArgs(interp, 1, objv, "av opts lopts"); + return (TCL_ERROR); + } + + /* Set the C optind variable from its L counterpart. */ + s = (char *)Tcl_GetVar(interp, "optind", TCL_GLOBAL_ONLY); + if (s) optind = atoi(s); + + if (Tcl_ListObjGetElements(interp, objv[1], &ac, &objs) != TCL_OK) { + return (TCL_ERROR); + } + av = (char **)ckalloc(ac * sizeof(char *)); + for (i = 0; i < ac; ++i) { + av[i] = TclGetString(objs[i]); + } + opts = (objv[2]->undef ? "" : TclGetString(objv[2])); + /* + * For long opts, the C API wants an array of <char*,int>, and + * the L call sent in a string array, so map the long opt name to + * its L array index + 300 (values <= 256 are reserved for the + * short opts and GETOPT_ERR). + */ + if (Tcl_ListObjGetElements(interp, objv[3], &n, &objs) != TCL_OK) { + ret = TCL_ERROR; + goto done; + } + if (n) { + lopts = (longopt *)ckalloc((n+1) * sizeof(longopt)); + for (i = 0; i < n; ++i) { + lopts[i].name = TclGetString(objs[i]); + lopts[i].ret = 300 + i; + } + lopts[i].name = NULL; + } + i = getopt(ac, av, opts, lopts); + switch (i) { + case GETOPT_EOF: + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + break; + case GETOPT_ERR: + Tcl_SetObjResult(interp, Tcl_NewStringObj("", 0)); + break; + default: + if (i < 300) { + // short opt + char str[1]; + str[0] = i; + Tcl_SetObjResult(interp, Tcl_NewStringObj(str, 1)); + } else { + // long opt -- map back to the longopts array entry + // and strip any trailing :;| + s = TclGetStringFromObj(objs[i-300], &n); + if ((s[n-1] == ':') || (s[n-1] == ';') || + (s[n-1] == '|')) { + Tcl_SetObjResult(interp, + Tcl_NewStringObj(s,n-1)); + } else { + Tcl_SetObjResult(interp, objs[i-300]); + } + } + break; + } + /* Set the optind, optopt, and optarg globals from the C variables. */ + s = cksprintf("%d", optind); + Tcl_SetVar(interp, "optind", s, TCL_GLOBAL_ONLY); + ckfree(s); + s = cksprintf("%c", optopt); + Tcl_SetVar(interp, "optopt", s, TCL_GLOBAL_ONLY); + ckfree(s); + if (optarg) { + Tcl_SetVar(interp, "optarg", optarg, TCL_GLOBAL_ONLY); + } else { + Tcl_SetVar2Ex(interp, "optarg", NULL, *L_undefObjPtrPtr(), + TCL_GLOBAL_ONLY); + } + done: + ckfree((char *)av); + ckfree((char *)lopts); + return (ret); +} + +int +Tcl_GetOptResetObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + unless (objc == 1) { + Tcl_WrongNumArgs(interp, 1, objv, NULL); + return (TCL_ERROR); + } + getoptReset(); + Tcl_SetVar(interp, "optind", "0", TCL_GLOBAL_ONLY); + Tcl_SetVar(interp, "optopt", "", TCL_GLOBAL_ONLY); + Tcl_SetVar2Ex(interp, "optarg", NULL, *L_undefObjPtrPtr(), + TCL_GLOBAL_ONLY); + return (TCL_OK); +} + +/* + * Parts of the next two functions are taken from Tcl_GetsObjCmd(). + * do_getline() is like Tcl_GetsObjCmd() except that it results in + * undef on error or EOF, and it returns the result object so you + * don't have to pull it out of the interp to see what happened. + */ + +private Tcl_Obj * +do_getline(Tcl_Interp *interp, Tcl_Channel chan) +{ + Tcl_Obj *ret; + + ret = Tcl_NewObj(); + if (Tcl_GetsObj(chan, ret) < 0) { + Tcl_DecrRefCount(ret); + if (!Tcl_Eof(chan) && !Tcl_InputBlocked(chan)) { + /* + * TIP #219. Capture error messages put by the + * driver into the bypass area and put them + * into the regular interpreter result. Fall + * back to the regular message if nothing was + * found in the bypass. + */ + if (!TclChanCaughtErrorBypass(interp, chan)) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, Tcl_PosixError(interp), + NULL); + } + Tcl_SetVar2Ex(interp, "::stdio_lasterr", NULL, + Tcl_GetObjResult(interp), + TCL_GLOBAL_ONLY); + return (NULL); + } + ret = *L_undefObjPtrPtr(); + } + Tcl_SetObjResult(interp, ret); + return (ret); +} + +int +Tcl_FGetlineObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int mode; + Tcl_Channel chan; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "channelId"); + return (TCL_ERROR); + } + if (TclGetChannelFromObj(interp, objv[1], &chan, + &mode, 0) != TCL_OK) { + goto err; + } + unless (mode & TCL_READABLE) { + Tcl_AppendResult(interp, "channel \"", TclGetString(objv[1]), + "\" wasn't opened for reading", NULL); + goto err; + } + unless (do_getline(interp, chan)) { + goto err; + } + return (TCL_OK); + err: + Tcl_SetVar2Ex(interp, "::stdio_lasterr", NULL, + Tcl_GetObjResult(interp), + TCL_GLOBAL_ONLY); + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + return (TCL_OK); +} + +int +Tcl_LAngleReadObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + Tcl_Obj *ret = NULL; + int argc, res; + Tcl_Obj **argv; + static int cur = 0; + static Tcl_Channel chan = NULL; + + if (objc != 1) { + Tcl_WrongNumArgs(interp, 1, objv, NULL); + return (TCL_ERROR); + } + unless (L->global->script_argc) { + Tcl_Obj *objv[2]; + + objv[0] = Tcl_NewStringObj("angle_read_", -1); + objv[1] = Tcl_NewStringObj("stdin", -1); + res = Tcl_FGetlineObjCmd(dummy, interp, 2, objv); + Tcl_DecrRefCount(objv[0]); + Tcl_DecrRefCount(objv[1]); + return (res); + } + Tcl_ListObjGetElements(L->interp, L->global->script_argv, &argc, &argv); + while (1) { + if (chan) { + ret = do_getline(interp, chan); + if (ret && !ret->undef) break; + Tcl_UnregisterChannel(interp, chan); + chan = NULL; + } + if (cur >= argc) { + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + break; + } + chan = Tcl_FSOpenFileChannel(interp, argv[cur++], "r", 0); + if (chan) { + Tcl_RegisterChannel(interp, chan); + } else { + fprintf(stderr, "%s\n", Tcl_GetStringResult(interp)); + Tcl_ResetResult(interp); + } + } + return (TCL_OK); +} + +extern int Tcl_WriteObjN(Tcl_Channel chan, Tcl_Obj *objPtr, int numBytes); + +int +Tcl_LWriteCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int mode, nbytes; + char *errmsg = ""; + Tcl_Channel chan; + + if (objc != 4) { + Tcl_WrongNumArgs(interp, 1, objv, "channel buffer numBytes"); + return (TCL_ERROR); + } + if (TclGetChannelFromObj(interp, objv[1], &chan, &mode, 0) != TCL_OK) { + return (TCL_ERROR); + } + if (!(mode & TCL_WRITABLE)) { + errmsg = "channel wasn't opened for writing"; + goto err; + } + if (Tcl_GetIntFromObj(interp, objv[3], &nbytes) != TCL_OK) { + return (TCL_ERROR); + } + nbytes = Tcl_WriteObjN(chan, objv[2], nbytes); + if (nbytes < 0) { + if (!TclChanCaughtErrorBypass(interp, chan)) { + errmsg = (char *)Tcl_PosixError(interp); + } + goto err; + } + out: + Tcl_SetObjResult(interp, Tcl_NewIntObj(nbytes)); + return (TCL_OK); + err: + Tcl_SetVar2(interp, "::stdio_lasterr", NULL, errmsg, TCL_GLOBAL_ONLY); + nbytes = -1; + goto out; +} + +int +Tcl_LReadCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int mode, nbytes = -1; + char *errmsg = ""; + Tcl_Channel chan; + Tcl_Obj *buf; + + if ((objc != 4) && (objc != 3)) { + Tcl_WrongNumArgs(interp, 1, objv, "channel varName ?numBytes"); + return (TCL_ERROR); + } + if (TclGetChannelFromObj(interp, objv[1], &chan, &mode, 0) != TCL_OK) { + return (TCL_ERROR); + } + if (!(mode & TCL_READABLE)) { + errmsg = "channel wasn't opened for reading"; + goto err; + } + if (Tcl_Eof(chan)) { + errmsg = "end of file"; + goto err; + } + if (objc == 4) { + if (Tcl_GetIntFromObj(interp, objv[3], &nbytes) != TCL_OK) { + return (TCL_ERROR); + } + } + buf = Tcl_NewObj(); + Tcl_IncrRefCount(buf); + nbytes = Tcl_ReadChars(chan, buf, nbytes, 0); + if (nbytes < 0) { + if (!TclChanCaughtErrorBypass(interp, chan)) { + errmsg = (char *)Tcl_PosixError(interp); + } + Tcl_DecrRefCount(buf); + goto err; + } + Tcl_ObjSetVar2(interp, objv[2], NULL, buf, TCL_LEAVE_ERR_MSG); + Tcl_DecrRefCount(buf); + Tcl_SetObjResult(interp, Tcl_NewIntObj(nbytes)); + return (TCL_OK); + err: + Tcl_SetVar(interp, "::stdio_lasterr", errmsg, TCL_GLOBAL_ONLY); + Tcl_SetObjResult(interp, Tcl_NewIntObj(-1)); + return (TCL_OK); +} + +int +Tcl_LRefCnt( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "object"); + return (TCL_ERROR); + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(objv[1]->refCount)); + return (TCL_OK); +} + +/* + * This defines a defined() proc even though it also is a compiler + * built-in. When L code uses defined(), it gets the built-in. + * Having the proc allows access to this functionality from Tcl code. + */ +int +Tcl_LDefined( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "object"); + return (TCL_ERROR); + } + Tcl_SetObjResult(interp, Tcl_NewIntObj(objv[1]->undef ? 0 : 1)); + return (TCL_OK); +} + +/* + * This evaluates an Lhtml document. All input is passed through + * to Tcl's stdout channel with two kinds of interpolation: + * + * - Anything between <? and ?> is taken to be L statements + * and is replaced by whatever that L code outputs. + * + * - Anything between <?= and ?> is taken to be an L expression and is + * replaced by whatever it evaluates to (this is just like regular L + * string interpolation). + * + * This works by putting the scanner into an Lhtml mode where + * <?, <?=, and ?> are recognized. The parser contains rules for + * wrapping the html in puts() calls. + */ +int +Tcl_LHtmlObjCmd( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int ret; + + L_lex_begLhtml(); + ret = Tcl_LObjCmd(NULL, interp, objc, objv); + L_lex_endLhtml(); + return (ret); +} + +/* + * A Tcl_Obj type to store a pointer into a string buffer that we can + * walk down over time. The twpPtrValue internalrep is used, with the + * first ptr pointing to a ckalloc'd Bufptr struct (defined below) and + * the second ptr pointing to a copy of the buffer. + */ +static Tcl_ObjType L_bufPtrType = { + "l-bufPtrType", + NULL, /* freeIntRepProc */ + NULL, /* dupIntRepProc */ + NULL, /* updateStringProc */ + NULL /* setFromAnyProc */ +}; +typedef struct { + char *p; + char *end; +} Bufptr; + +int +Tcl_LGetNextLineInit( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int len; + char *beg, *s; + Tcl_Obj *tmp; + Bufptr *bufptr; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "object"); + return (TCL_ERROR); + } + if (objv[1]->undef) { + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + return (TCL_OK); + } + + /* + * Make a copy of the string whose lines we will walk. Do + * this instead of copying the Tcl_Obj to avoid problems with + * possible shimmering (i.e., the Tcl_Obj's string-rep buffer is + * not guaranteed to remain). + */ + s = Tcl_GetStringFromObj(objv[1], &len); + beg = ckalloc(len + 1); + memcpy(beg, s, len); + beg[len] = '\0'; + + /* + * Stash the copied string and a Bufptr into it inside of a + * tmp Tcl_Obj that will live for the duration of the walk. + * Tcl_LGetNextLine() will process it. + */ + tmp = Tcl_NewObj(); + tmp->typePtr = &L_bufPtrType; + bufptr = (Bufptr *)ckalloc(sizeof(Bufptr)); + bufptr->p = beg; + bufptr->end = beg + len; + tmp->internalRep.twoPtrValue.ptr1 = bufptr; + tmp->internalRep.twoPtrValue.ptr2 = beg; + + Tcl_SetObjResult(interp, tmp); + return (TCL_OK); +} + +int +Tcl_LGetNextLine( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + Tcl_Obj *ret, *tmp; + char *beg, *p; + Bufptr *bufptr; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "tmp"); + return (TCL_ERROR); + } + tmp = objv[1]; + if (tmp->undef) goto nomore; + unless (tmp->typePtr == &L_bufPtrType) { + Tcl_SetObjResult(interp, + Tcl_NewStringObj("invalid tmp object", -1)); + return (TCL_ERROR); + } + bufptr = (Bufptr *)tmp->internalRep.twoPtrValue.ptr1; + unless (bufptr) goto nomore; + + beg = bufptr->p; + if (beg >= bufptr->end) goto nomore; + + for (p = beg; p < bufptr->end; ++p) { + if (p[0] == '\n') { + bufptr->p = p + 1; + break; + } + if (((p+1) < bufptr->end) && (p[0] == '\r') && (p[1] == '\n')) { + bufptr->p = p + 2; + break; + } + } + ret = Tcl_NewStringObj(beg, p - beg); + if (p == bufptr->end) { + ckfree(tmp->internalRep.twoPtrValue.ptr2); + ckfree((char *)bufptr); + tmp->internalRep.twoPtrValue.ptr1 = NULL; + tmp->internalRep.twoPtrValue.ptr2 = NULL; + } + Tcl_SetObjResult(interp, ret); + return (TCL_OK); + nomore: + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + return (TCL_OK); +} + +#ifdef _WIN32 + +int +Tcl_LGetDirX( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int len, ret; + Tcl_Obj *argv[2], *dirObjs, *eltObjs[3], *fileObjs, *listObj; + char *buf, *dir, *type, *utfname; + Tcl_DString ds; + HANDLE hFind; + WIN32_FIND_DATA f; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "directory"); + return (TCL_ERROR); + } + + // Append \* to the given directory path. + dir = cksprintf("%s\\*", Tcl_GetString(objv[1])); + Tcl_WinUtfToTChar(dir, -1, &ds); + + hFind = FindFirstFile((TCHAR *)Tcl_DStringValue(&ds), &f); + if (hFind == INVALID_HANDLE_VALUE) { + TclWinConvertError(GetLastError()); + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (char *)&buf, + 0, NULL); + // Chomp the cr,lf that windows added to buf. + len = strlen(buf); + if (len > 2) buf[len-2] = 0; + Tcl_SetVar(interp, "::stdio_lasterr", + buf, + TCL_GLOBAL_ONLY); + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + LocalFree(buf); + return (TCL_OK); + } + ckfree(dir); + Tcl_DStringFree(&ds); + + fileObjs = Tcl_NewListObj(0, NULL); + dirObjs = Tcl_NewListObj(0, NULL); + do { + utfname = Tcl_WinTCharToUtf(f.cFileName, -1, &ds); + eltObjs[0] = Tcl_NewStringObj(utfname, -1); + if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + type = "directory"; + } else { + type = "file"; + } + eltObjs[1] = Tcl_NewStringObj(type, -1); + if ((f.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) || + (*utfname == '.')) { + eltObjs[2] = Tcl_NewIntObj(1); + } else { + eltObjs[2] = Tcl_NewIntObj(0); + } + listObj = Tcl_NewListObj(3, eltObjs); + if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + Tcl_ListObjAppendElement(interp, dirObjs, listObj); + } else { + Tcl_ListObjAppendElement(interp, fileObjs, listObj); + } + Tcl_DStringFree(&ds); + } while (FindNextFile(hFind, &f)); + FindClose(hFind); + + // Sort the lists. + argv[1] = dirObjs; + Tcl_IncrRefCount(dirObjs); + Tcl_ResetResult(interp); + ret = Tcl_LsortObjCmd(NULL, interp, 2, argv); + Tcl_DecrRefCount(dirObjs); + if (ret == TCL_OK) { + dirObjs = Tcl_DuplicateObj(Tcl_GetObjResult(interp)); + } + + argv[1] = fileObjs; + Tcl_IncrRefCount(fileObjs); + Tcl_ResetResult(interp); + ret = Tcl_LsortObjCmd(NULL, interp, 2, argv); + Tcl_DecrRefCount(fileObjs); + if (ret == TCL_OK) { + fileObjs = Tcl_GetObjResult(interp); + } + + // Return a list with the file names after all the dir names. + Tcl_ListObjAppendList(interp, dirObjs, fileObjs); + Tcl_SetObjResult(interp, dirObjs); + return (TCL_OK); +} + +#else // #ifdef WIN32 + +int +Tcl_LGetDirX( + ClientData dummy, /* Not used. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument objects. */ +{ + int ret; + Tcl_Obj *argv[2], *dirObjs, *eltObjs[3], *fileObjs, *listObj; + DIR *d; + struct dirent *dent; + char *dir, *type; +#ifndef HAVE_STRUCT_DIRENT_D_TYPE + char *path; + struct stat st; +#endif + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "directory"); + return (TCL_ERROR); + } + + dir = Tcl_GetString(objv[1]); + d = opendir(dir); + unless (d) { + Tcl_SetVar(interp, "::stdio_lasterr", + strerror(errno), + TCL_GLOBAL_ONLY); + Tcl_SetObjResult(interp, *L_undefObjPtrPtr()); + return (TCL_OK); + } + + fileObjs = Tcl_NewListObj(0, NULL); + dirObjs = Tcl_NewListObj(0, NULL); + while (dent = readdir(d)) { + eltObjs[0] = Tcl_NewStringObj(dent->d_name, -1); +#ifdef HAVE_STRUCT_DIRENT_D_TYPE + switch (dent->d_type) { + case DT_REG: type = "file"; break; + case DT_DIR: type = "directory"; break; + default: type = "other"; break; + } +#else + path = cksprintf("%s/%s", dir, dent->d_name); + if (stat(path, &st)) { + type = "unknown"; + } else if (S_ISREG(st.st_mode)) { + type = "file"; + } else if (S_ISDIR(st.st_mode)) { + type = "directory"; + } else { + type = "other"; + } + ckfree(path); +#endif + eltObjs[1] = Tcl_NewStringObj(type, -1); + if (*dent->d_name == '.') { + eltObjs[2] = Tcl_NewIntObj(1); + } else { + eltObjs[2] = Tcl_NewIntObj(0); + } + listObj = Tcl_NewListObj(3, eltObjs); + if (*type == 'd') { + Tcl_ListObjAppendElement(interp, dirObjs, listObj); + } else { + Tcl_ListObjAppendElement(interp, fileObjs, listObj); + } + } + closedir(d); + + // Sort the lists. + argv[1] = dirObjs; + Tcl_IncrRefCount(dirObjs); + Tcl_ResetResult(interp); + ret = Tcl_LsortObjCmd(NULL, interp, 2, argv); + Tcl_DecrRefCount(dirObjs); + if (ret == TCL_OK) { + dirObjs = Tcl_DuplicateObj(Tcl_GetObjResult(interp)); + } + + argv[1] = fileObjs; + Tcl_IncrRefCount(fileObjs); + Tcl_ResetResult(interp); + ret = Tcl_LsortObjCmd(NULL, interp, 2, argv); + Tcl_DecrRefCount(fileObjs); + if (ret == TCL_OK) { + fileObjs = Tcl_GetObjResult(interp); + } + + // Return a list with the file names after all the dir names. + Tcl_ListObjAppendList(interp, dirObjs, fileObjs); + Tcl_SetObjResult(interp, dirObjs); + return (TCL_OK); +} + +#endif // #ifdef WIN32 diff --git a/generic/Lcompile.h b/generic/Lcompile.h new file mode 100644 index 0000000..8d0b422 --- /dev/null +++ b/generic/Lcompile.h @@ -0,0 +1,606 @@ +/* + * Copyright (c) 2006-2008 BitMover, Inc. + */ +#ifndef L_COMPILE_H +#define L_COMPILE_H + +#include <setjmp.h> +#include "tclInt.h" +#include "tclCompile.h" +#include "Last.h" + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +/* For jump fix-ups. */ +typedef struct Jmp Jmp; +struct Jmp { + int op; // jmp instruction bytecode (e.g., INST_JUMP1) + int size; // size of jmp instruction (1 or 4 bytes) + int offset; // bytecode offset of jmp instruction + Jmp *next; +}; + +/* Semantic stack frame. */ +typedef enum { + OUTER = 0x0001, // is outer-most + SCRIPT = 0x0002, // is file scope + TOPLEV = 0x0004, // is for file top-levels + CLS_OUTER = 0x0008, // is class outer-most + CLS_TOPLEV = 0x0010, // is for class top-levels + FUNC = 0x0020, // frame is at top level of a proc + LOOP = 0x0040, // frame is for a loop + SWITCH = 0x0080, // frame is for a switch stmt + SKIP = 0x0100, // skip frame when searching enclosing scopes + SEARCH = 0x0200, // don't skip this frame + KEEPSYMS = 0x0400, // don't free symtab when scope is closed +} Frame_f; +typedef enum { + LABEL_USE = 0x01, // label is being referenced + LABEL_DEF = 0x02, // label is being defined +} Label_f; +typedef struct Label { + char *name; + int offset; + Jmp *fixups; +} Label; +typedef struct Frame { + CompileEnv *envPtr; + CompileEnv *bodyEnvPtr; + CompileEnv *prologueEnvPtr; + Proc *proc; + char *name; + Tcl_HashTable *symtab; + Tcl_HashTable *labeltab; + ClsDecl *clsdecl; + Frame_f flags; + // When a compile frame corresponds to a block in the code, we + // store the AST node of the block here. + Ast *block; + // We collect jump fix-ups for all of the jumps emitted for break and + // continue statements, so that we can stuff in the correct jump targets + // once we're done compiling the loops. + Jmp *continue_jumps; + Jmp *break_jumps; + // Jump fix-up for the jump to the prologue code at the end of a proc, + // and the bytecode offset for the jump back. + Jmp *end_jmp; + int proc_top; + // Fix-ups for return stmts which all jmp to the end. + Jmp *ret_jmps; + // List of temps allocated in this frame. + Tmp *tmps; + struct Frame *prevFrame; +} Frame; + +/* Per-scope tables. Scopes are opened and close at parse time. */ +typedef struct scope Scope; +struct scope { + Tcl_HashTable *structs; + Tcl_HashTable *typedefs; + Scope *prev; +}; + +/* + * Global L state. There is only one of these, reachable via L->global. + * The general L command line is + * tclsh [-tclsh_opt1] ... [-tclsh_optn] script_name [-script_opt1] ... [-script_optm] + */ +typedef struct { + int tclsh_argc; + Tcl_Obj *tclsh_argv; + int script_argc; + Tcl_Obj *script_argv; + int forceL; // wrap input in #lang L directive +} Lglobal; + +/* + * Per-interp L state. When an interp is created, one of these is + * allocated for each interp and associated with the interp. Whenever + * the compiler is entered, it is extracted from the interp. + */ +typedef struct { + Lglobal *global; // L global state + Frame *frame; // current semantic stack frame + Scope *curr_scope; + Ast *ast_list; // list of all AST nodes + Type *type_list; // list of all type descriptors + void *ast; // ptr to AST root, set by parser + Tcl_Obj *errs; + int err; // =1 if there was any compile error + char *dir; // absolute path to dir containing L->file + char *file; + int line; + int prev_token_len; + int token_off; // offset of curr token from start of input + int prev_token_off; // offset of prev token from start of input + Tcl_Obj *script; // src of script being compiled + int script_len; + Tcl_Obj *options; // hash of command-line options + FnDecl *enclosing_func; + Frame *enclosing_func_frame; + Ast *mains_ast; // root of AST when main() last seen + Tcl_HashTable *include_table; + Tcl_Interp *interp; + Op_k idx_op; // kind of enclosing index (. -> [] {}) + int tmpnum; // for creating tmp variables + char *toplev; // name of toplevel proc + jmp_buf jmp; // for syntax error longjmp bail out + int expr_level; // compile_expr() recursion depth + int call_level; // compile_expr() level of last fn call + Tcl_Obj *fn_calls; // list of all fn calls compiled + Tcl_Obj *fn_decls; // hash of all L fns +} Linterp; + +/* + * Symbol table entry, for variables and functions (typedef and struct + * names have their own tables). The tclname can be different from + * the L name if we have to mangle the name as we do for L globals. + * The decl pointer is used to get line# info for error messages. + */ +typedef enum { + L_SYM_LVAR = 0x0001, // a local variable + L_SYM_GVAR = 0x0002, // a global variable + L_SYM_LSHADOW = 0x0004, // a global upvar shadow (these + // are also locals) + L_SYM_FN = 0x0008, // a function + L_SYM_FNBODY = 0x0010, // function body has been declared +} Sym_k; +struct Sym { + Sym_k kind; + char *name; // the L name + char *tclname; // the tcl name (can be same as L name) + Type *type; + int idx; // slot# for local var + int used_p; // TRUE iff var has been referenced + VarDecl *decl; +}; + +/* + * For our getopt. Note that this renders libc's getopt unusable, + * but the #define's are kept for compatibility with our getopt. + */ + +#define getopt mygetopt +#define optind myoptind +#define optarg myoptarg +#define optopt myoptopt + +extern int optind; +extern int optopt; +extern char *optarg; + +typedef struct { + char *name; /* name w args ex: "url:" */ + int ret; /* return value from getopt */ +} longopt; + +#define GETOPT_EOF -1 +#define GETOPT_ERR 256 + +extern char *cksprintf(const char *fmt, ...); +extern char *ckstrdup(const char *str); +extern char *ckstrndup(const char *str, int len); +extern char *ckvsprintf(const char *fmt, va_list ap, int len); +extern int getopt(int ac, char **av, char *opts, longopt *lopts); +extern void getoptReset(void); +extern void L_bomb(const char *format, ...); +extern void L_compile_attributes(Tcl_Obj *hash, Expr *expr, + char *allowed[]); +extern char *L_dirname(char *path); +extern void L_err(const char *s, ...); +extern void L_errf(void *node, const char *format, ...); +extern int L_isUndef(Tcl_Obj *o); +extern void L_lex_begLhtml(); +extern void L_lex_endLhtml(); +extern void L_lex_begReArg(int kind); +extern void L_lex_start(void); +extern int L_parse(void); // yyparse +extern void L_scope_enter(); +extern void L_scope_leave(); +extern void L_set_baseType(Type *type, Type *base_type); +extern void L_set_declBaseType(VarDecl *decl, Type *base_type); +extern Tcl_Obj *L_split(Tcl_Interp *interp, Tcl_Obj *strobj, + Tcl_Obj *delimobj, Tcl_Obj *limobj, Expr_f flags); +extern Type *L_struct_lookup(char *tag, int local); +extern Type *L_struct_store(char *tag, VarDecl *members); +extern void L_synerr(const char *s); // yyerror +extern void L_synerr2(const char *s, int offset); +extern void L_trace(const char *format, ...); +extern char *L_type_str(Type_k kind); +extern void L_typeck_init(); +extern int L_typeck_arrElt(Type *var, Type *array); +extern void L_typeck_assign(Expr *lhs, Type *rhs); +extern int L_typeck_compat(Type *lhs, Type *rhs); +extern int L_typeck_declType(VarDecl *decl); +extern void L_typeck_deny(Type_k deny, Expr *expr); +extern void L_typeck_expect(Type_k want, Expr *expr, char *msg); +extern void L_typeck_fncall(VarDecl *formals, Expr *call); +extern void L_typeck_main(VarDecl *decl); +extern int L_typeck_same(Type *a, Type *b); +extern Type *L_typedef_lookup(char *name); +extern void L_typedef_store(VarDecl *decl); +extern Tcl_Obj **L_undefObjPtrPtr(); +extern void L_warnf(void *node, const char *format, ...); + +extern Linterp *L; +extern char *L_attrs_attribute[]; +extern char *L_attrs_cmdLine[]; +extern char *L_attrs_pragma[]; +extern Tcl_ObjType L_undefType; +extern Type *L_int; +extern Type *L_float; +extern Type *L_string; +extern Type *L_void; +extern Type *L_poly; +extern Type *L_widget; + +static inline int +istype(Expr *expr, int type_flags) +{ + return (expr->type && (expr->type->kind & type_flags)); +} +static inline int +isarray(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_ARRAY)); +} +static inline int +ishash(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_HASH)); +} +static inline int +isstruct(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_STRUCT)); +} +static inline int +isint(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_INT)); +} +static inline int +isfloat(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_FLOAT)); +} +static inline int +isstring(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_STRING)); +} +static inline int +iswidget(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_WIDGET)); +} +static inline int +isvoid(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_VOID)); +} +static inline int +ispoly(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_POLY)); +} +static inline int +isscalar(Expr *expr) +{ + return (expr->type && (expr->type->kind & (L_INT | + L_FLOAT | + L_STRING | + L_WIDGET | + L_POLY))); +} +static inline int +isconst(Expr *expr) +{ + return (expr->kind == L_EXPR_CONST); +} +static inline int +islist(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_LIST)); +} +static inline int +isclass(Expr *expr) +{ + return (expr->type && (expr->type->kind == L_CLASS)); +} +static inline int +isregexp(Expr *expr) +{ + return ((expr->kind == L_EXPR_RE) || + ((expr->kind == L_EXPR_BINOP) && (expr->op == L_OP_INTERP_RE))); +} +static inline int +ispolytype(Type *type) +{ + return (type->kind == L_POLY); +} +static inline int +islisttype(Type *type) +{ + return (type->kind == L_LIST); +} +static inline int +ishashtype(Type *type) +{ + return (type->kind == L_HASH); +} +static inline int +isfntype(Type *type) +{ + return (type->kind == L_FUNCTION); +} +static inline int +isinttype(Type *type) +{ + return (type->kind == L_INT); +} +static inline int +isvoidtype(Type *type) +{ + return (type->kind == L_VOID); +} +static inline int +isnameoftype(Type *type) +{ + return (type->kind == L_NAMEOF); +} +static inline int +isclasstype(Type *type) +{ + return (type->kind == L_CLASS); +} +static inline int +isarrayoftype(Type *type, Type_k kind) +{ + return ((type->kind == L_ARRAY) && (type->base_type->kind & kind)); +} +static inline int +ishashoftype(Type *type, Type_k base, Type_k elt) +{ + return ((type->kind == L_HASH) && + (type->base_type->kind & base) && + (type->u.hash.idx_type->kind & elt)); +} +static inline int +isaddrof(Expr *expr) +{ + return ((expr->kind == L_EXPR_UNOP) && (expr->op == L_OP_ADDROF)); +} +static inline int +isexpand(Expr *expr) +{ + return ((expr->kind == L_EXPR_UNOP) && (expr->op == L_OP_EXPAND)); +} +static inline int +iskv(Expr *expr) +{ + return ((expr->kind == L_EXPR_BINOP) && (expr->op == L_OP_KV)); +} +static inline int +isinterp(Expr *expr) +{ + return ((expr->kind == L_EXPR_BINOP) && (expr->op == L_OP_INTERP_STRING)); +} +static inline int +isid(Expr *expr, char *s) +{ + return ((expr->kind == L_EXPR_ID) && !strcmp(expr->str, s)); +} +static inline int +isarrayof(Expr *expr, Type_k kind) +{ + return (isarray(expr) && (expr->type->base_type->kind & kind)); +} +/* + * Return the flags that match the kind of variable we can + * dereference: globals, locals, class variables, and class instance + * variables. + */ +static inline int +canDeref(Sym *sym) +{ + return (sym->decl->flags & (DECL_GLOBAL_VAR | DECL_LOCAL_VAR | + DECL_FN | DECL_CLASS_INST_VAR | + DECL_CLASS_VAR)); +} +/* + * This checks whether the Expr node is a deep-dive operation that has + * left a deep-ptr on the run-time stack. + */ +static inline int +isdeepdive(Expr *expr) +{ + return (expr->flags & (L_PUSH_PTR | L_PUSH_PTRVAL | L_PUSH_VALPTR)); +} +static inline int +isClsConstructor(VarDecl *decl) +{ + return (decl->flags & DECL_CLASS_CONST); +} +static inline int +isClsDestructor(VarDecl *decl) +{ + return (decl->flags & DECL_CLASS_DESTR); +} +static inline int +isClsFnPublic(VarDecl *decl) +{ + return ((decl->flags & (DECL_CLASS_FN | DECL_PUBLIC)) == + (DECL_CLASS_FN | DECL_PUBLIC)); +} +static inline int +isClsFnPrivate(VarDecl *decl) +{ + return ((decl->flags & (DECL_CLASS_FN | DECL_PRIVATE)) == + (DECL_CLASS_FN | DECL_PRIVATE)); +} +static inline int +typeis(Type *type, char *name) +{ + return (type->name && !strcmp(type->name, name)); +} +static inline int +typeisf(Expr *expr, char *name) +{ + return (expr->type->name && !strcmp(expr->type->name, name)); +} +static inline void +emit_load_scalar(int idx) +{ + /* + * The next line is a hack so we can generate disassemblable + * code even in the presence of obscure compilation errors + * that cause the value of a function name to be attempted to + * be loaded. Without this, tcl will die trying to output a + * disassembly since the local # (-1) would be invalid. + */ + if (idx == -1) idx = 0; + + if (idx <= 255) { + TclEmitInstInt1(INST_LOAD_SCALAR1, idx, L->frame->envPtr); + } else { + TclEmitInstInt4(INST_LOAD_SCALAR4, idx, L->frame->envPtr); + } +} +static inline void +emit_store_scalar(int idx) +{ + if (idx <= 255) { + TclEmitInstInt1(INST_STORE_SCALAR1, idx, L->frame->envPtr); + } else { + TclEmitInstInt4(INST_STORE_SCALAR4, idx, L->frame->envPtr); + } +} +static inline void +push_litf(const char *str, ...) +{ + va_list ap; + int len = 64; + char *buf; + + va_start(ap, str); + while (!(buf = ckvsprintf(str, ap, len))) { + va_end(ap); + va_start(ap, str); + len *= 2; + } + va_end(ap); + /* + * Subtle: register the literal in the body CompileEnv since + * all the code ends up there anyway. If we put it in the + * prologue CompileEnv, we'd have to fix-up all the literal + * numbers when we splice the prologue into the body. + */ + TclEmitPush(TclRegisterNewLiteral(L->frame->bodyEnvPtr, buf, strlen(buf)), + L->frame->envPtr); + ckfree(buf); +} +static inline void +push_lit(const char *str) +{ + /* See comment above about registering in the body CompileEnv. */ + TclEmitPush(TclRegisterNewLiteral(L->frame->bodyEnvPtr, str, + strlen(str)), L->frame->envPtr); +} +static inline void +emit_invoke(int size) +{ + if (size < 256) { + TclEmitInstInt1(INST_INVOKE_STK1, size, L->frame->envPtr); + } else { + TclEmitInstInt4(INST_INVOKE_STK4, size, L->frame->envPtr); + } +} +static inline void +emit_invoke_expanded() +{ + TclEmitOpcode(INST_INVOKE_EXPANDED, L->frame->envPtr); +} +static inline void +emit_pop() +{ + TclEmitOpcode(INST_POP, L->frame->envPtr); +} +static inline int +currOffset(CompileEnv *envPtr) +{ + /* Offset of the next instruction to be generated. */ + return (envPtr->codeNext - envPtr->codeStart); +} + +/* + * REVERSE() assumes that l is a singly linked list of type type with + * forward pointers named ptr. The last element in the list becomes + * the first and is stored back into l. + */ +#define REVERSE(type,ptr,l) \ + do { \ + type *a, *b, *c; \ + for (a = NULL, b = l, c = (l ? ((type *)l)->ptr : NULL); \ + b != NULL; \ + b->ptr = a, a = b, b = c, c = (c ? c->ptr : NULL)) ; \ + *(type **)&(l) = a; \ + } while (0) + +/* + * APPEND() starts at a, walks ptr until the end, and then attaches b + * to a. (Note that it's actually NCONC). + */ +#define APPEND(type,ptr,a,b) \ + do { \ + type *runner; \ + for (runner = a; runner->ptr; runner = runner->ptr) ; \ + runner->ptr = b; \ + } while (0) + +/* + * Like APPEND() but if a is NULL, set a to b. + */ +#define APPEND_OR_SET(type,ptr,a,b) \ + do { \ + if (a) { \ + type *runner; \ + for (runner = a; runner->ptr; runner = runner->ptr) ; \ + runner->ptr = b; \ + } else { \ + a = b; \ + } \ + } while (0) + +/* + * YYLOC_DEFAULT() is invoked by the scanner after matching a pattern + * and before executing its code. It tracks the source-file offset + * and line #. + */ +extern YYLTYPE L_lloc; +#define YYLLOC_DEFAULT(c,r,n) \ + do { \ + if (n) { \ + (c).beg = YYRHSLOC(r,1).beg; \ + (c).end = YYRHSLOC(r,n).end; \ + } else { \ + (c).beg = YYRHSLOC(r,0).beg; \ + (c).end = YYRHSLOC(r,0).end; \ + } \ + (c).line = L->line; \ + (c).file = L->file; \ + } while (0) + +#ifdef TCL_COMPILE_DEBUG +#define ASSERT(c) unless (c) \ + L_bomb("Assertion failed: %s:%d: %s\n", __FILE__, __LINE__, #c) +#else +#define ASSERT(c) do {} while(0) +#endif + +#endif /* L_COMPILE_H */ diff --git a/generic/Lgetopt.c b/generic/Lgetopt.c new file mode 100644 index 0000000..27676ec --- /dev/null +++ b/generic/Lgetopt.c @@ -0,0 +1,238 @@ +#include "Lcompile.h" + +/* for compat with code below */ +#define streq(a, b) (!strcmp(a, b)) +#define strneq(a, b, n) (!strncmp(a, b, n)) +#define assert(x) + +/* + * Copyright (c) 1997 L.W.McVoy + * + * This version handles + * + * - (leaves it and returns) + * -- end of options + * -a + * -abcd + * -r <arg> + * -r<arg> + * -abcr <arg> + * -abcr<arg> + * -r<arg> -R<arg>, etc. + * --long + * --long:<arg> + * --long=<arg> + * --long <arg> + * + * Patterns in getopt string: + * d boolean option -d + * d: required arg -dARG or -d ARG + * d; required arg no space -dARG + * d| optionial arg no space -dARG or -d + * + * With long options: + * long boolean option --long + * long: required arg --long=ARG or --long ARG + * long; required arg no space --long=ARG + * long| optionial arg no space --long=ARG or --long + */ + +int optopt; /* option that is in error, if we return an error */ +int optind; /* next arg in argv we process */ +char *optarg; /* argument to an option */ +static int n; /* current position == av[optind][n] */ +static int lastn; /* saved copy of last n */ + +private int doLong(int ac, char **av, longopt *lopts); + +void +getoptReset(void) +{ + optopt = optind = 0; + optarg = 0; +} + +void +getoptConsumed(int n1) +{ + optind--; + unless (optind) optind = 1; + n = lastn + n1; + // TRACE("optind = %d, n = %d, n1 = %d", optind, n, n1); +} + +/* + * Returns: + * - char if option found + * - GETOPT_EOF(-1) if end of arguments reached + * - GETOPT_ERR(256) if unknown option found. + */ +int +getopt(int ac, char **av, char *opts, longopt *lopts) +{ + char *t; + + optarg = 0; /* clear out arg from last round */ + optopt = 0; /* clear error return */ + if (!optind) { + optind = 1; + lastn = n; + n = 1; + } + // TRACE("GETOPT ind=%d n=%d av[%d]='%s'", optind, n, optind, av[optind]); + + if ((optind >= ac) || (av[optind][0] != '-') || !av[optind][1]) { + return (GETOPT_EOF); + } + /* Stop processing options at a -- and return arguments after */ + if (streq(av[optind], "--")) { + optind++; + lastn = n; + n = 1; + return (GETOPT_EOF); + } + if (strneq(av[optind], "--", 2)) return (doLong(ac, av, lopts)); + + assert(av[optind][n]); + for (t = (char *)opts; *t; t++) { + if (*t == av[optind][n]) { + break; + } + } + if (!*t) { + optopt = av[optind][n]; + // TRACE("%s", "ran out of option letters"); + lastn = n; + if (av[optind][n+1]) { + n++; + } else { + n = 1; + optind++; + } + return (GETOPT_ERR); + } + + /* OK, we found a legit option, let's see what to do with it. + * If it isn't one that takes an option, just advance and return. + */ + if (t[1] != ':' && t[1] != '|' && t[1] != ';') { + lastn = n; + if (!av[optind][n+1]) { + optind++; + n = 1; + } else { + n++; + } + // TRACE("Legit singleton %c", *t); + return (*t); + } + + /* got one with an option, see if it is cozied up to the flag */ + if (av[optind][n+1]) { + optarg = &av[optind][n+1]; + optind++; + lastn = n; + n = 1; + // TRACE("%c with %s", *t, optarg); + return (*t); + } + + /* If it was not there, and it is optional, OK */ + if (t[1] == '|') { + optind++; + lastn = n; + n = 1; + // TRACE("%c without arg", *t); + return (*t); + } + + /* was it supposed to be there? */ + if (t[1] == ';') { + optind++; + optopt = *t; + // TRACE("%s", "wanted another word"); + return (GETOPT_ERR); + } + + /* Nope, there had better be another word. */ + if ((optind + 1 == ac) || (av[optind+1][0] == '-')) { + optopt = av[optind][n]; + // TRACE("%s", "wanted another word"); + return (GETOPT_ERR); + } + optarg = av[optind+1]; + optind += 2; + lastn = n; + n = 1; + // TRACE("%c with arg %s", *t, optarg); + return (*t); +} + +private int +doLong(int ac, char **av, longopt *lopts) +{ + char *s, *t; + int len1, len2; + + unless (lopts) { +err: n = 1; + optind++; + optopt = 0; + return (GETOPT_ERR); + } + /* len of option without =value part */ + s = av[optind] + 2; + unless (t = strchr(s, '=')) t = strchr(s, ':'); + len1 = t ? (t - s) : strlen(s); + for (; (t = lopts->name); lopts++) { + s = av[optind] + 2; + /* len of lopts array without suffix */ + len2 = strlen(t); + if (strspn(t+len2-1, ":;|") == 1) --len2; + + if ((len1 == len2) && strneq(s, t, len1)) { + s += len1; + t += len2; + break; /* found a match */ + } + } + unless (t) goto err; + + /* OK, we found a legit option, let's see what to do with it. + * If it isn't one that takes an option, just advance and return. + */ + unless (*t) { + /* got option anyway */ + if ((*s == '=') || (*s == ':')) goto err; + optind++; + n = 1; + return (lopts->ret); + } + + /* got one with an option, see if it is cozied up to the flag */ + if ((*s == '=') || (*s == ':')) { + optarg = s + 1; + optind++; + n = 1; + return (lopts->ret); + } + + /* If it was not there, and it is optional, OK */ + if (*t == '|') { + optind++; + n = 1; + return (lopts->ret); + } + + /* was it supposed to be there? */ + if (*t == ';') goto err; + + /* Nope, there had better be another word. */ + if ((optind + 1 == ac) || (av[optind+1][0] == '-')) { + goto err; + } + optarg = av[optind+1]; + optind += 2; + n = 1; + return (lopts->ret); +} diff --git a/generic/Lgrammar-pregen.c b/generic/Lgrammar-pregen.c new file mode 100644 index 0000000..3245646 --- /dev/null +++ b/generic/Lgrammar-pregen.c @@ -0,0 +1,6447 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton implementation for Bison GLR parsers in C + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C GLR parser skeleton written by Paul Hilfinger. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.3" + +/* Skeleton name. */ +#define YYSKELETON_NAME "glr.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + + +/* Substitute the variable and function names. */ +#define yyparse L_parse +#define yylex L_lex +#define yyerror L_error +#define yylval L_lval +#define yychar L_char +#define yydebug L_debug +#define yynerrs L_nerrs +#define yylloc L_lloc + + + +#include "Lgrammar.h" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + +/* Default (constant) value used for initialization for null + right-hand sides. Unlike the standard yacc.c template, + here we set the default value of $$ to a zeroed-out value. + Since the default value is undefined, this behavior is + technically correct. */ +static YYSTYPE yyval_default; + +/* Copy the second part of user declarations. */ + + +/* Line 234 of glr.c. */ +#line 97 "Lgrammar.c" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(e) ((void) (e)) +#else +# define YYUSE(e) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(n) (n) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int i) +#else +static int +YYID (i) + int i; +#endif +{ + return i; +} +#endif + +#ifndef YYFREE +# define YYFREE free +#endif +#ifndef YYMALLOC +# define YYMALLOC malloc +#endif +#ifndef YYREALLOC +# define YYREALLOC realloc +#endif + +#define YYSIZEMAX ((size_t) -1) + +#ifdef __cplusplus + typedef bool yybool; +#else + typedef unsigned char yybool; +#endif +#define yytrue 1 +#define yyfalse 0 + +#ifndef YYSETJMP +# include <setjmp.h> +# define YYJMP_BUF jmp_buf +# define YYSETJMP(env) setjmp (env) +# define YYLONGJMP(env, val) longjmp (env, val) +#endif + +/*-----------------. +| GCC extensions. | +`-----------------*/ + +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if (! defined __GNUC__ || __GNUC__ < 2 \ + || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) +# define __attribute__(Spec) /* empty */ +# endif +#endif + +#define YYOPTIONAL_LOC(Name) Name + +#ifndef YYASSERT +# define YYASSERT(condition) ((void) ((condition) || (abort (), 0))) +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 3 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 4962 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 123 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 70 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 262 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 518 +/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ +#define YYMAXRHS 9 +/* YYMAXLEFT -- Maximum number of symbols to the left of a handle + accessed by $0, $-1, etc., in any rule. */ +#define YYMAXLEFT 1 + +/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 377 + +#define YYTRANSLATE(YYX) \ + ((YYX <= 0) ? YYEOF : \ + (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 119, 120, 121, 122 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned short int yyprhs[] = +{ + 0, 0, 3, 5, 8, 11, 15, 21, 24, 27, + 28, 29, 35, 36, 42, 46, 50, 53, 60, 66, + 69, 73, 79, 82, 86, 90, 93, 94, 96, 97, + 100, 104, 107, 110, 116, 122, 126, 129, 131, 133, + 135, 139, 141, 145, 149, 153, 159, 165, 168, 173, + 174, 176, 178, 180, 182, 184, 186, 189, 192, 195, + 198, 202, 206, 214, 219, 221, 228, 234, 241, 247, + 255, 258, 259, 265, 269, 271, 273, 276, 279, 280, + 286, 294, 301, 309, 319, 327, 329, 332, 334, 335, + 337, 340, 342, 343, 345, 349, 353, 357, 360, 363, + 366, 367, 369, 371, 374, 378, 382, 387, 390, 393, + 397, 402, 407, 410, 413, 416, 419, 422, 425, 428, + 431, 434, 438, 442, 448, 452, 456, 460, 464, 468, + 472, 476, 480, 484, 488, 492, 496, 503, 507, 511, + 515, 519, 523, 527, 531, 535, 539, 543, 547, 551, + 553, 555, 557, 559, 561, 566, 570, 575, 583, 589, + 594, 598, 602, 606, 610, 614, 618, 622, 626, 630, + 634, 638, 642, 646, 651, 656, 661, 665, 669, 673, + 677, 681, 685, 692, 697, 700, 706, 710, 713, 714, + 715, 717, 719, 723, 727, 732, 737, 743, 744, 746, + 749, 752, 756, 758, 760, 762, 765, 767, 771, 773, + 777, 779, 783, 785, 786, 789, 792, 796, 802, 803, + 808, 812, 817, 820, 823, 825, 827, 829, 831, 833, + 835, 837, 843, 848, 851, 853, 856, 859, 862, 864, + 868, 871, 873, 877, 879, 882, 885, 888, 892, 894, + 897, 899, 902, 905, 907, 910, 914, 919, 923, 928, + 930, 932, 935 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const short int yyrhs[] = +{ + 124, 0, -1, 125, -1, 125, 126, -1, 125, 132, + -1, 125, 177, 93, -1, 125, 105, 175, 173, 93, + -1, 125, 166, -1, 125, 135, -1, -1, -1, 13, + 161, 59, 127, 129, -1, -1, 13, 104, 59, 128, + 129, -1, 13, 161, 93, -1, 13, 104, 93, -1, + 130, 83, -1, 130, 54, 59, 165, 83, 131, -1, + 130, 54, 59, 83, 131, -1, 130, 166, -1, 130, + 177, 93, -1, 130, 105, 175, 173, 93, -1, 130, + 132, -1, 130, 16, 133, -1, 130, 19, 133, -1, + 130, 137, -1, -1, 93, -1, -1, 175, 133, -1, + 167, 175, 133, -1, 161, 134, -1, 74, 134, -1, + 66, 152, 90, 138, 163, -1, 66, 152, 90, 138, + 93, -1, 52, 14, 135, -1, 52, 14, -1, 139, + -1, 137, -1, 51, -1, 57, 158, 58, -1, 161, + -1, 161, 38, 161, -1, 161, 38, 56, -1, 136, + 15, 161, -1, 136, 15, 161, 38, 161, -1, 136, + 15, 161, 38, 56, -1, 113, 136, -1, 5, 66, + 156, 90, -1, -1, 140, -1, 163, -1, 141, -1, + 147, -1, 142, -1, 148, -1, 158, 93, -1, 12, + 93, -1, 17, 93, -1, 87, 93, -1, 87, 158, + 93, -1, 46, 52, 93, -1, 92, 163, 52, 66, + 158, 90, 163, -1, 92, 163, 52, 163, -1, 93, + -1, 53, 66, 158, 90, 163, 146, -1, 53, 66, + 158, 90, 140, -1, 106, 66, 158, 90, 163, 146, + -1, 106, 66, 158, 90, 140, -1, 114, 66, 158, + 90, 59, 143, 83, -1, 143, 144, -1, -1, 115, + 160, 145, 14, 150, -1, 116, 14, 150, -1, 187, + -1, 158, -1, 24, 163, -1, 24, 141, -1, -1, + 112, 66, 158, 90, 135, -1, 20, 135, 112, 66, + 158, 90, 93, -1, 44, 66, 149, 149, 90, 135, + -1, 44, 66, 149, 149, 158, 90, 135, -1, 45, + 66, 161, 4, 161, 161, 158, 90, 135, -1, 45, + 66, 162, 161, 158, 90, 135, -1, 93, -1, 158, + 93, -1, 151, -1, -1, 135, -1, 151, 135, -1, + 153, -1, -1, 154, -1, 153, 15, 154, -1, 155, + 175, 172, -1, 155, 23, 161, -1, 155, 107, -1, + 155, 108, -1, 155, 109, -1, -1, 158, -1, 157, + -1, 157, 158, -1, 156, 15, 158, -1, 156, 15, + 157, -1, 156, 15, 157, 158, -1, 52, 14, -1, + 116, 14, -1, 66, 158, 90, -1, 66, 175, 90, + 158, -1, 66, 40, 90, 158, -1, 6, 158, -1, + 10, 158, -1, 8, 158, -1, 69, 158, -1, 76, + 158, -1, 77, 158, -1, 70, 158, -1, 158, 77, + -1, 158, 70, -1, 158, 37, 187, -1, 158, 7, + 187, -1, 158, 37, 186, 188, 86, -1, 158, 96, + 158, -1, 158, 94, 158, -1, 158, 75, 158, -1, + 158, 76, 158, -1, 158, 69, 158, -1, 158, 25, + 158, -1, 158, 71, 158, -1, 158, 68, 158, -1, + 158, 61, 158, -1, 158, 50, 158, -1, 158, 47, + 158, -1, 158, 39, 158, -1, 25, 66, 158, 15, + 158, 90, -1, 158, 72, 158, -1, 158, 48, 158, + -1, 158, 49, 158, -1, 158, 64, 158, -1, 158, + 65, 158, -1, 158, 3, 158, -1, 158, 73, 158, + -1, 158, 67, 158, -1, 158, 91, 158, -1, 158, + 9, 158, -1, 158, 8, 158, -1, 158, 11, 158, + -1, 161, -1, 183, -1, 185, -1, 56, -1, 43, + -1, 161, 66, 156, 90, -1, 161, 66, 90, -1, + 101, 66, 156, 90, -1, 95, 66, 159, 187, 15, + 156, 90, -1, 95, 66, 159, 156, 90, -1, 191, + 66, 156, 90, -1, 191, 66, 90, -1, 158, 38, + 158, -1, 158, 33, 158, -1, 158, 31, 158, -1, + 158, 35, 158, -1, 158, 36, 158, -1, 158, 32, + 158, -1, 158, 26, 158, -1, 158, 27, 158, -1, + 158, 28, 158, -1, 158, 30, 158, -1, 158, 34, + 158, -1, 158, 29, 158, -1, 18, 66, 158, 90, + -1, 158, 60, 158, 84, -1, 158, 59, 158, 83, + -1, 158, 100, 158, -1, 158, 21, 52, -1, 158, + 78, 52, -1, 104, 21, 52, -1, 104, 78, 52, + -1, 158, 15, 158, -1, 158, 60, 158, 22, 158, + 84, -1, 59, 164, 181, 83, -1, 59, 83, -1, + 158, 82, 158, 14, 158, -1, 64, 158, 48, -1, + 64, 48, -1, -1, -1, 52, -1, 161, -1, 161, + 15, 162, -1, 59, 164, 83, -1, 59, 164, 151, + 83, -1, 59, 164, 165, 83, -1, 59, 164, 165, + 151, 83, -1, -1, 166, -1, 165, 166, -1, 168, + 93, -1, 167, 168, 93, -1, 80, -1, 81, -1, + 41, -1, 175, 169, -1, 171, -1, 169, 15, 171, + -1, 173, -1, 170, 15, 173, -1, 173, -1, 173, + 38, 158, -1, 173, -1, -1, 161, 174, -1, 104, + 174, -1, 8, 161, 174, -1, 8, 161, 66, 152, + 90, -1, -1, 60, 158, 84, 174, -1, 60, 84, + 174, -1, 59, 176, 83, 174, -1, 176, 174, -1, + 177, 174, -1, 101, -1, 55, -1, 42, -1, 79, + -1, 111, -1, 110, -1, 104, -1, 102, 52, 59, + 178, 83, -1, 102, 59, 178, 83, -1, 102, 52, + -1, 179, -1, 178, 179, -1, 180, 93, -1, 175, + 170, -1, 182, -1, 181, 15, 182, -1, 181, 15, + -1, 158, -1, 158, 4, 158, -1, 99, -1, 189, + 99, -1, 184, 99, -1, 97, 98, -1, 184, 97, + 98, -1, 98, -1, 189, 98, -1, 85, -1, 190, + 85, -1, 186, 86, -1, 103, -1, 190, 103, -1, + 62, 158, 88, -1, 189, 62, 158, 88, -1, 63, + 158, 89, -1, 190, 63, 158, 89, -1, 21, -1, + 192, -1, 21, 52, -1, 192, 21, 52, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short int yyrline[] = +{ + 0, 250, 250, 258, 268, 279, 283, 289, 304, 310, + 315, 314, 336, 335, 355, 367, 378, 394, 411, 412, + 429, 430, 435, 449, 458, 467, 478, 482, 483, 487, + 493, 503, 509, 527, 534, 544, 550, 555, 556, 561, + 570, 582, 583, 587, 592, 598, 604, 614, 623, 630, + 634, 635, 639, 644, 649, 654, 659, 664, 668, 672, + 676, 681, 686, 698, 703, 707, 712, 716, 720, 727, + 744, 753, 757, 762, 771, 777, 782, 787, 792, 796, + 800, 804, 808, 815, 823, 834, 835, 839, 840, 844, + 849, 863, 880, 884, 885, 894, 906, 915, 916, 917, + 918, 922, 923, 924, 930, 936, 942, 959, 965, 973, + 979, 984, 988, 992, 996, 1000, 1004, 1008, 1012, 1016, + 1020, 1024, 1028, 1032, 1039, 1043, 1047, 1051, 1055, 1059, + 1063, 1067, 1071, 1075, 1079, 1083, 1087, 1091, 1095, 1099, + 1103, 1107, 1111, 1115, 1119, 1123, 1127, 1131, 1135, 1139, + 1140, 1141, 1142, 1146, 1150, 1155, 1159, 1165, 1179, 1186, + 1191, 1195, 1199, 1203, 1207, 1211, 1215, 1219, 1223, 1227, + 1231, 1235, 1239, 1243, 1247, 1251, 1255, 1259, 1264, 1269, + 1275, 1281, 1285, 1293, 1300, 1304, 1308, 1312, 1319, 1323, + 1327, 1335, 1336, 1345, 1351, 1358, 1369, 1384, 1388, 1389, + 1401, 1402, 1414, 1415, 1416, 1420, 1432, 1433, 1441, 1442, + 1450, 1451, 1460, 1461, 1465, 1469, 1476, 1482, 1494, 1497, + 1501, 1505, 1512, 1521, 1533, 1534, 1535, 1536, 1537, 1538, + 1539, 1543, 1549, 1555, 1563, 1564, 1573, 1577, 1589, 1590, + 1595, 1599, 1603, 1611, 1615, 1620, 1628, 1635, 1646, 1651, + 1659, 1663, 1671, 1684, 1688, 1696, 1701, 1709, 1714, 1722, + 1726, 1734, 1742 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "\"end of file\"", "error", "$undefined", "\"&&\"", "\"=>\"", + "\"_attribute\"", "\"!\"", "\"!~\"", "\"&\"", "\"|\"", "\"~\"", "\"^\"", + "\"break\"", "\"class\"", "\":\"", "\",\"", "\"constructor\"", + "\"continue\"", "\"defined\"", "\"destructor\"", "\"do\"", "\".\"", + "\"..\"", "\"...\"", "\"else\"", "\"eq\"", "\"&=\"", "\"|=\"", "\"^=\"", + "\".=\"", "\"<<=\"", "\"-=\"", "\"%=\"", "\"+=\"", "\">>=\"", "\"*=\"", + "\"/=\"", "\"=~\"", "\"=\"", "\"==\"", "\"(expand)\"", "\"extern\"", + "\"float\"", "\"float constant\"", "\"for\"", "\"foreach\"", "\"goto\"", + "\"ge\"", "\">\"", "\">=\"", "\"gt\"", "T_HTML", "\"id\"", "\"if\"", + "\"instance\"", "\"int\"", "\"integer constant\"", "\"<?=\"", "\"?>\"", + "\"{\"", "\"[\"", "\"le\"", "\"${\"", "\"${ (in re)\"", "\"<\"", + "\"<=\"", "\"(\"", "\"<<\"", "\"lt\"", "\"-\"", "\"--\"", "\"ne\"", + "\"!=\"", "\"||\"", "\"pattern function\"", "\"%\"", "\"+\"", "\"++\"", + "\"->\"", "\"poly\"", "\"private\"", "\"public\"", "\"?\"", "\"}\"", + "\"]\"", "\"regular expression\"", "\"regexp modifier\"", "\"return\"", + "\"} (end of interpolation)\"", "\"} (end of interpolation in re)\"", + "\")\"", "\">>\"", "\"try\"", "\";\"", "\"/\"", "\"split\"", "\"*\"", + "\"backtick\"", "\"`\"", "\"string constant\"", "\" . \"", "\"string\"", + "\"struct\"", "\"=~ s/a/b/\"", "\"type name\"", "\"typedef\"", + "\"unless\"", "\"_argused\"", "\"_optional\"", "\"_mustbetype\"", + "\"void\"", "\"widget\"", "\"while\"", "\"#pragma\"", "\"switch\"", + "\"case\"", "\"default\"", "LOWEST", "ADDRESS", "UMINUS", "UPLUS", + "PREFIX_INCDEC", "HIGHEST", "$accept", "start", "toplevel_code", + "class_decl", "@1", "@2", "class_decl_tail", "class_code", "opt_semi", + "function_decl", "fundecl_tail", "fundecl_tail1", "stmt", + "pragma_expr_list", "pragma", "opt_attribute", "unlabeled_stmt", + "single_stmt", "selection_stmt", "switch_stmt", "switch_cases", + "switch_case", "case_expr", "optional_else", "iteration_stmt", + "foreach_stmt", "expression_stmt", "opt_stmt_list", "stmt_list", + "parameter_list", "parameter_decl_list", "parameter_decl", + "parameter_attrs", "argument_expr_list", "option_arg", "expr", + "re_start_split", "re_start_case", "id", "id_list", "compound_stmt", + "enter_scope", "declaration_list", "declaration", "decl_qualifier", + "declaration2", "init_declarator_list", "declarator_list", + "init_declarator", "opt_declarator", "declarator", "array_or_hash_type", + "type_specifier", "scalar_type_specifier", "struct_specifier", + "struct_decl_list", "struct_decl", "struct_declarator_list", "list", + "list_element", "string_literal", "here_doc_backtick", + "cmdsubst_literal", "regexp_literal", "regexp_literal_mod", + "subst_literal", "interpolated_expr", "interpolated_expr_re", + "dotted_id", "dotted_id_1", 0 +}; +#endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 123, 124, 125, 125, 125, 125, 125, 125, 125, + 127, 126, 128, 126, 126, 126, 129, 130, 130, 130, + 130, 130, 130, 130, 130, 130, 130, 131, 131, 132, + 132, 133, 133, 134, 134, 135, 135, 135, 135, 135, + 135, 136, 136, 136, 136, 136, 136, 137, 138, 138, + 139, 139, 140, 140, 140, 140, 140, 140, 140, 140, + 140, 140, 140, 140, 140, 141, 141, 141, 141, 142, + 143, 143, 144, 144, 145, 145, 146, 146, 146, 147, + 147, 147, 147, 148, 148, 149, 149, 150, 150, 151, + 151, 152, 152, 153, 153, 154, 154, 155, 155, 155, + 155, 156, 156, 156, 156, 156, 156, 157, 157, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 159, 160, + 161, 162, 162, 163, 163, 163, 163, 164, 165, 165, + 166, 166, 167, 167, 167, 168, 169, 169, 170, 170, + 171, 171, 172, 172, 173, 173, 173, 173, 174, 174, + 174, 174, 175, 175, 176, 176, 176, 176, 176, 176, + 176, 177, 177, 177, 178, 178, 179, 180, 181, 181, + 181, 182, 182, 183, 183, 183, 184, 184, 185, 185, + 186, 186, 187, 188, 188, 189, 189, 190, 190, 191, + 191, 192, 192 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 1, 2, 2, 3, 5, 2, 2, 0, + 0, 5, 0, 5, 3, 3, 2, 6, 5, 2, + 3, 5, 2, 3, 3, 2, 0, 1, 0, 2, + 3, 2, 2, 5, 5, 3, 2, 1, 1, 1, + 3, 1, 3, 3, 3, 5, 5, 2, 4, 0, + 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 7, 4, 1, 6, 5, 6, 5, 7, + 2, 0, 5, 3, 1, 1, 2, 2, 0, 5, + 7, 6, 7, 9, 7, 1, 2, 1, 0, 1, + 2, 1, 0, 1, 3, 3, 3, 2, 2, 2, + 0, 1, 1, 2, 3, 3, 4, 2, 2, 3, + 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 3, 3, 5, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, + 1, 1, 1, 1, 4, 3, 4, 7, 5, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, + 3, 3, 6, 4, 2, 5, 3, 2, 0, 0, + 1, 1, 3, 3, 4, 4, 5, 0, 1, 2, + 2, 3, 1, 1, 1, 2, 1, 3, 1, 3, + 1, 3, 1, 0, 2, 2, 3, 5, 0, 4, + 3, 4, 2, 2, 1, 1, 1, 1, 1, 1, + 1, 5, 4, 2, 1, 2, 2, 2, 1, 3, + 2, 1, 3, 1, 2, 2, 2, 3, 1, 2, + 1, 2, 2, 1, 2, 3, 4, 3, 4, 1, + 1, 2, 3 +}; + +/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ +static const unsigned char yydprec[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 +}; + +/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ +static const unsigned char yymerger[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 +}; + +/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE + doesn't specify something else to do. Zero means the default is an + error. */ +static const unsigned short int yydefact[] = +{ + 9, 0, 2, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 259, 0, 204, 226, 153, 0, 0, 0, + 39, 190, 0, 225, 152, 0, 197, 0, 0, 0, + 0, 0, 0, 0, 227, 202, 203, 0, 0, 64, + 0, 0, 248, 243, 224, 0, 230, 0, 0, 229, + 228, 0, 0, 0, 3, 4, 8, 38, 37, 50, + 52, 54, 53, 55, 0, 149, 51, 7, 0, 0, + 0, 218, 218, 150, 0, 151, 0, 0, 260, 190, + 197, 0, 0, 112, 114, 113, 57, 0, 0, 58, + 0, 0, 261, 0, 0, 0, 0, 36, 0, 0, + 184, 0, 0, 187, 0, 0, 0, 0, 218, 115, + 118, 116, 117, 59, 0, 197, 0, 188, 246, 0, + 233, 0, 0, 0, 224, 230, 0, 0, 0, 47, + 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 120, 0, 0, 0, + 0, 0, 119, 0, 0, 0, 56, 0, 0, 0, + 0, 0, 0, 200, 0, 0, 218, 29, 218, 205, + 206, 210, 0, 0, 222, 5, 223, 0, 245, 0, + 249, 244, 0, 0, 0, 12, 15, 10, 14, 0, + 0, 0, 85, 0, 0, 191, 0, 61, 35, 0, + 40, 193, 89, 0, 241, 0, 198, 0, 0, 0, + 238, 255, 186, 0, 109, 0, 60, 0, 0, 0, + 190, 0, 0, 102, 101, 0, 0, 0, 234, 0, + 179, 180, 218, 0, 0, 0, 0, 0, 0, 142, + 0, 250, 0, 122, 0, 147, 146, 148, 181, 177, + 129, 167, 168, 169, 172, 170, 163, 166, 162, 171, + 164, 165, 0, 121, 161, 135, 134, 138, 139, 133, + 0, 0, 132, 140, 141, 144, 131, 128, 130, 137, + 143, 126, 127, 178, 0, 145, 125, 124, 176, 155, + 0, 201, 30, 218, 100, 32, 215, 31, 214, 0, + 0, 0, 218, 0, 247, 0, 160, 0, 262, 241, + 26, 26, 173, 0, 0, 0, 86, 0, 0, 0, + 0, 194, 90, 0, 195, 0, 199, 240, 183, 111, + 110, 0, 63, 0, 0, 107, 108, 0, 156, 103, + 0, 237, 208, 232, 235, 236, 6, 0, 0, 44, + 43, 42, 0, 0, 252, 0, 251, 253, 0, 0, + 175, 0, 174, 0, 154, 100, 216, 0, 91, 93, + 0, 207, 211, 218, 220, 218, 256, 159, 13, 0, + 11, 0, 181, 0, 0, 0, 191, 192, 0, 66, + 78, 242, 196, 239, 0, 158, 0, 105, 104, 231, + 0, 68, 78, 79, 0, 71, 257, 0, 123, 254, + 0, 185, 0, 49, 100, 0, 97, 98, 99, 213, + 221, 219, 0, 0, 0, 16, 0, 22, 25, 19, + 218, 0, 136, 81, 0, 0, 0, 0, 65, 0, + 0, 106, 209, 67, 46, 45, 0, 258, 182, 217, + 0, 0, 94, 96, 95, 212, 23, 0, 24, 0, + 0, 20, 80, 82, 0, 84, 77, 76, 62, 157, + 69, 189, 0, 70, 0, 34, 33, 28, 0, 0, + 0, 0, 88, 0, 27, 18, 28, 21, 83, 0, + 75, 74, 73, 87, 48, 17, 88, 72 +}; + +/* YYPDEFGOTO[NTERM-NUM]. */ +static const short int yydefgoto[] = +{ + -1, 1, 2, 54, 331, 330, 398, 399, 505, 55, + 187, 317, 222, 129, 57, 471, 58, 59, 60, 61, + 466, 493, 509, 458, 62, 63, 213, 512, 223, 387, + 388, 389, 390, 242, 243, 64, 239, 501, 65, 216, + 66, 101, 225, 226, 227, 69, 189, 361, 190, 474, + 191, 196, 228, 71, 108, 247, 248, 249, 229, 230, + 73, 74, 75, 262, 263, 378, 76, 264, 77, 78 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -278 +static const short int yypact[] = +{ + -278, 32, 781, -278, 1976, 1976, 1976, -41, -28, -33, + 45, 1306, 18, 70, -278, -278, -278, 106, 121, 23, + -278, 53, 149, -278, -278, 1976, -278, 1976, 1691, 1569, + 1976, 1976, 1976, 1976, -278, -278, -278, 1748, 21, -278, + 150, 122, -278, -278, 151, 68, 8, 547, 152, -278, + -278, 162, 177, 164, -278, -278, -278, -278, -278, -278, + -278, -278, -278, -278, 2135, 167, -278, -278, 547, 142, + 14, 143, 19, -278, 96, -278, -7, 170, 216, -278, + 157, 151, 8, -6, -6, -6, -278, -12, 64, -278, + 1976, 130, -278, 1976, 1805, 177, 159, 1405, 1976, 2212, + -278, 890, 2289, -278, 3987, 154, 2367, 169, 143, -6, + -6, -6, -6, -278, 2444, -278, 204, -278, -278, 684, + 206, 547, 211, 217, -278, -278, 9, 1976, 1976, 255, + 233, 1976, 1976, 47, 1976, 1976, 1976, 1976, 220, 1976, + 1976, 1976, 1976, 1976, 1976, 1976, 1976, 1976, 1976, 1976, + 1976, 47, 1976, 1976, 1976, 1976, 1976, 1976, 1976, 1976, + 1976, 1976, 1976, 1976, 1976, 1976, -278, 1976, 1976, 1976, + 1976, 1976, -278, 225, 1976, 1976, -278, 1976, 1976, 1976, + 534, 185, 14, -278, 177, 213, 143, -278, 132, 265, + -278, 243, 172, 1862, -278, -278, -278, 186, -278, 1976, + -278, -278, 609, 235, 1976, -278, -278, -278, -278, 2521, + 227, 4064, -278, 1805, 2598, 58, 177, -278, -278, 2675, + -278, -278, -278, 1108, 2751, 999, -278, 547, 9, 10, + -278, -278, 191, 1976, -278, 1976, -278, 890, -9, 450, + 280, 286, 11, 1976, 4369, 547, 9, 331, -278, 208, + -278, -278, 143, 209, 2828, 2905, 177, 83, 2982, 4593, + 1976, -278, 218, -278, 119, 4804, 4665, 4737, 4369, -278, + 4862, 4369, 4369, 4369, 4369, 4369, 4369, 4369, 4369, 4369, + 4369, 4369, -21, -278, 4369, 4862, 1705, 1705, 1705, 1705, + 3059, 2057, 1705, 1705, 1705, 696, 1705, 237, 4862, 4862, + 4521, -6, 237, -278, 3137, 696, -6, -6, 237, -278, + 12, -278, -278, 166, 215, -278, -278, -278, -278, 9, + 1976, 223, 143, 3214, -278, 3292, -278, 13, -278, 4140, + -278, -278, -278, 1976, 1976, 1919, -278, 177, 177, 1976, + 1504, -278, -278, 1976, -278, 1207, -278, 1976, -278, -6, + -6, 1976, -278, 26, 288, -278, -278, 684, -278, 4369, + 1079, 293, -278, -278, -278, -278, -278, 1504, 1306, 273, + -278, -278, 254, 3370, -278, 1976, -278, -278, 230, -14, + -278, 1976, -278, 1976, -278, 215, -278, 229, 306, -278, + 268, -278, 4369, 143, -278, 143, -278, -278, -278, 4, + -278, 3447, 4216, 1306, 3524, 177, 307, -278, 3601, -278, + 300, 4369, -278, -278, 3678, -278, 684, 1976, 4369, -278, + 9, -278, 300, -278, 144, -278, -278, 3755, -278, -278, + 3832, 4445, 238, 320, -278, 177, -278, -278, -278, 9, + -278, -278, 137, 137, 270, -278, 547, -278, -278, -278, + 38, 234, -278, -278, 1306, 1976, 1306, 15, -278, 21, + 29, 4369, -278, -278, -278, -278, 107, -278, -278, -278, + 264, 120, -278, -278, -278, -278, -278, 213, -278, 4667, + 9, -278, -278, -278, 3910, -278, -278, -278, -278, -278, + -278, -278, 324, -278, 684, -278, -278, 241, 4738, 249, + 1306, 1626, 1306, 36, -278, -278, 241, -278, -278, 330, + 4293, -278, -278, 1306, -278, -278, 1306, -278 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const short int yypgoto[] = +{ + -278, -278, -278, -278, -278, -278, 17, -278, -160, -48, + -168, 165, -2, -278, -45, -278, -278, -277, -102, -278, + -278, -278, -278, -63, -278, -278, 147, -154, -217, -20, + -278, -67, -278, -162, 27, 6, -278, -278, 136, 30, + -31, -59, -108, -1, 0, -49, -278, -278, 55, -278, + -122, -58, 1, 188, 3, 138, -231, -278, -278, 41, + -278, -278, -278, 239, -145, -278, -278, 103, -278, -278 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -93 +static const short int yytable[] = +{ + 56, 67, 68, 70, 253, 72, 283, 116, 345, 91, + 83, 84, 85, 194, 312, 138, 364, 184, 310, 181, + 442, 204, 184, 443, 79, 347, 357, 357, 357, 122, + 107, 99, 3, 102, 104, 106, 109, 110, 111, 112, + 327, 357, 260, 114, 357, 14, 15, 205, 126, 375, + 115, 357, 86, 158, 159, 199, 237, 351, 444, 23, + 89, 79, 337, 409, 166, 374, 79, 97, 22, 182, + 92, 172, 173, 338, 115, 96, 87, 353, 192, 193, + 115, 206, 377, 34, 35, 36, 123, 445, 185, 429, + 421, 200, 201, 348, 354, 218, 209, 192, 193, 211, + 214, 358, 384, 397, 219, 124, 45, 224, 125, 446, + 260, 90, 195, 186, 49, 50, 415, 52, 186, 489, + 120, 48, 246, 207, 362, 244, 514, 121, 316, 364, + 318, 481, 261, 254, 255, 79, 93, 258, 259, 370, + 265, 266, 267, 268, 88, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 208, 284, 285, + 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, + 296, 297, 94, 298, 299, 300, 301, 302, 181, 115, + 304, 305, 375, 306, 307, 308, 244, 95, 130, 79, + 490, 192, 193, 197, 318, 198, 79, 4, 314, 323, + 464, 6, 192, 193, 376, 325, 188, 352, 244, 10, + 329, 185, 12, 495, 15, 98, 117, 119, 127, 214, + 118, 342, 491, 492, 346, 192, 193, 23, 128, 79, + 131, 215, 385, 180, 16, 183, 202, 203, 287, 349, + 100, 350, 210, 79, 233, 244, 246, 24, 246, 359, + 80, 34, 217, 27, 460, 386, 238, 29, 138, 235, + 30, 31, 252, 250, 394, 245, 373, 32, 33, 251, + 256, 257, 269, 124, 476, 478, 125, 303, 311, 314, + 319, 320, 49, 50, 324, 513, 40, 328, 41, 42, + 43, 435, 81, 333, 355, 82, 158, 159, 462, 513, + 356, 365, 366, 416, 374, -92, 393, 166, 420, 410, + 15, 424, 170, 425, 172, 173, 428, 475, 188, 433, + 313, 434, 338, 23, 457, 470, 392, 482, 469, 479, + 494, 177, 503, 178, 504, 440, 422, 441, 502, 401, + 402, 404, 507, 342, 516, 408, 515, 34, 400, 411, + 315, 447, 339, 329, 448, 486, 511, 414, 499, 463, + 335, 246, 517, 418, 252, 432, 423, 472, 407, 124, + 45, 498, 125, 15, 391, 436, 437, 438, 49, 50, + 321, 427, 252, 360, 417, 379, 23, 430, 413, 431, + 282, 439, 369, 371, 0, 0, 0, 0, 449, 68, + 70, 453, 450, 0, 0, 0, 0, 0, 0, 0, + 34, 0, 0, 0, 363, 0, 0, 0, 0, 0, + 0, 0, 244, 461, 0, 0, 487, 0, 488, 0, + 0, 0, 124, 45, 0, 125, 0, 0, 0, 0, + 496, 49, 50, 0, 0, 0, 0, 480, 0, 0, + 0, 0, 483, 0, 485, 252, 4, 0, 5, 0, + 6, 484, 0, 0, 0, 0, 0, 0, 10, 0, + 0, 12, 0, 405, 406, 13, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 16, 0, 0, 0, 346, 508, 0, + 244, 0, 240, 0, 0, 0, 24, 510, 0, 80, + 0, 342, 27, 260, 28, 0, 29, 0, 0, 30, + 31, 0, 0, 0, 0, 0, 32, 33, 0, 0, + 0, 0, 0, 0, 0, 261, 0, 0, 0, 0, + 4, 455, 5, 0, 6, 40, 0, 41, 42, 43, + 0, 81, 10, 0, 82, 12, 252, 0, 0, 13, + 465, 0, 0, 0, 0, 0, 241, 0, 0, 0, + 0, 473, 0, 0, 0, 252, 0, 16, 477, 477, + 0, 0, 0, 0, 0, 0, 240, 0, 0, 15, + 24, 0, 0, 80, 0, 0, 27, 0, 28, 0, + 29, 0, 23, 30, 31, 0, 0, 0, 0, 0, + 32, 33, 0, 0, 0, 4, 252, 5, 0, 6, + 0, 0, 0, 0, 309, 0, 34, 10, 0, 40, + 12, 41, 42, 43, 13, 81, 0, 0, 82, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 124, 45, + 241, 125, 16, 0, 0, 0, 0, 49, 50, 0, + 0, 240, 0, 0, 0, 24, 0, 0, 80, 0, + 0, 27, 0, 28, 0, 29, 0, 0, 30, 31, + 0, 0, 0, 0, 0, 32, 33, 0, 0, 0, + 4, 0, 5, 0, 6, 0, 0, 0, 0, 326, + 0, 0, 10, 0, 40, 12, 41, 42, 43, 13, + 81, 0, 0, 82, 0, 0, 0, 138, 0, 0, + 0, 0, 0, 0, 0, 241, 0, 16, 0, 0, + 0, 0, 0, 0, 0, 0, 240, 0, 0, 0, + 24, 0, 0, 80, 0, 0, 27, 0, 28, 0, + 29, 0, 0, 30, 31, 158, 159, 0, 0, 0, + 32, 33, 0, 0, 0, 165, 166, 0, 0, 0, + 0, 170, 171, 172, 173, 0, 0, 0, 0, 40, + 0, 41, 42, 43, 0, 81, 0, 4, 82, 5, + 177, 6, 178, 7, 8, 0, 179, 0, 9, 10, + 241, 11, 12, 0, 0, 0, 13, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 14, 15, 16, 17, 18, 19, 0, 0, + 0, 0, 20, 21, 22, 0, 23, 24, 25, 0, + 26, 0, 0, 27, 0, 28, 0, 29, 0, 0, + 30, 31, 0, 0, 0, 0, 0, 32, 33, 0, + 34, 35, 36, 0, 0, 0, 0, 0, 37, 0, + 0, 0, 0, 38, 39, 0, 40, 0, 41, 42, + 43, 0, 44, 45, 0, 46, 47, 48, 0, 0, + 0, 49, 50, 51, 52, 53, 4, 0, 5, 0, + 6, 0, 7, 0, 0, 0, 0, 9, 10, 0, + 11, 12, 0, 0, 0, 13, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 14, 15, 16, 17, 18, 19, 0, 0, 0, + 0, 20, 21, 22, 0, 23, 24, 25, 0, 26, + 0, 0, 27, 0, 28, 0, 29, 0, 0, 30, + 31, 0, 0, 0, 0, 0, 32, 33, 0, 34, + 35, 36, 0, 221, 0, 0, 0, 37, 0, 0, + 0, 0, 38, 39, 0, 40, 0, 41, 42, 43, + 0, 44, 45, 0, 46, 0, 48, 0, 0, 0, + 49, 50, 51, 52, 53, 4, 0, 5, 0, 6, + 0, 7, 0, 0, 0, 0, 9, 10, 0, 11, + 12, 0, 0, 0, 13, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 14, 15, 16, 17, 18, 19, 0, 0, 0, 0, + 20, 21, 22, 0, 23, 24, 25, 0, 26, 0, + 0, 27, 0, 28, 0, 29, 0, 0, 30, 31, + 0, 0, 0, 0, 0, 32, 33, 0, 34, 35, + 36, 0, 344, 0, 0, 0, 37, 0, 0, 0, + 0, 38, 39, 0, 40, 0, 41, 42, 43, 0, + 44, 45, 0, 46, 0, 48, 0, 0, 0, 49, + 50, 51, 52, 53, 4, 0, 5, 0, 6, 0, + 7, 15, 0, 0, 0, 9, 10, 0, 11, 12, + 0, 0, 0, 13, 23, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 16, 17, 18, 19, 0, 0, 0, 34, 20, + 21, 22, 419, 0, 24, 25, 0, 26, 0, 0, + 27, 0, 28, 0, 29, 0, 0, 30, 31, 0, + 124, 45, 0, 125, 32, 33, 0, 0, 0, 49, + 50, 341, 0, 0, 0, 37, 0, 0, 0, 0, + 38, 39, 0, 40, 0, 41, 42, 43, 0, 81, + 0, 0, 82, 4, 48, 5, 0, 6, 0, 7, + 51, 52, 53, 0, 9, 10, 0, 11, 12, 0, + 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 16, 17, 18, 19, 0, 0, 0, 0, 20, 21, + 22, 0, 0, 24, 25, 0, 26, 0, 0, 27, + 0, 28, 0, 29, 0, 0, 30, 31, 0, 0, + 0, 0, 0, 32, 33, 0, 0, 0, 0, 0, + 412, 0, 0, 0, 37, 0, 0, 0, 0, 38, + 39, 0, 40, 0, 41, 42, 43, 0, 81, 0, + 0, 82, 4, 48, 5, 0, 6, 0, 7, 51, + 52, 53, 0, 9, 10, 0, 11, 12, 0, 0, + 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, + 17, 18, 19, 0, 0, 0, 0, 20, 21, 22, + 0, 0, 24, 25, 0, 26, 0, 0, 27, 0, + 28, 0, 29, 0, 0, 30, 31, 0, 0, 0, + 0, 0, 32, 33, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 37, 0, 0, 0, 0, 38, 39, + 0, 40, 0, 41, 42, 43, 0, 81, 0, 0, + 82, 4, 48, 5, 0, 6, 0, 7, 51, 52, + 53, 0, 9, 10, 0, 11, 12, 0, 0, 0, + 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 16, 17, + 18, 19, 0, 0, 0, 0, 20, 21, 22, 0, + 0, 24, 25, 0, 26, 0, 0, 27, 0, 28, + 0, 29, 0, 0, 30, 31, 0, 0, 0, 0, + 0, 32, 33, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 37, 0, 0, 0, 0, 38, 39, 0, + 40, 0, 41, 42, 43, 0, 81, 0, 0, 82, + 4, 48, 5, 0, 6, 0, 7, 51, 52, 53, + 0, 9, 10, 0, 11, 12, 0, 0, 0, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 16, 17, 18, + 19, 0, 0, 0, 0, 0, 79, 22, 0, 0, + 24, 0, 0, 26, 0, 0, 27, 0, 28, 0, + 29, 0, 0, 30, 31, 4, 0, 5, 0, 6, + 32, 33, 0, 0, 0, 0, 0, 10, 0, 0, + 12, 37, 0, 0, 13, 0, 38, 39, 0, 40, + 0, 41, 42, 43, 0, 81, 0, 0, 82, 105, + 48, 15, 16, 0, 0, 0, 51, 0, 53, 0, + 0, 79, 0, 0, 23, 24, 0, 0, 80, 0, + 0, 27, 4, 28, 5, 29, 6, 0, 30, 31, + 0, 0, 0, 0, 10, 32, 33, 12, 34, 0, + 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 41, 42, 43, 16, + 44, 45, 0, 46, 0, 0, 0, 0, 79, 49, + 50, 0, 24, 0, 0, 80, 0, 0, 27, 260, + 28, 0, 29, 0, 0, 30, 31, 4, 0, 5, + 0, 6, 32, 33, 0, 0, 0, 0, 0, 10, + 0, 261, 12, 0, 0, 0, 13, 0, 0, 0, + 0, 40, 0, 41, 42, 43, 138, 81, 0, 0, + 82, 0, 0, 0, 16, 0, 0, 0, 0, 103, + 0, 0, 0, 79, 0, 0, 0, 24, 0, 0, + 80, 0, 0, 27, 4, 28, 5, 29, 6, 0, + 30, 31, 0, 0, 158, 159, 10, 32, 33, 12, + 0, 0, 163, 13, 165, 166, 0, 0, 0, 0, + 170, 171, 172, 173, 0, 0, 40, 0, 41, 42, + 43, 16, 81, 0, 0, 82, 175, 0, 0, 177, + 79, 178, 0, 0, 24, 179, 0, 80, 0, 0, + 27, 4, 28, 5, 29, 6, 0, 30, 31, 0, + 0, 0, 0, 10, 32, 33, 12, 0, 0, 0, + 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 113, 0, 40, 0, 41, 42, 43, 16, 81, + 0, 0, 82, 0, 0, 0, 0, 79, 0, 0, + 0, 24, 0, 0, 80, 0, 0, 27, 4, 28, + 5, 29, 6, 0, 30, 31, 0, 0, 0, 0, + 10, 32, 33, 12, 0, 0, 0, 13, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 212, 0, + 40, 0, 41, 42, 43, 16, 81, 0, 0, 82, + 0, 0, 0, 0, 79, 0, 0, 0, 24, 0, + 0, 80, 0, 0, 27, 4, 28, 5, 29, 6, + 0, 30, 31, 0, 0, 0, 0, 10, 32, 33, + 12, 0, 0, 0, 13, 0, 322, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 40, 0, 41, + 42, 43, 16, 81, 0, 0, 82, 0, 0, 0, + 0, 79, 0, 0, 0, 24, 0, 0, 80, 0, + 0, 27, 4, 28, 5, 29, 6, 0, 30, 31, + 0, 0, 0, 0, 10, 32, 33, 12, 0, 0, + 0, 13, 0, 0, 0, 0, 0, 0, 0, 403, + 0, 0, 0, 0, 40, 0, 41, 42, 43, 16, + 81, 0, 0, 82, 0, 0, 0, 0, 79, 0, + 0, 0, 24, 0, 0, 80, 0, 0, 27, 0, + 28, 0, 29, 0, 0, 30, 31, 0, 0, 0, + 0, 0, 32, 33, 0, 0, 0, 0, 0, 0, + 132, 0, 0, 0, 133, 134, 135, 0, 136, 0, + 0, 40, 137, 41, 42, 43, 0, 81, 138, 381, + 82, 0, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 0, 0, 0, + 0, 0, 0, 0, 154, 155, 156, 157, 0, 0, + 0, 0, 0, 0, 0, 0, 158, 159, 160, 0, + 0, 161, 162, 0, 163, 164, 165, 166, 167, 168, + 169, 0, 170, 171, 172, 173, 0, 0, 132, 174, + 0, 382, 133, 134, 135, 0, 136, 0, 175, 0, + 137, 177, 0, 178, 0, 0, 138, 179, 0, 0, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 150, 151, 152, 153, 0, 0, 0, 0, 0, + 0, 0, 154, 155, 156, 157, 0, 0, 0, 0, + 0, 0, 0, 0, 158, 159, 160, 0, 0, 161, + 162, 0, 163, 164, 165, 166, 167, 168, 169, 0, + 170, 171, 172, 173, 0, 132, 0, 174, 0, 133, + 134, 135, 0, 136, 0, 0, 175, 137, 176, 177, + 0, 178, 0, 138, 0, 179, 0, 139, 140, 141, + 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 0, 0, 0, 0, 0, 0, 0, 154, + 155, 156, 157, 0, 0, 0, 0, 0, 0, 0, + 220, 158, 159, 160, 0, 0, 161, 162, 0, 163, + 164, 165, 166, 167, 168, 169, 0, 170, 171, 172, + 173, 0, 132, 0, 174, 0, 133, 134, 135, 0, + 136, 0, 0, 175, 137, 0, 177, 0, 178, 0, + 138, 0, 179, 0, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 0, + 0, 0, 0, 0, 0, 0, 154, 155, 156, 157, + 0, 0, 0, 0, 0, 0, 0, 0, 158, 159, + 160, 0, 0, 161, 162, 0, 163, 164, 165, 166, + 167, 168, 169, 0, 170, 171, 172, 173, 0, 0, + 132, 174, 0, 0, 133, 134, 135, 231, 136, 0, + 175, 0, 137, 177, 0, 178, 0, 0, 138, 179, + 0, 0, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 0, 0, 0, + 0, 0, 0, 0, 154, 155, 156, 157, 0, 0, + 0, 0, 0, 0, 0, 0, 158, 159, 160, 0, + 0, 161, 162, 0, 163, 164, 165, 166, 167, 168, + 169, 0, 170, 171, 172, 173, 0, 132, 0, 174, + 0, 133, 134, 135, 0, 136, 0, 234, 175, 137, + 0, 177, 0, 178, 0, 138, 0, 179, 0, 139, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 0, 0, 0, 0, 0, 0, + 0, 154, 155, 156, 157, 0, 0, 0, 0, 0, + 0, 0, 0, 158, 159, 160, 0, 0, 161, 162, + 0, 163, 164, 165, 166, 167, 168, 169, 0, 170, + 171, 172, 173, 0, 132, 0, 174, 0, 133, 134, + 135, 0, 136, 0, 0, 175, 137, 236, 177, 0, + 178, 0, 138, 0, 179, 0, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, + 153, 0, 0, 0, 0, 0, 0, 0, 154, 155, + 156, 157, 0, 0, 0, 0, 0, 0, 0, 0, + 158, 159, 160, 0, 0, 161, 162, 0, 163, 164, + 165, 166, 167, 168, 169, 0, 170, 171, 172, 173, + 0, 132, 0, 174, 0, 133, 134, 135, 0, 136, + 0, 332, 175, 137, 0, 177, 0, 178, 0, 138, + 0, 179, 0, 139, 140, 141, 142, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 0, 0, + 0, 0, 0, 0, 0, 154, 155, 156, 157, 0, + 0, 0, 0, 0, 0, 0, 0, 158, 159, 160, + 0, 0, 161, 162, 0, 163, 164, 165, 166, 167, + 168, 169, 0, 170, 171, 172, 173, 0, 132, 0, + 174, 0, 133, 134, 135, 0, 136, 0, 0, 175, + 137, 336, 177, 0, 178, 0, 138, 0, 179, 0, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 150, 151, 152, 153, 0, 0, 0, 0, 0, + 0, 0, 154, 155, 156, 157, 0, 0, 0, 0, + 0, 0, 0, 0, 158, 159, 160, 0, 0, 161, + 162, 0, 163, 164, 165, 166, 167, 168, 169, 0, + 170, 171, 172, 173, 132, 343, 0, 174, 133, 134, + 135, 0, 136, 0, 0, 340, 175, 0, 0, 177, + 0, 178, 138, 0, 0, 179, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, + 153, 0, 0, 0, 0, 0, 0, 0, 154, 155, + 156, 157, 0, 0, 0, 0, 0, 0, 0, 0, + 158, 159, 160, 0, 0, 161, 162, 0, 163, 164, + 165, 166, 167, 168, 169, 0, 170, 171, 172, 173, + 0, 132, 0, 174, 0, 133, 134, 135, 0, 136, + 0, 0, 175, 137, 176, 177, 0, 178, 0, 138, + 0, 179, 0, 139, 140, 141, 142, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 0, 0, + 0, 0, 0, 0, 0, 154, 155, 156, 157, 0, + 0, 0, 0, 0, 0, 0, 0, 158, 159, 160, + 0, 0, 161, 162, 0, 163, 164, 165, 166, 167, + 168, 169, 0, 170, 171, 172, 173, 0, 132, 0, + 174, 0, 133, 134, 135, 0, 136, 0, 367, 175, + 137, 0, 177, 0, 178, 0, 138, 0, 179, 0, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 150, 151, 152, 153, 0, 0, 0, 0, 0, + 0, 0, 154, 155, 156, 157, 0, 0, 0, 0, + 0, 0, 0, 0, 158, 159, 160, 0, 0, 161, + 162, 0, 163, 164, 165, 166, 167, 168, 169, 0, + 170, 171, 172, 173, 0, 132, 0, 174, 0, 133, + 134, 135, 0, 136, 0, 368, 175, 137, 0, 177, + 0, 178, 0, 138, 0, 179, 0, 139, 140, 141, + 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 0, 0, 0, 0, 0, 0, 0, 154, + 155, 156, 157, 0, 0, 0, 0, 0, 0, 0, + 0, 158, 159, 160, 0, 0, 161, 162, 0, 163, + 164, 165, 166, 167, 168, 169, 0, 170, 171, 172, + 173, 0, 132, 0, 174, 0, 133, 134, 135, 0, + 136, 0, 372, 175, 137, 0, 177, 0, 178, 0, + 138, 0, 179, 0, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 0, + 0, 0, 0, 0, 0, 0, 154, 155, 156, 157, + 0, 0, 0, 0, 0, 0, 0, 0, 158, 159, + 160, 0, 0, 161, 162, 0, 163, 164, 165, 166, + 167, 168, 169, 0, 170, 171, 172, 173, 0, 0, + 132, 174, 380, 0, 133, 134, 135, 0, 136, 0, + 175, 383, 137, 177, 0, 178, 0, 0, 138, 179, + 0, 0, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 0, 0, 0, + 0, 0, 0, 0, 154, 155, 156, 157, 0, 0, + 0, 0, 0, 0, 0, 0, 158, 159, 160, 0, + 0, 161, 162, 0, 163, 164, 165, 166, 167, 168, + 169, 0, 170, 171, 172, 173, 0, 132, 0, 174, + 0, 133, 134, 135, 0, 136, 0, 0, 175, 137, + 0, 177, 0, 178, 0, 138, 0, 179, 0, 139, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 0, 0, 0, 0, 0, 0, + 0, 154, 155, 156, 157, 0, 0, 0, 0, 0, + 0, 0, 0, 158, 159, 160, 0, 0, 161, 162, + 0, 163, 164, 165, 166, 167, 168, 169, 0, 170, + 171, 172, 173, 0, 0, 132, 174, 0, 395, 133, + 134, 135, 0, 136, 0, 175, 0, 137, 177, 0, + 178, 0, 0, 138, 179, 0, 0, 139, 140, 141, + 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 0, 0, 0, 0, 0, 0, 0, 154, + 155, 156, 157, 0, 0, 0, 0, 0, 0, 0, + 0, 158, 159, 160, 0, 0, 161, 162, 0, 163, + 164, 165, 166, 167, 168, 169, 0, 170, 171, 172, + 173, 0, 0, 132, 174, 0, 0, 133, 134, 135, + 396, 136, 0, 175, 0, 137, 177, 0, 178, 0, + 0, 138, 179, 0, 0, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, + 0, 0, 0, 0, 0, 0, 0, 154, 155, 156, + 157, 0, 0, 0, 0, 0, 0, 0, 0, 158, + 159, 160, 0, 0, 161, 162, 0, 163, 164, 165, + 166, 167, 168, 169, 0, 170, 171, 172, 173, 0, + 132, 0, 174, 0, 133, 134, 135, 0, 136, 426, + 0, 175, 137, 0, 177, 0, 178, 0, 138, 0, + 179, 0, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 0, 0, 0, + 0, 0, 0, 0, 154, 155, 156, 157, 0, 0, + 0, 0, 0, 0, 0, 0, 158, 159, 160, 0, + 0, 161, 162, 0, 163, 164, 165, 166, 167, 168, + 169, 0, 170, 171, 172, 173, 0, 132, 0, 174, + 0, 133, 134, 135, 0, 136, 0, 451, 175, 137, + 0, 177, 0, 178, 0, 138, 0, 179, 0, 139, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 0, 0, 0, 0, 0, 0, + 0, 154, 155, 156, 157, 0, 0, 0, 0, 0, + 0, 0, 0, 158, 159, 160, 0, 0, 161, 162, + 0, 163, 164, 165, 166, 167, 168, 169, 0, 170, + 171, 172, 173, 0, 132, 0, 174, 0, 133, 134, + 135, 0, 136, 0, 454, 175, 137, 0, 177, 0, + 178, 0, 138, 0, 179, 0, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, + 153, 0, 0, 0, 0, 0, 0, 0, 154, 155, + 156, 157, 0, 0, 0, 0, 0, 0, 0, 0, + 158, 159, 160, 0, 0, 161, 162, 0, 163, 164, + 165, 166, 167, 168, 169, 0, 170, 171, 172, 173, + 0, 132, 0, 174, 0, 133, 134, 135, 0, 136, + 0, 456, 175, 137, 0, 177, 0, 178, 0, 138, + 0, 179, 0, 139, 140, 141, 142, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 0, 0, + 0, 0, 0, 0, 0, 154, 155, 156, 157, 0, + 0, 0, 0, 0, 0, 0, 0, 158, 159, 160, + 0, 0, 161, 162, 0, 163, 164, 165, 166, 167, + 168, 169, 0, 170, 171, 172, 173, 0, 132, 0, + 174, 0, 133, 134, 135, 0, 136, 0, 459, 175, + 137, 0, 177, 0, 178, 0, 138, 0, 179, 0, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 150, 151, 152, 153, 0, 0, 0, 0, 0, + 0, 0, 154, 155, 156, 157, 0, 0, 0, 0, + 0, 0, 0, 0, 158, 159, 160, 0, 0, 161, + 162, 0, 163, 164, 165, 166, 167, 168, 169, 0, + 170, 171, 172, 173, 0, 132, 0, 174, 0, 133, + 134, 135, 0, 136, 467, 0, 175, 137, 0, 177, + 0, 178, 0, 138, 0, 179, 0, 139, 140, 141, + 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 0, 0, 0, 0, 0, 0, 0, 154, + 155, 156, 157, 0, 0, 0, 0, 0, 0, 0, + 0, 158, 159, 160, 0, 0, 161, 162, 0, 163, + 164, 165, 166, 167, 168, 169, 0, 170, 171, 172, + 173, 0, 0, 132, 174, 0, 468, 133, 134, 135, + 0, 136, 0, 175, 0, 137, 177, 0, 178, 0, + 0, 138, 179, 0, 0, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, + 0, 0, 0, 0, 0, 0, 0, 154, 155, 156, + 157, 0, 0, 0, 0, 0, 0, 0, 0, 158, + 159, 160, 0, 0, 161, 162, 0, 163, 164, 165, + 166, 167, 168, 169, 0, 170, 171, 172, 173, 0, + 132, 0, 174, 0, 133, 134, 135, 0, 136, 0, + 500, 175, 137, 0, 177, 0, 178, 0, 138, 0, + 179, 0, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 0, 0, 0, + 0, 0, 0, 0, 154, 232, 156, 157, 0, 0, + 0, 0, 0, 0, 0, 0, 158, 159, 160, 0, + 0, 161, 162, 0, 163, 164, 165, 166, 167, 168, + 169, 0, 170, 171, 172, 173, 0, 132, 0, 174, + 0, 133, 134, 135, 0, 136, 0, 0, 175, 334, + 0, 177, 0, 178, 0, 138, 0, 179, 0, 139, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 0, 0, 0, 0, 0, 0, + 0, 154, 155, 156, 157, 0, 0, 0, 0, 0, + 0, 0, 0, 158, 159, 160, 0, 0, 161, 162, + 0, 163, 164, 165, 166, 167, 168, 169, 0, 170, + 171, 172, 173, 132, 343, 0, 174, 133, 134, 135, + 0, 136, 0, 0, 0, 175, 0, 0, 177, 0, + 178, 138, 0, 0, 179, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, + 0, 0, 0, 0, 0, 0, 0, 154, 155, 156, + 157, 0, 0, 0, 0, 0, 0, 0, 0, 158, + 159, 160, 0, 0, 161, 162, 0, 163, 164, 165, + 166, 167, 168, 169, 0, 170, 171, 172, 173, 132, + 0, 0, 174, 133, 134, 135, 0, 136, 0, 0, + 0, 175, 0, 0, 177, 0, 178, 138, 0, 0, + 179, 139, 140, 141, 142, 143, 144, 145, 146, 147, + 148, 149, 150, 151, 152, 153, 0, 0, 0, 0, + 0, 0, 0, 154, 155, 156, 157, 0, 0, 0, + 0, 0, 0, 0, 0, 158, 159, 160, 0, 0, + 161, 162, 0, 163, 164, 165, 166, 167, 168, 169, + 0, 170, 171, 172, 173, 0, 132, 0, 174, 0, + 133, 134, 135, 0, 136, 0, 452, 175, 137, 0, + 177, 0, 178, 0, 138, 0, 179, 0, 139, 140, + 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, + 151, 152, 153, 0, 0, 0, 0, 0, 0, 0, + 154, 155, 156, 157, 0, 0, 0, 0, 0, 0, + 0, 0, 158, 159, 160, 0, 0, 161, 162, 0, + 163, 164, 165, 166, 167, 168, 169, 0, 170, 171, + 172, 173, 132, 0, 0, 174, 133, 134, 135, 0, + 136, 0, 0, 0, 175, 0, 0, 177, 0, 178, + 138, 0, 0, 179, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 0, + 0, 0, 0, 0, 0, 0, 154, 155, 156, 157, + 0, 0, 0, 0, 0, 0, 0, 0, 158, 159, + 160, 0, 0, 161, 162, 0, 163, 164, 165, 166, + 167, 168, 169, 0, 170, 171, 172, 173, 132, 0, + 0, 174, 133, 134, 135, 0, 136, 0, 0, 0, + 175, 0, 0, 177, 0, 178, 138, 0, 0, 179, + 139, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 151, 0, 153, 0, 0, 0, 0, 0, + 0, 0, 154, 155, 156, 157, 0, 0, 0, 0, + 0, 0, 0, 0, 158, 159, 160, 0, 0, 161, + 162, 0, 163, 164, 165, 166, 167, 168, 169, 0, + 170, 171, 172, 173, 132, 0, 0, 174, 133, 134, + 135, 0, 136, 0, 0, 0, 175, 0, 0, 177, + 0, 178, 138, 0, 0, 179, 139, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 151, 0, + 153, 0, 0, 0, 0, 0, 0, 0, 154, 155, + 156, 157, 0, 0, 0, 0, 0, 0, 0, 0, + 158, 159, 160, 0, 0, 161, 162, 0, 163, 164, + 165, 166, 167, 168, 0, 0, 170, 171, 172, 173, + 133, 134, 135, 0, 136, 0, 0, 0, 0, 0, + 0, 0, 175, 0, 138, 177, 0, 178, 139, 0, + 0, 179, 0, 0, 0, 0, 0, 0, 0, 0, + 151, 0, 153, 0, 0, 0, 0, 0, 0, 0, + 154, 155, 156, 157, 0, 0, 0, 0, 0, 0, + 0, 0, 158, 159, 160, 0, 0, 161, 162, 0, + 163, 164, 165, 166, 167, 168, 0, 0, 170, 171, + 172, 173, 133, 134, 0, 0, 136, 0, 0, 0, + 0, 0, 0, 0, 175, 0, 138, 177, 0, 178, + 139, 0, 0, 179, 0, 0, 0, 0, 0, 0, + 0, 0, 151, 0, 153, 0, 0, 0, 14, 15, + 0, 0, 154, 155, 156, 157, 0, 0, 0, 0, + 0, 0, 23, 0, 158, 159, 160, 0, 0, 161, + 162, 0, 163, 164, 165, 166, 167, 168, 0, 0, + 170, 171, 172, 173, 133, 134, 34, 35, 36, 0, + 497, 0, 0, 0, 0, 0, 175, 0, 138, 177, + 0, 178, 139, 0, 0, 179, 0, 0, 124, 45, + 0, 125, 0, 0, 151, 0, 153, 49, 50, 14, + 15, 0, 0, 0, 154, 155, 156, 157, 0, 0, + 0, 0, 0, 23, 0, 0, 158, 159, 160, 0, + 0, 161, 162, 0, 163, 164, 165, 166, 167, 168, + 0, 133, 170, 171, 172, 173, 0, 34, 35, 36, + 0, 506, 0, 0, 0, 138, 0, 0, 175, 139, + 0, 177, 0, 178, 0, 0, 0, 179, 0, 124, + 45, 151, 125, 153, 0, 0, 0, 0, 49, 50, + 0, 154, 155, 156, 157, 0, 0, 0, 0, 0, + 0, 0, 0, 158, 159, 160, 0, 0, 161, 162, + 0, 163, 164, 165, 166, 167, 168, 0, 0, 170, + 171, 172, 173, 138, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 175, 0, 0, 177, 0, + 178, 0, 0, 0, 179, 0, 0, 0, 0, 154, + 155, 156, 157, 0, 0, 0, 0, 0, 0, 0, + 0, 158, 159, 160, 0, 0, 161, 162, 0, 163, + 164, 165, 166, 0, 0, 0, 0, 170, 171, 172, + 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 175, 0, 0, 177, 0, 178, 0, + 0, 0, 179 +}; + +/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of + list of conflicting reductions corresponding to action entry for + state STATE-NUM in yytable. 0 means no conflicts. The list in + yyconfl is terminated by a rule number of 0. */ +static const unsigned char yyconflp[] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 +}; + +/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by + 0, pointed into by YYCONFLP. */ +static const short int yyconfl[] = +{ + 0, 36, 0 +}; + +static const short int yycheck[] = +{ + 2, 2, 2, 2, 126, 2, 151, 38, 225, 11, + 4, 5, 6, 71, 182, 21, 247, 8, 180, 68, + 16, 80, 8, 19, 52, 15, 15, 15, 15, 21, + 29, 25, 0, 27, 28, 29, 30, 31, 32, 33, + 202, 15, 63, 37, 15, 41, 42, 59, 47, 63, + 59, 15, 93, 59, 60, 62, 115, 66, 54, 55, + 93, 52, 4, 340, 70, 86, 52, 14, 53, 68, + 52, 77, 78, 15, 59, 52, 104, 239, 59, 60, + 59, 93, 103, 79, 80, 81, 78, 83, 74, 103, + 367, 98, 99, 83, 239, 97, 90, 59, 60, 93, + 94, 90, 90, 90, 98, 101, 102, 101, 104, 105, + 63, 66, 93, 104, 110, 111, 90, 113, 104, 90, + 52, 106, 121, 59, 246, 119, 90, 59, 186, 360, + 188, 93, 85, 127, 128, 52, 66, 131, 132, 56, + 134, 135, 136, 137, 8, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 93, 152, 153, + 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, + 164, 165, 66, 167, 168, 169, 170, 171, 227, 59, + 174, 175, 63, 177, 178, 179, 180, 66, 52, 52, + 83, 59, 60, 97, 252, 99, 52, 6, 66, 193, + 56, 10, 59, 60, 85, 199, 70, 238, 202, 18, + 204, 74, 21, 93, 42, 66, 66, 66, 66, 213, + 98, 223, 115, 116, 225, 59, 60, 55, 66, 52, + 66, 95, 66, 66, 43, 93, 66, 21, 232, 233, + 83, 235, 112, 52, 90, 239, 245, 56, 247, 243, + 59, 79, 93, 62, 416, 313, 52, 66, 21, 90, + 69, 70, 126, 52, 322, 59, 260, 76, 77, 52, + 15, 38, 52, 101, 442, 443, 104, 52, 93, 66, + 15, 38, 110, 111, 98, 502, 95, 52, 97, 98, + 99, 23, 101, 66, 14, 104, 59, 60, 420, 516, + 14, 93, 93, 15, 86, 90, 83, 70, 15, 340, + 42, 38, 75, 59, 77, 78, 86, 439, 182, 90, + 184, 15, 15, 55, 24, 5, 320, 93, 90, 59, + 66, 94, 494, 96, 93, 393, 367, 395, 14, 333, + 334, 335, 93, 345, 14, 339, 506, 79, 331, 343, + 185, 399, 216, 347, 399, 457, 501, 351, 480, 422, + 213, 360, 516, 357, 228, 385, 368, 434, 338, 101, + 102, 479, 104, 42, 319, 107, 108, 109, 110, 111, + 192, 375, 246, 245, 357, 282, 55, 381, 347, 383, + 151, 390, 256, 257, -1, -1, -1, -1, 399, 399, + 399, 403, 399, -1, -1, -1, -1, -1, -1, -1, + 79, -1, -1, -1, 83, -1, -1, -1, -1, -1, + -1, -1, 416, 417, -1, -1, 457, -1, 459, -1, + -1, -1, 101, 102, -1, 104, -1, -1, -1, -1, + 471, 110, 111, -1, -1, -1, -1, 446, -1, -1, + -1, -1, 454, -1, 456, 319, 6, -1, 8, -1, + 10, 455, -1, -1, -1, -1, -1, -1, 18, -1, + -1, 21, -1, 337, 338, 25, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 43, -1, -1, -1, 498, 500, -1, + 494, -1, 52, -1, -1, -1, 56, 501, -1, 59, + -1, 513, 62, 63, 64, -1, 66, -1, -1, 69, + 70, -1, -1, -1, -1, -1, 76, 77, -1, -1, + -1, -1, -1, -1, -1, 85, -1, -1, -1, -1, + 6, 405, 8, -1, 10, 95, -1, 97, 98, 99, + -1, 101, 18, -1, 104, 21, 420, -1, -1, 25, + 424, -1, -1, -1, -1, -1, 116, -1, -1, -1, + -1, 435, -1, -1, -1, 439, -1, 43, 442, 443, + -1, -1, -1, -1, -1, -1, 52, -1, -1, 42, + 56, -1, -1, 59, -1, -1, 62, -1, 64, -1, + 66, -1, 55, 69, 70, -1, -1, -1, -1, -1, + 76, 77, -1, -1, -1, 6, 480, 8, -1, 10, + -1, -1, -1, -1, 90, -1, 79, 18, -1, 95, + 21, 97, 98, 99, 25, 101, -1, -1, 104, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 101, 102, + 116, 104, 43, -1, -1, -1, -1, 110, 111, -1, + -1, 52, -1, -1, -1, 56, -1, -1, 59, -1, + -1, 62, -1, 64, -1, 66, -1, -1, 69, 70, + -1, -1, -1, -1, -1, 76, 77, -1, -1, -1, + 6, -1, 8, -1, 10, -1, -1, -1, -1, 90, + -1, -1, 18, -1, 95, 21, 97, 98, 99, 25, + 101, -1, -1, 104, -1, -1, -1, 21, -1, -1, + -1, -1, -1, -1, -1, 116, -1, 43, -1, -1, + -1, -1, -1, -1, -1, -1, 52, -1, -1, -1, + 56, -1, -1, 59, -1, -1, 62, -1, 64, -1, + 66, -1, -1, 69, 70, 59, 60, -1, -1, -1, + 76, 77, -1, -1, -1, 69, 70, -1, -1, -1, + -1, 75, 76, 77, 78, -1, -1, -1, -1, 95, + -1, 97, 98, 99, -1, 101, -1, 6, 104, 8, + 94, 10, 96, 12, 13, -1, 100, -1, 17, 18, + 116, 20, 21, -1, -1, -1, 25, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 41, 42, 43, 44, 45, 46, -1, -1, + -1, -1, 51, 52, 53, -1, 55, 56, 57, -1, + 59, -1, -1, 62, -1, 64, -1, 66, -1, -1, + 69, 70, -1, -1, -1, -1, -1, 76, 77, -1, + 79, 80, 81, -1, -1, -1, -1, -1, 87, -1, + -1, -1, -1, 92, 93, -1, 95, -1, 97, 98, + 99, -1, 101, 102, -1, 104, 105, 106, -1, -1, + -1, 110, 111, 112, 113, 114, 6, -1, 8, -1, + 10, -1, 12, -1, -1, -1, -1, 17, 18, -1, + 20, 21, -1, -1, -1, 25, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 41, 42, 43, 44, 45, 46, -1, -1, -1, + -1, 51, 52, 53, -1, 55, 56, 57, -1, 59, + -1, -1, 62, -1, 64, -1, 66, -1, -1, 69, + 70, -1, -1, -1, -1, -1, 76, 77, -1, 79, + 80, 81, -1, 83, -1, -1, -1, 87, -1, -1, + -1, -1, 92, 93, -1, 95, -1, 97, 98, 99, + -1, 101, 102, -1, 104, -1, 106, -1, -1, -1, + 110, 111, 112, 113, 114, 6, -1, 8, -1, 10, + -1, 12, -1, -1, -1, -1, 17, 18, -1, 20, + 21, -1, -1, -1, 25, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 41, 42, 43, 44, 45, 46, -1, -1, -1, -1, + 51, 52, 53, -1, 55, 56, 57, -1, 59, -1, + -1, 62, -1, 64, -1, 66, -1, -1, 69, 70, + -1, -1, -1, -1, -1, 76, 77, -1, 79, 80, + 81, -1, 83, -1, -1, -1, 87, -1, -1, -1, + -1, 92, 93, -1, 95, -1, 97, 98, 99, -1, + 101, 102, -1, 104, -1, 106, -1, -1, -1, 110, + 111, 112, 113, 114, 6, -1, 8, -1, 10, -1, + 12, 42, -1, -1, -1, 17, 18, -1, 20, 21, + -1, -1, -1, 25, 55, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, 45, 46, -1, -1, -1, 79, 51, + 52, 53, 83, -1, 56, 57, -1, 59, -1, -1, + 62, -1, 64, -1, 66, -1, -1, 69, 70, -1, + 101, 102, -1, 104, 76, 77, -1, -1, -1, 110, + 111, 83, -1, -1, -1, 87, -1, -1, -1, -1, + 92, 93, -1, 95, -1, 97, 98, 99, -1, 101, + -1, -1, 104, 6, 106, 8, -1, 10, -1, 12, + 112, 113, 114, -1, 17, 18, -1, 20, 21, -1, + -1, -1, 25, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 43, 44, 45, 46, -1, -1, -1, -1, 51, 52, + 53, -1, -1, 56, 57, -1, 59, -1, -1, 62, + -1, 64, -1, 66, -1, -1, 69, 70, -1, -1, + -1, -1, -1, 76, 77, -1, -1, -1, -1, -1, + 83, -1, -1, -1, 87, -1, -1, -1, -1, 92, + 93, -1, 95, -1, 97, 98, 99, -1, 101, -1, + -1, 104, 6, 106, 8, -1, 10, -1, 12, 112, + 113, 114, -1, 17, 18, -1, 20, 21, -1, -1, + -1, 25, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, 45, 46, -1, -1, -1, -1, 51, 52, 53, + -1, -1, 56, 57, -1, 59, -1, -1, 62, -1, + 64, -1, 66, -1, -1, 69, 70, -1, -1, -1, + -1, -1, 76, 77, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 87, -1, -1, -1, -1, 92, 93, + -1, 95, -1, 97, 98, 99, -1, 101, -1, -1, + 104, 6, 106, 8, -1, 10, -1, 12, 112, 113, + 114, -1, 17, 18, -1, 20, 21, -1, -1, -1, + 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, + 45, 46, -1, -1, -1, -1, 51, 52, 53, -1, + -1, 56, 57, -1, 59, -1, -1, 62, -1, 64, + -1, 66, -1, -1, 69, 70, -1, -1, -1, -1, + -1, 76, 77, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 87, -1, -1, -1, -1, 92, 93, -1, + 95, -1, 97, 98, 99, -1, 101, -1, -1, 104, + 6, 106, 8, -1, 10, -1, 12, 112, 113, 114, + -1, 17, 18, -1, 20, 21, -1, -1, -1, 25, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 43, 44, 45, + 46, -1, -1, -1, -1, -1, 52, 53, -1, -1, + 56, -1, -1, 59, -1, -1, 62, -1, 64, -1, + 66, -1, -1, 69, 70, 6, -1, 8, -1, 10, + 76, 77, -1, -1, -1, -1, -1, 18, -1, -1, + 21, 87, -1, -1, 25, -1, 92, 93, -1, 95, + -1, 97, 98, 99, -1, 101, -1, -1, 104, 40, + 106, 42, 43, -1, -1, -1, 112, -1, 114, -1, + -1, 52, -1, -1, 55, 56, -1, -1, 59, -1, + -1, 62, 6, 64, 8, 66, 10, -1, 69, 70, + -1, -1, -1, -1, 18, 76, 77, 21, 79, -1, + -1, 25, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 95, -1, 97, 98, 99, 43, + 101, 102, -1, 104, -1, -1, -1, -1, 52, 110, + 111, -1, 56, -1, -1, 59, -1, -1, 62, 63, + 64, -1, 66, -1, -1, 69, 70, 6, -1, 8, + -1, 10, 76, 77, -1, -1, -1, -1, -1, 18, + -1, 85, 21, -1, -1, -1, 25, -1, -1, -1, + -1, 95, -1, 97, 98, 99, 21, 101, -1, -1, + 104, -1, -1, -1, 43, -1, -1, -1, -1, 48, + -1, -1, -1, 52, -1, -1, -1, 56, -1, -1, + 59, -1, -1, 62, 6, 64, 8, 66, 10, -1, + 69, 70, -1, -1, 59, 60, 18, 76, 77, 21, + -1, -1, 67, 25, 69, 70, -1, -1, -1, -1, + 75, 76, 77, 78, -1, -1, 95, -1, 97, 98, + 99, 43, 101, -1, -1, 104, 91, -1, -1, 94, + 52, 96, -1, -1, 56, 100, -1, 59, -1, -1, + 62, 6, 64, 8, 66, 10, -1, 69, 70, -1, + -1, -1, -1, 18, 76, 77, 21, -1, -1, -1, + 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 93, -1, 95, -1, 97, 98, 99, 43, 101, + -1, -1, 104, -1, -1, -1, -1, 52, -1, -1, + -1, 56, -1, -1, 59, -1, -1, 62, 6, 64, + 8, 66, 10, -1, 69, 70, -1, -1, -1, -1, + 18, 76, 77, 21, -1, -1, -1, 25, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 93, -1, + 95, -1, 97, 98, 99, 43, 101, -1, -1, 104, + -1, -1, -1, -1, 52, -1, -1, -1, 56, -1, + -1, 59, -1, -1, 62, 6, 64, 8, 66, 10, + -1, 69, 70, -1, -1, -1, -1, 18, 76, 77, + 21, -1, -1, -1, 25, -1, 84, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 95, -1, 97, + 98, 99, 43, 101, -1, -1, 104, -1, -1, -1, + -1, 52, -1, -1, -1, 56, -1, -1, 59, -1, + -1, 62, 6, 64, 8, 66, 10, -1, 69, 70, + -1, -1, -1, -1, 18, 76, 77, 21, -1, -1, + -1, 25, -1, -1, -1, -1, -1, -1, -1, 90, + -1, -1, -1, -1, 95, -1, 97, 98, 99, 43, + 101, -1, -1, 104, -1, -1, -1, -1, 52, -1, + -1, -1, 56, -1, -1, 59, -1, -1, 62, -1, + 64, -1, 66, -1, -1, 69, 70, -1, -1, -1, + -1, -1, 76, 77, -1, -1, -1, -1, -1, -1, + 3, -1, -1, -1, 7, 8, 9, -1, 11, -1, + -1, 95, 15, 97, 98, 99, -1, 101, 21, 22, + 104, -1, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, + -1, -1, -1, -1, 47, 48, 49, 50, -1, -1, + -1, -1, -1, -1, -1, -1, 59, 60, 61, -1, + -1, 64, 65, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, -1, -1, 3, 82, + -1, 84, 7, 8, 9, -1, 11, -1, 91, -1, + 15, 94, -1, 96, -1, -1, 21, 100, -1, -1, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, + -1, -1, 47, 48, 49, 50, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 60, 61, -1, -1, 64, + 65, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, -1, 3, -1, 82, -1, 7, + 8, 9, -1, 11, -1, -1, 91, 15, 93, 94, + -1, 96, -1, 21, -1, 100, -1, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, -1, -1, -1, -1, -1, -1, -1, 47, + 48, 49, 50, -1, -1, -1, -1, -1, -1, -1, + 58, 59, 60, 61, -1, -1, 64, 65, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, -1, 3, -1, 82, -1, 7, 8, 9, -1, + 11, -1, -1, 91, 15, -1, 94, -1, 96, -1, + 21, -1, 100, -1, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, -1, + -1, -1, -1, -1, -1, -1, 47, 48, 49, 50, + -1, -1, -1, -1, -1, -1, -1, -1, 59, 60, + 61, -1, -1, 64, 65, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, -1, -1, + 3, 82, -1, -1, 7, 8, 9, 88, 11, -1, + 91, -1, 15, 94, -1, 96, -1, -1, 21, 100, + -1, -1, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, + -1, -1, -1, -1, 47, 48, 49, 50, -1, -1, + -1, -1, -1, -1, -1, -1, 59, 60, 61, -1, + -1, 64, 65, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, -1, 3, -1, 82, + -1, 7, 8, 9, -1, 11, -1, 90, 91, 15, + -1, 94, -1, 96, -1, 21, -1, 100, -1, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, -1, -1, -1, -1, -1, -1, + -1, 47, 48, 49, 50, -1, -1, -1, -1, -1, + -1, -1, -1, 59, 60, 61, -1, -1, 64, 65, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, -1, 3, -1, 82, -1, 7, 8, + 9, -1, 11, -1, -1, 91, 15, 93, 94, -1, + 96, -1, 21, -1, 100, -1, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, -1, -1, -1, -1, -1, -1, -1, 47, 48, + 49, 50, -1, -1, -1, -1, -1, -1, -1, -1, + 59, 60, 61, -1, -1, 64, 65, -1, 67, 68, + 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, + -1, 3, -1, 82, -1, 7, 8, 9, -1, 11, + -1, 90, 91, 15, -1, 94, -1, 96, -1, 21, + -1, 100, -1, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, -1, -1, + -1, -1, -1, -1, -1, 47, 48, 49, 50, -1, + -1, -1, -1, -1, -1, -1, -1, 59, 60, 61, + -1, -1, 64, 65, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, -1, 3, -1, + 82, -1, 7, 8, 9, -1, 11, -1, -1, 91, + 15, 93, 94, -1, 96, -1, 21, -1, 100, -1, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, + -1, -1, 47, 48, 49, 50, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 60, 61, -1, -1, 64, + 65, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, 3, 4, -1, 82, 7, 8, + 9, -1, 11, -1, -1, 90, 91, -1, -1, 94, + -1, 96, 21, -1, -1, 100, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, -1, -1, -1, -1, -1, -1, -1, 47, 48, + 49, 50, -1, -1, -1, -1, -1, -1, -1, -1, + 59, 60, 61, -1, -1, 64, 65, -1, 67, 68, + 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, + -1, 3, -1, 82, -1, 7, 8, 9, -1, 11, + -1, -1, 91, 15, 93, 94, -1, 96, -1, 21, + -1, 100, -1, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, -1, -1, + -1, -1, -1, -1, -1, 47, 48, 49, 50, -1, + -1, -1, -1, -1, -1, -1, -1, 59, 60, 61, + -1, -1, 64, 65, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, -1, 3, -1, + 82, -1, 7, 8, 9, -1, 11, -1, 90, 91, + 15, -1, 94, -1, 96, -1, 21, -1, 100, -1, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, + -1, -1, 47, 48, 49, 50, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 60, 61, -1, -1, 64, + 65, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, -1, 3, -1, 82, -1, 7, + 8, 9, -1, 11, -1, 90, 91, 15, -1, 94, + -1, 96, -1, 21, -1, 100, -1, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, -1, -1, -1, -1, -1, -1, -1, 47, + 48, 49, 50, -1, -1, -1, -1, -1, -1, -1, + -1, 59, 60, 61, -1, -1, 64, 65, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, -1, 3, -1, 82, -1, 7, 8, 9, -1, + 11, -1, 90, 91, 15, -1, 94, -1, 96, -1, + 21, -1, 100, -1, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, -1, + -1, -1, -1, -1, -1, -1, 47, 48, 49, 50, + -1, -1, -1, -1, -1, -1, -1, -1, 59, 60, + 61, -1, -1, 64, 65, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, -1, -1, + 3, 82, 83, -1, 7, 8, 9, -1, 11, -1, + 91, 14, 15, 94, -1, 96, -1, -1, 21, 100, + -1, -1, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, + -1, -1, -1, -1, 47, 48, 49, 50, -1, -1, + -1, -1, -1, -1, -1, -1, 59, 60, 61, -1, + -1, 64, 65, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, -1, 3, -1, 82, + -1, 7, 8, 9, -1, 11, -1, -1, 91, 15, + -1, 94, -1, 96, -1, 21, -1, 100, -1, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, -1, -1, -1, -1, -1, -1, + -1, 47, 48, 49, 50, -1, -1, -1, -1, -1, + -1, -1, -1, 59, 60, 61, -1, -1, 64, 65, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, -1, -1, 3, 82, -1, 84, 7, + 8, 9, -1, 11, -1, 91, -1, 15, 94, -1, + 96, -1, -1, 21, 100, -1, -1, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, -1, -1, -1, -1, -1, -1, -1, 47, + 48, 49, 50, -1, -1, -1, -1, -1, -1, -1, + -1, 59, 60, 61, -1, -1, 64, 65, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, -1, -1, 3, 82, -1, -1, 7, 8, 9, + 88, 11, -1, 91, -1, 15, 94, -1, 96, -1, + -1, 21, 100, -1, -1, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + -1, -1, -1, -1, -1, -1, -1, 47, 48, 49, + 50, -1, -1, -1, -1, -1, -1, -1, -1, 59, + 60, 61, -1, -1, 64, 65, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, -1, + 3, -1, 82, -1, 7, 8, 9, -1, 11, 89, + -1, 91, 15, -1, 94, -1, 96, -1, 21, -1, + 100, -1, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, + -1, -1, -1, -1, 47, 48, 49, 50, -1, -1, + -1, -1, -1, -1, -1, -1, 59, 60, 61, -1, + -1, 64, 65, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, -1, 3, -1, 82, + -1, 7, 8, 9, -1, 11, -1, 90, 91, 15, + -1, 94, -1, 96, -1, 21, -1, 100, -1, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, -1, -1, -1, -1, -1, -1, + -1, 47, 48, 49, 50, -1, -1, -1, -1, -1, + -1, -1, -1, 59, 60, 61, -1, -1, 64, 65, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, -1, 3, -1, 82, -1, 7, 8, + 9, -1, 11, -1, 90, 91, 15, -1, 94, -1, + 96, -1, 21, -1, 100, -1, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, -1, -1, -1, -1, -1, -1, -1, 47, 48, + 49, 50, -1, -1, -1, -1, -1, -1, -1, -1, + 59, 60, 61, -1, -1, 64, 65, -1, 67, 68, + 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, + -1, 3, -1, 82, -1, 7, 8, 9, -1, 11, + -1, 90, 91, 15, -1, 94, -1, 96, -1, 21, + -1, 100, -1, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, -1, -1, + -1, -1, -1, -1, -1, 47, 48, 49, 50, -1, + -1, -1, -1, -1, -1, -1, -1, 59, 60, 61, + -1, -1, 64, 65, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, -1, 3, -1, + 82, -1, 7, 8, 9, -1, 11, -1, 90, 91, + 15, -1, 94, -1, 96, -1, 21, -1, 100, -1, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, + -1, -1, 47, 48, 49, 50, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 60, 61, -1, -1, 64, + 65, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, -1, 3, -1, 82, -1, 7, + 8, 9, -1, 11, 89, -1, 91, 15, -1, 94, + -1, 96, -1, 21, -1, 100, -1, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, -1, -1, -1, -1, -1, -1, -1, 47, + 48, 49, 50, -1, -1, -1, -1, -1, -1, -1, + -1, 59, 60, 61, -1, -1, 64, 65, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, -1, -1, 3, 82, -1, 84, 7, 8, 9, + -1, 11, -1, 91, -1, 15, 94, -1, 96, -1, + -1, 21, 100, -1, -1, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + -1, -1, -1, -1, -1, -1, -1, 47, 48, 49, + 50, -1, -1, -1, -1, -1, -1, -1, -1, 59, + 60, 61, -1, -1, 64, 65, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, -1, + 3, -1, 82, -1, 7, 8, 9, -1, 11, -1, + 90, 91, 15, -1, 94, -1, 96, -1, 21, -1, + 100, -1, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, + -1, -1, -1, -1, 47, 48, 49, 50, -1, -1, + -1, -1, -1, -1, -1, -1, 59, 60, 61, -1, + -1, 64, 65, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, -1, 3, -1, 82, + -1, 7, 8, 9, -1, 11, -1, -1, 91, 15, + -1, 94, -1, 96, -1, 21, -1, 100, -1, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, -1, -1, -1, -1, -1, -1, + -1, 47, 48, 49, 50, -1, -1, -1, -1, -1, + -1, -1, -1, 59, 60, 61, -1, -1, 64, 65, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 3, 4, -1, 82, 7, 8, 9, + -1, 11, -1, -1, -1, 91, -1, -1, 94, -1, + 96, 21, -1, -1, 100, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + -1, -1, -1, -1, -1, -1, -1, 47, 48, 49, + 50, -1, -1, -1, -1, -1, -1, -1, -1, 59, + 60, 61, -1, -1, 64, 65, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 3, + -1, -1, 82, 7, 8, 9, -1, 11, -1, -1, + -1, 91, -1, -1, 94, -1, 96, 21, -1, -1, + 100, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, -1, -1, -1, -1, + -1, -1, -1, 47, 48, 49, 50, -1, -1, -1, + -1, -1, -1, -1, -1, 59, 60, 61, -1, -1, + 64, 65, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, -1, 3, -1, 82, -1, + 7, 8, 9, -1, 11, -1, 90, 91, 15, -1, + 94, -1, 96, -1, 21, -1, 100, -1, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 38, 39, -1, -1, -1, -1, -1, -1, -1, + 47, 48, 49, 50, -1, -1, -1, -1, -1, -1, + -1, -1, 59, 60, 61, -1, -1, 64, 65, -1, + 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, + 77, 78, 3, -1, -1, 82, 7, 8, 9, -1, + 11, -1, -1, -1, 91, -1, -1, 94, -1, 96, + 21, -1, -1, 100, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, -1, + -1, -1, -1, -1, -1, -1, 47, 48, 49, 50, + -1, -1, -1, -1, -1, -1, -1, -1, 59, 60, + 61, -1, -1, 64, 65, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 3, -1, + -1, 82, 7, 8, 9, -1, 11, -1, -1, -1, + 91, -1, -1, 94, -1, 96, 21, -1, -1, 100, + 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 37, -1, 39, -1, -1, -1, -1, -1, + -1, -1, 47, 48, 49, 50, -1, -1, -1, -1, + -1, -1, -1, -1, 59, 60, 61, -1, -1, 64, + 65, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, 3, -1, -1, 82, 7, 8, + 9, -1, 11, -1, -1, -1, 91, -1, -1, 94, + -1, 96, 21, -1, -1, 100, 25, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 37, -1, + 39, -1, -1, -1, -1, -1, -1, -1, 47, 48, + 49, 50, -1, -1, -1, -1, -1, -1, -1, -1, + 59, 60, 61, -1, -1, 64, 65, -1, 67, 68, + 69, 70, 71, 72, -1, -1, 75, 76, 77, 78, + 7, 8, 9, -1, 11, -1, -1, -1, -1, -1, + -1, -1, 91, -1, 21, 94, -1, 96, 25, -1, + -1, 100, -1, -1, -1, -1, -1, -1, -1, -1, + 37, -1, 39, -1, -1, -1, -1, -1, -1, -1, + 47, 48, 49, 50, -1, -1, -1, -1, -1, -1, + -1, -1, 59, 60, 61, -1, -1, 64, 65, -1, + 67, 68, 69, 70, 71, 72, -1, -1, 75, 76, + 77, 78, 7, 8, -1, -1, 11, -1, -1, -1, + -1, -1, -1, -1, 91, -1, 21, 94, -1, 96, + 25, -1, -1, 100, -1, -1, -1, -1, -1, -1, + -1, -1, 37, -1, 39, -1, -1, -1, 41, 42, + -1, -1, 47, 48, 49, 50, -1, -1, -1, -1, + -1, -1, 55, -1, 59, 60, 61, -1, -1, 64, + 65, -1, 67, 68, 69, 70, 71, 72, -1, -1, + 75, 76, 77, 78, 7, 8, 79, 80, 81, -1, + 83, -1, -1, -1, -1, -1, 91, -1, 21, 94, + -1, 96, 25, -1, -1, 100, -1, -1, 101, 102, + -1, 104, -1, -1, 37, -1, 39, 110, 111, 41, + 42, -1, -1, -1, 47, 48, 49, 50, -1, -1, + -1, -1, -1, 55, -1, -1, 59, 60, 61, -1, + -1, 64, 65, -1, 67, 68, 69, 70, 71, 72, + -1, 7, 75, 76, 77, 78, -1, 79, 80, 81, + -1, 83, -1, -1, -1, 21, -1, -1, 91, 25, + -1, 94, -1, 96, -1, -1, -1, 100, -1, 101, + 102, 37, 104, 39, -1, -1, -1, -1, 110, 111, + -1, 47, 48, 49, 50, -1, -1, -1, -1, -1, + -1, -1, -1, 59, 60, 61, -1, -1, 64, 65, + -1, 67, 68, 69, 70, 71, 72, -1, -1, 75, + 76, 77, 78, 21, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 91, -1, -1, 94, -1, + 96, -1, -1, -1, 100, -1, -1, -1, -1, 47, + 48, 49, 50, -1, -1, -1, -1, -1, -1, -1, + -1, 59, 60, 61, -1, -1, 64, 65, -1, 67, + 68, 69, 70, -1, -1, -1, -1, 75, 76, 77, + 78, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 91, -1, -1, 94, -1, 96, -1, + -1, -1, 100 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 124, 125, 0, 6, 8, 10, 12, 13, 17, + 18, 20, 21, 25, 41, 42, 43, 44, 45, 46, + 51, 52, 53, 55, 56, 57, 59, 62, 64, 66, + 69, 70, 76, 77, 79, 80, 81, 87, 92, 93, + 95, 97, 98, 99, 101, 102, 104, 105, 106, 110, + 111, 112, 113, 114, 126, 132, 135, 137, 139, 140, + 141, 142, 147, 148, 158, 161, 163, 166, 167, 168, + 175, 176, 177, 183, 184, 185, 189, 191, 192, 52, + 59, 101, 104, 158, 158, 158, 93, 104, 161, 93, + 66, 135, 52, 66, 66, 66, 52, 14, 66, 158, + 83, 164, 158, 48, 158, 40, 158, 175, 177, 158, + 158, 158, 158, 93, 158, 59, 163, 66, 98, 66, + 52, 59, 21, 78, 101, 104, 175, 66, 66, 136, + 161, 66, 3, 7, 8, 9, 11, 15, 21, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 47, 48, 49, 50, 59, 60, + 61, 64, 65, 67, 68, 69, 70, 71, 72, 73, + 75, 76, 77, 78, 82, 91, 93, 94, 96, 100, + 66, 168, 175, 93, 8, 74, 104, 133, 161, 169, + 171, 173, 59, 60, 174, 93, 174, 97, 99, 62, + 98, 99, 66, 21, 164, 59, 93, 59, 93, 158, + 112, 158, 93, 149, 158, 161, 162, 93, 135, 158, + 58, 83, 135, 151, 158, 165, 166, 167, 175, 181, + 182, 88, 48, 90, 90, 90, 93, 164, 52, 159, + 52, 116, 156, 157, 158, 59, 175, 178, 179, 180, + 52, 52, 161, 173, 158, 158, 15, 38, 158, 158, + 63, 85, 186, 187, 190, 158, 158, 158, 158, 52, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 186, 187, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, + 158, 158, 158, 52, 158, 158, 158, 158, 158, 90, + 156, 93, 133, 161, 66, 134, 174, 134, 174, 15, + 38, 176, 84, 158, 98, 158, 90, 156, 52, 158, + 128, 127, 90, 66, 15, 149, 93, 4, 15, 161, + 90, 83, 135, 4, 83, 151, 166, 15, 83, 158, + 158, 66, 163, 156, 187, 14, 14, 15, 90, 158, + 178, 170, 173, 83, 179, 93, 93, 90, 90, 161, + 56, 161, 90, 158, 86, 63, 85, 103, 188, 190, + 83, 22, 84, 14, 90, 66, 174, 152, 153, 154, + 155, 171, 158, 83, 174, 84, 88, 90, 129, 130, + 129, 158, 158, 90, 158, 161, 161, 162, 158, 140, + 163, 158, 83, 182, 158, 90, 15, 157, 158, 83, + 15, 140, 163, 135, 38, 59, 89, 158, 86, 103, + 158, 158, 152, 90, 15, 23, 107, 108, 109, 175, + 174, 174, 16, 19, 54, 83, 105, 132, 137, 166, + 177, 90, 90, 135, 90, 161, 90, 24, 146, 90, + 156, 158, 173, 146, 56, 161, 143, 89, 84, 90, + 5, 138, 154, 161, 172, 173, 133, 161, 133, 59, + 175, 93, 93, 135, 158, 135, 141, 163, 163, 90, + 83, 115, 116, 144, 66, 93, 163, 83, 165, 173, + 90, 160, 14, 156, 93, 131, 83, 93, 135, 145, + 158, 187, 150, 151, 90, 131, 14, 150 +}; + + +/* Prevent warning if -Wmissing-prototypes. */ +int yyparse (void); + +/* Error token number */ +#define YYTERROR 1 + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + + +#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +# define YY_LOCATION_PRINT(File, Loc) \ + fprintf (File, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column) +#endif + + +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ +#define YYLEX yylex () + +YYSTYPE yylval; + +YYLTYPE yylloc; + +int yynerrs; +int yychar; + +static const int YYEOF = 0; +static const int YYEMPTY = -2; + +typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; + +#define YYCHK(YYE) \ + do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ + while (YYID (0)) + +#if YYDEBUG + +# ifndef YYFPRINTF +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +{ + if (!yyvaluep) + return; + YYUSE (yylocationp); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp); + YYFPRINTF (yyoutput, ")"); +} + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, Type, \ + Value, Location); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; + +#else /* !YYDEBUG */ + +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) + +#endif /* !YYDEBUG */ + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + +/* Minimum number of free items on the stack allowed after an + allocation. This is to allow allocation and initialization + to be completed by functions that call yyexpandGLRStack before the + stack is expanded, thus insuring that all necessary pointers get + properly redirected to new data. */ +#define YYHEADROOM 2 + +#ifndef YYSTACKEXPANDABLE +# if (! defined __cplusplus \ + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)) +# define YYSTACKEXPANDABLE 1 +# else +# define YYSTACKEXPANDABLE 0 +# endif +#endif + +#if YYSTACKEXPANDABLE +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyexpandGLRStack (Yystack); \ + } while (YYID (0)) +#else +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyMemoryExhausted (Yystack); \ + } while (YYID (0)) +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static size_t +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + size_t yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return strlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +#endif /* !YYERROR_VERBOSE */ + +/** State numbers, as in LALR(1) machine */ +typedef int yyStateNum; + +/** Rule numbers, as in LALR(1) machine */ +typedef int yyRuleNum; + +/** Grammar symbol */ +typedef short int yySymbol; + +/** Item references, as in LALR(1) machine */ +typedef short int yyItemNum; + +typedef struct yyGLRState yyGLRState; +typedef struct yyGLRStateSet yyGLRStateSet; +typedef struct yySemanticOption yySemanticOption; +typedef union yyGLRStackItem yyGLRStackItem; +typedef struct yyGLRStack yyGLRStack; + +struct yyGLRState { + /** Type tag: always true. */ + yybool yyisState; + /** Type tag for yysemantics. If true, yysval applies, otherwise + * yyfirstVal applies. */ + yybool yyresolved; + /** Number of corresponding LALR(1) machine state. */ + yyStateNum yylrState; + /** Preceding state in this stack */ + yyGLRState* yypred; + /** Source position of the first token produced by my symbol */ + size_t yyposn; + union { + /** First in a chain of alternative reductions producing the + * non-terminal corresponding to this state, threaded through + * yynext. */ + yySemanticOption* yyfirstVal; + /** Semantic value for this state. */ + YYSTYPE yysval; + } yysemantics; + /** Source location for this state. */ + YYLTYPE yyloc; +}; + +struct yyGLRStateSet { + yyGLRState** yystates; + /** During nondeterministic operation, yylookaheadNeeds tracks which + * stacks have actually needed the current lookahead. During deterministic + * operation, yylookaheadNeeds[0] is not maintained since it would merely + * duplicate yychar != YYEMPTY. */ + yybool* yylookaheadNeeds; + size_t yysize, yycapacity; +}; + +struct yySemanticOption { + /** Type tag: always false. */ + yybool yyisState; + /** Rule number for this reduction */ + yyRuleNum yyrule; + /** The last RHS state in the list of states to be reduced. */ + yyGLRState* yystate; + /** The lookahead for this reduction. */ + int yyrawchar; + YYSTYPE yyval; + YYLTYPE yyloc; + /** Next sibling in chain of options. To facilitate merging, + * options are chained in decreasing order by address. */ + yySemanticOption* yynext; +}; + +/** Type of the items in the GLR stack. The yyisState field + * indicates which item of the union is valid. */ +union yyGLRStackItem { + yyGLRState yystate; + yySemanticOption yyoption; +}; + +struct yyGLRStack { + int yyerrState; + /* To compute the location of the error token. */ + yyGLRStackItem yyerror_range[3]; + + YYJMP_BUF yyexception_buffer; + yyGLRStackItem* yyitems; + yyGLRStackItem* yynextFree; + size_t yyspaceLeft; + yyGLRState* yysplitPoint; + yyGLRState* yylastDeleted; + yyGLRStateSet yytops; +}; + +#if YYSTACKEXPANDABLE +static void yyexpandGLRStack (yyGLRStack* yystackp); +#endif + +static void yyFail (yyGLRStack* yystackp, const char* yymsg) + __attribute__ ((__noreturn__)); +static void +yyFail (yyGLRStack* yystackp, const char* yymsg) +{ + if (yymsg != NULL) + yyerror (yymsg); + YYLONGJMP (yystackp->yyexception_buffer, 1); +} + +static void yyMemoryExhausted (yyGLRStack* yystackp) + __attribute__ ((__noreturn__)); +static void +yyMemoryExhausted (yyGLRStack* yystackp) +{ + YYLONGJMP (yystackp->yyexception_buffer, 2); +} + +#if YYDEBUG || YYERROR_VERBOSE +/** A printable representation of TOKEN. */ +static inline const char* +yytokenName (yySymbol yytoken) +{ + if (yytoken == YYEMPTY) + return ""; + + return yytname[yytoken]; +} +#endif + +/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting + * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred + * containing the pointer to the next state in the chain. */ +static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__)); +static void +yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) +{ + yyGLRState* s; + int i; + s = yyvsp[yylow0].yystate.yypred; + for (i = yylow0-1; i >= yylow1; i -= 1) + { + YYASSERT (s->yyresolved); + yyvsp[i].yystate.yyresolved = yytrue; + yyvsp[i].yystate.yysemantics.yysval = s->yysemantics.yysval; + yyvsp[i].yystate.yyloc = s->yyloc; + s = yyvsp[i].yystate.yypred = s->yypred; + } +} + +/* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in + * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. + * For convenience, always return YYLOW1. */ +static inline int yyfill (yyGLRStackItem *, int *, int, yybool) + __attribute__ ((__unused__)); +static inline int +yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) +{ + if (!yynormal && yylow1 < *yylow) + { + yyfillin (yyvsp, *yylow, yylow1); + *yylow = yylow1; + } + return yylow1; +} + +/** Perform user action for rule number YYN, with RHS length YYRHSLEN, + * and top stack item YYVSP. YYLVALP points to place to put semantic + * value ($$), and yylocp points to place for location information + * (@$). Returns yyok for normal return, yyaccept for YYACCEPT, + * yyerr for YYERROR, yyabort for YYABORT. */ +/*ARGSUSED*/ static YYRESULTTAG +yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, + YYSTYPE* yyvalp, + YYLTYPE* YYOPTIONAL_LOC (yylocp), + yyGLRStack* yystackp + ) +{ + yybool yynormal __attribute__ ((__unused__)) = + (yystackp->yysplitPoint == NULL); + int yylow; +# undef yyerrok +# define yyerrok (yystackp->yyerrState = 0) +# undef YYACCEPT +# define YYACCEPT return yyaccept +# undef YYABORT +# define YYABORT return yyabort +# undef YYERROR +# define YYERROR return yyerrok, yyerr +# undef YYRECOVERING +# define YYRECOVERING() (yystackp->yyerrState != 0) +# undef yyclearin +# define yyclearin (yychar = YYEMPTY) +# undef YYFILL +# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal) +# undef YYBACKUP +# define YYBACKUP(Token, Value) \ + return yyerror (YY_("syntax error: cannot back up")), \ + yyerrok, yyerr + + yylow = 1; + if (yyrhslen == 0) + *yyvalp = yyval_default; + else + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval; + YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); + yystackp->yyerror_range[1].yystate.yyloc = *yylocp; + + switch (yyn) + { + case 2: +#line 251 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(TopLev, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.TopLev)); + L->ast = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.TopLev); + ;} + break; + + case 3: +#line 259 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.ClsDecl)) { + ((*yyvalp).TopLev) = ast_mkTopLevel(L_TOPLEVEL_CLASS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.TopLev), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).TopLev)->u.class = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.ClsDecl); + } else { + // Don't create a node for a forward class declaration. + ((*yyvalp).TopLev) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.TopLev); + } + ;} + break; + + case 4: +#line 269 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).TopLev) = ast_mkTopLevel(L_TOPLEVEL_FUN, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.TopLev), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= DECL_FN; + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags & DECL_PRIVATE) { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= SCOPE_SCRIPT; + } else { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= SCOPE_GLOBAL; + } + ((*yyvalp).TopLev)->u.fun = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl); + ;} + break; + + case 5: +#line 280 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).TopLev) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.TopLev); // nothing more to do + ;} + break; + + case 6: +#line 284 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + L_set_declBaseType((((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Type)); + L_typedef_store((((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl)); + ((*yyvalp).TopLev) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yysemantics.yysval.TopLev); // nothing more to do + ;} + break; + + case 7: +#line 290 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // Global variable declaration. + VarDecl *v; + ((*yyvalp).TopLev) = ast_mkTopLevel(L_TOPLEVEL_GLOBAL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.TopLev), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->flags |= DECL_GLOBAL_VAR; + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl)->flags & DECL_PRIVATE) { + v->flags |= SCOPE_SCRIPT; + } else { + v->flags |= SCOPE_GLOBAL; + } + } + ((*yyvalp).TopLev)->u.global = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); + ;} + break; + + case 8: +#line 305 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // Top-level statement. + ((*yyvalp).TopLev) = ast_mkTopLevel(L_TOPLEVEL_STMT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.TopLev), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).TopLev)->u.stmt = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Stmt); + ;} + break; + + case 9: +#line 310 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).TopLev) = NULL; ;} + break; + + case 10: +#line 315 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* + * This is a new class declaration. + * Alloc the VarDecl now and associate it with + * the class name so that it is available while + * parsing the class body. + */ + Type *t = type_mkClass(); + VarDecl *d = ast_mkVarDecl(t, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc)); + ClsDecl *c = ast_mkClsDecl(d, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc)); + t->u.class.clsdecl = c; + ASSERT(!L_typedef_lookup((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr)->str)); + L_typedef_store(d); + ((*yyvalp).ClsDecl) = c; + ;} + break; + + case 11: +#line 330 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).ClsDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.ClsDecl); + /* silence unused warning */ + (void)(((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.ClsDecl); + ;} + break; + + case 12: +#line 336 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* + * This is a class declaration where the type name was + * previously declared. Use the ClsDecl from the + * prior decl. + */ + ClsDecl *c = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Typename).t->u.class.clsdecl; + unless (c->decl->flags & DECL_FORWARD) { + L_err("redeclaration of %s", (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Typename).s); + } + ASSERT(isclasstype(c->decl->type)); + c->decl->flags &= ~DECL_FORWARD; + ((*yyvalp).ClsDecl) = c; + ;} + break; + + case 13: +#line 350 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).ClsDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.ClsDecl); + /* silence unused warning */ + (void)(((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.ClsDecl); + ;} + break; + + case 14: +#line 356 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* This is a forward class declaration. */ + Type *t = type_mkClass(); + VarDecl *d = ast_mkVarDecl(t, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ClsDecl *c = ast_mkClsDecl(d, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ASSERT(!L_typedef_lookup((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr)->str)); + t->u.class.clsdecl = c; + d->flags |= DECL_FORWARD; + L_typedef_store(d); + ((*yyvalp).ClsDecl) = NULL; + ;} + break; + + case 15: +#line 368 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* Empty declaration of an already declared type. */ + unless (isclasstype((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Typename).t)) { + L_err("%s not a class type", (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Typename).s); + } + ((*yyvalp).ClsDecl) = NULL; + ;} + break; + + case 16: +#line 379 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).ClsDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((0) - (2))].yystate.yysemantics.yysval.ClsDecl); + ((*yyvalp).ClsDecl)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc).end; + ((*yyvalp).ClsDecl)->decl->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc).end; + /* If constructor or destructor were omitted, make defaults. */ + unless (((*yyvalp).ClsDecl)->constructors) { + ((*yyvalp).ClsDecl)->constructors = ast_mkConstructor(((*yyvalp).ClsDecl)); + } + unless (((*yyvalp).ClsDecl)->destructors) { + ((*yyvalp).ClsDecl)->destructors = ast_mkDestructor(((*yyvalp).ClsDecl)); + } + ;} + break; + + case 17: +#line 395 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + ClsDecl *clsdecl = (((yyGLRStackItem const *)yyvsp)[YYFILL ((0) - (6))].yystate.yysemantics.yysval.ClsDecl); + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (6))].yystate.yysemantics.yysval.VarDecl)); + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (6))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->clsdecl = clsdecl; + v->flags |= SCOPE_CLASS | DECL_CLASS_INST_VAR; + unless (v->flags & (DECL_PUBLIC | DECL_PRIVATE)) { + L_errf(v, "class instance variable %s not " + "declared public or private", + v->id->str); + v->flags |= DECL_PUBLIC; + } + } + APPEND_OR_SET(VarDecl, next, clsdecl->instvars, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (6))].yystate.yysemantics.yysval.VarDecl)); + ;} + break; + + case 19: +#line 413 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + ClsDecl *clsdecl = (((yyGLRStackItem const *)yyvsp)[YYFILL ((0) - (2))].yystate.yysemantics.yysval.ClsDecl); + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl)); + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->clsdecl = clsdecl; + v->flags |= SCOPE_CLASS | DECL_CLASS_VAR; + unless (v->flags & (DECL_PUBLIC | DECL_PRIVATE)) { + L_errf(v, "class variable %s not " + "declared public or private", + v->id->str); + v->flags |= DECL_PUBLIC; + } + } + APPEND_OR_SET(VarDecl, next, clsdecl->clsvars, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl)); + ;} + break; + + case 21: +#line 431 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + L_set_declBaseType((((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Type)); + L_typedef_store((((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl)); + ;} + break; + + case 22: +#line 436 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ClsDecl *clsdecl = (((yyGLRStackItem const *)yyvsp)[YYFILL ((0) - (2))].yystate.yysemantics.yysval.ClsDecl); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->clsdecl = clsdecl; + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= DECL_CLASS_FN; + unless ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags & DECL_PRIVATE) { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= SCOPE_GLOBAL | DECL_PUBLIC; + } else { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= SCOPE_CLASS; + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->tclprefix = cksprintf("_L_class_%s_", + clsdecl->decl->id->str); + } + APPEND_OR_SET(FnDecl, next, clsdecl->fns, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)); + ;} + break; + + case 23: +#line 450 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ClsDecl *clsdecl = (((yyGLRStackItem const *)yyvsp)[YYFILL ((0) - (3))].yystate.yysemantics.yysval.ClsDecl); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->type->base_type = clsdecl->decl->type; + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->clsdecl = clsdecl; + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= SCOPE_GLOBAL | DECL_CLASS_FN | DECL_PUBLIC | + DECL_CLASS_CONST; + APPEND_OR_SET(FnDecl, next, clsdecl->constructors, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)); + ;} + break; + + case 24: +#line 459 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ClsDecl *clsdecl = (((yyGLRStackItem const *)yyvsp)[YYFILL ((0) - (3))].yystate.yysemantics.yysval.ClsDecl); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->type->base_type = L_void; + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->clsdecl = clsdecl; + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= SCOPE_GLOBAL | DECL_CLASS_FN | DECL_PUBLIC | + DECL_CLASS_DESTR; + APPEND_OR_SET(FnDecl, next, clsdecl->destructors, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)); + ;} + break; + + case 25: +#line 468 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* + * We don't store the things that make up class_code + * in order, so there's no place in which to + * interleave #pragmas. So don't create an AST node, + * just update L->options now; it gets used when other + * AST nodes are created. + */ + L_compile_attributes(L->options, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), L_attrs_pragma); + ;} + break; + + case 29: +#line 488 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->type->base_type = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type); + ((*yyvalp).FnDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl); + ((*yyvalp).FnDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + ;} + break; + + case 30: +#line 494 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->type->base_type = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Type); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl)->decl->flags |= (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.i); + ((*yyvalp).FnDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.FnDecl); + ((*yyvalp).FnDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc); + ;} + break; + + case 31: +#line 504 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).FnDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl); + ((*yyvalp).FnDecl)->decl->id = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).FnDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + ;} + break; + + case 32: +#line 510 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *new_param; + Expr *dollar1 = ast_mkId("$1", (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + + ((*yyvalp).FnDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl); + ((*yyvalp).FnDecl)->decl->id = ast_mkId((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.s)); + ((*yyvalp).FnDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + /* Prepend a new arg "$1" as the first formal. */ + new_param = ast_mkVarDecl(L_string, dollar1, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + new_param->flags = SCOPE_LOCAL | DECL_LOCAL_VAR; + new_param->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.FnDecl)->decl->type->u.func.formals; + ((*yyvalp).FnDecl)->decl->type->u.func.formals = new_param; + ;} + break; + + case 33: +#line 528 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Type *type = type_mkFunc(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (5))].yystate.yysemantics.yysval.VarDecl)); + VarDecl *decl = ast_mkVarDecl(type, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yyloc)); + decl->attrs = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).FnDecl) = ast_mkFnDecl(decl, (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Stmt)->u.block, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 34: +#line 535 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Type *type = type_mkFunc(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (5))].yystate.yysemantics.yysval.VarDecl)); + VarDecl *decl = ast_mkVarDecl(type, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yyloc)); + decl->attrs = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).FnDecl) = ast_mkFnDecl(decl, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 35: +#line 545 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_LABEL, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.label = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.s); + ((*yyvalp).Stmt)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Stmt); + ;} + break; + + case 36: +#line 551 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_LABEL, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.label = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.s); + ;} + break; + + case 38: +#line 557 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + L_compile_attributes(L->options, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Expr), L_attrs_pragma); + ((*yyvalp).Stmt) = NULL; + ;} + break; + + case 39: +#line 562 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // Wrap the html in a puts(-nonewline) call. + Expr *fn = ast_mkId("puts", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + Expr *arg = ast_mkConst(L_string, "-nonewline", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + arg->next = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_EXPR, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.expr = ast_mkFnCall(fn, arg, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 40: +#line 571 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // Wrap expr in a puts(-nonewline) call. + Expr *fn = ast_mkId("puts", (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc)); + Expr *arg = ast_mkConst(L_string, "-nonewline", (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc)); + arg->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_EXPR, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.expr = ast_mkFnCall(fn, arg, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 42: +#line 584 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 43: +#line 588 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *lit = ast_mkConst(L_int, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), lit, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 44: +#line 593 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.beg = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc).beg; + ;} + break; + + case 45: +#line 599 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ((*yyvalp).Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.beg = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc).beg; + ;} + break; + + case 46: +#line 605 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *lit = ast_mkConst(L_int, (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), lit, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ((*yyvalp).Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.beg = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc).beg; + ;} + break; + + case 47: +#line 615 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.beg = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc).beg; + ;} + break; + + case 48: +#line 624 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.beg = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc).beg; + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc).end; + ;} + break; + + case 49: +#line 630 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Expr) = NULL; ;} + break; + + case 52: +#line 640 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_COND, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.cond = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Cond); + ;} + break; + + case 53: +#line 645 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_LOOP, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.loop = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Loop); + ;} + break; + + case 54: +#line 650 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_SWITCH, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.swich = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Switch); + ;} + break; + + case 55: +#line 655 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_FOREACH, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.foreach = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.ForEach); + ;} + break; + + case 56: +#line 660 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_EXPR, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.expr = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr); + ;} + break; + + case 57: +#line 665 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_BREAK, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + ;} + break; + + case 58: +#line 669 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_CONTINUE, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + ;} + break; + + case 59: +#line 673 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_RETURN, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + ;} + break; + + case 60: +#line 677 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_RETURN, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.expr = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr); + ;} + break; + + case 61: +#line 682 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_GOTO, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.label = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.s); + ;} + break; + + case 62: +#line 687 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* + * We don't want to make "catch" a keyword since it's a Tcl + * function name, so allow any ID here but check it. + */ + unless (!strcmp((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (7))].yystate.yysemantics.yysval.s), "catch")) { + L_synerr2("syntax error -- expected 'catch'", (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (7))].yystate.yyloc).beg); + } + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_TRY, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.try = ast_mkTry((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (7))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yysemantics.yysval.Stmt)); + ;} + break; + + case 63: +#line 699 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_TRY, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.try = ast_mkTry((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yysemantics.yysval.Stmt), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Stmt)); + ;} + break; + + case 64: +#line 703 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Stmt) = NULL; ;} + break; + + case 65: +#line 708 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Cond) = ast_mkIfUnless((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (6))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (6))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yyloc)); + ;} + break; + + case 66: +#line 713 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Cond) = ast_mkIfUnless((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Stmt), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 67: +#line 717 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Cond) = ast_mkIfUnless((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (6))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (6))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yyloc)); + ;} + break; + + case 68: +#line 721 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Cond) = ast_mkIfUnless((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 69: +#line 728 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Case *c, *def; + + for (c = (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (7))].yystate.yysemantics.yysval.Case), def = NULL; c; c = c->next) { + if (c->expr) continue; + if (def) { + L_errf(c, + "multiple default cases in switch statement"); + } + def = c; + } + ((*yyvalp).Switch) = ast_mkSwitch((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (7))].yystate.yysemantics.yysval.Case), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yyloc)); + ;} + break; + + case 70: +#line 745 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Case)) { + APPEND(Case, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Case), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Case)); + ((*yyvalp).Case) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Case); + } else { + ((*yyvalp).Case) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Case); + } + ;} + break; + + case 71: +#line 753 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Case) = NULL; ;} + break; + + case 72: +#line 758 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Stmt)); + ((*yyvalp).Case) = ast_mkCase((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 73: +#line 763 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* The default case is distinguished by a NULL expr. */ + REVERSE(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Stmt)); + ((*yyvalp).Case) = ast_mkCase(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc)); + ;} + break; + + case 74: +#line 772 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Expr)->flags & L_EXPR_RE_G) { + L_errf((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Expr), "illegal regular expression modifier"); + } + ;} + break; + + case 76: +#line 783 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Stmt); + ((*yyvalp).Stmt)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + ;} + break; + + case 77: +#line 788 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_COND, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.cond = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Cond); + ;} + break; + + case 78: +#line 792 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Stmt) = NULL; ;} + break; + + case 79: +#line 797 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Loop) = ast_mkLoop(L_LOOP_WHILE, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 80: +#line 801 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Loop) = ast_mkLoop(L_LOOP_DO, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (7))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (7))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (7))].yystate.yyloc)); + ;} + break; + + case 81: +#line 805 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Loop) = ast_mkLoop(L_LOOP_FOR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (6))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (6))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yyloc)); + ;} + break; + + case 82: +#line 809 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Loop) = ast_mkLoop(L_LOOP_FOR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yyloc)); + ;} + break; + + case 83: +#line 816 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).ForEach) = ast_mkForeach((((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (9))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (9))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (9))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((9) - (9))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (9))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((9) - (9))].yystate.yyloc)); + unless (isid((((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (9))].yystate.yysemantics.yysval.Expr), "in")) { + L_synerr2("syntax error -- expected 'in' in foreach", + (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (9))].yystate.yyloc).beg); + } + ;} + break; + + case 84: +#line 824 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).ForEach) = ast_mkForeach((((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (7))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yyloc)); + unless (isid((((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (7))].yystate.yysemantics.yysval.Expr), "in")) { + L_synerr2("syntax error -- expected 'in' in foreach", + (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (7))].yystate.yyloc).beg); + } + ;} + break; + + case 85: +#line 834 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Expr) = NULL; ;} + break; + + case 88: +#line 840 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Stmt) = NULL; ;} + break; + + case 89: +#line 845 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Stmt)); + ((*yyvalp).Stmt) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Stmt); + ;} + break; + + case 90: +#line 850 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Stmt)) { + REVERSE(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Stmt)); + APPEND(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Stmt)); + ((*yyvalp).Stmt) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Stmt); + } else { + // Empty stmt. + ((*yyvalp).Stmt) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Stmt); + } + ;} + break; + + case 91: +#line 864 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl)); + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + } + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl); + /* + * Special case a parameter list of "void" -- a single + * formal of type void with no arg name. This really + * means there are no args. + */ + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl) && !(((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl)->next && !(((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl)->id && ((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.VarDecl)->type == L_void)) { + ((*yyvalp).VarDecl) = NULL; + } + ;} + break; + + case 92: +#line 880 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).VarDecl) = NULL; ;} + break; + + case 94: +#line 886 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc); + ;} + break; + + case 95: +#line 895 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl)) { + L_set_declBaseType((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Type)); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl); + } else { + ((*yyvalp).VarDecl) = ast_mkVarDecl((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Type), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc)); + if (isnameoftype((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Type))) ((*yyvalp).VarDecl)->flags |= DECL_REF; + } + ((*yyvalp).VarDecl)->flags |= (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.i); + ((*yyvalp).VarDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc); + ;} + break; + + case 96: +#line 907 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Type *t = type_mkArray(NULL, L_poly); + ((*yyvalp).VarDecl) = ast_mkVarDecl(t, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).VarDecl)->flags |= (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.i) | DECL_REST_ARG; + ;} + break; + + case 97: +#line 915 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.i) | DECL_ARGUSED; ;} + break; + + case 98: +#line 916 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.i) | DECL_OPTIONAL; ;} + break; + + case 99: +#line 917 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.i) | DECL_NAME_EQUIV; ;} + break; + + case 100: +#line 918 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = 0; ;} + break; + + case 103: +#line 925 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + ;} + break; + + case 104: +#line 931 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc).end; + ;} + break; + + case 105: +#line 937 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc).end; + ;} + break; + + case 106: +#line 943 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc).end; + ;} + break; + + case 107: +#line 960 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + char *s = cksprintf("-%s", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.s)); + ((*yyvalp).Expr) = ast_mkConst(L_string, s, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.s)); + ;} + break; + + case 108: +#line 966 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + char *s = cksprintf("-default"); + ((*yyvalp).Expr) = ast_mkConst(L_string, s, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 109: +#line 974 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc); + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc).end; + ;} + break; + + case 110: +#line 980 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // This is a binop where an arg is a Type*. + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_CAST, (Expr *)(((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yysemantics.yysval.Type), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 111: +#line 985 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_EXPAND, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 112: +#line 989 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_BANG, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 113: +#line 993 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_BITNOT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 114: +#line 997 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_ADDROF, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 115: +#line 1001 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_UMINUS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 116: +#line 1005 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_UPLUS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 117: +#line 1009 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_PLUSPLUS_PRE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 118: +#line 1013 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_MINUSMINUS_PRE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 119: +#line 1017 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_PLUSPLUS_POST, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 120: +#line 1021 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_MINUSMINUS_POST, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 121: +#line 1025 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQTWID, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 122: +#line 1029 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_BANGTWID, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 123: +#line 1033 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if (strchr((((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.s), 'i')) (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr)->flags |= L_EXPR_RE_I; + if (strchr((((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.s), 'g')) (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr)->flags |= L_EXPR_RE_G; + ((*yyvalp).Expr) = ast_mkTrinOp(L_OP_EQTWID, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.s)); + ;} + break; + + case 124: +#line 1040 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STAR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 125: +#line 1044 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_SLASH, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 126: +#line 1048 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_PERC, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 127: +#line 1052 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_PLUS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 128: +#line 1056 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_MINUS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 129: +#line 1060 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STR_EQ, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 130: +#line 1064 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STR_NE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 131: +#line 1068 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STR_LT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 132: +#line 1072 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STR_LE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 133: +#line 1076 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STR_GT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 134: +#line 1080 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_STR_GE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 135: +#line 1084 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALEQUAL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 136: +#line 1088 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALEQUAL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (6))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (6))].yystate.yyloc)); + ;} + break; + + case 137: +#line 1092 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_NOTEQUAL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 138: +#line 1096 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_GREATER, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 139: +#line 1100 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_GREATEREQ, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 140: +#line 1104 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_LESSTHAN, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 141: +#line 1108 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_LESSTHANEQ, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 142: +#line 1112 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_ANDAND, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 143: +#line 1116 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_OROR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 144: +#line 1120 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_LSHIFT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 145: +#line 1124 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_RSHIFT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 146: +#line 1128 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_BITOR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 147: +#line 1132 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_BITAND, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 148: +#line 1136 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_BITXOR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 152: +#line 1143 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkConst(L_int, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 153: +#line 1147 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkConst(L_float, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 154: +#line 1151 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = ast_mkFnCall((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 155: +#line 1156 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkFnCall((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 156: +#line 1160 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *id = ast_mkId("string", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc)); + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = ast_mkFnCall(id, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 157: +#line 1166 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *id = ast_mkId("split", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc)); + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (7))].yystate.yysemantics.yysval.Expr)); + (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (7))].yystate.yysemantics.yysval.Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((6) - (7))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr) = ast_mkFnCall(id, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (7))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (7))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((7) - (7))].yystate.yyloc)); + ;} + break; + + case 158: +#line 1180 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *id = ast_mkId("split", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc)); + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = ast_mkFnCall(id, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 159: +#line 1187 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Expr, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = ast_mkFnCall((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 160: +#line 1192 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkFnCall((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 161: +#line 1196 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQUALS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 162: +#line 1200 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQPLUS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 163: +#line 1204 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQMINUS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 164: +#line 1208 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQSTAR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 165: +#line 1212 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQSLASH, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 166: +#line 1216 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQPERC, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 167: +#line 1220 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQBITAND, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 168: +#line 1224 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQBITOR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 169: +#line 1228 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQBITXOR, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 170: +#line 1232 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQLSHIFT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 171: +#line 1236 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQRSHIFT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 172: +#line 1240 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_EQDOT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 173: +#line 1244 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_DEFINED, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 174: +#line 1248 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_ARRAY_INDEX, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 175: +#line 1252 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_HASH_INDEX, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 176: +#line 1256 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_CONCAT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 177: +#line 1260 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_DOT, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Expr)->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s); + ;} + break; + + case 178: +#line 1265 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_POINTS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Expr)->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s); + ;} + break; + + case 179: +#line 1270 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // This is a binop where an arg is a Type*. + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_CLASS_INDEX, (Expr *)(((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Typename).t, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Expr)->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s); + ;} + break; + + case 180: +#line 1276 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + // This is a binop where an arg is a Type*. + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_CLASS_INDEX, (Expr *)(((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Typename).t, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Expr)->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s); + ;} + break; + + case 181: +#line 1282 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_COMMA, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 182: +#line 1286 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkTrinOp(L_OP_ARRAY_SLICE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (6))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (6))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (6))].yystate.yyloc)); + ;} + break; + + case 183: +#line 1294 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc); + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc).end; + L_scope_leave(); + ;} + break; + + case 184: +#line 1301 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_LIST, NULL, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 185: +#line 1305 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkTrinOp(L_OP_TERNARY_COND, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ;} + break; + + case 186: +#line 1309 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_FILE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 187: +#line 1313 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_FILE, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 188: +#line 1319 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { L_lex_begReArg(0); ;} + break; + + case 189: +#line 1323 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { L_lex_begReArg(1); ;} + break; + + case 190: +#line 1328 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkId((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s)); + ;} + break; + + case 192: +#line 1337 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr); + ((*yyvalp).Expr)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc).end; + ;} + break; + + case 193: +#line 1346 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_BLOCK, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.block = ast_mkBlock(NULL, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + L_scope_leave(); + ;} + break; + + case 194: +#line 1352 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Stmt)); + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_BLOCK, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.block = ast_mkBlock(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + L_scope_leave(); + ;} + break; + + case 195: +#line 1359 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.VarDecl)); + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + } + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_BLOCK, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.block = ast_mkBlock((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.VarDecl), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + L_scope_leave(); + ;} + break; + + case 196: +#line 1370 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.VarDecl)); + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + } + REVERSE(Stmt, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Stmt)); + ((*yyvalp).Stmt) = ast_mkStmt(L_STMT_BLOCK, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ((*yyvalp).Stmt)->u.block = ast_mkBlock((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (5))].yystate.yysemantics.yysval.VarDecl), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.Stmt), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + L_scope_leave(); + ;} + break; + + case 197: +#line 1384 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { L_scope_enter(); ;} + break; + + case 199: +#line 1390 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* + * Each declaration is a list of declarators. Here we + * append the lists. + */ + APPEND(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.VarDecl)); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); + ;} + break; + + case 201: +#line 1403 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + v->flags |= (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.i); + } + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc); + ;} + break; + + case 202: +#line 1414 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = DECL_PRIVATE; ;} + break; + + case 203: +#line 1415 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = DECL_PUBLIC; ;} + break; + + case 204: +#line 1416 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).i) = DECL_EXTERN; ;} + break; + + case 205: +#line 1421 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* Don't REVERSE $2; it's done as part of declaration_list. */ + VarDecl *v; + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + L_set_declBaseType(v, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type)); + } + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); + ;} + break; + + case 207: +#line 1434 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl); + ;} + break; + + case 209: +#line 1443 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl)->next = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.VarDecl); + ;} + break; + + case 211: +#line 1452 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.VarDecl)->initializer = ast_mkBinOp(L_OP_EQUALS, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.VarDecl)->id, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc).end; + ;} + break; + + case 213: +#line 1461 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).VarDecl) = NULL; ;} + break; + + case 214: +#line 1466 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).VarDecl) = ast_mkVarDecl((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 215: +#line 1470 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *id = ast_mkId((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Typename).s, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + ((*yyvalp).VarDecl) = ast_mkVarDecl((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type), id, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + if (isnameoftype((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Typename).t)) ((*yyvalp).VarDecl)->flags |= DECL_REF; + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Typename).s); + ;} + break; + + case 216: +#line 1477 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Type *t = type_mkNameOf((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Type)); + ((*yyvalp).VarDecl) = ast_mkVarDecl(t, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).VarDecl)->flags |= DECL_REF; + ;} + break; + + case 217: +#line 1483 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Type *tf = type_mkFunc(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl)); + Type *tn = type_mkNameOf(tf); + ((*yyvalp).VarDecl) = ast_mkVarDecl(tn, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (5))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (5))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((5) - (5))].yystate.yyloc)); + ((*yyvalp).VarDecl)->flags |= DECL_REF; + ;} + break; + + case 218: +#line 1494 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Type) = NULL; + ;} + break; + + case 219: +#line 1498 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Type) = type_mkArray((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Type)); + ;} + break; + + case 220: +#line 1502 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Type) = type_mkArray(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Type)); + ;} + break; + + case 221: +#line 1506 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Type) = type_mkHash((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yysemantics.yysval.Type), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yysemantics.yysval.Type)); + ;} + break; + + case 222: +#line 1513 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type)) { + L_set_baseType((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type)); + ((*yyvalp).Type) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type); + } else { + ((*yyvalp).Type) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type); + } + ;} + break; + + case 223: +#line 1522 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + if ((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type)) { + L_set_baseType((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type)); + ((*yyvalp).Type) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.Type); + } else { + ((*yyvalp).Type) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type); + } + ;} + break; + + case 224: +#line 1533 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = L_string; ;} + break; + + case 225: +#line 1534 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = L_int; ;} + break; + + case 226: +#line 1535 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = L_float; ;} + break; + + case 227: +#line 1536 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = L_poly; ;} + break; + + case 228: +#line 1537 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = L_widget; ;} + break; + + case 229: +#line 1538 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = L_void; ;} + break; + + case 230: +#line 1539 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).Type) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Typename).t; ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Typename).s); ;} + break; + + case 231: +#line 1544 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl)); + ((*yyvalp).Type) = L_struct_store((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (5))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (5))].yystate.yysemantics.yysval.VarDecl)); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (5))].yystate.yysemantics.yysval.s)); + ;} + break; + + case 232: +#line 1550 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + REVERSE(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.VarDecl)); + (void)L_struct_store(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.VarDecl)); // to sanity check member types + ((*yyvalp).Type) = type_mkStruct(NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.VarDecl)); + ;} + break; + + case 233: +#line 1556 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Type) = L_struct_lookup((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), FALSE); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s)); + ;} + break; + + case 235: +#line 1565 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + APPEND(VarDecl, next, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.VarDecl)); + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + ;} + break; + + case 236: +#line 1573 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { ((*yyvalp).VarDecl)->node.loc.end = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc).end; ;} + break; + + case 237: +#line 1578 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + VarDecl *v; + for (v = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); v; v = v->next) { + L_set_declBaseType(v, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Type)); + } + ((*yyvalp).VarDecl) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.VarDecl); + ((*yyvalp).VarDecl)->node.loc = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc); + ;} + break; + + case 239: +#line 1591 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + APPEND(Expr, b, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr)); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr); + ;} + break; + + case 241: +#line 1600 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_LIST, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.Expr), NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 242: +#line 1604 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *kv = ast_mkBinOp(L_OP_KV, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_LIST, kv, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 243: +#line 1612 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 244: +#line 1616 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *right = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_STRING, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), right, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 245: +#line 1621 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *right = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_STRING, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), right, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 246: +#line 1629 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *left = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc)); + Expr *right = ast_mkUnOp(L_OP_CMDSUBST, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + right->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_STRING, left, right, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 247: +#line 1636 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *middle = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yyloc)); + Expr *right = ast_mkUnOp(L_OP_CMDSUBST, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + right->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s); + ((*yyvalp).Expr) = ast_mkTrinOp(L_OP_INTERP_STRING, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.Expr), middle, right, + (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 248: +#line 1647 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_CMDSUBST, NULL, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ((*yyvalp).Expr)->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s); + ;} + break; + + case 249: +#line 1652 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkUnOp(L_OP_CMDSUBST, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Expr)->str = (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s); + ;} + break; + + case 250: +#line 1660 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkRegexp((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 251: +#line 1664 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *right = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_RE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), right, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 252: +#line 1672 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + /* Note: the scanner catches illegal modifiers. */ + if (strchr((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), 'i')) (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr)->flags |= L_EXPR_RE_I; + if (strchr((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), 'g')) (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr)->flags |= L_EXPR_RE_G; + if (strchr((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), 'l')) (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr)->flags |= L_EXPR_RE_L; + if (strchr((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), 't')) (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr)->flags |= L_EXPR_RE_T; + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s)); + ((*yyvalp).Expr) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr); + ;} + break; + + case 253: +#line 1685 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 254: +#line 1689 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *right = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_RE, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yysemantics.yysval.Expr), right, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (2))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yyloc)); + ;} + break; + + case 255: +#line 1697 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *left = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_STRING, left, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 256: +#line 1702 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *middle = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkTrinOp(L_OP_INTERP_STRING, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr), middle, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 257: +#line 1710 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *left = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkBinOp(L_OP_INTERP_STRING, left, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (3))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yyloc)); + ;} + break; + + case 258: +#line 1715 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Expr *middle = ast_mkConst(L_string, (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yysemantics.yysval.s), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (4))].yystate.yyloc)); + ((*yyvalp).Expr) = ast_mkTrinOp(L_OP_INTERP_STRING, (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yysemantics.yysval.Expr), middle, (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (4))].yystate.yysemantics.yysval.Expr), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (4))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((4) - (4))].yystate.yyloc)); + ;} + break; + + case 259: +#line 1723 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkId(".", (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + ;} + break; + + case 260: +#line 1727 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).Expr) = ast_mkId(Tcl_GetString((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.obj)), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc), (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yyloc)); + Tcl_DecrRefCount((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (1))].yystate.yysemantics.yysval.obj)); + ;} + break; + + case 261: +#line 1735 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + ((*yyvalp).obj) = Tcl_NewObj(); + Tcl_IncrRefCount(((*yyvalp).obj)); + Tcl_AppendToObj(((*yyvalp).obj), ".", 1); + Tcl_AppendToObj(((*yyvalp).obj), (((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s), -1); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((2) - (2))].yystate.yysemantics.yysval.s)); + ;} + break; + + case 262: +#line 1743 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + { + Tcl_AppendToObj((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.obj), ".", 1); + Tcl_AppendToObj((((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.obj), (((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s), -1); + ((*yyvalp).obj) = (((yyGLRStackItem const *)yyvsp)[YYFILL ((1) - (3))].yystate.yysemantics.yysval.obj); + ckfree((((yyGLRStackItem const *)yyvsp)[YYFILL ((3) - (3))].yystate.yysemantics.yysval.s)); + ;} + break; + + +/* Line 930 of glr.c. */ +#line 4767 "Lgrammar.c" + default: break; + } + + return yyok; +# undef yyerrok +# undef YYABORT +# undef YYACCEPT +# undef YYERROR +# undef YYBACKUP +# undef yyclearin +# undef YYRECOVERING +} + + +/*ARGSUSED*/ static void +yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) +{ + YYUSE (yy0); + YYUSE (yy1); + + switch (yyn) + { + + default: break; + } +} + + /* Bison grammar-table manipulation. */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp) +{ + YYUSE (yyvaluep); + YYUSE (yylocationp); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + +/** Number of symbols composing the right hand side of rule #RULE. */ +static inline int +yyrhsLength (yyRuleNum yyrule) +{ + return yyr2[yyrule]; +} + +static void +yydestroyGLRState (char const *yymsg, yyGLRState *yys) +{ + if (yys->yyresolved) + yydestruct (yymsg, yystos[yys->yylrState], + &yys->yysemantics.yysval, &yys->yyloc); + else + { +#if YYDEBUG + if (yydebug) + { + if (yys->yysemantics.yyfirstVal) + YYFPRINTF (stderr, "%s unresolved ", yymsg); + else + YYFPRINTF (stderr, "%s incomplete ", yymsg); + yy_symbol_print (stderr, yystos[yys->yylrState], + NULL, &yys->yyloc); + YYFPRINTF (stderr, "\n"); + } +#endif + + if (yys->yysemantics.yyfirstVal) + { + yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; + yyGLRState *yyrh; + int yyn; + for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); + yyn > 0; + yyrh = yyrh->yypred, yyn -= 1) + yydestroyGLRState (yymsg, yyrh); + } + } +} + +/** Left-hand-side symbol for rule #RULE. */ +static inline yySymbol +yylhsNonterm (yyRuleNum yyrule) +{ + return yyr1[yyrule]; +} + +#define yyis_pact_ninf(yystate) \ + ((yystate) == YYPACT_NINF) + +/** True iff LR state STATE has only a default reduction (regardless + * of token). */ +static inline yybool +yyisDefaultedState (yyStateNum yystate) +{ + return yyis_pact_ninf (yypact[yystate]); +} + +/** The default reduction for STATE, assuming it has one. */ +static inline yyRuleNum +yydefaultAction (yyStateNum yystate) +{ + return yydefact[yystate]; +} + +#define yyis_table_ninf(yytable_value) \ + YYID (0) + +/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. + * Result R means + * R < 0: Reduce on rule -R. + * R = 0: Error. + * R > 0: Shift to state R. + * Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of + * conflicting reductions. + */ +static inline void +yygetLRActions (yyStateNum yystate, int yytoken, + int* yyaction, const short int** yyconflicts) +{ + int yyindex = yypact[yystate] + yytoken; + if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) + { + *yyaction = -yydefact[yystate]; + *yyconflicts = yyconfl; + } + else if (! yyis_table_ninf (yytable[yyindex])) + { + *yyaction = yytable[yyindex]; + *yyconflicts = yyconfl + yyconflp[yyindex]; + } + else + { + *yyaction = 0; + *yyconflicts = yyconfl + yyconflp[yyindex]; + } +} + +static inline yyStateNum +yyLRgotoState (yyStateNum yystate, yySymbol yylhs) +{ + int yyr; + yyr = yypgoto[yylhs - YYNTOKENS] + yystate; + if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) + return yytable[yyr]; + else + return yydefgoto[yylhs - YYNTOKENS]; +} + +static inline yybool +yyisShiftAction (int yyaction) +{ + return 0 < yyaction; +} + +static inline yybool +yyisErrorAction (int yyaction) +{ + return yyaction == 0; +} + + /* GLRStates */ + +/** Return a fresh GLRStackItem. Callers should call + * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient + * headroom. */ + +static inline yyGLRStackItem* +yynewGLRStackItem (yyGLRStack* yystackp, yybool yyisState) +{ + yyGLRStackItem* yynewItem = yystackp->yynextFree; + yystackp->yyspaceLeft -= 1; + yystackp->yynextFree += 1; + yynewItem->yystate.yyisState = yyisState; + return yynewItem; +} + +/** Add a new semantic action that will execute the action for rule + * RULENUM on the semantic values in RHS to the list of + * alternative actions for STATE. Assumes that RHS comes from + * stack #K of *STACKP. */ +static void +yyaddDeferredAction (yyGLRStack* yystackp, size_t yyk, yyGLRState* yystate, + yyGLRState* rhs, yyRuleNum yyrule) +{ + yySemanticOption* yynewOption = + &yynewGLRStackItem (yystackp, yyfalse)->yyoption; + yynewOption->yystate = rhs; + yynewOption->yyrule = yyrule; + if (yystackp->yytops.yylookaheadNeeds[yyk]) + { + yynewOption->yyrawchar = yychar; + yynewOption->yyval = yylval; + yynewOption->yyloc = yylloc; + } + else + yynewOption->yyrawchar = YYEMPTY; + yynewOption->yynext = yystate->yysemantics.yyfirstVal; + yystate->yysemantics.yyfirstVal = yynewOption; + + YY_RESERVE_GLRSTACK (yystackp); +} + + /* GLRStacks */ + +/** Initialize SET to a singleton set containing an empty stack. */ +static yybool +yyinitStateSet (yyGLRStateSet* yyset) +{ + yyset->yysize = 1; + yyset->yycapacity = 16; + yyset->yystates = (yyGLRState**) YYMALLOC (16 * sizeof yyset->yystates[0]); + if (! yyset->yystates) + return yyfalse; + yyset->yystates[0] = NULL; + yyset->yylookaheadNeeds = + (yybool*) YYMALLOC (16 * sizeof yyset->yylookaheadNeeds[0]); + if (! yyset->yylookaheadNeeds) + { + YYFREE (yyset->yystates); + return yyfalse; + } + return yytrue; +} + +static void yyfreeStateSet (yyGLRStateSet* yyset) +{ + YYFREE (yyset->yystates); + YYFREE (yyset->yylookaheadNeeds); +} + +/** Initialize STACK to a single empty stack, with total maximum + * capacity for all stacks of SIZE. */ +static yybool +yyinitGLRStack (yyGLRStack* yystackp, size_t yysize) +{ + yystackp->yyerrState = 0; + yynerrs = 0; + yystackp->yyspaceLeft = yysize; + yystackp->yyitems = + (yyGLRStackItem*) YYMALLOC (yysize * sizeof yystackp->yynextFree[0]); + if (!yystackp->yyitems) + return yyfalse; + yystackp->yynextFree = yystackp->yyitems; + yystackp->yysplitPoint = NULL; + yystackp->yylastDeleted = NULL; + return yyinitStateSet (&yystackp->yytops); +} + + +#if YYSTACKEXPANDABLE +# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ + &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE + +/** If STACK is expandable, extend it. WARNING: Pointers into the + stack from outside should be considered invalid after this call. + We always expand when there are 1 or fewer items left AFTER an + allocation, so that we can avoid having external pointers exist + across an allocation. */ +static void +yyexpandGLRStack (yyGLRStack* yystackp) +{ + yyGLRStackItem* yynewItems; + yyGLRStackItem* yyp0, *yyp1; + size_t yysize, yynewSize; + size_t yyn; + yysize = yystackp->yynextFree - yystackp->yyitems; + if (YYMAXDEPTH - YYHEADROOM < yysize) + yyMemoryExhausted (yystackp); + yynewSize = 2*yysize; + if (YYMAXDEPTH < yynewSize) + yynewSize = YYMAXDEPTH; + yynewItems = (yyGLRStackItem*) YYMALLOC (yynewSize * sizeof yynewItems[0]); + if (! yynewItems) + yyMemoryExhausted (yystackp); + for (yyp0 = yystackp->yyitems, yyp1 = yynewItems, yyn = yysize; + 0 < yyn; + yyn -= 1, yyp0 += 1, yyp1 += 1) + { + *yyp1 = *yyp0; + if (*(yybool *) yyp0) + { + yyGLRState* yys0 = &yyp0->yystate; + yyGLRState* yys1 = &yyp1->yystate; + if (yys0->yypred != NULL) + yys1->yypred = + YYRELOC (yyp0, yyp1, yys0->yypred, yystate); + if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL) + yys1->yysemantics.yyfirstVal = + YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption); + } + else + { + yySemanticOption* yyv0 = &yyp0->yyoption; + yySemanticOption* yyv1 = &yyp1->yyoption; + if (yyv0->yystate != NULL) + yyv1->yystate = YYRELOC (yyp0, yyp1, yyv0->yystate, yystate); + if (yyv0->yynext != NULL) + yyv1->yynext = YYRELOC (yyp0, yyp1, yyv0->yynext, yyoption); + } + } + if (yystackp->yysplitPoint != NULL) + yystackp->yysplitPoint = YYRELOC (yystackp->yyitems, yynewItems, + yystackp->yysplitPoint, yystate); + + for (yyn = 0; yyn < yystackp->yytops.yysize; yyn += 1) + if (yystackp->yytops.yystates[yyn] != NULL) + yystackp->yytops.yystates[yyn] = + YYRELOC (yystackp->yyitems, yynewItems, + yystackp->yytops.yystates[yyn], yystate); + YYFREE (yystackp->yyitems); + yystackp->yyitems = yynewItems; + yystackp->yynextFree = yynewItems + yysize; + yystackp->yyspaceLeft = yynewSize - yysize; +} +#endif + +static void +yyfreeGLRStack (yyGLRStack* yystackp) +{ + YYFREE (yystackp->yyitems); + yyfreeStateSet (&yystackp->yytops); +} + +/** Assuming that S is a GLRState somewhere on STACK, update the + * splitpoint of STACK, if needed, so that it is at least as deep as + * S. */ +static inline void +yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys) +{ + if (yystackp->yysplitPoint != NULL && yystackp->yysplitPoint > yys) + yystackp->yysplitPoint = yys; +} + +/** Invalidate stack #K in STACK. */ +static inline void +yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk) +{ + if (yystackp->yytops.yystates[yyk] != NULL) + yystackp->yylastDeleted = yystackp->yytops.yystates[yyk]; + yystackp->yytops.yystates[yyk] = NULL; +} + +/** Undelete the last stack that was marked as deleted. Can only be + done once after a deletion, and only when all other stacks have + been deleted. */ +static void +yyundeleteLastStack (yyGLRStack* yystackp) +{ + if (yystackp->yylastDeleted == NULL || yystackp->yytops.yysize != 0) + return; + yystackp->yytops.yystates[0] = yystackp->yylastDeleted; + yystackp->yytops.yysize = 1; + YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n")); + yystackp->yylastDeleted = NULL; +} + +static inline void +yyremoveDeletes (yyGLRStack* yystackp) +{ + size_t yyi, yyj; + yyi = yyj = 0; + while (yyj < yystackp->yytops.yysize) + { + if (yystackp->yytops.yystates[yyi] == NULL) + { + if (yyi == yyj) + { + YYDPRINTF ((stderr, "Removing dead stacks.\n")); + } + yystackp->yytops.yysize -= 1; + } + else + { + yystackp->yytops.yystates[yyj] = yystackp->yytops.yystates[yyi]; + /* In the current implementation, it's unnecessary to copy + yystackp->yytops.yylookaheadNeeds[yyi] since, after + yyremoveDeletes returns, the parser immediately either enters + deterministic operation or shifts a token. However, it doesn't + hurt, and the code might evolve to need it. */ + yystackp->yytops.yylookaheadNeeds[yyj] = + yystackp->yytops.yylookaheadNeeds[yyi]; + if (yyj != yyi) + { + YYDPRINTF ((stderr, "Rename stack %lu -> %lu.\n", + (unsigned long int) yyi, (unsigned long int) yyj)); + } + yyj += 1; + } + yyi += 1; + } +} + +/** Shift to a new state on stack #K of STACK, corresponding to LR state + * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */ +static inline void +yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, + size_t yyposn, + YYSTYPE* yyvalp, YYLTYPE* yylocp) +{ + yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yytrue; + yynewState->yypred = yystackp->yytops.yystates[yyk]; + yynewState->yysemantics.yysval = *yyvalp; + yynewState->yyloc = *yylocp; + yystackp->yytops.yystates[yyk] = yynewState; + + YY_RESERVE_GLRSTACK (yystackp); +} + +/** Shift stack #K of YYSTACK, to a new state corresponding to LR + * state YYLRSTATE, at input position YYPOSN, with the (unresolved) + * semantic value of YYRHS under the action for YYRULE. */ +static inline void +yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, + size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule) +{ + yyGLRState* yynewState = &yynewGLRStackItem (yystackp, yytrue)->yystate; + + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yyfalse; + yynewState->yypred = yystackp->yytops.yystates[yyk]; + yynewState->yysemantics.yyfirstVal = NULL; + yystackp->yytops.yystates[yyk] = yynewState; + + /* Invokes YY_RESERVE_GLRSTACK. */ + yyaddDeferredAction (yystackp, yyk, yynewState, rhs, yyrule); +} + +/** Pop the symbols consumed by reduction #RULE from the top of stack + * #K of STACK, and perform the appropriate semantic action on their + * semantic values. Assumes that all ambiguities in semantic values + * have been previously resolved. Set *VALP to the resulting value, + * and *LOCP to the computed location (if any). Return value is as + * for userAction. */ +static inline YYRESULTTAG +yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, + YYSTYPE* yyvalp, YYLTYPE* yylocp) +{ + int yynrhs = yyrhsLength (yyrule); + + if (yystackp->yysplitPoint == NULL) + { + /* Standard special case: single stack. */ + yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; + YYASSERT (yyk == 0); + yystackp->yynextFree -= yynrhs; + yystackp->yyspaceLeft += yynrhs; + yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; + return yyuserAction (yyrule, yynrhs, rhs, + yyvalp, yylocp, yystackp); + } + else + { + /* At present, doAction is never called in nondeterministic + * mode, so this branch is never taken. It is here in + * anticipation of a future feature that will allow immediate + * evaluation of selected actions in nondeterministic mode. */ + int yyi; + yyGLRState* yys; + yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred + = yystackp->yytops.yystates[yyk]; + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc; + for (yyi = 0; yyi < yynrhs; yyi += 1) + { + yys = yys->yypred; + YYASSERT (yys); + } + yyupdateSplit (yystackp, yys); + yystackp->yytops.yystates[yyk] = yys; + return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yyvalp, yylocp, yystackp); + } +} + +#if !YYDEBUG +# define YY_REDUCE_PRINT(Args) +#else +# define YY_REDUCE_PRINT(Args) \ +do { \ + if (yydebug) \ + yy_reduce_print Args; \ +} while (YYID (0)) + +/*----------------------------------------------------------. +| Report that the RULE is going to be reduced on stack #K. | +`----------------------------------------------------------*/ + +/*ARGSUSED*/ static inline void +yy_reduce_print (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, + YYSTYPE* yyvalp, YYLTYPE* yylocp) +{ + int yynrhs = yyrhsLength (yyrule); + yybool yynormal __attribute__ ((__unused__)) = + (yystackp->yysplitPoint == NULL); + yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; + int yylow = 1; + int yyi; + YYUSE (yyvalp); + YYUSE (yylocp); + YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n", + (unsigned long int) yyk, yyrule - 1, + (unsigned long int) yyrline[yyrule]); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + fprintf (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(((yyGLRStackItem const *)yyvsp)[YYFILL ((yyi + 1) - (yynrhs))].yystate.yysemantics.yysval) + , &(((yyGLRStackItem const *)yyvsp)[YYFILL ((yyi + 1) - (yynrhs))].yystate.yyloc) ); + fprintf (stderr, "\n"); + } +} +#endif + +/** Pop items off stack #K of STACK according to grammar rule RULE, + * and push back on the resulting nonterminal symbol. Perform the + * semantic action associated with RULE and store its value with the + * newly pushed state, if FORCEEVAL or if STACK is currently + * unambiguous. Otherwise, store the deferred semantic action with + * the new state. If the new state would have an identical input + * position, LR state, and predecessor to an existing state on the stack, + * it is identified with that existing state, eliminating stack #K from + * the STACK. In this case, the (necessarily deferred) semantic value is + * added to the options for the existing state's semantic value. + */ +static inline YYRESULTTAG +yyglrReduce (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, + yybool yyforceEval) +{ + size_t yyposn = yystackp->yytops.yystates[yyk]->yyposn; + + if (yyforceEval || yystackp->yysplitPoint == NULL) + { + YYSTYPE yysval; + YYLTYPE yyloc; + + YY_REDUCE_PRINT ((yystackp, yyk, yyrule, &yysval, &yyloc)); + YYCHK (yydoAction (yystackp, yyk, yyrule, &yysval, + &yyloc)); + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc); + yyglrShift (yystackp, yyk, + yyLRgotoState (yystackp->yytops.yystates[yyk]->yylrState, + yylhsNonterm (yyrule)), + yyposn, &yysval, &yyloc); + } + else + { + size_t yyi; + int yyn; + yyGLRState* yys, *yys0 = yystackp->yytops.yystates[yyk]; + yyStateNum yynewLRState; + + for (yys = yystackp->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); + 0 < yyn; yyn -= 1) + { + yys = yys->yypred; + YYASSERT (yys); + } + yyupdateSplit (yystackp, yys); + yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule)); + YYDPRINTF ((stderr, + "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n", + (unsigned long int) yyk, yyrule - 1, yynewLRState)); + for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) + if (yyi != yyk && yystackp->yytops.yystates[yyi] != NULL) + { + yyGLRState* yyp, *yysplit = yystackp->yysplitPoint; + yyp = yystackp->yytops.yystates[yyi]; + while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn) + { + if (yyp->yylrState == yynewLRState && yyp->yypred == yys) + { + yyaddDeferredAction (yystackp, yyk, yyp, yys0, yyrule); + yymarkStackDeleted (yystackp, yyk); + YYDPRINTF ((stderr, "Merging stack %lu into stack %lu.\n", + (unsigned long int) yyk, + (unsigned long int) yyi)); + return yyok; + } + yyp = yyp->yypred; + } + } + yystackp->yytops.yystates[yyk] = yys; + yyglrShiftDefer (yystackp, yyk, yynewLRState, yyposn, yys0, yyrule); + } + return yyok; +} + +static size_t +yysplitStack (yyGLRStack* yystackp, size_t yyk) +{ + if (yystackp->yysplitPoint == NULL) + { + YYASSERT (yyk == 0); + yystackp->yysplitPoint = yystackp->yytops.yystates[yyk]; + } + if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity) + { + yyGLRState** yynewStates; + yybool* yynewLookaheadNeeds; + + yynewStates = NULL; + + if (yystackp->yytops.yycapacity + > (YYSIZEMAX / (2 * sizeof yynewStates[0]))) + yyMemoryExhausted (yystackp); + yystackp->yytops.yycapacity *= 2; + + yynewStates = + (yyGLRState**) YYREALLOC (yystackp->yytops.yystates, + (yystackp->yytops.yycapacity + * sizeof yynewStates[0])); + if (yynewStates == NULL) + yyMemoryExhausted (yystackp); + yystackp->yytops.yystates = yynewStates; + + yynewLookaheadNeeds = + (yybool*) YYREALLOC (yystackp->yytops.yylookaheadNeeds, + (yystackp->yytops.yycapacity + * sizeof yynewLookaheadNeeds[0])); + if (yynewLookaheadNeeds == NULL) + yyMemoryExhausted (yystackp); + yystackp->yytops.yylookaheadNeeds = yynewLookaheadNeeds; + } + yystackp->yytops.yystates[yystackp->yytops.yysize] + = yystackp->yytops.yystates[yyk]; + yystackp->yytops.yylookaheadNeeds[yystackp->yytops.yysize] + = yystackp->yytops.yylookaheadNeeds[yyk]; + yystackp->yytops.yysize += 1; + return yystackp->yytops.yysize-1; +} + +/** True iff Y0 and Y1 represent identical options at the top level. + * That is, they represent the same rule applied to RHS symbols + * that produce the same terminal symbols. */ +static yybool +yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1) +{ + if (yyy0->yyrule == yyy1->yyrule) + { + yyGLRState *yys0, *yys1; + int yyn; + for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, + yyn = yyrhsLength (yyy0->yyrule); + yyn > 0; + yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) + if (yys0->yyposn != yys1->yyposn) + return yyfalse; + return yytrue; + } + else + return yyfalse; +} + +/** Assuming identicalOptions (Y0,Y1), destructively merge the + * alternative semantic values for the RHS-symbols of Y1 and Y0. */ +static void +yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1) +{ + yyGLRState *yys0, *yys1; + int yyn; + for (yys0 = yyy0->yystate, yys1 = yyy1->yystate, + yyn = yyrhsLength (yyy0->yyrule); + yyn > 0; + yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1) + { + if (yys0 == yys1) + break; + else if (yys0->yyresolved) + { + yys1->yyresolved = yytrue; + yys1->yysemantics.yysval = yys0->yysemantics.yysval; + } + else if (yys1->yyresolved) + { + yys0->yyresolved = yytrue; + yys0->yysemantics.yysval = yys1->yysemantics.yysval; + } + else + { + yySemanticOption** yyz0p; + yySemanticOption* yyz1; + yyz0p = &yys0->yysemantics.yyfirstVal; + yyz1 = yys1->yysemantics.yyfirstVal; + while (YYID (yytrue)) + { + if (yyz1 == *yyz0p || yyz1 == NULL) + break; + else if (*yyz0p == NULL) + { + *yyz0p = yyz1; + break; + } + else if (*yyz0p < yyz1) + { + yySemanticOption* yyz = *yyz0p; + *yyz0p = yyz1; + yyz1 = yyz1->yynext; + (*yyz0p)->yynext = yyz; + } + yyz0p = &(*yyz0p)->yynext; + } + yys1->yysemantics.yyfirstVal = yys0->yysemantics.yyfirstVal; + } + } +} + +/** Y0 and Y1 represent two possible actions to take in a given + * parsing state; return 0 if no combination is possible, + * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ +static int +yypreference (yySemanticOption* y0, yySemanticOption* y1) +{ + yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule; + int p0 = yydprec[r0], p1 = yydprec[r1]; + + if (p0 == p1) + { + if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) + return 0; + else + return 1; + } + if (p0 == 0 || p1 == 0) + return 0; + if (p0 < p1) + return 3; + if (p1 < p0) + return 2; + return 0; +} + +static YYRESULTTAG yyresolveValue (yyGLRState* yys, + yyGLRStack* yystackp); + + +/** Resolve the previous N states starting at and including state S. If result + * != yyok, some states may have been left unresolved possibly with empty + * semantic option chains. Regardless of whether result = yyok, each state + * has been left with consistent data so that yydestroyGLRState can be invoked + * if necessary. */ +static YYRESULTTAG +yyresolveStates (yyGLRState* yys, int yyn, + yyGLRStack* yystackp) +{ + if (0 < yyn) + { + YYASSERT (yys->yypred); + YYCHK (yyresolveStates (yys->yypred, yyn-1, yystackp)); + if (! yys->yyresolved) + YYCHK (yyresolveValue (yys, yystackp)); + } + return yyok; +} + +/** Resolve the states for the RHS of OPT, perform its user action, and return + * the semantic value and location. Regardless of whether result = yyok, all + * RHS states have been destroyed (assuming the user action destroys all RHS + * semantic values if invoked). */ +static YYRESULTTAG +yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystackp, + YYSTYPE* yyvalp, YYLTYPE* yylocp) +{ + yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; + int yynrhs; + int yychar_current; + YYSTYPE yylval_current; + YYLTYPE yylloc_current; + YYRESULTTAG yyflag; + + yynrhs = yyrhsLength (yyopt->yyrule); + yyflag = yyresolveStates (yyopt->yystate, yynrhs, yystackp); + if (yyflag != yyok) + { + yyGLRState *yys; + for (yys = yyopt->yystate; yynrhs > 0; yys = yys->yypred, yynrhs -= 1) + yydestroyGLRState ("Cleanup: popping", yys); + return yyflag; + } + + yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate; + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc; + yychar_current = yychar; + yylval_current = yylval; + yylloc_current = yylloc; + yychar = yyopt->yyrawchar; + yylval = yyopt->yyval; + yylloc = yyopt->yyloc; + yyflag = yyuserAction (yyopt->yyrule, yynrhs, + yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, + yyvalp, yylocp, yystackp); + yychar = yychar_current; + yylval = yylval_current; + yylloc = yylloc_current; + return yyflag; +} + +#if YYDEBUG +static void +yyreportTree (yySemanticOption* yyx, int yyindent) +{ + int yynrhs = yyrhsLength (yyx->yyrule); + int yyi; + yyGLRState* yys; + yyGLRState* yystates[1 + YYMAXRHS]; + yyGLRState yyleftmost_state; + + for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred) + yystates[yyi] = yys; + if (yys == NULL) + { + yyleftmost_state.yyposn = 0; + yystates[0] = &yyleftmost_state; + } + else + yystates[0] = yys; + + if (yyx->yystate->yyposn < yys->yyposn + 1) + YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n", + yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), + yyx->yyrule - 1); + else + YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %lu .. %lu>\n", + yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), + yyx->yyrule - 1, (unsigned long int) (yys->yyposn + 1), + (unsigned long int) yyx->yystate->yyposn); + for (yyi = 1; yyi <= yynrhs; yyi += 1) + { + if (yystates[yyi]->yyresolved) + { + if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) + YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "", + yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1])); + else + YYFPRINTF (stderr, "%*s%s <tokens %lu .. %lu>\n", yyindent+2, "", + yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]), + (unsigned long int) (yystates[yyi - 1]->yyposn + 1), + (unsigned long int) yystates[yyi]->yyposn); + } + else + yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2); + } +} +#endif + +/*ARGSUSED*/ static YYRESULTTAG +yyreportAmbiguity (yySemanticOption* yyx0, + yySemanticOption* yyx1) +{ + YYUSE (yyx0); + YYUSE (yyx1); + +#if YYDEBUG + YYFPRINTF (stderr, "Ambiguity detected.\n"); + YYFPRINTF (stderr, "Option 1,\n"); + yyreportTree (yyx0, 2); + YYFPRINTF (stderr, "\nOption 2,\n"); + yyreportTree (yyx1, 2); + YYFPRINTF (stderr, "\n"); +#endif + + yyerror (YY_("syntax is ambiguous")); + return yyabort; +} + +/** Starting at and including state S1, resolve the location for each of the + * previous N1 states that is unresolved. The first semantic option of a state + * is always chosen. */ +static void +yyresolveLocations (yyGLRState* yys1, int yyn1, + yyGLRStack *yystackp) +{ + if (0 < yyn1) + { + yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp); + if (!yys1->yyresolved) + { + yySemanticOption *yyoption; + yyGLRStackItem yyrhsloc[1 + YYMAXRHS]; + int yynrhs; + int yychar_current; + YYSTYPE yylval_current; + YYLTYPE yylloc_current; + yyoption = yys1->yysemantics.yyfirstVal; + YYASSERT (yyoption != NULL); + yynrhs = yyrhsLength (yyoption->yyrule); + if (yynrhs > 0) + { + yyGLRState *yys; + int yyn; + yyresolveLocations (yyoption->yystate, yynrhs, + yystackp); + for (yys = yyoption->yystate, yyn = yynrhs; + yyn > 0; + yys = yys->yypred, yyn -= 1) + yyrhsloc[yyn].yystate.yyloc = yys->yyloc; + } + else + { + /* Both yyresolveAction and yyresolveLocations traverse the GSS + in reverse rightmost order. It is only necessary to invoke + yyresolveLocations on a subforest for which yyresolveAction + would have been invoked next had an ambiguity not been + detected. Thus the location of the previous state (but not + necessarily the previous state itself) is guaranteed to be + resolved already. */ + yyGLRState *yyprevious = yyoption->yystate; + yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; + } + yychar_current = yychar; + yylval_current = yylval; + yylloc_current = yylloc; + yychar = yyoption->yyrawchar; + yylval = yyoption->yyval; + yylloc = yyoption->yyloc; + YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs); + yychar = yychar_current; + yylval = yylval_current; + yylloc = yylloc_current; + } + } +} + +/** Resolve the ambiguity represented in state S, perform the indicated + * actions, and set the semantic value of S. If result != yyok, the chain of + * semantic options in S has been cleared instead or it has been left + * unmodified except that redundant options may have been removed. Regardless + * of whether result = yyok, S has been left with consistent data so that + * yydestroyGLRState can be invoked if necessary. */ +static YYRESULTTAG +yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp) +{ + yySemanticOption* yyoptionList = yys->yysemantics.yyfirstVal; + yySemanticOption* yybest; + yySemanticOption** yypp; + yybool yymerge; + YYSTYPE yysval; + YYRESULTTAG yyflag; + YYLTYPE *yylocp = &yys->yyloc; + + yybest = yyoptionList; + yymerge = yyfalse; + for (yypp = &yyoptionList->yynext; *yypp != NULL; ) + { + yySemanticOption* yyp = *yypp; + + if (yyidenticalOptions (yybest, yyp)) + { + yymergeOptionSets (yybest, yyp); + *yypp = yyp->yynext; + } + else + { + switch (yypreference (yybest, yyp)) + { + case 0: + yyresolveLocations (yys, 1, yystackp); + return yyreportAmbiguity (yybest, yyp); + break; + case 1: + yymerge = yytrue; + break; + case 2: + break; + case 3: + yybest = yyp; + yymerge = yyfalse; + break; + default: + /* This cannot happen so it is not worth a YYASSERT (yyfalse), + but some compilers complain if the default case is + omitted. */ + break; + } + yypp = &yyp->yynext; + } + } + + if (yymerge) + { + yySemanticOption* yyp; + int yyprec = yydprec[yybest->yyrule]; + yyflag = yyresolveAction (yybest, yystackp, &yysval, + yylocp); + if (yyflag == yyok) + for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext) + { + if (yyprec == yydprec[yyp->yyrule]) + { + YYSTYPE yysval_other; + YYLTYPE yydummy; + yyflag = yyresolveAction (yyp, yystackp, &yysval_other, + &yydummy); + if (yyflag != yyok) + { + yydestruct ("Cleanup: discarding incompletely merged value for", + yystos[yys->yylrState], + &yysval, yylocp); + break; + } + yyuserMerge (yymerger[yyp->yyrule], &yysval, &yysval_other); + } + } + } + else + yyflag = yyresolveAction (yybest, yystackp, &yysval, yylocp); + + if (yyflag == yyok) + { + yys->yyresolved = yytrue; + yys->yysemantics.yysval = yysval; + } + else + yys->yysemantics.yyfirstVal = NULL; + return yyflag; +} + +static YYRESULTTAG +yyresolveStack (yyGLRStack* yystackp) +{ + if (yystackp->yysplitPoint != NULL) + { + yyGLRState* yys; + int yyn; + + for (yyn = 0, yys = yystackp->yytops.yystates[0]; + yys != yystackp->yysplitPoint; + yys = yys->yypred, yyn += 1) + continue; + YYCHK (yyresolveStates (yystackp->yytops.yystates[0], yyn, yystackp + )); + } + return yyok; +} + +static void +yycompressStack (yyGLRStack* yystackp) +{ + yyGLRState* yyp, *yyq, *yyr; + + if (yystackp->yytops.yysize != 1 || yystackp->yysplitPoint == NULL) + return; + + for (yyp = yystackp->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL; + yyp != yystackp->yysplitPoint; + yyr = yyp, yyp = yyq, yyq = yyp->yypred) + yyp->yypred = yyr; + + yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; + yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1; + yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; + yystackp->yysplitPoint = NULL; + yystackp->yylastDeleted = NULL; + + while (yyr != NULL) + { + yystackp->yynextFree->yystate = *yyr; + yyr = yyr->yypred; + yystackp->yynextFree->yystate.yypred = &yystackp->yynextFree[-1].yystate; + yystackp->yytops.yystates[0] = &yystackp->yynextFree->yystate; + yystackp->yynextFree += 1; + yystackp->yyspaceLeft -= 1; + } +} + +static YYRESULTTAG +yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, + size_t yyposn) +{ + int yyaction; + const short int* yyconflicts; + yyRuleNum yyrule; + + while (yystackp->yytops.yystates[yyk] != NULL) + { + yyStateNum yystate = yystackp->yytops.yystates[yyk]->yylrState; + YYDPRINTF ((stderr, "Stack %lu Entering state %d\n", + (unsigned long int) yyk, yystate)); + + YYASSERT (yystate != YYFINAL); + + if (yyisDefaultedState (yystate)) + { + yyrule = yydefaultAction (yystate); + if (yyrule == 0) + { + YYDPRINTF ((stderr, "Stack %lu dies.\n", + (unsigned long int) yyk)); + yymarkStackDeleted (yystackp, yyk); + return yyok; + } + YYCHK (yyglrReduce (yystackp, yyk, yyrule, yyfalse)); + } + else + { + yySymbol yytoken; + yystackp->yytops.yylookaheadNeeds[yyk] = yytrue; + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + else + yytoken = YYTRANSLATE (yychar); + yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); + + while (*yyconflicts != 0) + { + size_t yynewStack = yysplitStack (yystackp, yyk); + YYDPRINTF ((stderr, "Splitting off stack %lu from %lu.\n", + (unsigned long int) yynewStack, + (unsigned long int) yyk)); + YYCHK (yyglrReduce (yystackp, yynewStack, + *yyconflicts, yyfalse)); + YYCHK (yyprocessOneStack (yystackp, yynewStack, + yyposn)); + yyconflicts += 1; + } + + if (yyisShiftAction (yyaction)) + break; + else if (yyisErrorAction (yyaction)) + { + YYDPRINTF ((stderr, "Stack %lu dies.\n", + (unsigned long int) yyk)); + yymarkStackDeleted (yystackp, yyk); + break; + } + else + YYCHK (yyglrReduce (yystackp, yyk, -yyaction, + yyfalse)); + } + } + return yyok; +} + +/*ARGSUSED*/ static void +yyreportSyntaxError (yyGLRStack* yystackp) +{ + if (yystackp->yyerrState == 0) + { +#if YYERROR_VERBOSE + int yyn; + yyn = yypact[yystackp->yytops.yystates[0]->yylrState]; + if (YYPACT_NINF < yyn && yyn <= YYLAST) + { + yySymbol yytoken = YYTRANSLATE (yychar); + size_t yysize0 = yytnamerr (NULL, yytokenName (yytoken)); + size_t yysize = yysize0; + size_t yysize1; + yybool yysize_overflow = yyfalse; + char* yymsg = NULL; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + int yyx; + char *yyfmt; + char const *yyf; + static char const yyunexpected[] = "syntax error, unexpected %s"; + static char const yyexpecting[] = ", expecting %s"; + static char const yyor[] = " or %s"; + char yyformat[sizeof yyunexpected + + sizeof yyexpecting - 1 + + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) + * (sizeof yyor - 1))]; + char const *yyprefix = yyexpecting; + + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 1; + + yyarg[0] = yytokenName (yytoken); + yyfmt = yystpcpy (yyformat, yyunexpected); + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + yyformat[sizeof yyunexpected - 1] = '\0'; + break; + } + yyarg[yycount++] = yytokenName (yyx); + yysize1 = yysize + yytnamerr (NULL, yytokenName (yyx)); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + yyfmt = yystpcpy (yyfmt, yyprefix); + yyprefix = yyor; + } + + yyf = YY_(yyformat); + yysize1 = yysize + strlen (yyf); + yysize_overflow |= yysize1 < yysize; + yysize = yysize1; + + if (!yysize_overflow) + yymsg = (char *) YYMALLOC (yysize); + + if (yymsg) + { + char *yyp = yymsg; + int yyi = 0; + while ((*yyp = *yyf)) + { + if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyf += 2; + } + else + { + yyp++; + yyf++; + } + } + yyerror (yymsg); + YYFREE (yymsg); + } + else + { + yyerror (YY_("syntax error")); + yyMemoryExhausted (yystackp); + } + } + else +#endif /* YYERROR_VERBOSE */ + yyerror (YY_("syntax error")); + yynerrs += 1; + } +} + +/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP, + yylval, and yylloc are the syntactic category, semantic value, and location + of the look-ahead. */ +/*ARGSUSED*/ static void +yyrecoverSyntaxError (yyGLRStack* yystackp) +{ + size_t yyk; + int yyj; + + if (yystackp->yyerrState == 3) + /* We just shifted the error token and (perhaps) took some + reductions. Skip tokens until we can proceed. */ + while (YYID (yytrue)) + { + yySymbol yytoken; + if (yychar == YYEOF) + yyFail (yystackp, NULL); + if (yychar != YYEMPTY) + { + /* We throw away the lookahead, but the error range + of the shifted error token must take it into account. */ + yyGLRState *yys = yystackp->yytops.yystates[0]; + yyGLRStackItem yyerror_range[3]; + yyerror_range[1].yystate.yyloc = yys->yyloc; + yyerror_range[2].yystate.yyloc = yylloc; + YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2); + yytoken = YYTRANSLATE (yychar); + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc); + } + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; + if (yyis_pact_ninf (yyj)) + return; + yyj += yytoken; + if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken) + { + if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0) + return; + } + else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj])) + return; + } + + /* Reduce to one stack. */ + for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) + if (yystackp->yytops.yystates[yyk] != NULL) + break; + if (yyk >= yystackp->yytops.yysize) + yyFail (yystackp, NULL); + for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) + yymarkStackDeleted (yystackp, yyk); + yyremoveDeletes (yystackp); + yycompressStack (yystackp); + + /* Now pop stack until we find a state that shifts the error token. */ + yystackp->yyerrState = 3; + while (yystackp->yytops.yystates[0] != NULL) + { + yyGLRState *yys = yystackp->yytops.yystates[0]; + yyj = yypact[yys->yylrState]; + if (! yyis_pact_ninf (yyj)) + { + yyj += YYTERROR; + if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR + && yyisShiftAction (yytable[yyj])) + { + /* Shift the error token having adjusted its location. */ + YYLTYPE yyerrloc; + yystackp->yyerror_range[2].yystate.yyloc = yylloc; + YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2); + YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]], + &yylval, &yyerrloc); + yyglrShift (yystackp, 0, yytable[yyj], + yys->yyposn, &yylval, &yyerrloc); + yys = yystackp->yytops.yystates[0]; + break; + } + } + yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc; + yydestroyGLRState ("Error: popping", yys); + yystackp->yytops.yystates[0] = yys->yypred; + yystackp->yynextFree -= 1; + yystackp->yyspaceLeft += 1; + } + if (yystackp->yytops.yystates[0] == NULL) + yyFail (yystackp, NULL); +} + +#define YYCHK1(YYE) \ + do { \ + switch (YYE) { \ + case yyok: \ + break; \ + case yyabort: \ + goto yyabortlab; \ + case yyaccept: \ + goto yyacceptlab; \ + case yyerr: \ + goto yyuser_error; \ + default: \ + goto yybuglab; \ + } \ + } while (YYID (0)) + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + int yyresult; + yyGLRStack yystack; + yyGLRStack* const yystackp = &yystack; + size_t yyposn; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yychar = YYEMPTY; + yylval = yyval_default; + +#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + yylloc.first_line = yylloc.last_line = 1; + yylloc.first_column = yylloc.last_column = 0; +#endif + + + if (! yyinitGLRStack (yystackp, YYINITDEPTH)) + goto yyexhaustedlab; + switch (YYSETJMP (yystack.yyexception_buffer)) + { + case 0: break; + case 1: goto yyabortlab; + case 2: goto yyexhaustedlab; + default: goto yybuglab; + } + yyglrShift (&yystack, 0, 0, 0, &yylval, &yylloc); + yyposn = 0; + + while (YYID (yytrue)) + { + /* For efficiency, we have two loops, the first of which is + specialized to deterministic operation (single stack, no + potential ambiguity). */ + /* Standard mode */ + while (YYID (yytrue)) + { + yyRuleNum yyrule; + int yyaction; + const short int* yyconflicts; + + yyStateNum yystate = yystack.yytops.yystates[0]->yylrState; + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + if (yystate == YYFINAL) + goto yyacceptlab; + if (yyisDefaultedState (yystate)) + { + yyrule = yydefaultAction (yystate); + if (yyrule == 0) + { + yystack.yyerror_range[1].yystate.yyloc = yylloc; + yyreportSyntaxError (&yystack); + goto yyuser_error; + } + YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue)); + } + else + { + yySymbol yytoken; + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + else + yytoken = YYTRANSLATE (yychar); + yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); + if (*yyconflicts != 0) + break; + if (yyisShiftAction (yyaction)) + { + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + if (yychar != YYEOF) + yychar = YYEMPTY; + yyposn += 1; + yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc); + if (0 < yystack.yyerrState) + yystack.yyerrState -= 1; + } + else if (yyisErrorAction (yyaction)) + { + yystack.yyerror_range[1].yystate.yyloc = yylloc; + yyreportSyntaxError (&yystack); + goto yyuser_error; + } + else + YYCHK1 (yyglrReduce (&yystack, 0, -yyaction, yytrue)); + } + } + + while (YYID (yytrue)) + { + yySymbol yytoken_to_shift; + size_t yys; + + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY; + + /* yyprocessOneStack returns one of three things: + + - An error flag. If the caller is yyprocessOneStack, it + immediately returns as well. When the caller is finally + yyparse, it jumps to an error label via YYCHK1. + + - yyok, but yyprocessOneStack has invoked yymarkStackDeleted + (&yystack, yys), which sets the top state of yys to NULL. Thus, + yyparse's following invocation of yyremoveDeletes will remove + the stack. + + - yyok, when ready to shift a token. + + Except in the first case, yyparse will invoke yyremoveDeletes and + then shift the next token onto all remaining stacks. This + synchronization of the shift (that is, after all preceding + reductions on all stacks) helps prevent double destructor calls + on yylval in the event of memory exhaustion. */ + + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + YYCHK1 (yyprocessOneStack (&yystack, yys, yyposn)); + yyremoveDeletes (&yystack); + if (yystack.yytops.yysize == 0) + { + yyundeleteLastStack (&yystack); + if (yystack.yytops.yysize == 0) + yyFail (&yystack, YY_("syntax error")); + YYCHK1 (yyresolveStack (&yystack)); + YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); + yystack.yyerror_range[1].yystate.yyloc = yylloc; + yyreportSyntaxError (&yystack); + goto yyuser_error; + } + + /* If any yyglrShift call fails, it will fail after shifting. Thus, + a copy of yylval will already be on stack 0 in the event of a + failure in the following loop. Thus, yychar is set to YYEMPTY + before the loop to make sure the user destructor for yylval isn't + called twice. */ + yytoken_to_shift = YYTRANSLATE (yychar); + yychar = YYEMPTY; + yyposn += 1; + for (yys = 0; yys < yystack.yytops.yysize; yys += 1) + { + int yyaction; + const short int* yyconflicts; + yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState; + yygetLRActions (yystate, yytoken_to_shift, &yyaction, + &yyconflicts); + /* Note that yyconflicts were handled by yyprocessOneStack. */ + YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long int) yys)); + YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc); + yyglrShift (&yystack, yys, yyaction, yyposn, + &yylval, &yylloc); + YYDPRINTF ((stderr, "Stack %lu now in state #%d\n", + (unsigned long int) yys, + yystack.yytops.yystates[yys]->yylrState)); + } + + if (yystack.yytops.yysize == 1) + { + YYCHK1 (yyresolveStack (&yystack)); + YYDPRINTF ((stderr, "Returning to deterministic operation.\n")); + yycompressStack (&yystack); + break; + } + } + continue; + yyuser_error: + yyrecoverSyntaxError (&yystack); + yyposn = yystack.yytops.yystates[0]->yyposn; + } + + yyacceptlab: + yyresult = 0; + goto yyreturn; + + yybuglab: + YYASSERT (yyfalse); + goto yyabortlab; + + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + goto yyreturn; + + yyreturn: + if (yychar != YYEOF && yychar != YYEMPTY) + yydestruct ("Cleanup: discarding lookahead", + YYTRANSLATE (yychar), + &yylval, &yylloc); + + /* If the stack is well-formed, pop the stack until it is empty, + destroying its entries as we go. But free the stack regardless + of whether it is well-formed. */ + if (yystack.yyitems) + { + yyGLRState** yystates = yystack.yytops.yystates; + if (yystates) + { + size_t yysize = yystack.yytops.yysize; + size_t yyk; + for (yyk = 0; yyk < yysize; yyk += 1) + if (yystates[yyk]) + { + while (yystates[yyk]) + { + yyGLRState *yys = yystates[yyk]; + yystack.yyerror_range[1].yystate.yyloc = yys->yyloc; + yydestroyGLRState ("Cleanup: popping", yys); + yystates[yyk] = yys->yypred; + yystack.yynextFree -= 1; + yystack.yyspaceLeft += 1; + } + break; + } + } + yyfreeGLRStack (&yystack); + } + + /* Make sure YYID is used. */ + return YYID (yyresult); +} + +/* DEBUGGING ONLY */ +#ifdef YYDEBUG +static void yypstack (yyGLRStack* yystackp, size_t yyk) + __attribute__ ((__unused__)); +static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__)); + +static void +yy_yypstack (yyGLRState* yys) +{ + if (yys->yypred) + { + yy_yypstack (yys->yypred); + fprintf (stderr, " -> "); + } + fprintf (stderr, "%d@%lu", yys->yylrState, (unsigned long int) yys->yyposn); +} + +static void +yypstates (yyGLRState* yyst) +{ + if (yyst == NULL) + fprintf (stderr, "<null>"); + else + yy_yypstack (yyst); + fprintf (stderr, "\n"); +} + +static void +yypstack (yyGLRStack* yystackp, size_t yyk) +{ + yypstates (yystackp->yytops.yystates[yyk]); +} + +#define YYINDEX(YYX) \ + ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystackp->yyitems) + + +static void +yypdumpstack (yyGLRStack* yystackp) +{ + yyGLRStackItem* yyp; + size_t yyi; + for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1) + { + fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - yystackp->yyitems)); + if (*(yybool *) yyp) + { + fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld", + yyp->yystate.yyresolved, yyp->yystate.yylrState, + (unsigned long int) yyp->yystate.yyposn, + (long int) YYINDEX (yyp->yystate.yypred)); + if (! yyp->yystate.yyresolved) + fprintf (stderr, ", firstVal: %ld", + (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal)); + } + else + { + fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld", + yyp->yyoption.yyrule - 1, + (long int) YYINDEX (yyp->yyoption.yystate), + (long int) YYINDEX (yyp->yyoption.yynext)); + } + fprintf (stderr, "\n"); + } + fprintf (stderr, "Tops:"); + for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1) + fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi, + (long int) YYINDEX (yystackp->yytops.yystates[yyi])); + fprintf (stderr, "\n"); +} +#endif + + +#line 1750 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + + diff --git a/generic/Lgrammar.h b/generic/Lgrammar.h new file mode 100644 index 0000000..4135082 --- /dev/null +++ b/generic/Lgrammar.h @@ -0,0 +1,233 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton interface for Bison GLR parsers in C + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + END = 0, + T_ANDAND = 258, + T_ARROW = 259, + T_ATTRIBUTE = 260, + T_BANG = 261, + T_BANGTWID = 262, + T_BITAND = 263, + T_BITOR = 264, + T_BITNOT = 265, + T_BITXOR = 266, + T_BREAK = 267, + T_CLASS = 268, + T_COLON = 269, + T_COMMA = 270, + T_CONSTRUCTOR = 271, + T_CONTINUE = 272, + T_DEFINED = 273, + T_DESTRUCTOR = 274, + T_DO = 275, + T_DOT = 276, + T_DOTDOT = 277, + T_ELLIPSIS = 278, + T_ELSE = 279, + T_EQ = 280, + T_EQBITAND = 281, + T_EQBITOR = 282, + T_EQBITXOR = 283, + T_EQDOT = 284, + T_EQLSHIFT = 285, + T_EQMINUS = 286, + T_EQPERC = 287, + T_EQPLUS = 288, + T_EQRSHIFT = 289, + T_EQSTAR = 290, + T_EQSLASH = 291, + T_EQTWID = 292, + T_EQUALS = 293, + T_EQUALEQUAL = 294, + T_EXPAND = 295, + T_EXTERN = 296, + T_FLOAT = 297, + T_FLOAT_LITERAL = 298, + T_FOR = 299, + T_FOREACH = 300, + T_GOTO = 301, + T_GE = 302, + T_GREATER = 303, + T_GREATEREQ = 304, + T_GT = 305, + T_HTML = 306, + T_ID = 307, + T_IF = 308, + T_INSTANCE = 309, + T_INT = 310, + T_INT_LITERAL = 311, + T_LHTML_EXPR_START = 312, + T_LHTML_EXPR_END = 313, + T_LBRACE = 314, + T_LBRACKET = 315, + T_LE = 316, + T_LEFT_INTERPOL = 317, + T_LEFT_INTERPOL_RE = 318, + T_LESSTHAN = 319, + T_LESSTHANEQ = 320, + T_LPAREN = 321, + T_LSHIFT = 322, + T_LT = 323, + T_MINUS = 324, + T_MINUSMINUS = 325, + T_NE = 326, + T_NOTEQUAL = 327, + T_OROR = 328, + T_PATTERN = 329, + T_PERC = 330, + T_PLUS = 331, + T_PLUSPLUS = 332, + T_POINTS = 333, + T_POLY = 334, + T_PRIVATE = 335, + T_PUBLIC = 336, + T_QUESTION = 337, + T_RBRACE = 338, + T_RBRACKET = 339, + T_RE = 340, + T_RE_MODIFIER = 341, + T_RETURN = 342, + T_RIGHT_INTERPOL = 343, + T_RIGHT_INTERPOL_RE = 344, + T_RPAREN = 345, + T_RSHIFT = 346, + T_TRY = 347, + T_SEMI = 348, + T_SLASH = 349, + T_SPLIT = 350, + T_STAR = 351, + T_START_BACKTICK = 352, + T_STR_BACKTICK = 353, + T_STR_LITERAL = 354, + T_STRCAT = 355, + T_STRING = 356, + T_STRUCT = 357, + T_SUBST = 358, + T_TYPE = 359, + T_TYPEDEF = 360, + T_UNLESS = 361, + T_ARGUSED = 362, + T_OPTIONAL = 363, + T_MUSTBETYPE = 364, + T_VOID = 365, + T_WIDGET = 366, + T_WHILE = 367, + T_PRAGMA = 368, + T_SWITCH = 369, + T_CASE = 370, + T_DEFAULT = 371, + LOWEST = 372, + ADDRESS = 373, + UMINUS = 374, + UPLUS = 375, + PREFIX_INCDEC = 376, + HIGHEST = 377 + }; +#endif + + +/* Copy the first part of user declarations. */ +#line 1 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" + +/* + * Copyright (c) 2006-2008 BitMover, Inc. + */ +#include <stdio.h> +#include "Lcompile.h" + +/* L_lex is generated by flex. */ +extern int L_lex (void); + +#define YYERROR_VERBOSE +#define L_error L_synerr + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +#line 53 "/Users/rob/bk/dev-L-lhtml-fix/src/gui/tcltk/tcl/generic/Lgrammar.y" +{ + long i; + char *s; + Tcl_Obj *obj; + Type *Type; + Expr *Expr; + Block *Block; + ForEach *ForEach; + Switch *Switch; + Case *Case; + FnDecl *FnDecl; + Cond *Cond; + Loop *Loop; + Stmt *Stmt; + TopLev *TopLev; + VarDecl *VarDecl; + ClsDecl *ClsDecl; + struct { + Type *t; + char *s; + } Typename; +} +/* Line 2616 of glr.c. */ +#line 209 "Lgrammar.h" + YYSTYPE; +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + + int first_line; + int first_column; + int last_line; + int last_column; + +} YYLTYPE; +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +extern YYSTYPE L_lval; + +extern YYLTYPE L_lloc; + + diff --git a/generic/Lgrammar.y b/generic/Lgrammar.y new file mode 100644 index 0000000..2b6ee8f --- /dev/null +++ b/generic/Lgrammar.y @@ -0,0 +1,1750 @@ +%{ +/* + * Copyright (c) 2006-2008 BitMover, Inc. + */ +#include <stdio.h> +#include "Lcompile.h" + +/* L_lex is generated by flex. */ +extern int L_lex (void); + +#define YYERROR_VERBOSE +#define L_error L_synerr +%} + +/* + * We need a GLR parser because of a shift/reduce conflict introduced + * by hash-element types. This production is the culprit: + * + * array_or_hash_type: "{" scalar_type_specifier "}" + * + * This introduced a shift/reduce conflict on "{" due to "{" being in + * the FOLLOW set of scalar_type_specifier because "{" can follow + * type_specifier in function_decl. For example, after you + * have seen + * + * struct s + * + * and "{" is the next token, the parser can't tell whether to shift + * and proceed to parse a struct_specifier that declares a struct: + * + * struct s { int x,y; } + * + * or whether to reduce and proceed in to a array_or_hash_type: + * + * struct s { int } f() {} + * + * To make this grammar LALR(1) seemed difficult. The grammar seems + * to want to be LALR(3) perhaps(?). The best we could do was to extend + * the language by pushing the array_or_hash_type syntax down into + * scalar_type_specifier and struct_specifier. This would allow + * inputs that should be syntax errors, so extra checking would have + * been needed to detect these cases. + * + * The GLR parser has no problem with this type of conflict and keeps + * the grammar nice. + * + * Note that the %expect 1 below is for this conflict. Although the + * GLR parser handles it, it is still reported as a conflict. + */ +%glr-parser +%expect 1 + +%union { + long i; + char *s; + Tcl_Obj *obj; + Type *Type; + Expr *Expr; + Block *Block; + ForEach *ForEach; + Switch *Switch; + Case *Case; + FnDecl *FnDecl; + Cond *Cond; + Loop *Loop; + Stmt *Stmt; + TopLev *TopLev; + VarDecl *VarDecl; + ClsDecl *ClsDecl; + struct { + Type *t; + char *s; + } Typename; +} + +%token T_ANDAND "&&" +%token T_ARROW "=>" +%token T_ATTRIBUTE "_attribute" +%token T_BANG "!" +%token T_BANGTWID "!~" +%token T_BITAND "&" +%token T_BITOR "|" +%token T_BITNOT "~" +%token T_BITXOR "^" +%token T_BREAK "break" +%token T_CLASS "class" +%token T_COLON ":" +%token T_COMMA "," +%token T_CONSTRUCTOR "constructor" +%token T_CONTINUE "continue" +%token T_DEFINED "defined" +%token T_DESTRUCTOR "destructor" +%token T_DO "do" +%token T_DOT "." +%token T_DOTDOT ".." +%token T_ELLIPSIS "..." +%token T_ELSE "else" +%token T_EQ "eq" +%token T_EQBITAND "&=" +%token T_EQBITOR "|=" +%token T_EQBITXOR "^=" +%token T_EQDOT ".=" +%token T_EQLSHIFT "<<=" +%token T_EQMINUS "-=" +%token T_EQPERC "%=" +%token T_EQPLUS "+=" +%token T_EQRSHIFT ">>=" +%token T_EQSTAR "*=" +%token T_EQSLASH "/=" +%token T_EQTWID "=~" +%token T_EQUALS "=" +%token T_EQUALEQUAL "==" +%token T_EXPAND "(expand)" +%token T_EXTERN "extern" +%token T_FLOAT "float" +%token <s> T_FLOAT_LITERAL "float constant" +%token T_FOR "for" +%token T_FOREACH "foreach" +%token T_GOTO "goto" +%token T_GE "ge" +%token T_GREATER ">" +%token T_GREATEREQ ">=" +%token T_GT "gt" +%token <s> T_HTML +%token <s> T_ID "id" +%token T_IF "if" +%token T_INSTANCE "instance" +%token T_INT "int" +%token <s> T_INT_LITERAL "integer constant" +%token <s> T_LHTML_EXPR_START "<?=" +%token <s> T_LHTML_EXPR_END "?>" +%token T_LBRACE "{" +%token T_LBRACKET "[" +%token T_LE "le" +%token <s> T_LEFT_INTERPOL "${" +%token <s> T_LEFT_INTERPOL_RE "${ (in re)" +%token T_LESSTHAN "<" +%token T_LESSTHANEQ "<=" +%token T_LPAREN "(" +%token T_LSHIFT "<<" +%token T_LT "lt" +%token T_MINUS "-" +%token T_MINUSMINUS "--" +%token T_NE "ne" +%token T_NOTEQUAL "!=" +%token T_OROR "||" +%token <s> T_PATTERN "pattern function" +%token T_PERC "%" +%token T_PLUS "+" +%token T_PLUSPLUS "++" +%token T_POINTS "->" +%token T_POLY "poly" +%token T_PRIVATE "private" +%token T_PUBLIC "public" +%token T_QUESTION "?" +%token T_RBRACE "}" +%token T_RBRACKET "]" +%token <s> T_RE "regular expression" +%token <s> T_RE_MODIFIER "regexp modifier" +%token T_RETURN "return" +%token T_RIGHT_INTERPOL "} (end of interpolation)" +%token T_RIGHT_INTERPOL_RE "} (end of interpolation in re)" +%token T_RPAREN ")" +%token T_RSHIFT ">>" +%token T_TRY "try" +%token T_SEMI ";" +%token T_SLASH "/" +%token T_SPLIT "split" +%token T_STAR "*" +%token <s> T_START_BACKTICK "backtick" +%token <s> T_STR_BACKTICK "`" +%token <s> T_STR_LITERAL "string constant" +%token T_STRCAT " . " +%token T_STRING "string" +%token T_STRUCT "struct" +%token <s> T_SUBST "=~ s/a/b/" +%token <Typename> T_TYPE "type name" +%token T_TYPEDEF "typedef" +%token T_UNLESS "unless" +%token T_ARGUSED "_argused" +%token T_OPTIONAL "_optional" +%token T_MUSTBETYPE "_mustbetype" +%token T_VOID "void" +%token T_WIDGET "widget" +%token T_WHILE "while" +%token T_PRAGMA "#pragma" +%token T_SWITCH "switch" +%token T_CASE "case" +%token T_DEFAULT "default" +%token END 0 "end of file" + +/* + * This follows the C operator-precedence rules, from lowest to + * highest precedence. + */ +%left LOWEST +// The following %nonassoc lines are defined to resolve a conflict with +// labeled statements (see the stmt nonterm). +%nonassoc T_IF T_UNLESS T_RETURN T_ID T_STR_LITERAL T_LEFT_INTERPOL +%nonassoc T_STR_BACKTICK T_INT_LITERAL T_FLOAT_LITERAL T_TYPE T_WHILE +%nonassoc T_FOR T_DO T_DEFINED T_STRING T_FOREACH T_BREAK T_CONTINUE +%nonassoc T_SPLIT T_GOTO T_WIDGET T_PRAGMA T_SWITCH T_START_BACKTICK T_TRY +%nonassoc T_HTML T_LHTML_EXPR_START +%left T_COMMA +%nonassoc T_ELSE T_SEMI +%right T_EQUALS T_EQPLUS T_EQMINUS T_EQSTAR T_EQSLASH T_EQPERC + T_EQBITAND T_EQBITOR T_EQBITXOR T_EQLSHIFT T_EQRSHIFT T_EQDOT +%right T_QUESTION +%left T_OROR +%left T_ANDAND +%left T_BITOR +%left T_BITXOR +%left T_BITAND +%left T_EQ T_NE T_EQUALEQUAL T_NOTEQUAL T_EQTWID T_BANGTWID +%left T_GT T_GE T_LT T_LE T_GREATER T_GREATEREQ T_LESSTHAN T_LESSTHANEQ +%left T_LSHIFT T_RSHIFT +%left T_PLUS T_MINUS T_STRCAT +%left T_STAR T_SLASH T_PERC +%right PREFIX_INCDEC UPLUS UMINUS T_BANG T_BITNOT ADDRESS +%left T_LBRACKET T_LBRACE T_RBRACE T_DOT T_POINTS T_PLUSPLUS T_MINUSMINUS +%left HIGHEST + +%type <TopLev> toplevel_code +%type <ClsDecl> class_decl class_decl_tail +%type <FnDecl> function_decl fundecl_tail fundecl_tail1 +%type <Stmt> stmt single_stmt compound_stmt stmt_list opt_stmt_list +%type <Stmt> unlabeled_stmt optional_else +%type <Cond> selection_stmt +%type <Loop> iteration_stmt +%type <ForEach> foreach_stmt +%type <Switch> switch_stmt +%type <Case> switch_cases switch_case +%type <Expr> expr expression_stmt argument_expr_list pragma_expr_list +%type <Expr> id id_list string_literal cmdsubst_literal dotted_id +%type <Expr> regexp_literal regexp_literal_mod subst_literal interpolated_expr +%type <Expr> interpolated_expr_re list list_element case_expr option_arg +%type <Expr> here_doc_backtick opt_attribute pragma +%type <VarDecl> parameter_list parameter_decl_list parameter_decl +%type <VarDecl> declaration_list declaration declaration2 +%type <VarDecl> init_declarator_list declarator_list init_declarator +%type <VarDecl> declarator opt_declarator struct_decl_list struct_decl +%type <VarDecl> struct_declarator_list +%type <Type> array_or_hash_type type_specifier scalar_type_specifier +%type <Type> struct_specifier +%type <obj> dotted_id_1 +%type <i> decl_qualifier parameter_attrs + +%% + +start: toplevel_code + { + REVERSE(TopLev, next, $1); + L->ast = $1; + } + ; + +toplevel_code: + toplevel_code class_decl + { + if ($2) { + $$ = ast_mkTopLevel(L_TOPLEVEL_CLASS, $1, @2, @2); + $$->u.class = $2; + } else { + // Don't create a node for a forward class declaration. + $$ = $1; + } + } + | toplevel_code function_decl + { + $$ = ast_mkTopLevel(L_TOPLEVEL_FUN, $1, @2, @2); + $2->decl->flags |= DECL_FN; + if ($2->decl->flags & DECL_PRIVATE) { + $2->decl->flags |= SCOPE_SCRIPT; + } else { + $2->decl->flags |= SCOPE_GLOBAL; + } + $$->u.fun = $2; + } + | toplevel_code struct_specifier ";" + { + $$ = $1; // nothing more to do + } + | toplevel_code T_TYPEDEF type_specifier declarator ";" + { + L_set_declBaseType($4, $3); + L_typedef_store($4); + $$ = $1; // nothing more to do + } + | toplevel_code declaration + { + // Global variable declaration. + VarDecl *v; + $$ = ast_mkTopLevel(L_TOPLEVEL_GLOBAL, $1, @2, @2); + for (v = $2; v; v = v->next) { + v->flags |= DECL_GLOBAL_VAR; + if ($2->flags & DECL_PRIVATE) { + v->flags |= SCOPE_SCRIPT; + } else { + v->flags |= SCOPE_GLOBAL; + } + } + $$->u.global = $2; + } + | toplevel_code stmt + { + // Top-level statement. + $$ = ast_mkTopLevel(L_TOPLEVEL_STMT, $1, @2, @2); + $$->u.stmt = $2; + } + | /* epsilon */ { $$ = NULL; } + ; + +class_decl: + T_CLASS id "{" + { + /* + * This is a new class declaration. + * Alloc the VarDecl now and associate it with + * the class name so that it is available while + * parsing the class body. + */ + Type *t = type_mkClass(); + VarDecl *d = ast_mkVarDecl(t, $2, @1, @1); + ClsDecl *c = ast_mkClsDecl(d, @1, @1); + t->u.class.clsdecl = c; + ASSERT(!L_typedef_lookup($2->str)); + L_typedef_store(d); + $<ClsDecl>$ = c; + } class_decl_tail + { + $$ = $5; + /* silence unused warning */ + (void)$<ClsDecl>4; + } + | T_CLASS T_TYPE "{" + { + /* + * This is a class declaration where the type name was + * previously declared. Use the ClsDecl from the + * prior decl. + */ + ClsDecl *c = $2.t->u.class.clsdecl; + unless (c->decl->flags & DECL_FORWARD) { + L_err("redeclaration of %s", $2.s); + } + ASSERT(isclasstype(c->decl->type)); + c->decl->flags &= ~DECL_FORWARD; + $<ClsDecl>$ = c; + } class_decl_tail + { + $$ = $5; + /* silence unused warning */ + (void)$<ClsDecl>4; + } + | T_CLASS id ";" + { + /* This is a forward class declaration. */ + Type *t = type_mkClass(); + VarDecl *d = ast_mkVarDecl(t, $2, @1, @3); + ClsDecl *c = ast_mkClsDecl(d, @1, @3); + ASSERT(!L_typedef_lookup($2->str)); + t->u.class.clsdecl = c; + d->flags |= DECL_FORWARD; + L_typedef_store(d); + $<ClsDecl>$ = NULL; + } + | T_CLASS T_TYPE ";" + { + /* Empty declaration of an already declared type. */ + unless (isclasstype($2.t)) { + L_err("%s not a class type", $2.s); + } + $<ClsDecl>$ = NULL; + } + ; + +class_decl_tail: + class_code "}" + { + $$ = $<ClsDecl>0; + $$->node.loc.end = @2.end; + $$->decl->node.loc.end = @2.end; + /* If constructor or destructor were omitted, make defaults. */ + unless ($$->constructors) { + $$->constructors = ast_mkConstructor($$); + } + unless ($$->destructors) { + $$->destructors = ast_mkDestructor($$); + } + } + ; + +class_code: + class_code T_INSTANCE "{" declaration_list "}" opt_semi + { + VarDecl *v; + ClsDecl *clsdecl = $<ClsDecl>0; + REVERSE(VarDecl, next, $4); + for (v = $4; v; v = v->next) { + v->clsdecl = clsdecl; + v->flags |= SCOPE_CLASS | DECL_CLASS_INST_VAR; + unless (v->flags & (DECL_PUBLIC | DECL_PRIVATE)) { + L_errf(v, "class instance variable %s not " + "declared public or private", + v->id->str); + v->flags |= DECL_PUBLIC; + } + } + APPEND_OR_SET(VarDecl, next, clsdecl->instvars, $4); + } + | class_code T_INSTANCE "{" "}" opt_semi + | class_code declaration + { + VarDecl *v; + ClsDecl *clsdecl = $<ClsDecl>0; + REVERSE(VarDecl, next, $2); + for (v = $2; v; v = v->next) { + v->clsdecl = clsdecl; + v->flags |= SCOPE_CLASS | DECL_CLASS_VAR; + unless (v->flags & (DECL_PUBLIC | DECL_PRIVATE)) { + L_errf(v, "class variable %s not " + "declared public or private", + v->id->str); + v->flags |= DECL_PUBLIC; + } + } + APPEND_OR_SET(VarDecl, next, clsdecl->clsvars, $2); + } + | class_code struct_specifier ";" + | class_code T_TYPEDEF type_specifier declarator ";" + { + L_set_declBaseType($4, $3); + L_typedef_store($4); + } + | class_code function_decl + { + ClsDecl *clsdecl = $<ClsDecl>0; + $2->decl->clsdecl = clsdecl; + $2->decl->flags |= DECL_CLASS_FN; + unless ($2->decl->flags & DECL_PRIVATE) { + $2->decl->flags |= SCOPE_GLOBAL | DECL_PUBLIC; + } else { + $2->decl->flags |= SCOPE_CLASS; + $2->decl->tclprefix = cksprintf("_L_class_%s_", + clsdecl->decl->id->str); + } + APPEND_OR_SET(FnDecl, next, clsdecl->fns, $2); + } + | class_code T_CONSTRUCTOR fundecl_tail + { + ClsDecl *clsdecl = $<ClsDecl>0; + $3->decl->type->base_type = clsdecl->decl->type; + $3->decl->clsdecl = clsdecl; + $3->decl->flags |= SCOPE_GLOBAL | DECL_CLASS_FN | DECL_PUBLIC | + DECL_CLASS_CONST; + APPEND_OR_SET(FnDecl, next, clsdecl->constructors, $3); + } + | class_code T_DESTRUCTOR fundecl_tail + { + ClsDecl *clsdecl = $<ClsDecl>0; + $3->decl->type->base_type = L_void; + $3->decl->clsdecl = clsdecl; + $3->decl->flags |= SCOPE_GLOBAL | DECL_CLASS_FN | DECL_PUBLIC | + DECL_CLASS_DESTR; + APPEND_OR_SET(FnDecl, next, clsdecl->destructors, $3); + } + | class_code pragma + { + /* + * We don't store the things that make up class_code + * in order, so there's no place in which to + * interleave #pragmas. So don't create an AST node, + * just update L->options now; it gets used when other + * AST nodes are created. + */ + L_compile_attributes(L->options, $2, L_attrs_pragma); + } + | /* epsilon */ + ; + +opt_semi: + ";" + | /* epsilon */ + ; + +function_decl: + type_specifier fundecl_tail + { + $2->decl->type->base_type = $1; + $$ = $2; + $$->node.loc = @1; + } + | decl_qualifier type_specifier fundecl_tail + { + $3->decl->type->base_type = $2; + $3->decl->flags |= $1; + $$ = $3; + $$->node.loc = @1; + } + ; + +fundecl_tail: + id fundecl_tail1 + { + $$ = $2; + $$->decl->id = $1; + $$->node.loc = @1; + } + | T_PATTERN fundecl_tail1 + { + VarDecl *new_param; + Expr *dollar1 = ast_mkId("$1", @2, @2); + + $$ = $2; + $$->decl->id = ast_mkId($1, @1, @1); + ckfree($1); + $$->node.loc = @1; + /* Prepend a new arg "$1" as the first formal. */ + new_param = ast_mkVarDecl(L_string, dollar1, @1, @2); + new_param->flags = SCOPE_LOCAL | DECL_LOCAL_VAR; + new_param->next = $2->decl->type->u.func.formals; + $$->decl->type->u.func.formals = new_param; + } + ; + +fundecl_tail1: + "(" parameter_list ")" opt_attribute compound_stmt + { + Type *type = type_mkFunc(NULL, $2); + VarDecl *decl = ast_mkVarDecl(type, NULL, @1, @3); + decl->attrs = $4; + $$ = ast_mkFnDecl(decl, $5->u.block, @1, @5); + } + | "(" parameter_list ")" opt_attribute ";" + { + Type *type = type_mkFunc(NULL, $2); + VarDecl *decl = ast_mkVarDecl(type, NULL, @1, @3); + decl->attrs = $4; + $$ = ast_mkFnDecl(decl, NULL, @1, @5); + } + ; + +stmt: + T_ID ":" stmt + { + $$ = ast_mkStmt(L_STMT_LABEL, NULL, @1, @3); + $$->u.label = $1; + $$->next = $3; + } + | T_ID ":" %prec LOWEST + { + $$ = ast_mkStmt(L_STMT_LABEL, NULL, @1, @2); + $$->u.label = $1; + } + | unlabeled_stmt + | pragma + { + L_compile_attributes(L->options, $1, L_attrs_pragma); + $$ = NULL; + } + | T_HTML + { + // Wrap the html in a puts(-nonewline) call. + Expr *fn = ast_mkId("puts", @1, @1); + Expr *arg = ast_mkConst(L_string, "-nonewline", @1, @1); + arg->next = ast_mkConst(L_string, $1, @1, @1); + $$ = ast_mkStmt(L_STMT_EXPR, NULL, @1, @1); + $$->u.expr = ast_mkFnCall(fn, arg, @1, @1); + } + | T_LHTML_EXPR_START expr T_LHTML_EXPR_END + { + // Wrap expr in a puts(-nonewline) call. + Expr *fn = ast_mkId("puts", @2, @2); + Expr *arg = ast_mkConst(L_string, "-nonewline", @2, @2); + arg->next = $2; + $$ = ast_mkStmt(L_STMT_EXPR, NULL, @1, @3); + $$->u.expr = ast_mkFnCall(fn, arg, @1, @3); + } + ; + +pragma_expr_list: + id + | id "=" id + { + $$ = ast_mkBinOp(L_OP_EQUALS, $1, $3, @1, @3); + } + | id "=" T_INT_LITERAL + { + Expr *lit = ast_mkConst(L_int, $3, @3, @3); + $$ = ast_mkBinOp(L_OP_EQUALS, $1, lit, @1, @3); + } + | pragma_expr_list "," id + { + $3->next = $1; + $$ = $3; + $$->node.loc.beg = @1.beg; + } + | pragma_expr_list "," id "=" id + { + $$ = ast_mkBinOp(L_OP_EQUALS, $3, $5, @3, @5); + $$->next = $1; + $$->node.loc.beg = @1.beg; + } + | pragma_expr_list "," id "=" T_INT_LITERAL + { + Expr *lit = ast_mkConst(L_int, $5, @5, @5); + $$ = ast_mkBinOp(L_OP_EQUALS, $3, lit, @3, @5); + $$->next = $1; + $$->node.loc.beg = @1.beg; + } + ; + +pragma: + T_PRAGMA pragma_expr_list + { + REVERSE(Expr, next, $2); + $$ = $2; + $$->node.loc.beg = @1.beg; + } + ; + +opt_attribute: + T_ATTRIBUTE "(" argument_expr_list ")" + { + REVERSE(Expr, next, $3); + $$ = $3; + $$->node.loc.beg = @1.beg; + $$->node.loc.end = @4.end; + } + | { $$ = NULL; } + ; + +unlabeled_stmt: + single_stmt + | compound_stmt + ; + +single_stmt: + selection_stmt + { + $$ = ast_mkStmt(L_STMT_COND, NULL, @1, @1); + $$->u.cond = $1; + } + | iteration_stmt + { + $$ = ast_mkStmt(L_STMT_LOOP, NULL, @1, @1); + $$->u.loop = $1; + } + | switch_stmt + { + $$ = ast_mkStmt(L_STMT_SWITCH, NULL, @1, @1); + $$->u.swich = $1; + } + | foreach_stmt + { + $$ = ast_mkStmt(L_STMT_FOREACH, NULL, @1, @1); + $$->u.foreach = $1; + } + | expr ";" + { + $$ = ast_mkStmt(L_STMT_EXPR, NULL, @1, @1); + $$->u.expr = $1; + } + | T_BREAK ";" + { + $$ = ast_mkStmt(L_STMT_BREAK, NULL, @1, @1); + } + | T_CONTINUE ";" + { + $$ = ast_mkStmt(L_STMT_CONTINUE, NULL, @1, @1); + } + | T_RETURN ";" + { + $$ = ast_mkStmt(L_STMT_RETURN, NULL, @1, @1); + } + | T_RETURN expr ";" + { + $$ = ast_mkStmt(L_STMT_RETURN, NULL, @1, @2); + $$->u.expr = $2; + } + | T_GOTO T_ID ";" + { + $$ = ast_mkStmt(L_STMT_GOTO, NULL, @1, @3); + $$->u.label = $2; + } + | "try" compound_stmt T_ID "(" expr ")" compound_stmt + { + /* + * We don't want to make "catch" a keyword since it's a Tcl + * function name, so allow any ID here but check it. + */ + unless (!strcmp($3, "catch")) { + L_synerr2("syntax error -- expected 'catch'", @3.beg); + } + $$ = ast_mkStmt(L_STMT_TRY, NULL, @1, @7); + $$->u.try = ast_mkTry($2, $5, $7); + } + | "try" compound_stmt T_ID compound_stmt + { + $$ = ast_mkStmt(L_STMT_TRY, NULL, @1, @4); + $$->u.try = ast_mkTry($2, NULL, $4); + } + | ";" { $$ = NULL; } + ; + +selection_stmt: + T_IF "(" expr ")" compound_stmt optional_else + { + $$ = ast_mkIfUnless($3, $5, $6, @1, @6); + } + /* If you have no curly braces, you get no else. */ + | T_IF "(" expr ")" single_stmt + { + $$ = ast_mkIfUnless($3, $5, NULL, @1, @5); + } + | T_UNLESS "(" expr ")" compound_stmt optional_else + { + $$ = ast_mkIfUnless($3, $6, $5, @1, @6); + } + | T_UNLESS "(" expr ")" single_stmt + { + $$ = ast_mkIfUnless($3, NULL, $5, @1, @5); + } + ; + +switch_stmt: + T_SWITCH "(" expr ")" "{" switch_cases "}" + { + Case *c, *def; + + for (c = $6, def = NULL; c; c = c->next) { + if (c->expr) continue; + if (def) { + L_errf(c, + "multiple default cases in switch statement"); + } + def = c; + } + $$ = ast_mkSwitch($3, $6, @1, @7); + } + ; + +switch_cases: + switch_cases switch_case + { + if ($1) { + APPEND(Case, next, $1, $2); + $$ = $1; + } else { + $$ = $2; + } + } + | /* epsilon */ { $$ = NULL; } + ; + +switch_case: + "case" re_start_case case_expr ":" opt_stmt_list + { + REVERSE(Stmt, next, $5); + $$ = ast_mkCase($3, $5, @1, @5); + } + | "default" ":" opt_stmt_list + { + /* The default case is distinguished by a NULL expr. */ + REVERSE(Stmt, next, $3); + $$ = ast_mkCase(NULL, $3, @1, @2); + } + ; + +case_expr: + regexp_literal_mod + { + if ($1->flags & L_EXPR_RE_G) { + L_errf($1, "illegal regular expression modifier"); + } + } + | expr + ; + +optional_else: + /* Else clause must either have curly braces or be another if/unless. */ + T_ELSE compound_stmt + { + $$ = $2; + $$->node.loc = @1; + } + | T_ELSE selection_stmt + { + $$ = ast_mkStmt(L_STMT_COND, NULL, @1, @2); + $$->u.cond = $2; + } + | /* epsilon */ { $$ = NULL; } + ; + +iteration_stmt: + T_WHILE "(" expr ")" stmt + { + $$ = ast_mkLoop(L_LOOP_WHILE, NULL, $3, NULL, $5, @1, @5); + } + | T_DO stmt T_WHILE "(" expr ")" ";" + { + $$ = ast_mkLoop(L_LOOP_DO, NULL, $5, NULL, $2, @1, @6); + } + | T_FOR "(" expression_stmt expression_stmt ")" stmt + { + $$ = ast_mkLoop(L_LOOP_FOR, $3, $4, NULL, $6, @1, @6); + } + | T_FOR "(" expression_stmt expression_stmt expr ")" stmt + { + $$ = ast_mkLoop(L_LOOP_FOR, $3, $4, $5, $7, @1, @7); + } + ; + +foreach_stmt: + T_FOREACH "(" id "=>" id id expr ")" stmt + { + $$ = ast_mkForeach($7, $3, $5, $9, @1, @9); + unless (isid($6, "in")) { + L_synerr2("syntax error -- expected 'in' in foreach", + @6.beg); + } + } + | T_FOREACH "(" id_list id expr ")" stmt + { + $$ = ast_mkForeach($5, $3, NULL, $7, @1, @7); + unless (isid($4, "in")) { + L_synerr2("syntax error -- expected 'in' in foreach", + @4.beg); + } + } + ; + +expression_stmt: + ";" { $$ = NULL; } + | expr ";" + ; + +opt_stmt_list: + stmt_list + | { $$ = NULL; } + ; + +stmt_list: + stmt + { + REVERSE(Stmt, next, $1); + $$ = $1; + } + | stmt_list stmt + { + if ($2) { + REVERSE(Stmt, next, $2); + APPEND(Stmt, next, $2, $1); + $$ = $2; + } else { + // Empty stmt. + $$ = $1; + } + } + ; + +parameter_list: + parameter_decl_list + { + VarDecl *v; + REVERSE(VarDecl, next, $1); + for (v = $1; v; v = v->next) { + v->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + } + $$ = $1; + /* + * Special case a parameter list of "void" -- a single + * formal of type void with no arg name. This really + * means there are no args. + */ + if ($1 && !$1->next && !$1->id && ($1->type == L_void)) { + $$ = NULL; + } + } + | /* epsilon */ { $$ = NULL; } + ; + +parameter_decl_list: + parameter_decl + | parameter_decl_list "," parameter_decl + { + $3->next = $1; + $$ = $3; + $$->node.loc = @1; + } + ; + +parameter_decl: + parameter_attrs type_specifier opt_declarator + { + if ($3) { + L_set_declBaseType($3, $2); + $$ = $3; + } else { + $$ = ast_mkVarDecl($2, NULL, @2, @2); + if (isnameoftype($2)) $$->flags |= DECL_REF; + } + $$->flags |= $1; + $$->node.loc = @1; + } + | parameter_attrs T_ELLIPSIS id + { + Type *t = type_mkArray(NULL, L_poly); + $$ = ast_mkVarDecl(t, $3, @1, @3); + $$->flags |= $1 | DECL_REST_ARG; + } + ; + +parameter_attrs: + parameter_attrs T_ARGUSED { $$ = $1 | DECL_ARGUSED; } + | parameter_attrs T_OPTIONAL { $$ = $1 | DECL_OPTIONAL; } + | parameter_attrs T_MUSTBETYPE { $$ = $1 | DECL_NAME_EQUIV; } + | /* epsilon */ { $$ = 0; } + ; + +argument_expr_list: + expr %prec T_COMMA + | option_arg + | option_arg expr %prec T_COMMA + { + $2->next = $1; + $$ = $2; + $$->node.loc = @1; + } + | argument_expr_list "," expr + { + $3->next = $1; + $$ = $3; + $$->node.loc.end = @3.end; + } + | argument_expr_list "," option_arg + { + $3->next = $1; + $$ = $3; + $$->node.loc.end = @3.end; + } + | argument_expr_list "," option_arg expr %prec T_COMMA + { + $4->next = $3; + $3->next = $1; + $$ = $4; + $$->node.loc.end = @4.end; + } + ; + +/* + * option_arg is an actual parameter "arg:" that becomes "-arg". + * Allow both "T_ID:" and "default:" to overcome a nasty grammar + * conflict with statement labels that otherwise results. The scanner + * returns T_DEFAULT T_COLON when it sees "default:" but returns T_ID + * T_COLON for the other cases even if they include a reserved word. + */ +option_arg: + T_ID ":" + { + char *s = cksprintf("-%s", $1); + $$ = ast_mkConst(L_string, s, @1, @2); + ckfree($1); + } + | "default" ":" + { + char *s = cksprintf("-default"); + $$ = ast_mkConst(L_string, s, @1, @2); + } + ; + +expr: + "(" expr ")" + { + $$ = $2; + $$->node.loc = @1; + $$->node.loc.end = @3.end; + } + | "(" type_specifier ")" expr %prec PREFIX_INCDEC + { + // This is a binop where an arg is a Type*. + $$ = ast_mkBinOp(L_OP_CAST, (Expr *)$2, $4, @1, @4); + } + | "(" T_EXPAND ")" expr %prec PREFIX_INCDEC + { + $$ = ast_mkUnOp(L_OP_EXPAND, $4, @1, @4); + } + | T_BANG expr + { + $$ = ast_mkUnOp(L_OP_BANG, $2, @1, @2); + } + | T_BITNOT expr + { + $$ = ast_mkUnOp(L_OP_BITNOT, $2, @1, @2); + } + | T_BITAND expr %prec ADDRESS + { + $$ = ast_mkUnOp(L_OP_ADDROF, $2, @1, @2); + } + | T_MINUS expr %prec UMINUS + { + $$ = ast_mkUnOp(L_OP_UMINUS, $2, @1, @2); + } + | T_PLUS expr %prec UPLUS + { + $$ = ast_mkUnOp(L_OP_UPLUS, $2, @1, @2); + } + | T_PLUSPLUS expr %prec PREFIX_INCDEC + { + $$ = ast_mkUnOp(L_OP_PLUSPLUS_PRE, $2, @1, @2); + } + | T_MINUSMINUS expr %prec PREFIX_INCDEC + { + $$ = ast_mkUnOp(L_OP_MINUSMINUS_PRE, $2, @1, @2); + } + | expr T_PLUSPLUS + { + $$ = ast_mkUnOp(L_OP_PLUSPLUS_POST, $1, @1, @2); + } + | expr T_MINUSMINUS + { + $$ = ast_mkUnOp(L_OP_MINUSMINUS_POST, $1, @1, @2); + } + | expr T_EQTWID regexp_literal_mod + { + $$ = ast_mkBinOp(L_OP_EQTWID, $1, $3, @1, @3); + } + | expr T_BANGTWID regexp_literal_mod + { + $$ = ast_mkBinOp(L_OP_BANGTWID, $1, $3, @1, @3); + } + | expr T_EQTWID regexp_literal subst_literal T_RE_MODIFIER + { + if (strchr($5, 'i')) $3->flags |= L_EXPR_RE_I; + if (strchr($5, 'g')) $3->flags |= L_EXPR_RE_G; + $$ = ast_mkTrinOp(L_OP_EQTWID, $1, $3, $4, @1, @5); + ckfree($5); + } + | expr T_STAR expr + { + $$ = ast_mkBinOp(L_OP_STAR, $1, $3, @1, @3); + } + | expr T_SLASH expr + { + $$ = ast_mkBinOp(L_OP_SLASH, $1, $3, @1, @3); + } + | expr T_PERC expr + { + $$ = ast_mkBinOp(L_OP_PERC, $1, $3, @1, @3); + } + | expr T_PLUS expr + { + $$ = ast_mkBinOp(L_OP_PLUS, $1, $3, @1, @3); + } + | expr T_MINUS expr + { + $$ = ast_mkBinOp(L_OP_MINUS, $1, $3, @1, @3); + } + | expr T_EQ expr + { + $$ = ast_mkBinOp(L_OP_STR_EQ, $1, $3, @1, @3); + } + | expr T_NE expr + { + $$ = ast_mkBinOp(L_OP_STR_NE, $1, $3, @1, @3); + } + | expr T_LT expr + { + $$ = ast_mkBinOp(L_OP_STR_LT, $1, $3, @1, @3); + } + | expr T_LE expr + { + $$ = ast_mkBinOp(L_OP_STR_LE, $1, $3, @1, @3); + } + | expr T_GT expr + { + $$ = ast_mkBinOp(L_OP_STR_GT, $1, $3, @1, @3); + } + | expr T_GE expr + { + $$ = ast_mkBinOp(L_OP_STR_GE, $1, $3, @1, @3); + } + | expr T_EQUALEQUAL expr + { + $$ = ast_mkBinOp(L_OP_EQUALEQUAL, $1, $3, @1, @3); + } + | T_EQ "(" expr "," expr ")" + { + $$ = ast_mkBinOp(L_OP_EQUALEQUAL, $3, $5, @1, @6); + } + | expr T_NOTEQUAL expr + { + $$ = ast_mkBinOp(L_OP_NOTEQUAL, $1, $3, @1, @3); + } + | expr T_GREATER expr + { + $$ = ast_mkBinOp(L_OP_GREATER, $1, $3, @1, @3); + } + | expr T_GREATEREQ expr + { + $$ = ast_mkBinOp(L_OP_GREATEREQ, $1, $3, @1, @3); + } + | expr T_LESSTHAN expr + { + $$ = ast_mkBinOp(L_OP_LESSTHAN, $1, $3, @1, @3); + } + | expr T_LESSTHANEQ expr + { + $$ = ast_mkBinOp(L_OP_LESSTHANEQ, $1, $3, @1, @3); + } + | expr T_ANDAND expr + { + $$ = ast_mkBinOp(L_OP_ANDAND, $1, $3, @1, @3); + } + | expr T_OROR expr + { + $$ = ast_mkBinOp(L_OP_OROR, $1, $3, @1, @3); + } + | expr T_LSHIFT expr + { + $$ = ast_mkBinOp(L_OP_LSHIFT, $1, $3, @1, @3); + } + | expr T_RSHIFT expr + { + $$ = ast_mkBinOp(L_OP_RSHIFT, $1, $3, @1, @3); + } + | expr T_BITOR expr + { + $$ = ast_mkBinOp(L_OP_BITOR, $1, $3, @1, @3); + } + | expr T_BITAND expr + { + $$ = ast_mkBinOp(L_OP_BITAND, $1, $3, @1, @3); + } + | expr T_BITXOR expr + { + $$ = ast_mkBinOp(L_OP_BITXOR, $1, $3, @1, @3); + } + | id + | string_literal + | cmdsubst_literal + | T_INT_LITERAL + { + $$ = ast_mkConst(L_int, $1, @1, @1); + } + | T_FLOAT_LITERAL + { + $$ = ast_mkConst(L_float, $1, @1, @1); + } + | id "(" argument_expr_list ")" + { + REVERSE(Expr, next, $3); + $$ = ast_mkFnCall($1, $3, @1, @4); + } + | id "(" ")" + { + $$ = ast_mkFnCall($1, NULL, @1, @3); + } + | T_STRING "(" argument_expr_list ")" + { + Expr *id = ast_mkId("string", @1, @1); + REVERSE(Expr, next, $3); + $$ = ast_mkFnCall(id, $3, @1, @4); + } + | T_SPLIT "(" re_start_split regexp_literal_mod "," argument_expr_list ")" + { + Expr *id = ast_mkId("split", @1, @1); + REVERSE(Expr, next, $6); + $4->next = $6; + $$ = ast_mkFnCall(id, $4, @1, @7); + } + /* + * Even though there is no regexp arg in this form, the + * re_start_split is necessary to be able to scan either a + * regexp or a non-regexp first argument. The scanner makes + * that decision based on the first one or two characters and + * then returns appropriate tokens. + */ + | T_SPLIT "(" re_start_split argument_expr_list ")" + { + Expr *id = ast_mkId("split", @1, @1); + REVERSE(Expr, next, $4); + $$ = ast_mkFnCall(id, $4, @1, @5); + } + /* this is to allow calling Tk widget functions */ + | dotted_id "(" argument_expr_list ")" + { + REVERSE(Expr, next, $3); + $$ = ast_mkFnCall($1, $3, @1, @4); + } + | dotted_id "(" ")" + { + $$ = ast_mkFnCall($1, NULL, @1, @3); + } + | expr T_EQUALS expr + { + $$ = ast_mkBinOp(L_OP_EQUALS, $1, $3, @1, @3); + } + | expr T_EQPLUS expr + { + $$ = ast_mkBinOp(L_OP_EQPLUS, $1, $3, @1, @3); + } + | expr T_EQMINUS expr + { + $$ = ast_mkBinOp(L_OP_EQMINUS, $1, $3, @1, @3); + } + | expr T_EQSTAR expr + { + $$ = ast_mkBinOp(L_OP_EQSTAR, $1, $3, @1, @3); + } + | expr T_EQSLASH expr + { + $$ = ast_mkBinOp(L_OP_EQSLASH, $1, $3, @1, @3); + } + | expr T_EQPERC expr + { + $$ = ast_mkBinOp(L_OP_EQPERC, $1, $3, @1, @3); + } + | expr T_EQBITAND expr + { + $$ = ast_mkBinOp(L_OP_EQBITAND, $1, $3, @1, @3); + } + | expr T_EQBITOR expr + { + $$ = ast_mkBinOp(L_OP_EQBITOR, $1, $3, @1, @3); + } + | expr T_EQBITXOR expr + { + $$ = ast_mkBinOp(L_OP_EQBITXOR, $1, $3, @1, @3); + } + | expr T_EQLSHIFT expr + { + $$ = ast_mkBinOp(L_OP_EQLSHIFT, $1, $3, @1, @3); + } + | expr T_EQRSHIFT expr + { + $$ = ast_mkBinOp(L_OP_EQRSHIFT, $1, $3, @1, @3); + } + | expr T_EQDOT expr + { + $$ = ast_mkBinOp(L_OP_EQDOT, $1, $3, @1, @3); + } + | T_DEFINED "(" expr ")" + { + $$ = ast_mkUnOp(L_OP_DEFINED, $3, @1, @4); + } + | expr "[" expr "]" + { + $$ = ast_mkBinOp(L_OP_ARRAY_INDEX, $1, $3, @1, @4); + } + | expr "{" expr "}" + { + $$ = ast_mkBinOp(L_OP_HASH_INDEX, $1, $3, @1, @4); + } + | expr T_STRCAT expr + { + $$ = ast_mkBinOp(L_OP_CONCAT, $1, $3, @1, @3); + } + | expr "." T_ID + { + $$ = ast_mkBinOp(L_OP_DOT, $1, NULL, @1, @3); + $$->str = $3; + } + | expr "->" T_ID + { + $$ = ast_mkBinOp(L_OP_POINTS, $1, NULL, @1, @3); + $$->str = $3; + } + | T_TYPE "." T_ID + { + // This is a binop where an arg is a Type*. + $$ = ast_mkBinOp(L_OP_CLASS_INDEX, (Expr *)$1.t, NULL, @1, @3); + $$->str = $3; + } + | T_TYPE "->" T_ID + { + // This is a binop where an arg is a Type*. + $$ = ast_mkBinOp(L_OP_CLASS_INDEX, (Expr *)$1.t, NULL, @1, @3); + $$->str = $3; + } + | expr "," expr + { + $$ = ast_mkBinOp(L_OP_COMMA, $1, $3, @1, @3); + } + | expr "[" expr T_DOTDOT expr "]" + { + $$ = ast_mkTrinOp(L_OP_ARRAY_SLICE, $1, $3, $5, @1, @3); + } + /* + * We don't really need to open a scope here, but it doesn't hurt, and + * it avoids a shift/reduce conflict with a compound_stmt production. + */ + | "{" enter_scope list "}" + { + $$ = $3; + $$->node.loc = @1; + $$->node.loc.end = @4.end; + L_scope_leave(); + } + | "{" "}" + { + $$ = ast_mkBinOp(L_OP_LIST, NULL, NULL, @1, @2); + } + | expr "?" expr ":" expr %prec T_QUESTION + { + $$ = ast_mkTrinOp(L_OP_TERNARY_COND, $1, $3, $5, @1, @5); + } + | "<" expr ">" + { + $$ = ast_mkUnOp(L_OP_FILE, $2, @1, @3); + } + | "<" ">" + { + $$ = ast_mkUnOp(L_OP_FILE, NULL, @1, @2); + } + ; + +re_start_split: + { L_lex_begReArg(0); } + ; + +re_start_case: + { L_lex_begReArg(1); } + ; + +id: + T_ID + { + $$ = ast_mkId($1, @1, @1); + ckfree($1); + } + ; + +id_list: + id + | id "," id_list + { + $$ = $1; + $$->next = $3; + $$->node.loc.end = @3.end; + } + ; + +compound_stmt: + "{" enter_scope "}" + { + $$ = ast_mkStmt(L_STMT_BLOCK, NULL, @1, @3); + $$->u.block = ast_mkBlock(NULL, NULL, @1, @3); + L_scope_leave(); + } + | "{" enter_scope stmt_list "}" + { + REVERSE(Stmt, next, $3); + $$ = ast_mkStmt(L_STMT_BLOCK, NULL, @1, @4); + $$->u.block = ast_mkBlock(NULL, $3, @1, @4); + L_scope_leave(); + } + | "{" enter_scope declaration_list "}" + { + VarDecl *v; + REVERSE(VarDecl, next, $3); + for (v = $3; v; v = v->next) { + v->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + } + $$ = ast_mkStmt(L_STMT_BLOCK, NULL, @1, @4); + $$->u.block = ast_mkBlock($3, NULL, @1, @4); + L_scope_leave(); + } + | "{" enter_scope declaration_list stmt_list "}" + { + VarDecl *v; + REVERSE(VarDecl, next, $3); + for (v = $3; v; v = v->next) { + v->flags |= SCOPE_LOCAL | DECL_LOCAL_VAR; + } + REVERSE(Stmt, next, $4); + $$ = ast_mkStmt(L_STMT_BLOCK, NULL, @1, @5); + $$->u.block = ast_mkBlock($3, $4, @1, @5); + L_scope_leave(); + } + ; + +enter_scope: + /* epsilon */ %prec HIGHEST { L_scope_enter(); } + ; + +declaration_list: + declaration + | declaration_list declaration + { + /* + * Each declaration is a list of declarators. Here we + * append the lists. + */ + APPEND(VarDecl, next, $2, $1); + $$ = $2; + } + ; + +declaration: + declaration2 ";" + | decl_qualifier declaration2 ";" + { + VarDecl *v; + for (v = $2; v; v = v->next) { + v->flags |= $1; + } + $$ = $2; + $$->node.loc = @1; + } + ; + +decl_qualifier: + T_PRIVATE { $$ = DECL_PRIVATE; } + | T_PUBLIC { $$ = DECL_PUBLIC; } + | T_EXTERN { $$ = DECL_EXTERN; } + ; + +declaration2: + type_specifier init_declarator_list + { + /* Don't REVERSE $2; it's done as part of declaration_list. */ + VarDecl *v; + for (v = $2; v; v = v->next) { + L_set_declBaseType(v, $1); + } + $$ = $2; + } + ; + +init_declarator_list: + init_declarator + | init_declarator_list "," init_declarator + { + $3->next = $1; + $$ = $3; + } + ; + +declarator_list: + declarator + | declarator_list "," declarator + { + $3->next = $1; + $$ = $3; + } + ; + +init_declarator: + declarator + | declarator T_EQUALS expr + { + $1->initializer = ast_mkBinOp(L_OP_EQUALS, $1->id, $3, @3, @3); + $$ = $1; + $$->node.loc.end = @3.end; + } + ; + +opt_declarator: + declarator + | { $$ = NULL; } + ; + +declarator: + id array_or_hash_type + { + $$ = ast_mkVarDecl($2, $1, @1, @2); + } + | T_TYPE array_or_hash_type + { + Expr *id = ast_mkId($1.s, @1, @1); + $$ = ast_mkVarDecl($2, id, @1, @2); + if (isnameoftype($1.t)) $$->flags |= DECL_REF; + ckfree($1.s); + } + | T_BITAND id array_or_hash_type + { + Type *t = type_mkNameOf($3); + $$ = ast_mkVarDecl(t, $2, @1, @3); + $$->flags |= DECL_REF; + } + | T_BITAND id "(" parameter_list ")" + { + Type *tf = type_mkFunc(NULL, $4); + Type *tn = type_mkNameOf(tf); + $$ = ast_mkVarDecl(tn, $2, @1, @5); + $$->flags |= DECL_REF; + } + ; + +/* Right recursion OK here since depth is typically low. */ +array_or_hash_type: + /* epsilon */ + { + $$ = NULL; + } + | "[" expr "]" array_or_hash_type + { + $$ = type_mkArray($2, $4); + } + | "[" "]" array_or_hash_type + { + $$ = type_mkArray(NULL, $3); + } + | "{" scalar_type_specifier "}" array_or_hash_type + { + $$ = type_mkHash($2, $4); + } + ; + +type_specifier: + scalar_type_specifier array_or_hash_type + { + if ($2) { + L_set_baseType($2, $1); + $$ = $2; + } else { + $$ = $1; + } + } + | struct_specifier array_or_hash_type + { + if ($2) { + L_set_baseType($2, $1); + $$ = $2; + } else { + $$ = $1; + } + } + ; + +scalar_type_specifier: + T_STRING { $$ = L_string; } + | T_INT { $$ = L_int; } + | T_FLOAT { $$ = L_float; } + | T_POLY { $$ = L_poly; } + | T_WIDGET { $$ = L_widget; } + | T_VOID { $$ = L_void; } + | T_TYPE { $$ = $1.t; ckfree($1.s); } + ; + +struct_specifier: + T_STRUCT T_ID "{" struct_decl_list "}" + { + REVERSE(VarDecl, next, $4); + $$ = L_struct_store($2, $4); + ckfree($2); + } + | T_STRUCT "{" struct_decl_list "}" + { + REVERSE(VarDecl, next, $3); + (void)L_struct_store(NULL, $3); // to sanity check member types + $$ = type_mkStruct(NULL, $3); + } + | T_STRUCT T_ID + { + $$ = L_struct_lookup($2, FALSE); + ckfree($2); + } + ; + +struct_decl_list: + struct_decl + | struct_decl_list struct_decl + { + APPEND(VarDecl, next, $2, $1); + $$ = $2; + $$->node.loc = @1; + } + ; + +struct_decl: + struct_declarator_list ";" { $$->node.loc.end = @2.end; } + ; + +struct_declarator_list: + type_specifier declarator_list + { + VarDecl *v; + for (v = $2; v; v = v->next) { + L_set_declBaseType(v, $1); + } + $$ = $2; + $$->node.loc = @1; + } + ; + +list: + list_element + | list "," list_element + { + APPEND(Expr, b, $1, $3); + $$ = $1; + } + | list "," + ; + +list_element: + expr %prec HIGHEST + { + $$ = ast_mkBinOp(L_OP_LIST, $1, NULL, @1, @1); + } + | expr "=>" expr %prec HIGHEST + { + Expr *kv = ast_mkBinOp(L_OP_KV, $1, $3, @1, @3); + $$ = ast_mkBinOp(L_OP_LIST, kv, NULL, @1, @3); + } + ; + +string_literal: + T_STR_LITERAL + { + $$ = ast_mkConst(L_string, $1, @1, @1); + } + | interpolated_expr T_STR_LITERAL + { + Expr *right = ast_mkConst(L_string, $2, @2, @2); + $$ = ast_mkBinOp(L_OP_INTERP_STRING, $1, right, @1, @2); + } + | here_doc_backtick T_STR_LITERAL + { + Expr *right = ast_mkConst(L_string, $2, @2, @2); + $$ = ast_mkBinOp(L_OP_INTERP_STRING, $1, right, @1, @2); + } + ; + +here_doc_backtick: + T_START_BACKTICK T_STR_BACKTICK + { + Expr *left = ast_mkConst(L_string, $1, @1, @1); + Expr *right = ast_mkUnOp(L_OP_CMDSUBST, NULL, @2, @2); + right->str = $2; + $$ = ast_mkBinOp(L_OP_INTERP_STRING, left, right, @1, @2); + } + | here_doc_backtick T_START_BACKTICK T_STR_BACKTICK + { + Expr *middle = ast_mkConst(L_string, $2, @2, @2); + Expr *right = ast_mkUnOp(L_OP_CMDSUBST, NULL, @3, @3); + right->str = $3; + $$ = ast_mkTrinOp(L_OP_INTERP_STRING, $1, middle, right, + @1, @3); + } + ; + +cmdsubst_literal: + T_STR_BACKTICK + { + $$ = ast_mkUnOp(L_OP_CMDSUBST, NULL, @1, @1); + $$->str = $1; + } + | interpolated_expr T_STR_BACKTICK + { + $$ = ast_mkUnOp(L_OP_CMDSUBST, $1, @1, @2); + $$->str = $2; + } + ; + +regexp_literal: + T_RE + { + $$ = ast_mkRegexp($1, @1, @1); + } + | interpolated_expr_re T_RE + { + Expr *right = ast_mkConst(L_string, $2, @2, @2); + $$ = ast_mkBinOp(L_OP_INTERP_RE, $1, right, @1, @2); + } + ; + +regexp_literal_mod: + regexp_literal T_RE_MODIFIER + { + /* Note: the scanner catches illegal modifiers. */ + if (strchr($2, 'i')) $1->flags |= L_EXPR_RE_I; + if (strchr($2, 'g')) $1->flags |= L_EXPR_RE_G; + if (strchr($2, 'l')) $1->flags |= L_EXPR_RE_L; + if (strchr($2, 't')) $1->flags |= L_EXPR_RE_T; + ckfree($2); + $$ = $1; + } + ; + +subst_literal: + T_SUBST + { + $$ = ast_mkConst(L_string, $1, @1, @1); + } + | interpolated_expr_re T_SUBST + { + Expr *right = ast_mkConst(L_string, $2, @2, @2); + $$ = ast_mkBinOp(L_OP_INTERP_RE, $1, right, @1, @2); + } + ; + +interpolated_expr: + T_LEFT_INTERPOL expr T_RIGHT_INTERPOL + { + Expr *left = ast_mkConst(L_string, $1, @1, @1); + $$ = ast_mkBinOp(L_OP_INTERP_STRING, left, $2, @1, @3); + } + | interpolated_expr T_LEFT_INTERPOL expr T_RIGHT_INTERPOL + { + Expr *middle = ast_mkConst(L_string, $2, @2, @2); + $$ = ast_mkTrinOp(L_OP_INTERP_STRING, $1, middle, $3, @1, @4); + } + ; + +interpolated_expr_re: + T_LEFT_INTERPOL_RE expr T_RIGHT_INTERPOL_RE + { + Expr *left = ast_mkConst(L_string, $1, @1, @1); + $$ = ast_mkBinOp(L_OP_INTERP_STRING, left, $2, @1, @3); + } + | interpolated_expr_re T_LEFT_INTERPOL_RE expr T_RIGHT_INTERPOL_RE + { + Expr *middle = ast_mkConst(L_string, $2, @2, @2); + $$ = ast_mkTrinOp(L_OP_INTERP_STRING, $1, middle, $3, @1, @4); + } + ; + +dotted_id: + "." + { + $$ = ast_mkId(".", @1, @1); + } + | dotted_id_1 + { + $$ = ast_mkId(Tcl_GetString($1), @1, @1); + Tcl_DecrRefCount($1); + } + ; + +dotted_id_1: + "." T_ID + { + $$ = Tcl_NewObj(); + Tcl_IncrRefCount($$); + Tcl_AppendToObj($$, ".", 1); + Tcl_AppendToObj($$, $2, -1); + ckfree($2); + } + | dotted_id_1 "." T_ID + { + Tcl_AppendToObj($1, ".", 1); + Tcl_AppendToObj($1, $3, -1); + $$ = $1; + ckfree($3); + } + ; +%% diff --git a/generic/Lscanner-pregen.c b/generic/Lscanner-pregen.c new file mode 100644 index 0000000..2af2ada --- /dev/null +++ b/generic/Lscanner-pregen.c @@ -0,0 +1,4739 @@ + +#line 3 "<stdout>" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define yy_create_buffer L__create_buffer +#define yy_delete_buffer L__delete_buffer +#define yy_flex_debug L__flex_debug +#define yy_init_buffer L__init_buffer +#define yy_flush_buffer L__flush_buffer +#define yy_load_buffer_state L__load_buffer_state +#define yy_switch_to_buffer L__switch_to_buffer +#define yyin L_in +#define yyleng L_leng +#define yylex L_lex +#define yylineno L_lineno +#define yyout L_out +#define yyrestart L_restart +#define yytext L_text +#define yywrap L_wrap +#define yyalloc L_alloc +#define yyrealloc L_realloc +#define yyfree L_free + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 39 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE L_restart(L_in ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t L_leng; + +extern FILE *L_in, *L_out; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up L_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up L_text again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + yy_size_t yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via L_restart()), so that the user can continue scanning by + * just pointing L_in at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when L_text is formed. */ +static char yy_hold_char; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t L_leng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow L_wrap()'s to do buffer switches + * instead of setting up a fresh L_in. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void L_restart (FILE *input_file ); +void L__switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE L__create_buffer (FILE *file,int size ); +void L__delete_buffer (YY_BUFFER_STATE b ); +void L__flush_buffer (YY_BUFFER_STATE b ); +void L_push_buffer_state (YY_BUFFER_STATE new_buffer ); +void L_pop_buffer_state (void ); + +static void L_ensure_buffer_stack (void ); +static void L__load_buffer_state (void ); +static void L__init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER L__flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE L__scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE L__scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE L__scan_bytes (yyconst char *bytes,yy_size_t len ); + +void *L_alloc (yy_size_t ); +void *L_realloc (void *,yy_size_t ); +void L_free (void * ); + +#define yy_new_buffer L__create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + L_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + L__create_buffer(L_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + L_ensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + L__create_buffer(L_in,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define L_wrap() 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *L_in = (FILE *) 0, *L_out = (FILE *) 0; + +typedef int yy_state_type; + +extern int L_lineno; + +int L_lineno = 1; + +extern char *L_text; +#define yytext_ptr L_text + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up L_text. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + L_leng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 206 +#define YY_END_OF_BUFFER 207 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_acclist[819] = + { 0, + 138, 138, 142, 142, 207, 205, 206, 117, 205, 206, + 118, 206, 118, 205, 206, 118, 205, 206, 7, 205, + 206, 119, 205, 206, 205, 206, 12, 205, 206, 28, + 205, 206, 120, 205, 206, 1, 205, 206, 2, 205, + 206, 10, 205, 206, 8, 205, 206, 6, 205, 206, + 9, 205, 206, 36, 205, 206, 11, 205, 206, 103, + 205, 206, 103, 205, 206, 92, 205, 206, 35, 205, + 206, 89, 205, 206, 34, 205, 206, 87, 205, 206, + 93, 205, 206, 99, 205, 206, 4, 205, 206, 5, + 205, 206, 30, 205, 206, 99, 205, 206, 121, 205, + + 206, 99, 205, 206, 99, 205, 206, 99, 205, 206, + 99, 205, 206, 99, 205, 206, 99, 205, 206, 99, + 205, 206, 99, 205, 206, 99, 205, 206, 99, 205, + 206, 99, 205, 206, 99, 205, 206, 99, 205, 206, + 99, 205, 206, 99, 205, 206, 99, 205, 206, 99, + 205, 206, 99, 205, 206, 99, 205, 206, 99, 205, + 206, 3, 205, 206, 29, 205, 206, 146, 205, 206, + 31, 205, 206, 205, 206, 200, 206, 199, 206, 202, + 206, 201, 202, 206, 141, 206, 138, 141, 206, 138, + 206, 139, 141, 206, 141, 206, 145, 206, 142, 145, + + 206, 142, 206, 143, 145, 206, 145, 206, 198, 206, + 196, 206, 198, 206, 198, 206, 191, 206, 192, 206, + 159, 206, 158, 206, 162, 206, 157, 206, 206, 168, + 206, 166, 206, 170, 206, 206, 175, 206, 176, 206, + 174, 206, 206, 178, 206, 148, 206, 117, 148, 206, + 118, 148, 206, 118, 148, 206, 7, 148, 206, 119, + 148, 206, 148, 206, 12, 148, 206, 28, 148, 206, + 120, 148, 206, 1, 148, 206, 2, 148, 206, 10, + 148, 206, 8, 148, 206, 6, 148, 206, 9, 148, + 206, 36, 148, 206, 11, 148, 206, 103, 148, 206, + + 103, 148, 206, 92, 148, 206, 35, 148, 206, 89, + 148, 206, 34, 148, 206, 87, 148, 206, 93, 148, + 206, 99, 148, 206, 4, 148, 206, 5, 148, 206, + 30, 148, 206, 99, 148, 206, 121, 148, 206, 99, + 148, 206, 99, 148, 206, 99, 148, 206, 99, 148, + 206, 99, 148, 206, 99, 148, 206, 99, 148, 206, + 99, 148, 206, 99, 148, 206, 99, 148, 206, 99, + 148, 206, 99, 148, 206, 99, 148, 206, 99, 148, + 206, 99, 148, 206, 99, 148, 206, 99, 148, 206, + 99, 148, 206, 99, 148, 206, 99, 148, 206, 3, + + 148, 206, 29, 148, 206, 147, 148, 206, 31, 148, + 206, 148, 206, 190, 206, 190, 206, 190, 206, 187, + 190, 206, 189, 190, 206, 190, 206, 181, 206, 180, + 181, 206, 181, 206, 203, 206, 204, 206, 136, 206, + 136, 206, 136, 206, 137, 206, 117, 86, 102, 17, + 26, 18, 15, 24, 13, 25, 14, 91, 38, 106, + 23, 122, 16, 103, 99, 32, 90, 85, 78, 88, + 33, 94, 99, 100, 99, 20, 99, 100, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 54, 99, 99, + 79, 99, 99, 99, 99, 84, 99, 99, 83, 99, + + 50, 99, 99, 82, 99, 81, 99, 80, 99, 99, + 97, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 19, 27, 114, 114, + 201, 138, 140, 142, 144, 197, 194, 195, 191, 193, + 159, 161, 160, 156, 150, 156, 149, 156, 151, 156, + 156, 168, 169, 167, 165, 164, 167, 163, 167, 175, + 177, 173, 172, 171, 173, 186, 185, 183, 182, 184, + 189, 188, 180, 179, 135, 115, 115, 37, 124, 39, + 116, 116, 104, 105, 21, 22, 101, 99, 99, 99, + 99, 95, 99, 99, 99, 99, 99, 99, 99, 99, + + 99, 99, 99, 55, 99, 99, 99, 46, 99, 96, + 99, 99, 99, 99, 99, 99, 99, 99, 77, 99, + 99, 99, 99, 99, 99, 98, 99, 114, 152, 135, + 115, 123, 116, 125, 99, 99, 99, 99, 99, 75, + 99, 99, 99, 99, 99, 99, 99, 51, 99, 99, + 99, 99, 99, 73, 99, 99, 48, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 43, 99, 99, + 99, 153, 131, 131, 128, 131, 130, 126, 130, 99, + 99, 99, 99, 60, 99, 40, 99, 99, 99, 99, + 99, 99, 99, 99, 47, 99, 99, 99, 99, 99, + + 99, 49, 99, 99, 99, 99, 99, 99, 53, 99, + 99, 154, 131, 131, 128, 131, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 67, 99, 41, 99, 99, + 99, 99, 64, 99, 42, 99, 44, 99, 56, 99, + 74, 99, 99, 52, 99, 45, 99, 109, 114, 114, + 155, 133, 132, 127, 129, 99, 99, 99, 99, 99, + 99, 76, 99, 58, 99, 99, 59, 99, 99, 63, + 99, 57, 99, 109, 114, 68, 99, 99, 99, 99, + 99, 61, 99, 99, 62, 99, 112, 107, 109, 114, + 113, 134, 99, 99, 71, 99, 99, 99, 69, 99, + + 99, 99, 66, 99, 114, 114, 114, 70, 99, 72, + 99, 65, 99, 110, 111, 108, 109, 114 + } ; + +static yyconst flex_int16_t yy_accept[584] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 6, 8, 11, 13, 16, + 19, 22, 25, 27, 30, 33, 36, 39, 42, 45, + 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, + 78, 81, 84, 87, 90, 93, 96, 99, 102, 105, + 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, + 138, 141, 144, 147, 150, 153, 156, 159, 162, 165, + 168, 171, 174, 176, 178, 180, 182, 185, 187, 190, + + 192, 195, 197, 199, 202, 204, 207, 209, 211, 213, + 215, 217, 219, 221, 223, 225, 227, 229, 230, 232, + 234, 236, 237, 239, 241, 243, 244, 246, 248, 251, + 254, 257, 260, 263, 265, 268, 271, 274, 277, 280, + 283, 286, 289, 292, 295, 298, 301, 304, 307, 310, + 313, 316, 319, 322, 325, 328, 331, 334, 337, 340, + 343, 346, 349, 352, 355, 358, 361, 364, 367, 370, + 373, 376, 379, 382, 385, 388, 391, 394, 397, 400, + 403, 406, 409, 412, 414, 416, 418, 420, 423, 426, + 428, 430, 433, 435, 437, 439, 441, 443, 445, 447, + + 448, 448, 448, 448, 449, 449, 450, 451, 452, 453, + 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, + 463, 464, 464, 465, 465, 465, 466, 467, 468, 468, + 468, 469, 470, 470, 471, 472, 473, 474, 475, 476, + 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, + 487, 488, 490, 491, 493, 494, 495, 496, 498, 499, + 501, 503, 504, 506, 508, 510, 511, 513, 514, 515, + 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, + 526, 527, 528, 529, 529, 530, 531, 531, 531, 531, + 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, + + 542, 542, 543, 544, 545, 547, 549, 551, 552, 553, + 553, 554, 555, 556, 558, 560, 561, 562, 563, 564, + 566, 567, 568, 569, 570, 571, 572, 572, 573, 573, + 573, 574, 574, 575, 575, 575, 576, 576, 576, 577, + 578, 579, 579, 580, 580, 581, 581, 582, 583, 584, + 585, 586, 586, 586, 586, 587, 588, 589, 590, 591, + 592, 594, 595, 596, 597, 598, 599, 600, 601, 602, + 603, 604, 606, 607, 608, 610, 612, 613, 614, 615, + 616, 617, 618, 619, 621, 622, 623, 624, 625, 626, + 628, 629, 629, 629, 629, 630, 631, 631, 632, 633, + + 634, 634, 634, 634, 634, 635, 636, 637, 638, 639, + 640, 642, 643, 644, 645, 646, 647, 648, 650, 651, + 652, 653, 654, 656, 657, 659, 660, 661, 662, 663, + 664, 665, 666, 667, 668, 670, 671, 672, 672, 672, + 672, 673, 673, 674, 674, 675, 675, 677, 678, 679, + 680, 681, 682, 683, 684, 686, 688, 689, 690, 691, + 692, 693, 694, 695, 697, 698, 699, 700, 701, 702, + 704, 705, 706, 707, 708, 709, 711, 712, 712, 712, + 712, 713, 713, 714, 714, 714, 715, 715, 717, 718, + 719, 720, 721, 722, 723, 724, 725, 726, 728, 730, + + 731, 732, 733, 735, 737, 739, 741, 743, 744, 746, + 748, 748, 748, 748, 750, 751, 751, 752, 752, 753, + 753, 754, 755, 756, 756, 757, 758, 759, 760, 761, + 762, 764, 766, 767, 769, 770, 772, 774, 774, 774, + 776, 776, 776, 778, 779, 780, 781, 782, 784, 785, + 787, 788, 788, 791, 792, 793, 794, 795, 797, 798, + 799, 799, 799, 799, 799, 801, 802, 803, 805, 805, + 806, 806, 807, 807, 808, 808, 810, 812, 814, 815, + 816, 819, 819 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 4, 5, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 22, + 22, 22, 22, 22, 22, 23, 23, 24, 25, 26, + 27, 28, 29, 1, 30, 30, 30, 30, 30, 30, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, + + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 47, 63, 64, 65, 66, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[67] = + { 0, + 1, 2, 3, 1, 4, 1, 5, 1, 6, 1, + 1, 7, 4, 8, 9, 1, 1, 1, 1, 1, + 10, 10, 10, 11, 12, 1, 1, 1, 1, 13, + 14, 1, 15, 1, 1, 16, 17, 13, 13, 13, + 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 1, 1, 1, 1 + } ; + +static yyconst flex_int16_t yy_base[637] = + { 0, + 0, 1883, 1885, 1881, 23, 24, 72, 80, 84, 88, + 85, 92, 93, 94, 1866, 1865, 102, 103, 95, 111, + 110, 112, 149, 1870, 207, 243, 0, 304, 1874, 1871, + 1844, 91, 0, 0, 1867, 2002, 215, 219, 2002, 223, + 192, 2002, 110, 1839, 113, 2002, 2002, 2002, 1836, 121, + 2002, 209, 227, 236, 210, 238, 1836, 2002, 52, 305, + 114, 1831, 211, 2002, 2002, 1831, 215, 2002, 217, 254, + 287, 343, 344, 289, 345, 1833, 348, 346, 352, 351, + 355, 288, 358, 354, 219, 349, 376, 356, 2002, 250, + 2002, 2002, 378, 2002, 2002, 2002, 271, 2002, 316, 321, + + 2002, 0, 2002, 387, 423, 2002, 0, 2002, 2002, 411, + 0, 0, 1836, 0, 2002, 433, 1790, 386, 0, 2002, + 443, 417, 0, 2002, 1773, 414, 2002, 2002, 451, 2002, + 458, 203, 2002, 443, 1792, 385, 2002, 2002, 2002, 1754, + 239, 2002, 440, 457, 442, 464, 469, 1753, 2002, 445, + 491, 454, 1747, 350, 2002, 2002, 1747, 451, 2002, 449, + 471, 475, 478, 474, 390, 480, 1749, 488, 487, 491, + 481, 490, 510, 514, 485, 517, 497, 527, 526, 2002, + 519, 2002, 2002, 550, 2002, 1709, 551, 2002, 1769, 427, + 2002, 1768, 555, 2002, 2002, 2002, 1738, 1715, 2002, 574, + + 587, 324, 505, 2002, 561, 564, 2002, 2002, 2002, 2002, + 2002, 2002, 2002, 2002, 2002, 1744, 579, 2002, 2002, 556, + 2002, 586, 591, 548, 0, 580, 1735, 2002, 592, 1735, + 2002, 2002, 617, 2002, 1733, 2002, 581, 1735, 105, 2002, + 1734, 1733, 574, 567, 591, 597, 599, 60, 602, 600, + 603, 1732, 604, 1731, 608, 606, 609, 1728, 611, 1724, + 1722, 615, 1721, 1720, 1719, 612, 1718, 621, 610, 298, + 618, 625, 623, 630, 619, 624, 631, 633, 638, 642, + 639, 2002, 2002, 647, 2002, 682, 683, 686, 687, 649, + 694, 2002, 698, 2002, 2002, 2002, 2002, 0, 2002, 0, + + 702, 2002, 2002, 2002, 2002, 2002, 2002, 0, 0, 708, + 2002, 2002, 2002, 2002, 2002, 0, 2002, 2002, 2002, 2002, + 2002, 2002, 2002, 2002, 2002, 1739, 699, 2002, 705, 1735, + 1733, 711, 2002, 712, 1731, 1706, 1686, 713, 2002, 714, + 720, 724, 2002, 0, 2002, 728, 2002, 735, 724, 0, + 2002, 774, 839, 0, 2002, 2002, 697, 704, 711, 715, + 1707, 719, 723, 819, 821, 724, 822, 726, 725, 727, + 728, 729, 824, 823, 1706, 1705, 825, 360, 832, 826, + 827, 828, 831, 1704, 731, 829, 841, 834, 846, 1703, + 2002, 857, 858, 861, 0, 2002, 1675, 2002, 2002, 2002, + + 0, 909, 1694, 975, 2002, 833, 830, 843, 848, 844, + 1673, 845, 1018, 1019, 1020, 1021, 1022, 1670, 1023, 1024, + 1025, 869, 1648, 1026, 1640, 1028, 1027, 1029, 1030, 1032, + 1031, 1036, 1039, 1033, 1636, 1043, 1044, 1056, 1085, 1088, + 0, 1596, 0, 0, 1617, 0, 0, 2002, 2002, 0, + 1038, 1046, 1057, 1045, 1604, 1602, 1071, 1074, 1075, 1076, + 1077, 1078, 1079, 1591, 1080, 1082, 1083, 1088, 1085, 1568, + 1087, 1084, 1089, 1097, 1086, 1561, 1090, 1112, 900, 1140, + 0, 1574, 0, 1563, 1571, 1557, 1556, 0, 1113, 1099, + 1120, 1098, 1092, 1105, 1122, 1124, 1127, 1539, 1535, 1128, + + 1129, 1130, 1534, 1533, 1261, 1260, 1252, 532, 1243, 1225, + 1153, 751, 1175, 2002, 755, 1154, 2002, 1162, 2002, 1154, + 2002, 2002, 2002, 1046, 1147, 1137, 1136, 1144, 1151, 1157, + 740, 735, 1150, 688, 1162, 482, 473, 1184, 1198, 2002, + 1203, 1206, 425, 1178, 1152, 1187, 1186, 353, 1188, 292, + 1239, 1245, 2002, 1213, 2002, 1189, 629, 240, 1193, 1198, + 1252, 901, 1234, 1227, 1200, 1209, 1214, 122, 1261, 1267, + 1255, 1258, 1268, 1274, 893, 115, 52, 47, 1220, 1277, + 2002, 2002, 1286, 1303, 1320, 1337, 1354, 1371, 1388, 1405, + 1422, 1439, 1456, 1473, 1490, 1507, 1515, 1522, 1538, 1555, + + 1572, 1589, 1606, 1623, 1640, 1657, 1674, 1691, 1707, 1723, + 1737, 1752, 1766, 1782, 1799, 262, 552, 1816, 1833, 1517, + 1838, 1848, 1524, 1855, 1859, 1869, 1873, 1880, 1896, 1573, + 1907, 1923, 1934, 1950, 1967, 1984 + } ; + +static yyconst flex_int16_t yy_def[637] = + { 0, + 582, 1, 583, 583, 584, 584, 585, 585, 586, 586, + 587, 587, 587, 587, 588, 588, 589, 589, 590, 590, + 591, 591, 582, 23, 592, 592, 593, 593, 594, 594, + 595, 595, 596, 596, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 597, 582, 582, 582, 598, 582, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 582, 582, + 582, 582, 599, 582, 582, 582, 582, 582, 582, 582, + + 582, 600, 582, 582, 582, 582, 601, 582, 582, 582, + 602, 603, 582, 604, 582, 582, 582, 605, 606, 582, + 582, 607, 608, 582, 582, 609, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 597, 582, 582, 582, 598, 582, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 582, + 582, 582, 582, 599, 582, 582, 582, 582, 610, 611, + 582, 612, 613, 582, 582, 582, 582, 582, 582, 582, + + 582, 614, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 615, + 582, 582, 582, 582, 616, 597, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 597, 582, 598, 582, + 598, 582, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 582, 582, 599, 582, 599, 599, 599, 599, 582, + 582, 582, 582, 582, 582, 582, 582, 603, 582, 604, + + 582, 582, 582, 582, 582, 582, 582, 617, 606, 582, + 582, 582, 582, 582, 582, 608, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 610, 611, 582, 611, 582, + 612, 613, 582, 613, 582, 582, 582, 614, 582, 614, + 582, 582, 582, 618, 582, 615, 582, 615, 582, 616, + 582, 582, 582, 619, 582, 582, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 582, 599, 599, 599, 620, 582, 582, 582, 582, 582, + + 621, 582, 622, 582, 582, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 599, 599, 599, + 623, 582, 624, 625, 626, 627, 628, 582, 582, 404, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 599, 629, 599, + 630, 582, 624, 631, 632, 626, 633, 628, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + + 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, + 599, 629, 629, 582, 629, 599, 582, 582, 582, 631, + 582, 582, 582, 633, 598, 598, 598, 598, 598, 598, + 598, 598, 598, 598, 598, 598, 598, 599, 629, 582, + 599, 582, 598, 598, 598, 598, 598, 598, 598, 598, + 599, 629, 582, 599, 582, 598, 598, 598, 598, 598, + 599, 634, 635, 636, 598, 598, 598, 598, 634, 634, + 635, 635, 636, 636, 629, 598, 598, 598, 599, 599, + 582, 0, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582 + } ; + +static yyconst flex_int16_t yy_nxt[2069] = + { 0, + 36, 37, 38, 39, 40, 41, 42, 36, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, + 63, 64, 36, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 76, 76, 78, 76, + 79, 80, 81, 76, 82, 83, 84, 85, 86, 87, + 88, 76, 89, 90, 91, 92, 97, 97, 97, 97, + 242, 97, 97, 99, 100, 242, 99, 227, 228, 97, + 97, 99, 100, 242, 99, 104, 105, 109, 104, 104, + 105, 101, 104, 110, 109, 109, 109, 120, 198, 101, + + 110, 110, 110, 106, 115, 115, 121, 106, 116, 116, + 117, 117, 124, 120, 124, 363, 197, 111, 125, 356, + 125, 102, 121, 208, 111, 111, 111, 122, 242, 102, + 206, 206, 206, 107, 118, 118, 211, 107, 242, 209, + 234, 235, 126, 122, 126, 242, 127, 212, 127, 128, + 129, 38, 130, 131, 132, 133, 128, 134, 135, 136, + 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, + 147, 147, 148, 149, 150, 151, 152, 153, 154, 154, + 155, 128, 156, 157, 158, 159, 160, 161, 162, 163, + 164, 165, 166, 167, 168, 167, 167, 169, 167, 170, + + 171, 172, 167, 173, 174, 175, 176, 177, 178, 179, + 167, 180, 181, 182, 183, 186, 200, 201, 204, 201, + 201, 201, 202, 201, 201, 201, 213, 201, 222, 204, + 223, 223, 223, 203, 238, 214, 215, 203, 242, 187, + 242, 203, 242, 188, 189, 216, 239, 217, 217, 217, + 219, 186, 243, 218, 211, 220, 222, 205, 223, 223, + 223, 224, 221, 242, 244, 212, 245, 246, 205, 277, + 225, 350, 190, 190, 350, 187, 282, 242, 190, 188, + 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, + 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, + + 190, 190, 190, 190, 190, 192, 229, 229, 247, 229, + 242, 242, 242, 283, 290, 242, 290, 291, 291, 290, + 291, 242, 291, 291, 248, 291, 339, 290, 340, 271, + 230, 231, 232, 193, 193, 249, 379, 256, 250, 193, + 257, 193, 193, 193, 193, 193, 193, 193, 193, 193, + 193, 193, 193, 193, 193, 193, 193, 193, 193, 193, + 193, 193, 193, 193, 193, 193, 242, 242, 242, 242, + 233, 242, 242, 238, 242, 242, 242, 242, 242, 242, + 285, 242, 286, 242, 251, 239, 258, 263, 293, 293, + 261, 293, 253, 265, 252, 208, 259, 254, 262, 242, + + 278, 260, 264, 266, 255, 267, 268, 281, 275, 269, + 272, 209, 270, 242, 273, 276, 319, 274, 426, 313, + 279, 280, 320, 287, 293, 293, 288, 293, 314, 328, + 289, 295, 295, 295, 301, 301, 305, 301, 256, 302, + 306, 257, 307, 308, 310, 310, 320, 310, 242, 315, + 320, 330, 200, 201, 311, 201, 219, 213, 202, 201, + 201, 220, 201, 206, 206, 206, 214, 215, 221, 203, + 227, 228, 242, 296, 242, 216, 203, 217, 217, 217, + 234, 235, 222, 218, 223, 223, 223, 222, 243, 223, + 223, 223, 229, 229, 242, 229, 242, 242, 242, 246, + + 244, 242, 245, 242, 242, 242, 341, 341, 242, 341, + 242, 242, 248, 242, 242, 224, 230, 231, 232, 251, + 242, 258, 253, 249, 225, 247, 250, 254, 263, 252, + 261, 259, 265, 242, 255, 267, 260, 242, 262, 275, + 242, 268, 266, 264, 269, 282, 276, 270, 278, 242, + 242, 271, 285, 322, 286, 242, 233, 333, 347, 323, + 348, 395, 342, 342, 395, 342, 272, 277, 349, 349, + 273, 279, 280, 274, 537, 200, 201, 281, 201, 335, + 343, 202, 283, 324, 206, 206, 206, 325, 201, 201, + 242, 201, 203, 229, 229, 287, 229, 242, 288, 217, + + 217, 217, 289, 238, 238, 203, 217, 217, 217, 222, + 344, 223, 223, 223, 242, 239, 239, 230, 353, 353, + 242, 353, 242, 242, 359, 242, 242, 242, 357, 242, + 358, 242, 242, 242, 242, 242, 343, 361, 242, 364, + 362, 242, 242, 360, 242, 366, 242, 242, 242, 285, + 365, 286, 242, 242, 242, 378, 242, 371, 367, 368, + 369, 242, 242, 372, 370, 242, 344, 373, 376, 377, + 374, 375, 354, 381, 380, 383, 385, 382, 387, 386, + 384, 566, 389, 388, 391, 285, 286, 286, 285, 285, + 286, 286, 290, 390, 290, 291, 291, 290, 291, 293, + + 293, 328, 293, 301, 301, 290, 301, 328, 302, 310, + 310, 242, 310, 333, 333, 339, 398, 340, 340, 311, + 242, 341, 341, 330, 341, 342, 342, 242, 342, 330, + 347, 393, 348, 392, 242, 335, 335, 400, 242, 348, + 406, 394, 242, 343, 349, 349, 242, 242, 242, 242, + 242, 242, 242, 514, 242, 515, 410, 540, 242, 515, + 407, 415, 419, 242, 411, 421, 408, 418, 420, 416, + 422, 409, 433, 344, 401, 401, 401, 401, 401, 401, + 401, 401, 401, 401, 401, 402, 401, 401, 401, 401, + 401, 403, 401, 401, 401, 401, 401, 401, 401, 401, + + 401, 401, 401, 404, 404, 401, 401, 401, 401, 404, + 401, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 401, 401, 401, 401, + 353, 353, 242, 353, 242, 242, 242, 242, 242, 242, + 242, 242, 242, 242, 242, 242, 242, 242, 343, 285, + 285, 286, 286, 285, 242, 286, 242, 242, 242, 242, + 434, 242, 429, 430, 412, 423, 413, 414, 417, 424, + 427, 435, 436, 428, 452, 431, 425, 432, 344, 437, + 451, 455, 242, 454, 354, 581, 438, 515, 440, 453, + + 456, 513, 514, 285, 515, 570, 465, 284, 439, 444, + 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, + 444, 444, 444, 444, 444, 444, 444, 444, 444, 444, + 444, 444, 444, 444, 444, 444, 444, 444, 445, 445, + 444, 444, 444, 444, 445, 444, 445, 445, 445, 445, + 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, + 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, + 445, 444, 444, 444, 444, 448, 448, 449, 448, 448, + 448, 448, 448, 448, 448, 448, 448, 448, 448, 448, + 448, 448, 448, 448, 448, 450, 450, 450, 448, 448, + + 448, 448, 448, 448, 450, 450, 448, 448, 448, 448, + 450, 448, 450, 450, 450, 450, 450, 450, 450, 450, + 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, + 450, 450, 450, 450, 450, 450, 450, 448, 448, 448, + 448, 242, 242, 242, 242, 242, 242, 242, 242, 242, + 242, 242, 242, 242, 242, 242, 242, 523, 285, 242, + 286, 242, 242, 466, 458, 467, 242, 242, 242, 242, + 472, 460, 468, 462, 457, 473, 461, 459, 463, 474, + 242, 464, 471, 469, 476, 477, 470, 285, 475, 286, + 285, 490, 286, 489, 242, 491, 492, 242, 242, 242, + + 242, 242, 242, 242, 478, 242, 242, 242, 242, 242, + 242, 242, 242, 242, 285, 242, 286, 496, 498, 500, + 242, 242, 242, 495, 494, 493, 479, 503, 242, 499, + 505, 480, 501, 507, 497, 504, 242, 526, 508, 502, + 506, 509, 285, 242, 286, 242, 510, 242, 528, 529, + 242, 242, 242, 242, 525, 285, 285, 286, 286, 242, + 242, 527, 530, 518, 532, 519, 533, 242, 535, 511, + 242, 536, 534, 242, 242, 242, 513, 514, 531, 515, + 242, 546, 542, 542, 542, 242, 285, 543, 286, 516, + 547, 541, 545, 538, 544, 539, 539, 539, 548, 552, + + 553, 242, 515, 550, 554, 285, 549, 286, 555, 242, + 242, 242, 242, 557, 554, 285, 242, 286, 539, 539, + 539, 242, 285, 242, 286, 551, 542, 542, 542, 514, + 565, 574, 242, 575, 556, 558, 285, 242, 572, 560, + 561, 285, 559, 286, 567, 562, 552, 514, 242, 515, + 577, 564, 568, 561, 285, 576, 286, 285, 562, 572, + 391, 284, 572, 285, 563, 570, 242, 579, 578, 391, + 514, 570, 574, 579, 575, 242, 540, 563, 574, 285, + 575, 286, 580, 242, 242, 580, 94, 94, 94, 94, + 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, + + 94, 94, 94, 96, 96, 96, 96, 96, 96, 96, + 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, + 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, + 98, 98, 98, 98, 98, 98, 98, 103, 103, 103, + 103, 103, 103, 103, 103, 103, 103, 103, 103, 103, + 103, 103, 103, 103, 108, 108, 108, 108, 108, 108, + 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, + 108, 112, 112, 112, 112, 112, 112, 112, 112, 112, + 112, 112, 112, 112, 112, 112, 112, 112, 114, 114, + 114, 114, 114, 114, 114, 114, 114, 114, 114, 114, + + 114, 114, 114, 114, 114, 119, 119, 119, 119, 119, + 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, + 119, 119, 123, 123, 123, 123, 123, 123, 123, 123, + 123, 123, 123, 123, 123, 123, 123, 123, 123, 185, + 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, + 185, 185, 185, 185, 185, 185, 191, 191, 191, 191, + 191, 191, 191, 191, 191, 191, 191, 191, 191, 191, + 191, 191, 191, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, + 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, + + 196, 196, 196, 196, 196, 196, 196, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 237, 237, 441, 237, 237, 441, + 237, 241, 241, 481, 241, 241, 481, 241, 284, 284, + 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, + 284, 284, 284, 284, 284, 292, 242, 242, 242, 292, + 292, 292, 242, 292, 292, 292, 292, 523, 485, 292, + 292, 292, 294, 522, 519, 518, 294, 294, 294, 294, + 294, 294, 517, 294, 242, 517, 294, 294, 294, 297, + 297, 242, 297, 297, 297, 297, 297, 297, 297, 297, + + 297, 297, 297, 297, 297, 297, 298, 298, 298, 298, + 298, 298, 298, 298, 242, 298, 298, 298, 298, 298, + 298, 298, 298, 300, 300, 242, 300, 242, 485, 300, + 300, 300, 300, 300, 300, 300, 300, 482, 300, 300, + 304, 304, 304, 304, 304, 304, 304, 304, 304, 304, + 304, 304, 304, 304, 304, 304, 304, 309, 309, 242, + 309, 309, 309, 242, 309, 309, 309, 309, 309, 309, + 309, 242, 309, 309, 312, 312, 312, 312, 312, 312, + 312, 312, 312, 312, 312, 312, 312, 312, 312, 312, + 312, 316, 316, 242, 316, 316, 242, 316, 316, 316, + + 316, 316, 316, 316, 316, 446, 316, 318, 318, 318, + 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + 318, 318, 318, 318, 327, 442, 242, 242, 242, 242, + 242, 397, 396, 333, 331, 327, 327, 328, 327, 329, + 326, 242, 242, 242, 242, 242, 329, 242, 329, 329, + 329, 242, 329, 332, 242, 242, 241, 242, 237, 355, + 352, 351, 345, 337, 332, 332, 336, 332, 334, 331, + 326, 321, 242, 240, 236, 334, 226, 334, 334, 334, + 210, 334, 338, 338, 338, 338, 338, 338, 338, 338, + 338, 338, 338, 338, 338, 338, 338, 338, 338, 346, + + 346, 346, 346, 346, 346, 346, 346, 346, 346, 346, + 346, 346, 346, 346, 346, 346, 399, 399, 207, 399, + 399, 399, 399, 399, 399, 399, 399, 399, 399, 399, + 399, 399, 399, 405, 405, 317, 405, 405, 405, 405, + 405, 405, 405, 405, 405, 405, 405, 405, 405, 405, + 443, 443, 303, 443, 447, 299, 242, 240, 236, 226, + 447, 447, 210, 447, 483, 207, 582, 483, 483, 197, + 483, 484, 484, 195, 484, 486, 195, 184, 486, 113, + 113, 486, 486, 95, 486, 487, 487, 95, 487, 488, + 93, 582, 488, 488, 582, 488, 512, 512, 512, 512, + + 512, 512, 512, 512, 512, 512, 512, 512, 512, 512, + 512, 512, 512, 520, 582, 582, 520, 582, 582, 520, + 520, 582, 520, 521, 521, 521, 521, 521, 521, 521, + 521, 521, 521, 521, 521, 521, 521, 521, 521, 521, + 524, 582, 582, 524, 582, 582, 524, 524, 582, 524, + 569, 569, 569, 569, 569, 569, 569, 569, 569, 569, + 569, 569, 569, 569, 569, 569, 569, 571, 571, 571, + 571, 571, 571, 571, 571, 571, 571, 571, 571, 571, + 571, 571, 571, 571, 573, 573, 573, 573, 573, 573, + 573, 573, 573, 573, 573, 573, 573, 573, 573, 573, + + 573, 35, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582 + } ; + +static yyconst flex_int16_t yy_chk[2069] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 5, 6, 5, 6, + 578, 5, 6, 7, 7, 577, 7, 59, 59, 5, + 6, 8, 8, 248, 8, 9, 9, 11, 9, 10, + 10, 7, 10, 11, 12, 13, 14, 19, 32, 8, + + 12, 13, 14, 9, 17, 18, 19, 10, 17, 18, + 17, 18, 21, 20, 22, 248, 32, 11, 21, 239, + 22, 7, 20, 45, 12, 13, 14, 19, 239, 8, + 43, 43, 43, 9, 17, 18, 50, 10, 576, 45, + 61, 61, 21, 20, 22, 568, 21, 50, 22, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 25, 37, 37, 41, 37, + 38, 38, 37, 38, 40, 40, 52, 40, 55, 132, + 55, 55, 55, 37, 63, 52, 52, 38, 67, 25, + 69, 40, 85, 25, 26, 53, 63, 53, 53, 53, + 54, 26, 67, 53, 141, 54, 56, 41, 56, 56, + 56, 55, 54, 558, 67, 141, 67, 69, 132, 85, + 55, 616, 26, 26, 616, 26, 90, 70, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + + 26, 26, 26, 26, 26, 28, 60, 60, 70, 60, + 71, 82, 74, 90, 97, 550, 97, 99, 99, 97, + 99, 270, 100, 100, 71, 100, 202, 97, 202, 82, + 60, 60, 60, 28, 28, 71, 270, 74, 71, 28, + 74, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 72, 73, 75, 78, + 60, 77, 86, 154, 80, 79, 548, 84, 81, 88, + 93, 83, 93, 378, 72, 154, 75, 78, 104, 104, + 77, 104, 73, 79, 72, 136, 75, 73, 77, 87, + + 86, 75, 78, 79, 73, 80, 81, 88, 84, 81, + 83, 136, 81, 165, 83, 84, 126, 83, 378, 122, + 87, 87, 126, 93, 105, 105, 93, 105, 122, 190, + 93, 110, 110, 110, 116, 116, 118, 116, 165, 116, + 118, 165, 118, 118, 121, 121, 126, 121, 543, 122, + 126, 190, 129, 129, 121, 129, 145, 143, 129, 131, + 131, 145, 131, 134, 134, 134, 143, 143, 145, 129, + 150, 150, 160, 110, 158, 144, 131, 144, 144, 144, + 152, 152, 146, 144, 146, 146, 146, 147, 158, 147, + 147, 147, 151, 151, 161, 151, 537, 164, 162, 160, + + 158, 163, 158, 166, 171, 536, 203, 203, 175, 203, + 169, 168, 162, 172, 170, 146, 151, 151, 151, 163, + 177, 166, 164, 162, 146, 161, 162, 164, 169, 163, + 168, 166, 170, 173, 164, 171, 166, 174, 168, 175, + 176, 172, 170, 169, 172, 181, 175, 172, 177, 179, + 178, 173, 184, 187, 184, 508, 151, 193, 220, 187, + 220, 617, 205, 205, 617, 205, 174, 176, 224, 224, + 174, 178, 178, 174, 508, 200, 200, 179, 200, 193, + 205, 200, 181, 187, 206, 206, 206, 187, 201, 201, + 244, 201, 200, 229, 229, 184, 229, 243, 184, 217, + + 217, 217, 184, 226, 237, 201, 222, 222, 222, 223, + 205, 223, 223, 223, 245, 226, 237, 229, 233, 233, + 246, 233, 247, 250, 244, 249, 251, 253, 243, 256, + 243, 255, 257, 269, 259, 266, 233, 246, 262, 249, + 247, 271, 275, 245, 268, 251, 273, 276, 272, 284, + 250, 284, 557, 274, 277, 269, 278, 256, 251, 253, + 255, 279, 281, 257, 255, 280, 233, 259, 266, 268, + 262, 262, 233, 272, 271, 274, 276, 273, 278, 277, + 275, 557, 280, 279, 286, 287, 286, 287, 288, 289, + 288, 289, 290, 281, 290, 291, 291, 290, 291, 293, + + 293, 327, 293, 301, 301, 290, 301, 329, 301, 310, + 310, 534, 310, 332, 334, 338, 340, 338, 340, 310, + 357, 341, 341, 327, 341, 342, 342, 358, 342, 329, + 346, 288, 346, 287, 359, 332, 334, 348, 360, 348, + 357, 289, 362, 342, 349, 349, 363, 366, 369, 368, + 370, 371, 372, 512, 385, 512, 362, 515, 532, 515, + 358, 366, 369, 531, 363, 371, 359, 368, 370, 366, + 372, 360, 385, 342, 352, 352, 352, 352, 352, 352, + 352, 352, 352, 352, 352, 352, 352, 352, 352, 352, + 352, 352, 352, 352, 352, 352, 352, 352, 352, 352, + + 352, 352, 352, 352, 352, 352, 352, 352, 352, 352, + 352, 352, 352, 352, 352, 352, 352, 352, 352, 352, + 352, 352, 352, 352, 352, 352, 352, 352, 352, 352, + 352, 352, 352, 352, 352, 352, 352, 352, 352, 352, + 353, 353, 364, 353, 365, 367, 374, 373, 377, 380, + 381, 382, 386, 407, 383, 379, 406, 388, 353, 392, + 393, 392, 393, 394, 387, 394, 408, 410, 412, 389, + 386, 409, 381, 382, 364, 373, 365, 365, 367, 374, + 379, 387, 388, 380, 407, 382, 377, 383, 353, 389, + 406, 410, 422, 409, 353, 575, 392, 575, 394, 408, + + 412, 479, 479, 562, 479, 562, 422, 562, 393, 402, + 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, + 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, + 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, + 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, + 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, + 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, + 402, 402, 402, 402, 402, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, + 404, 413, 414, 415, 416, 417, 419, 420, 421, 424, + 427, 426, 428, 429, 431, 430, 434, 524, 438, 432, + 438, 451, 433, 424, 414, 426, 436, 437, 454, 452, + 431, 416, 427, 419, 413, 432, 417, 415, 420, 433, + 453, 421, 430, 428, 436, 437, 429, 439, 434, 439, + 440, 452, 440, 451, 457, 453, 454, 458, 459, 460, + + 461, 462, 463, 465, 438, 466, 467, 472, 469, 475, + 471, 468, 473, 477, 478, 493, 478, 460, 462, 465, + 474, 492, 490, 459, 458, 457, 439, 468, 494, 463, + 471, 440, 466, 473, 461, 469, 489, 490, 474, 467, + 472, 475, 480, 491, 480, 495, 477, 496, 492, 493, + 497, 500, 501, 502, 489, 511, 516, 511, 516, 527, + 526, 491, 494, 518, 496, 520, 497, 528, 501, 478, + 525, 502, 500, 533, 529, 545, 513, 513, 495, 513, + 530, 528, 518, 518, 518, 535, 538, 525, 538, 480, + 529, 516, 527, 511, 526, 513, 513, 513, 530, 539, + + 539, 544, 539, 535, 541, 541, 533, 541, 542, 547, + 546, 549, 556, 545, 554, 554, 559, 554, 539, 539, + 539, 560, 579, 565, 579, 538, 542, 542, 542, 564, + 556, 564, 566, 564, 544, 546, 563, 567, 563, 549, + 551, 551, 547, 551, 559, 551, 552, 552, 510, 552, + 566, 552, 560, 561, 561, 565, 561, 571, 561, 571, + 572, 563, 572, 569, 551, 569, 509, 569, 567, 570, + 573, 570, 573, 570, 573, 507, 574, 561, 574, 580, + 574, 580, 571, 506, 505, 572, 583, 583, 583, 583, + 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, + + 583, 583, 583, 584, 584, 584, 584, 584, 584, 584, + 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, + 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, + 585, 585, 585, 585, 585, 585, 585, 586, 586, 586, + 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, + 586, 586, 586, 586, 587, 587, 587, 587, 587, 587, + 587, 587, 587, 587, 587, 587, 587, 587, 587, 587, + 587, 588, 588, 588, 588, 588, 588, 588, 588, 588, + 588, 588, 588, 588, 588, 588, 588, 588, 589, 589, + 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, + + 589, 589, 589, 589, 589, 590, 590, 590, 590, 590, + 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, + 590, 590, 591, 591, 591, 591, 591, 591, 591, 591, + 591, 591, 591, 591, 591, 591, 591, 591, 591, 592, + 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, + 592, 592, 592, 592, 592, 592, 593, 593, 593, 593, + 593, 593, 593, 593, 593, 593, 593, 593, 593, 593, + 593, 593, 593, 594, 594, 594, 594, 594, 594, 594, + 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, + 595, 595, 595, 595, 595, 595, 595, 595, 595, 595, + + 595, 595, 595, 595, 595, 595, 595, 596, 596, 596, + 596, 596, 596, 596, 596, 596, 596, 596, 596, 596, + 596, 596, 596, 596, 597, 597, 620, 597, 597, 620, + 597, 598, 598, 623, 598, 598, 623, 598, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 600, 504, 503, 499, 600, + 600, 600, 498, 600, 600, 600, 600, 487, 486, 600, + 600, 600, 601, 485, 484, 482, 601, 601, 601, 601, + 601, 601, 630, 601, 476, 630, 601, 601, 601, 602, + 602, 470, 602, 602, 602, 602, 602, 602, 602, 602, + + 602, 602, 602, 602, 602, 602, 603, 603, 603, 603, + 603, 603, 603, 603, 464, 603, 603, 603, 603, 603, + 603, 603, 603, 604, 604, 456, 604, 455, 445, 604, + 604, 604, 604, 604, 604, 604, 604, 442, 604, 604, + 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, + 605, 605, 605, 605, 605, 605, 605, 606, 606, 435, + 606, 606, 606, 425, 606, 606, 606, 606, 606, 606, + 606, 423, 606, 606, 607, 607, 607, 607, 607, 607, + 607, 607, 607, 607, 607, 607, 607, 607, 607, 607, + 607, 608, 608, 418, 608, 608, 411, 608, 608, 608, + + 608, 608, 608, 608, 608, 403, 608, 609, 609, 609, + 609, 609, 609, 609, 609, 609, 609, 609, 609, 609, + 609, 609, 609, 609, 610, 397, 390, 384, 376, 375, + 361, 337, 336, 335, 331, 610, 610, 330, 610, 611, + 326, 267, 265, 264, 263, 261, 611, 260, 611, 611, + 611, 258, 611, 612, 254, 252, 242, 241, 238, 235, + 230, 227, 216, 198, 612, 612, 197, 612, 613, 192, + 189, 186, 167, 157, 153, 613, 148, 613, 613, 613, + 140, 613, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 615, + + 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, + 615, 615, 615, 615, 615, 615, 618, 618, 135, 618, + 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, + 618, 618, 618, 619, 619, 125, 619, 619, 619, 619, + 619, 619, 619, 619, 619, 619, 619, 619, 619, 619, + 621, 621, 117, 621, 622, 113, 76, 66, 62, 57, + 622, 622, 49, 622, 624, 44, 35, 624, 624, 31, + 624, 625, 625, 30, 625, 626, 29, 24, 626, 16, + 15, 626, 626, 4, 626, 627, 627, 3, 627, 628, + 2, 0, 628, 628, 0, 628, 629, 629, 629, 629, + + 629, 629, 629, 629, 629, 629, 629, 629, 629, 629, + 629, 629, 629, 631, 0, 0, 631, 0, 0, 631, + 631, 0, 631, 632, 632, 632, 632, 632, 632, 632, + 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, + 633, 0, 0, 633, 0, 0, 633, 633, 0, 633, + 634, 634, 634, 634, 634, 634, 634, 634, 634, 634, + 634, 634, 634, 634, 634, 634, 634, 635, 635, 635, + 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, + 635, 635, 635, 635, 636, 636, 636, 636, 636, 636, + 636, 636, 636, 636, 636, 636, 636, 636, 636, 636, + + 636, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, + 582, 582, 582, 582, 582, 582, 582, 582 + } ; + +extern int L__flex_debug; +int L__flex_debug = 0; + +static yy_state_type *yy_state_buf=0, *yy_state_ptr=0; +static char *yy_full_match; +static int yy_lp; +#define REJECT \ +{ \ +*yy_cp = (yy_hold_char); /* undo effects of setting up L_text */ \ +yy_cp = (yy_full_match); /* restore poss. backed-over text */ \ +++(yy_lp); \ +goto find_rule; \ +} + +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *L_text; +#line 1 "../generic/Lscanner.l" +#define YY_NO_INPUT 1 + + + + + + + + + + + + + + + + +#line 24 "../generic/Lscanner.l" +/* + * Copyright (c) 2006-2008 BitMover, Inc. + */ +#include <string.h> +#define _PWD_H // Some solaris9 conflict, we don't need pwd.h +#include "tclInt.h" +#include "Lcompile.h" +#include "Lgrammar.h" +#include "tommath.h" + +private void extract_re_delims(char c); +private int include_pop(); +private int include_push(Tcl_Channel chan, char *name); +private Tcl_Channel include_search(char *file, char **path, int cwdOnly); +private Tcl_Channel include_try(Tcl_Obj *fileObj, int *found); +private void inject(char *s); +private void interpol_lbrace(); +private void interpol_pop(); +private int interpol_push(); +private int interpol_rbrace(); +private void put_back(char c); +private void tally_newlines(char *s, int len, int tally); + +// Max nesting depth of string interpolations. +#define INTERPOL_STACK_SZ 10 + +// Stack for tracking include() statements. +#define INCLUDE_STACK_SZ 10 +typedef struct { + char *name; + char *dir; + int line; + YY_BUFFER_STATE buf; +} Include; + +private char re_start_delim; // delimiters for m|regexp| form +private char re_end_delim; +private Tcl_Obj *str; // string collection buffer +private int str_beg; // source offset of string +private char *here_delim = NULL; +private char *here_pfx = NULL; +private int include_top; +private Include include_stk[INCLUDE_STACK_SZ+1]; +private Tcl_HashTable *include_table = NULL; +private int interpol_top = -1; +private int interpol_stk[INTERPOL_STACK_SZ+1]; +private int in_lhtml = 0; // Lhtml mode + +#define STRBUF_START(beg) \ + do { \ + str = Tcl_NewObj(); \ + Tcl_IncrRefCount(str); \ + str_beg = (beg); \ + } while (0) + + +#define STRBUF_STRING() Tcl_GetString(str) + +#define STRBUF_STARTED() (str != NULL) + +#define STRBUF_ADD(s, len) Tcl_AppendToObj(str, s, len) + +#define STRBUF_STOP(e) \ + do { \ + Tcl_DecrRefCount(str); \ + str = NULL; \ + L_lloc.beg = str_beg; \ + L_lloc.end = (e); \ + } while (0) + +/* + * Keep track of the current offset in the input string. + * YY_USER_ACTION is run before each action. Note that some actions + * further modify L_lloc. + */ + +#define YY_USER_ACTION yy_user_action(); + +private void +yy_user_action() +{ + L->prev_token_off = L->token_off; + L->token_off += L->prev_token_len; + L->prev_token_len = L_leng; + + L_lloc.beg = L->token_off; + L_lloc.end = L->token_off + L_leng; + + tally_newlines(L_text, L_leng, 1); + L_lloc.line = L->line; + + L_lloc.file = L->file; + + /* + * Build up in L->script the text that the scanner scans. + * The compiler later passes this on to tcl as the script + * source. This allows include() stmts to be handled properly. + */ + Tcl_AppendToObj(L->script, L_text, L_leng); + L->script_len += L_leng; +} + +/* + * Un-do the effects of the YY_USER_ACTION on the token offset + * tracking. This is useful in include() processing where the + * characters in the '#include "file"' must be ignored. + */ +private void +undo_yy_user_action() +{ + L->prev_token_len = L->token_off - L->prev_token_off; + L->token_off = L->prev_token_off; + + L_lloc.beg = L->prev_token_off; + L_lloc.end = L->prev_token_off + L->prev_token_len; + + tally_newlines(L_text, L_leng, -1); + L_lloc.line = L->line; + + L->script_len -= L_leng; + Tcl_SetObjLength(L->script, L->script_len); +} + +/* + * Inject the given string into the L script text, but do not give it + * to the scanner. This is useful for inserting #line directives (for + * #include's) which need to remain in the script so Tcl can see them + * but which aren't parsed. + */ +private void +inject(char *s) +{ + int len = strlen(s); + + L->prev_token_len += len; + + Tcl_AppendToObj(L->script, s, len); + L->script_len += len; +} + +/* + * Count the newlines in a string and add the number to L->line. Pass + * in tally == 1 to count them and tally == -1 to undo it. + */ +private void +tally_newlines(char *s, int len, int tally) +{ + char *end, *p; + + for (p = s, end = p + len; p < end; p++) { + if (*p == '\n') { + L->line += tally; + } else if ((*p == '\r') && ((p+1) < end) && (*(p+1) != '\n')) { + /* Mac line endings. */ + L->line += tally; + } + } +} + +private Tcl_Channel +include_try(Tcl_Obj *fileObj, int *found) +{ + int new; + Tcl_Channel chan; + char *file = Tcl_GetString(fileObj); + char *path; + Tcl_Obj *pathObj; + + /* + * See if the normalized path has been included before. If the path + * isn't absolute, consider it to be relative to where L->file is. + */ + if (Tcl_FSGetPathType(fileObj) == TCL_PATH_ABSOLUTE) { + if ((pathObj = Tcl_FSGetNormalizedPath(NULL, fileObj)) == NULL){ + L_err("unable to normalize include file %s", file); + return (NULL); + } + } else { + pathObj = Tcl_ObjPrintf("%s/%s", L->dir, file); + } + Tcl_IncrRefCount(pathObj); + + path = Tcl_GetString(pathObj); + Tcl_CreateHashEntry(include_table, path, &new); + if (new) { + chan = Tcl_FSOpenFileChannel(L->interp, pathObj, "r", 0666); + *found = (chan != NULL); + return (chan); + } else { + *found = 1; // already included + return (NULL); + } + Tcl_DecrRefCount(pathObj); +} + +/* + * Search for an include file. If the path is absolute, use it. + * Else, for #include <file> (cwdOnly == 0) try + * $BIN/include (where BIN is where the running tclsh lives) + * /usr/local/include/L + * /usr/include/L + * For #include "file" (cwdOnly == 1) look only in the directory + * where the script doing the #include resides. + */ +private Tcl_Channel +include_search(char *file, char **path, int cwdOnly) +{ + int found, len; + Tcl_Channel chan; + Tcl_Obj *binObj = NULL; + Tcl_Obj *fileObj; + + unless (include_table) { + include_table = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(include_table, TCL_STRING_KEYS); + } + + fileObj = Tcl_NewStringObj(file, -1); + Tcl_IncrRefCount(fileObj); + if ((Tcl_FSGetPathType(fileObj) == TCL_PATH_ABSOLUTE) || cwdOnly) { + chan = include_try(fileObj, &found); + } else { + /* Try $BIN/include */ + binObj = TclGetObjNameOfExecutable(); + Tcl_GetStringFromObj(binObj, &len); + if (len > 0) { + Tcl_DecrRefCount(fileObj); + /* TclPathPart bumps the ref count. */ + fileObj = TclPathPart(L->interp, binObj, + TCL_PATH_DIRNAME); + Tcl_AppendPrintfToObj(fileObj, "/include/%s", file); + chan = include_try(fileObj, &found); + if (found) goto done; + } + /* Try /usr/local/include/L */ + Tcl_DecrRefCount(fileObj); + fileObj = Tcl_ObjPrintf("/usr/local/include/L/%s", file); + Tcl_IncrRefCount(fileObj); + chan = include_try(fileObj, &found); + if (found) goto done; + /* Try /usr/include/L */ + Tcl_DecrRefCount(fileObj); + fileObj = Tcl_ObjPrintf("/usr/include/L/%s", file); + Tcl_IncrRefCount(fileObj); + chan = include_try(fileObj, &found); + } + done: + unless (found) { + L_err("cannot find include file %s", file); + } + if (path) *path = ckstrdup(Tcl_GetString(fileObj)); + Tcl_DecrRefCount(fileObj); + return (chan); +} + +private int +include_push(Tcl_Channel chan, char *name) +{ + YY_BUFFER_STATE buf; + Tcl_Obj *objPtr; + char *dec = NULL, *script; + int len, ret; + + /* Read the file into memory. */ + objPtr = Tcl_NewObj(); + Tcl_IncrRefCount(objPtr); + if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) { + Tcl_Close(L->interp, chan); + L_err("error reading include file %s", name); + return (0); + } + Tcl_Close(L->interp, chan); + + /* If it is encrypted, decrypt it. */ + script = Tcl_GetStringFromObj(objPtr, &len); + + /* Create a new flex buffer with the file contents. */ + if (include_top >= INCLUDE_STACK_SZ) { + L_err("include file nesting too deep -- aborting"); + while (include_pop()) ; + ret = 0; + } else { + ++include_top; + include_stk[include_top].name = L->file; + include_stk[include_top].dir = L->dir; + include_stk[include_top].line = L->line; + include_stk[include_top].buf = YY_CURRENT_BUFFER; + buf = L__scan_bytes(script,len); + L->file = name; + L->dir = L_dirname(L->file); + L->line = 1; + inject("#line 1\n"); + ret = 1; + } + Tcl_DecrRefCount(objPtr); + if (dec) ckfree(dec); + return (ret); +} + +private int +include_pop() +{ + char *s; + + if (include_top >= 0) { + L->file = include_stk[include_top].name; + L->dir = include_stk[include_top].dir; + L->line = include_stk[include_top].line; + L__delete_buffer(YY_CURRENT_BUFFER); + L__switch_to_buffer(include_stk[include_top].buf); + --include_top; + s = cksprintf("#line %d\n", L->line); + inject(s); + ckfree(s); + return (1); + } else { + return (0); + } +} + +/* + * Given a decimal, hex, or octal integer constant of arbitrary + * precision, return a canonical string representation. This is done + * by converting it to a bignum and then taking its string rep. + */ +private char * +canonical_num(char *num) +{ + char *ret; + Tcl_Obj *obj; + mp_int big; + + obj = Tcl_NewStringObj(num, -1); + Tcl_IncrRefCount(obj); + Tcl_TakeBignumFromObj(NULL, obj, &big); + Tcl_SetBignumObj(obj, &big); + ret = ckstrdup(Tcl_GetString(obj)); + Tcl_DecrRefCount(obj); + return (ret); +} + +/* + * Work around a Windows problem where our getopt type conficts + * with the system's. + */ +#undef getopt +#undef optarg +#undef optind + +#line 1605 "<stdout>" + +#define INITIAL 0 +#define re_delim 1 +#define re_modifier 2 +#define re_arg_split 3 +#define re_arg_case 4 +#define glob_re 5 +#define subst_re 6 +#define comment 7 +#define str_double 8 +#define str_single 9 +#define str_backtick 10 +#define interpol 11 +#define here_doc_interp 12 +#define here_doc_nointerp 13 +#define eat_through_eol 14 +#define lhtml 15 +#define lhtml_expr_start 16 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int L_lex_destroy (void ); + +int L_get_debug (void ); + +void L_set_debug (int debug_flag ); + +YY_EXTRA_TYPE L_get_extra (void ); + +void L_set_extra (YY_EXTRA_TYPE user_defined ); + +FILE *L_get_in (void ); + +void L_set_in (FILE * in_str ); + +FILE *L_get_out (void ); + +void L_set_out (FILE * out_str ); + +yy_size_t L_get_leng (void ); + +char *L_get_text (void ); + +int L_get_lineno (void ); + +void L_set_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int L_wrap (void ); +#else +extern int L_wrap (void ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + + static int yy_start_stack_ptr = 0; + static int yy_start_stack_depth = 0; + static int *yy_start_stack = NULL; + + static void yy_push_state (int new_state ); + + static void yy_pop_state (void ); + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( L_text, L_leng, 1, L_out )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( L_in )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( L_in ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, L_in))==0 && ferror(L_in)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(L_in); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int L_lex (void); + +#define YY_DECL int L_lex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after L_text and L_leng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( L_leng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (L_text[L_leng - 1] == '\n'); \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + /* Create the reject buffer large enough to save one state per allowed character. */ + if ( ! (yy_state_buf) ) + (yy_state_buf) = (yy_state_type *)L_alloc(YY_STATE_BUF_SIZE ); + if ( ! (yy_state_buf) ) + YY_FATAL_ERROR( "out of dynamic memory in L_lex()" ); + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! L_in ) + L_in = stdin; + + if ( ! L_out ) + L_out = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + L_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + L__create_buffer(L_in,YY_BUF_SIZE ); + } + + L__load_buffer_state( ); + } + + { +#line 374 "../generic/Lscanner.l" + +#line 1854 "<stdout>" + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of L_text. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + (yy_state_ptr) = (yy_state_buf); + *(yy_state_ptr)++ = yy_current_state; + +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 583 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *(yy_state_ptr)++ = yy_current_state; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 2002 ); + +yy_find_action: + yy_current_state = *--(yy_state_ptr); + (yy_lp) = yy_accept[yy_current_state]; +find_rule: /* we branch to this label when backing up */ + for ( ; ; ) /* until we find what rule we matched */ + { + if ( (yy_lp) && (yy_lp) < yy_accept[yy_current_state + 1] ) + { + yy_act = yy_acclist[(yy_lp)]; + { + (yy_full_match) = yy_cp; + break; + } + } + --yy_cp; + yy_current_state = *--(yy_state_ptr); + (yy_lp) = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + +case 1: +YY_RULE_SETUP +#line 376 "../generic/Lscanner.l" +return T_LPAREN; + YY_BREAK +case 2: +YY_RULE_SETUP +#line 377 "../generic/Lscanner.l" +return T_RPAREN; + YY_BREAK +case 3: +YY_RULE_SETUP +#line 378 "../generic/Lscanner.l" +interpol_lbrace(); return T_LBRACE; + YY_BREAK +case 4: +YY_RULE_SETUP +#line 379 "../generic/Lscanner.l" +return T_LBRACKET; + YY_BREAK +case 5: +YY_RULE_SETUP +#line 380 "../generic/Lscanner.l" +return T_RBRACKET; + YY_BREAK +case 6: +YY_RULE_SETUP +#line 381 "../generic/Lscanner.l" +return T_COMMA; + YY_BREAK +case 7: +YY_RULE_SETUP +#line 382 "../generic/Lscanner.l" +return T_BANG; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 383 "../generic/Lscanner.l" +return T_PLUS; + YY_BREAK +case 9: +YY_RULE_SETUP +#line 384 "../generic/Lscanner.l" +return T_MINUS; + YY_BREAK +case 10: +YY_RULE_SETUP +#line 385 "../generic/Lscanner.l" +return T_STAR; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 386 "../generic/Lscanner.l" +return T_SLASH; + YY_BREAK +case 12: +YY_RULE_SETUP +#line 387 "../generic/Lscanner.l" +return T_PERC; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 388 "../generic/Lscanner.l" +return T_EQPLUS; + YY_BREAK +case 14: +YY_RULE_SETUP +#line 389 "../generic/Lscanner.l" +return T_EQMINUS; + YY_BREAK +case 15: +YY_RULE_SETUP +#line 390 "../generic/Lscanner.l" +return T_EQSTAR; + YY_BREAK +case 16: +YY_RULE_SETUP +#line 391 "../generic/Lscanner.l" +return T_EQSLASH; + YY_BREAK +case 17: +YY_RULE_SETUP +#line 392 "../generic/Lscanner.l" +return T_EQPERC; + YY_BREAK +case 18: +YY_RULE_SETUP +#line 393 "../generic/Lscanner.l" +return T_EQBITAND; + YY_BREAK +case 19: +YY_RULE_SETUP +#line 394 "../generic/Lscanner.l" +return T_EQBITOR; + YY_BREAK +case 20: +YY_RULE_SETUP +#line 395 "../generic/Lscanner.l" +return T_EQBITXOR; + YY_BREAK +case 21: +YY_RULE_SETUP +#line 396 "../generic/Lscanner.l" +return T_EQLSHIFT; + YY_BREAK +case 22: +YY_RULE_SETUP +#line 397 "../generic/Lscanner.l" +return T_EQRSHIFT; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 398 "../generic/Lscanner.l" +return T_EQDOT; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 399 "../generic/Lscanner.l" +return T_PLUSPLUS; + YY_BREAK +case 25: +YY_RULE_SETUP +#line 400 "../generic/Lscanner.l" +return T_MINUSMINUS; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 401 "../generic/Lscanner.l" +return T_ANDAND; + YY_BREAK +case 27: +YY_RULE_SETUP +#line 402 "../generic/Lscanner.l" +return T_OROR; + YY_BREAK +case 28: +YY_RULE_SETUP +#line 403 "../generic/Lscanner.l" +return T_BITAND; + YY_BREAK +case 29: +YY_RULE_SETUP +#line 404 "../generic/Lscanner.l" +return T_BITOR; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 405 "../generic/Lscanner.l" +return T_BITXOR; + YY_BREAK +case 31: +YY_RULE_SETUP +#line 406 "../generic/Lscanner.l" +return T_BITNOT; + YY_BREAK +case 32: +YY_RULE_SETUP +#line 407 "../generic/Lscanner.l" +return T_LSHIFT; + YY_BREAK +case 33: +YY_RULE_SETUP +#line 408 "../generic/Lscanner.l" +return T_RSHIFT; + YY_BREAK +case 34: +YY_RULE_SETUP +#line 409 "../generic/Lscanner.l" +return T_EQUALS; + YY_BREAK +case 35: +YY_RULE_SETUP +#line 410 "../generic/Lscanner.l" +return T_SEMI; + YY_BREAK +case 36: +YY_RULE_SETUP +#line 411 "../generic/Lscanner.l" +return T_DOT; + YY_BREAK +case 37: +/* rule 37 can match eol */ +YY_RULE_SETUP +#line 412 "../generic/Lscanner.l" +return T_STRCAT; + YY_BREAK +case 38: +YY_RULE_SETUP +#line 413 "../generic/Lscanner.l" +return T_DOTDOT; + YY_BREAK +case 39: +YY_RULE_SETUP +#line 414 "../generic/Lscanner.l" +return T_ELLIPSIS; + YY_BREAK +case 40: +YY_RULE_SETUP +#line 415 "../generic/Lscanner.l" +return T_CLASS; + YY_BREAK +case 41: +YY_RULE_SETUP +#line 416 "../generic/Lscanner.l" +return T_EXTERN; + YY_BREAK +case 42: +YY_RULE_SETUP +#line 417 "../generic/Lscanner.l" +return T_RETURN; + YY_BREAK +case 43: +YY_RULE_SETUP +#line 418 "../generic/Lscanner.l" +return T_VOID; + YY_BREAK +case 44: +YY_RULE_SETUP +#line 419 "../generic/Lscanner.l" +return T_STRING; + YY_BREAK +case 45: +YY_RULE_SETUP +#line 420 "../generic/Lscanner.l" +return T_WIDGET; + YY_BREAK +case 46: +YY_RULE_SETUP +#line 421 "../generic/Lscanner.l" +return T_INT; + YY_BREAK +case 47: +YY_RULE_SETUP +#line 422 "../generic/Lscanner.l" +return T_FLOAT; + YY_BREAK +case 48: +YY_RULE_SETUP +#line 423 "../generic/Lscanner.l" +return T_POLY; + YY_BREAK +case 49: +YY_RULE_SETUP +#line 424 "../generic/Lscanner.l" +return T_SPLIT; + YY_BREAK +case 50: +YY_RULE_SETUP +#line 425 "../generic/Lscanner.l" +return T_IF; + YY_BREAK +case 51: +YY_RULE_SETUP +#line 426 "../generic/Lscanner.l" +return T_ELSE; + YY_BREAK +case 52: +YY_RULE_SETUP +#line 427 "../generic/Lscanner.l" +return T_UNLESS; + YY_BREAK +case 53: +YY_RULE_SETUP +#line 428 "../generic/Lscanner.l" +return T_WHILE; + YY_BREAK +case 54: +YY_RULE_SETUP +#line 429 "../generic/Lscanner.l" +return T_DO; + YY_BREAK +case 55: +YY_RULE_SETUP +#line 430 "../generic/Lscanner.l" +return T_FOR; + YY_BREAK +case 56: +YY_RULE_SETUP +#line 431 "../generic/Lscanner.l" +return T_STRUCT; + YY_BREAK +case 57: +YY_RULE_SETUP +#line 432 "../generic/Lscanner.l" +return T_TYPEDEF; + YY_BREAK +case 58: +YY_RULE_SETUP +#line 433 "../generic/Lscanner.l" +return T_DEFINED; + YY_BREAK +case 59: +YY_RULE_SETUP +#line 434 "../generic/Lscanner.l" +return T_FOREACH; + YY_BREAK +case 60: +YY_RULE_SETUP +#line 435 "../generic/Lscanner.l" +return T_BREAK; + YY_BREAK +case 61: +YY_RULE_SETUP +#line 436 "../generic/Lscanner.l" +return T_CONTINUE; + YY_BREAK +case 62: +YY_RULE_SETUP +#line 437 "../generic/Lscanner.l" +return T_INSTANCE; + YY_BREAK +case 63: +YY_RULE_SETUP +#line 438 "../generic/Lscanner.l" +return T_PRIVATE; + YY_BREAK +case 64: +YY_RULE_SETUP +#line 439 "../generic/Lscanner.l" +return T_PUBLIC; + YY_BREAK +case 65: +YY_RULE_SETUP +#line 440 "../generic/Lscanner.l" +return T_CONSTRUCTOR; + YY_BREAK +case 66: +YY_RULE_SETUP +#line 441 "../generic/Lscanner.l" +return T_DESTRUCTOR; + YY_BREAK +case 67: +YY_RULE_SETUP +#line 442 "../generic/Lscanner.l" +return T_EXPAND; + YY_BREAK +case 68: +YY_RULE_SETUP +#line 443 "../generic/Lscanner.l" +return T_ARGUSED; + YY_BREAK +case 69: +YY_RULE_SETUP +#line 444 "../generic/Lscanner.l" +return T_ATTRIBUTE; + YY_BREAK +case 70: +YY_RULE_SETUP +#line 445 "../generic/Lscanner.l" +return T_ATTRIBUTE; + YY_BREAK +case 71: +YY_RULE_SETUP +#line 446 "../generic/Lscanner.l" +return T_OPTIONAL; + YY_BREAK +case 72: +YY_RULE_SETUP +#line 447 "../generic/Lscanner.l" +return T_MUSTBETYPE; + YY_BREAK +case 73: +YY_RULE_SETUP +#line 448 "../generic/Lscanner.l" +return T_GOTO; + YY_BREAK +case 74: +YY_RULE_SETUP +#line 449 "../generic/Lscanner.l" +return T_SWITCH; + YY_BREAK +case 75: +YY_RULE_SETUP +#line 450 "../generic/Lscanner.l" +return T_CASE; + YY_BREAK +case 76: +YY_RULE_SETUP +#line 451 "../generic/Lscanner.l" +return T_DEFAULT; + YY_BREAK +case 77: +YY_RULE_SETUP +#line 452 "../generic/Lscanner.l" +return T_TRY; + YY_BREAK +case 78: +YY_RULE_SETUP +#line 453 "../generic/Lscanner.l" +return T_ARROW; + YY_BREAK +case 79: +YY_RULE_SETUP +#line 454 "../generic/Lscanner.l" +return T_EQ; + YY_BREAK +case 80: +YY_RULE_SETUP +#line 455 "../generic/Lscanner.l" +return T_NE; + YY_BREAK +case 81: +YY_RULE_SETUP +#line 456 "../generic/Lscanner.l" +return T_LT; + YY_BREAK +case 82: +YY_RULE_SETUP +#line 457 "../generic/Lscanner.l" +return T_LE; + YY_BREAK +case 83: +YY_RULE_SETUP +#line 458 "../generic/Lscanner.l" +return T_GT; + YY_BREAK +case 84: +YY_RULE_SETUP +#line 459 "../generic/Lscanner.l" +return T_GE; + YY_BREAK +case 85: +YY_RULE_SETUP +#line 460 "../generic/Lscanner.l" +return T_EQUALEQUAL; + YY_BREAK +case 86: +YY_RULE_SETUP +#line 461 "../generic/Lscanner.l" +return T_NOTEQUAL; + YY_BREAK +case 87: +YY_RULE_SETUP +#line 462 "../generic/Lscanner.l" +return T_GREATER; + YY_BREAK +case 88: +YY_RULE_SETUP +#line 463 "../generic/Lscanner.l" +return T_GREATEREQ; + YY_BREAK +case 89: +YY_RULE_SETUP +#line 464 "../generic/Lscanner.l" +return T_LESSTHAN; + YY_BREAK +case 90: +YY_RULE_SETUP +#line 465 "../generic/Lscanner.l" +return T_LESSTHANEQ; + YY_BREAK +case 91: +YY_RULE_SETUP +#line 466 "../generic/Lscanner.l" +return T_POINTS; + YY_BREAK +case 92: +YY_RULE_SETUP +#line 467 "../generic/Lscanner.l" +return T_COLON; + YY_BREAK +case 93: +YY_RULE_SETUP +#line 468 "../generic/Lscanner.l" +return T_QUESTION; + YY_BREAK +case 94: +YY_RULE_SETUP +#line 469 "../generic/Lscanner.l" +{ + /* + * ?> marks the end of a script or expr + * inside of an lhtml document but is a + * syntax error otherwise. + */ + unless (in_lhtml) { + undo_yy_user_action(); + REJECT; + } + yy_pop_state(); + STRBUF_START(L_lloc.end); + if (YYSTATE == lhtml_expr_start) { + yy_pop_state(); // pop back to lhtml + ASSERT(YYSTATE == lhtml); + return T_LHTML_EXPR_END; + } + } + YY_BREAK +case 95: +YY_RULE_SETUP +#line 487 "../generic/Lscanner.l" +{ + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_ANDAND; + } + YY_BREAK +case 96: +YY_RULE_SETUP +#line 492 "../generic/Lscanner.l" +{ + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_BANG; + } + YY_BREAK +case 97: +YY_RULE_SETUP +#line 497 "../generic/Lscanner.l" +{ + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_OROR; + } + YY_BREAK +case 98: +YY_RULE_SETUP +#line 502 "../generic/Lscanner.l" +{ + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_BITXOR; + } + YY_BREAK +case 99: +YY_RULE_SETUP +#line 507 "../generic/Lscanner.l" +{ + Type *t = L_typedef_lookup(L_text); + if (t) { + L_lval.Typename.s = ckstrdup(L_text); + L_lval.Typename.t = t; + return T_TYPE; + } else { + L_lval.s = ckstrdup(L_text); + return T_ID; + } + } + YY_BREAK +case 100: +YY_RULE_SETUP +#line 518 "../generic/Lscanner.l" +{ + /* + * Push back the : and return a T_ID + * unless it's "default". The grammar relies + * on this to avoid a nasty conflict. + */ + put_back(':'); + if (!strncmp(L_text, "default", 7)) { + return T_DEFAULT; + } + L_lval.s = ckstrdup(L_text); + L_lval.s[L_leng-1] = 0; + return T_ID; + } + YY_BREAK +case 101: +YY_RULE_SETUP +#line 532 "../generic/Lscanner.l" +{ + L_lval.s = ckstrdup(L_text); + return T_PATTERN; + } + YY_BREAK +case 102: +YY_RULE_SETUP +#line 536 "../generic/Lscanner.l" +{ + /* Regular expression submatches */ + L_lval.s = ckstrdup(L_text); + return T_ID; + } + YY_BREAK +case 103: +YY_RULE_SETUP +#line 541 "../generic/Lscanner.l" +{ + /* + * Skip any leading 0's which would + * make it look like octal to Tcl. + */ + size_t z = strspn(L_text, "0"); + if (z == L_leng) z = 0; // number is all 0's + L_lval.s = canonical_num(L_text+z); + return T_INT_LITERAL; + } + YY_BREAK +case 104: +YY_RULE_SETUP +#line 551 "../generic/Lscanner.l" +{ + /* + * Create a leading 0 so it looks like + * octal to Tcl. + */ + L_text[1] = '0'; + L_lval.s = canonical_num(L_text+1); + return T_INT_LITERAL; + } + YY_BREAK +case 105: +YY_RULE_SETUP +#line 560 "../generic/Lscanner.l" +{ + L_lval.s = canonical_num(L_text); + return T_INT_LITERAL; + } + YY_BREAK +case 106: +YY_RULE_SETUP +#line 564 "../generic/Lscanner.l" +{ + L_lval.s = ckstrdup(L_text); + return T_FLOAT_LITERAL; + } + YY_BREAK +case 107: +/* rule 107 can match eol */ +YY_RULE_SETUP +#line 568 "../generic/Lscanner.l" +{ + int line = strtoul(L_text+5, NULL, 10); + + if (line <= 0) { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } else { + L->line = line; + } + } + YY_BREAK +case 108: +/* rule 108 can match eol */ +YY_RULE_SETUP +#line 579 "../generic/Lscanner.l" +{ + int line = strtoul(L_text+5, NULL, 10); + char *beg = strchr(L_text, '"') + 1; + char *end = strrchr(L_text, '"'); + char *name = ckstrndup(beg, end-beg); + + if (line <= 0) { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } else { + L->file = name; + L->line = line; + } + } + YY_BREAK +case 109: +/* rule 109 can match eol */ +YY_RULE_SETUP +#line 594 "../generic/Lscanner.l" +{ + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } + YY_BREAK +case 110: +YY_RULE_SETUP +#line 599 "../generic/Lscanner.l" +{ + char *beg = strchr(L_text, '"') + 1; + char *end = strrchr(L_text, '"'); + char *name = ckstrndup(beg, end-beg); + Tcl_Channel chan; + + chan = include_search(name, NULL, 1); + + undo_yy_user_action(); + if (chan && !include_push(chan, name)) { + /* Bail if includes nest too deeply. */ + yyterminate(); + } + } + YY_BREAK +case 111: +YY_RULE_SETUP +#line 613 "../generic/Lscanner.l" +{ + char *beg = strchr(L_text, '<') + 1; + char *end = strrchr(L_text, '>'); + char *name = ckstrndup(beg, end-beg); + char *path = NULL; + Tcl_Channel chan; + + chan = include_search(name, &path, 0); + ckfree(name); + + undo_yy_user_action(); + if (chan && !include_push(chan, path)) { + /* Bail if includes nest too deeply. */ + yyterminate(); + } + } + YY_BREAK +case 112: +YY_RULE_SETUP +#line 629 "../generic/Lscanner.l" +{ + L_err("malformed #include"); + yy_push_state(eat_through_eol); + } + YY_BREAK +case 113: +YY_RULE_SETUP +#line 633 "../generic/Lscanner.l" +return T_PRAGMA; + YY_BREAK +case 114: +/* rule 114 can match eol */ +YY_RULE_SETUP +#line 634 "../generic/Lscanner.l" +{ + /* + * Rather than using a start condition + * to separate out all the ^# patterns + * that don't end in \n, this is + * simpler. If it's not a comment, + * REJECT it so that flex then takes + * the second best rule (those above). + */ + if (!strncmp(L_text, "#pragma ", 8) || + !strncmp(L_text, "#pragma\t", 8)) { + undo_yy_user_action(); + REJECT; + } else if (!strncmp(L_text, "#include", 8)) { + undo_yy_user_action(); + REJECT; + } else unless (L->line == 2) { + --L->line; // since \n already scanned + L_err("# comment valid only on line 1"); + ++L->line; + } + } + YY_BREAK +case 115: +/* rule 115 can match eol */ +YY_RULE_SETUP +#line 656 "../generic/Lscanner.l" +{ + --L->line; // since \n already scanned + unless (L->line == 1) { + L_err("# comment valid only on line 1"); + } else { + L_err("# comment must start at " + "first column"); + } + ++L->line; + } + YY_BREAK +case 116: +/* rule 116 can match eol */ +YY_RULE_SETUP +#line 666 "../generic/Lscanner.l" + + YY_BREAK +case 117: +YY_RULE_SETUP +#line 667 "../generic/Lscanner.l" + + YY_BREAK +case 118: +/* rule 118 can match eol */ +YY_RULE_SETUP +#line 668 "../generic/Lscanner.l" + + YY_BREAK +case 119: +YY_RULE_SETUP +#line 669 "../generic/Lscanner.l" +yy_push_state(str_double); STRBUF_START(L->token_off); + YY_BREAK +case 120: +YY_RULE_SETUP +#line 670 "../generic/Lscanner.l" +yy_push_state(str_single); STRBUF_START(L->token_off); + YY_BREAK +case 121: +YY_RULE_SETUP +#line 671 "../generic/Lscanner.l" +yy_push_state(str_backtick); STRBUF_START(L->token_off); + YY_BREAK +case 122: +YY_RULE_SETUP +#line 672 "../generic/Lscanner.l" +yy_push_state(comment); + YY_BREAK +case 123: +/* rule 123 can match eol */ +YY_RULE_SETUP +#line 673 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 2); // next token starts at the "m" + extract_re_delims(L_text[L_leng-1]); + L_lloc.end = L_lloc.beg + 2; // this token spans the "=~" + return ((L_text[0] == '=') ? T_EQTWID : T_BANGTWID); + } + YY_BREAK +/* if / is used to delimit the regexp, the m can be omitted */ +case 124: +/* rule 124 can match eol */ +YY_RULE_SETUP +#line 682 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the "/" + extract_re_delims('/'); + L_lloc.end = L_lloc.beg + 2; // this token spans the "=~" + return ((L_text[0] == '=') ? T_EQTWID : T_BANGTWID); + } + YY_BREAK +/* a substitution pattern */ +case 125: +/* rule 125 can match eol */ +YY_RULE_SETUP +#line 691 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(subst_re); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 2); // next token starts at the "s" + extract_re_delims(L_text[L_leng-1]); + L_lloc.end = L_lloc.beg + 2; // this token spans the "=~" + return T_EQTWID; + } + YY_BREAK +/* here document (interpolated), valid only on rhs of an assignment */ +case 126: +/* rule 126 can match eol */ +YY_RULE_SETUP +#line 701 "../generic/Lscanner.l" +{ + char *p, *q; + + if (here_delim) { + L_err("nested here documents illegal"); + } + p = strchr(L_text, '<') + 2; // the < is guaranteed to exist + for (q = p; (q > L_text) && (*q != '\n'); --q) ; + if ((q > L_text) && (*q == '\n')) { + // \n then <<; the in-between whitespace is the here_pfx + here_pfx = ckstrndup(q+1, p-q-3); + } else { + // non-indented here document + here_pfx = ckstrdup(""); + } + here_delim = ckstrndup(p, L_leng - (p-L_text) - 1); + STRBUF_START(L->token_off); + L_lloc.end = L_lloc.beg + 1; + yy_push_state(here_doc_interp); + return T_EQUALS; + } + YY_BREAK +/* here document (uninterpolated), valid only on rhs of an assignment */ +case 127: +/* rule 127 can match eol */ +YY_RULE_SETUP +#line 723 "../generic/Lscanner.l" +{ + char *p, *q; + + if (here_delim) { + L_err("nested here documents illegal"); + } + p = strchr(L_text, '<') + 2; // the < is guaranteed to exist + for (q = p; (q > L_text) && (*q != '\n'); --q) ; + if ((q > L_text) && (*q == '\n')) { + // \n then <<; the in-between whitespace is the here_pfx + here_pfx = ckstrndup(q+1, p-q-3); + } else { + // non-indented here document + here_pfx = ckstrdup(""); + } + here_delim = ckstrndup(p+1, L_leng - (p-L_text) - 3); + STRBUF_START(L->token_off); + L_lloc.end = L_lloc.beg + 1; + yy_push_state(here_doc_nointerp); + return T_EQUALS; + } + YY_BREAK +/* illegal here documents (bad stuff before or after the delim) */ +case 128: +/* rule 128 can match eol */ +#line 746 "../generic/Lscanner.l" +case 129: +/* rule 129 can match eol */ +YY_RULE_SETUP +#line 746 "../generic/Lscanner.l" +{ + L_synerr("<<- unsupported, use =\\n\\t<<END to strip one " + "leading tab"); + } + YY_BREAK +case 130: +/* rule 130 can match eol */ +YY_RULE_SETUP +#line 750 "../generic/Lscanner.l" +{ + L_synerr("illegal characters after here-document delimeter"); + } + YY_BREAK +case 131: +/* rule 131 can match eol */ +YY_RULE_SETUP +#line 753 "../generic/Lscanner.l" +{ + L_synerr("illegal characters before here-document delimeter"); + } + YY_BREAK +case 132: +/* rule 132 can match eol */ +YY_RULE_SETUP +#line 756 "../generic/Lscanner.l" +{ + L_synerr("illegal characters after here-document delimeter"); + } + YY_BREAK +case 133: +/* rule 133 can match eol */ +YY_RULE_SETUP +#line 759 "../generic/Lscanner.l" +{ + L_synerr("illegal characters before here-document delimeter"); + } + YY_BREAK + + +/* + * The compiler prepends a #line directive to Lhtml source. + * This communicates the correct line number to the Tcl + * code that prints run-time error messages. + */ +case 134: +/* rule 134 can match eol */ +YY_RULE_SETUP +#line 770 "../generic/Lscanner.l" +{ + int line = strtoul(L_text+5, NULL, 10); + + if (line <= 0) { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } else { + L->line = line; + } + } + YY_BREAK +case 135: +YY_RULE_SETUP +#line 781 "../generic/Lscanner.l" +{ + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + if (L_leng == 2) { + yy_push_state(INITIAL); + } else { + yy_push_state(lhtml_expr_start); + } + return T_HTML; + } + YY_BREAK +case 136: +/* rule 136 can match eol */ +YY_RULE_SETUP +#line 791 "../generic/Lscanner.l" +STRBUF_ADD(L_text, L_leng); + YY_BREAK +case YY_STATE_EOF(lhtml): +#line 792 "../generic/Lscanner.l" +{ + unless (STRBUF_STARTED()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_HTML; + } + YY_BREAK + + +/* + * This start condition is here only so the rule for ?> can + * know whether we previously scanned <? or <?=. + */ +case 137: +/* rule 137 can match eol */ +YY_RULE_SETUP +#line 805 "../generic/Lscanner.l" +{ + unput(L_text[0]); + undo_yy_user_action(); + yy_push_state(INITIAL); + return T_LHTML_EXPR_START; + } + YY_BREAK + + +/* + * A regexp in the context of the first arg to split(). If + * it's not an RE, pop the start-condition stack and push it + * back, so we can continue as normal. + */ +case 138: +/* rule 138 can match eol */ +YY_RULE_SETUP +#line 819 "../generic/Lscanner.l" + + YY_BREAK +/* / starts an RE */ +case 139: +YY_RULE_SETUP +#line 821 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the "/" + extract_re_delims('/'); + } + YY_BREAK +/* + * m<punctuation> starts an RE, except for "m)" so that + * "split(m)" works. + */ +case 140: +YY_RULE_SETUP +#line 831 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the delim + extract_re_delims(L_text[L_leng-1]); + } + YY_BREAK +/* nothing else starts an RE */ +case 141: +YY_RULE_SETUP +#line 838 "../generic/Lscanner.l" +{ + unput(L_text[0]); + undo_yy_user_action(); + yy_pop_state(); + } + YY_BREAK + + +/* + * A regexp in the context of a case statement. If it's not + * an RE, pop the start-condition stack and push it back, so + * we can continue as normal. + */ +case 142: +/* rule 142 can match eol */ +YY_RULE_SETUP +#line 851 "../generic/Lscanner.l" + + YY_BREAK +/* / starts an RE */ +case 143: +YY_RULE_SETUP +#line 853 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the "/" + extract_re_delims('/'); + } + YY_BREAK +/* + * m<punctuation> starts an RE except for "m:" which we scan + * as the variable m (so that "case m:" works) or "m(" which + * is the start of a call to the function m (so that "case m():" + * or "case m(arg):" etc work). + */ +case 144: +YY_RULE_SETUP +#line 865 "../generic/Lscanner.l" +{ + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the delim + extract_re_delims(L_text[L_leng-1]); + } + YY_BREAK +/* nothing else starts an RE */ +case 145: +YY_RULE_SETUP +#line 872 "../generic/Lscanner.l" +{ + unput(L_text[0]); + undo_yy_user_action(); + yy_pop_state(); + } + YY_BREAK + + +case 146: +YY_RULE_SETUP +#line 880 "../generic/Lscanner.l" +return T_RBRACE; + YY_BREAK + + +case 147: +YY_RULE_SETUP +#line 884 "../generic/Lscanner.l" +{ + if (interpol_rbrace()) { + STRBUF_START(L_lloc.end); + interpol_pop(); + if ((YYSTATE == glob_re) || + (YYSTATE == subst_re)) { + return T_RIGHT_INTERPOL_RE; + } else { + return T_RIGHT_INTERPOL; + } + } else { + return T_RBRACE; + } + } + YY_BREAK +case 148: +YY_RULE_SETUP +#line 898 "../generic/Lscanner.l" +{ + L_synerr("illegal character"); + } + YY_BREAK + + +case 149: +YY_RULE_SETUP +#line 904 "../generic/Lscanner.l" +STRBUF_ADD("\r", 1); + YY_BREAK +case 150: +YY_RULE_SETUP +#line 905 "../generic/Lscanner.l" +STRBUF_ADD("\n", 1); + YY_BREAK +case 151: +YY_RULE_SETUP +#line 906 "../generic/Lscanner.l" +STRBUF_ADD("\t", 1); + YY_BREAK +case 152: +#line 908 "../generic/Lscanner.l" +case 153: +#line 909 "../generic/Lscanner.l" +case 154: +#line 910 "../generic/Lscanner.l" +case 155: +YY_RULE_SETUP +#line 910 "../generic/Lscanner.l" +{ + char buf[TCL_UTF_MAX]; + int ch; + TclParseHex(L_text+2, 4, &ch); + STRBUF_ADD(buf, Tcl_UniCharToUtf(ch, buf)); + } + YY_BREAK +case 156: +/* rule 156 can match eol */ +YY_RULE_SETUP +#line 916 "../generic/Lscanner.l" +STRBUF_ADD(L_text+1, 1); + YY_BREAK +case 157: +YY_RULE_SETUP +#line 917 "../generic/Lscanner.l" +STRBUF_ADD("$", 1); + YY_BREAK +case 158: +/* rule 158 can match eol */ +YY_RULE_SETUP +#line 918 "../generic/Lscanner.l" +{ + L_err("missing string terminator \""); + STRBUF_ADD("\n", 1); + } + YY_BREAK +case 159: +YY_RULE_SETUP +#line 922 "../generic/Lscanner.l" +STRBUF_ADD(L_text, L_leng); + YY_BREAK +case 160: +YY_RULE_SETUP +#line 923 "../generic/Lscanner.l" +{ + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL; + } + YY_BREAK +case 161: +/* rule 161 can match eol */ +YY_RULE_SETUP +#line 929 "../generic/Lscanner.l" + + YY_BREAK +case 162: +YY_RULE_SETUP +#line 930 "../generic/Lscanner.l" +{ + yy_pop_state(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + return T_STR_LITERAL; + } + YY_BREAK + + +case 163: +YY_RULE_SETUP +#line 939 "../generic/Lscanner.l" +STRBUF_ADD("\\", 1); + YY_BREAK +case 164: +YY_RULE_SETUP +#line 940 "../generic/Lscanner.l" +STRBUF_ADD("'", 1); + YY_BREAK +case 165: +/* rule 165 can match eol */ +YY_RULE_SETUP +#line 941 "../generic/Lscanner.l" +STRBUF_ADD("\n", 1); + YY_BREAK +case 166: +/* rule 166 can match eol */ +YY_RULE_SETUP +#line 942 "../generic/Lscanner.l" +{ + L_err("missing string terminator \'"); + STRBUF_ADD("\n", 1); + } + YY_BREAK +case 167: +#line 947 "../generic/Lscanner.l" +case 168: +YY_RULE_SETUP +#line 947 "../generic/Lscanner.l" +STRBUF_ADD(L_text, L_leng); + YY_BREAK +case 169: +/* rule 169 can match eol */ +YY_RULE_SETUP +#line 948 "../generic/Lscanner.l" + + YY_BREAK +case 170: +YY_RULE_SETUP +#line 949 "../generic/Lscanner.l" +{ + yy_pop_state(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + return T_STR_LITERAL; + } + YY_BREAK + + +case 171: +YY_RULE_SETUP +#line 958 "../generic/Lscanner.l" +STRBUF_ADD(L_text+1, 1); + YY_BREAK +case 172: +/* rule 172 can match eol */ +YY_RULE_SETUP +#line 959 "../generic/Lscanner.l" +/* ignore \<newline> */ + YY_BREAK +case 173: +#line 961 "../generic/Lscanner.l" +case 174: +#line 962 "../generic/Lscanner.l" +case 175: +YY_RULE_SETUP +#line 962 "../generic/Lscanner.l" +STRBUF_ADD(L_text, L_leng); + YY_BREAK +case 176: +/* rule 176 can match eol */ +YY_RULE_SETUP +#line 963 "../generic/Lscanner.l" +{ + L_err("missing string terminator `"); + STRBUF_ADD("\n", 1); + } + YY_BREAK +case 177: +YY_RULE_SETUP +#line 967 "../generic/Lscanner.l" +{ + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL; + } + YY_BREAK +case 178: +YY_RULE_SETUP +#line 973 "../generic/Lscanner.l" +{ + yy_pop_state(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + if (YYSTATE == here_doc_interp) { + STRBUF_START(L_lloc.end); + } + return T_STR_BACKTICK; + } + YY_BREAK + + +case 179: +*yy_cp = (yy_hold_char); /* undo effects of setting up L_text */ +(yy_c_buf_p) = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up L_text again */ +YY_RULE_SETUP +#line 985 "../generic/Lscanner.l" +{ + int len; + char *p = L_text; + + /* + * Look for whitespace-prefixed here_delim. + * Any amount of white space is allowed. + */ + while (isspace(*p)) ++p; + len = L_leng - (p - L_text); + if (p[len-1] == ';') --len; + if ((len == strlen(here_delim)) && + !strncmp(p, here_delim, len)) { + yy_pop_state(); + unput(';'); // for the parser + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + ckfree(here_delim); + ckfree(here_pfx); + here_delim = NULL; + here_pfx = NULL; + return T_STR_LITERAL; + } + /* + * It's a data line. It must begin with + * here_pfx or else it's an error. + */ + p = strstr(L_text, here_pfx); + if (p == L_text) { + p += strlen(here_pfx); + } else { + L_err("bad here-document prefix"); + p = L_text; + } + STRBUF_ADD(p, L_leng - (p - L_text)); + } + YY_BREAK +case 180: +YY_RULE_SETUP +#line 1021 "../generic/Lscanner.l" +{ + char *p = strstr(L_text, here_pfx); + if (p == L_text) { + p += strlen(here_pfx); + STRBUF_ADD(p, L_leng - (p - L_text)); + } else { + L_err("bad here-document prefix"); + p = L_text; + } + } + YY_BREAK +case 181: +/* rule 181 can match eol */ +YY_RULE_SETUP +#line 1031 "../generic/Lscanner.l" +STRBUF_ADD(L_text, 1); + YY_BREAK + + +case 182: +YY_RULE_SETUP +#line 1035 "../generic/Lscanner.l" +STRBUF_ADD("\\", 1); + YY_BREAK +case 183: +YY_RULE_SETUP +#line 1036 "../generic/Lscanner.l" +STRBUF_ADD("$", 1); + YY_BREAK +case 184: +YY_RULE_SETUP +#line 1037 "../generic/Lscanner.l" +STRBUF_ADD("`", 1); + YY_BREAK +case 185: +/* rule 185 can match eol */ +YY_RULE_SETUP +#line 1038 "../generic/Lscanner.l" +// ignore \<newline> + YY_BREAK +case 186: +YY_RULE_SETUP +#line 1039 "../generic/Lscanner.l" +{ + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL; + } + YY_BREAK +case 187: +YY_RULE_SETUP +#line 1045 "../generic/Lscanner.l" +{ + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + yy_push_state(str_backtick); + STRBUF_START(L->token_off); + return T_START_BACKTICK; + } + YY_BREAK +case 188: +*yy_cp = (yy_hold_char); /* undo effects of setting up L_text */ +(yy_c_buf_p) = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up L_text again */ +YY_RULE_SETUP +#line 1052 "../generic/Lscanner.l" +{ + int len; + char *p = L_text; + + /* + * Look for whitespace-prefixed here_delim. + * Any amount of white space is allowed. + */ + while (isspace(*p)) ++p; + len = L_leng - (p - L_text); + if (p[len-1] == ';') --len; + if ((len == strlen(here_delim)) && + !strncmp(p, here_delim, len)) { + yy_pop_state(); + unput(';'); // for the parser + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + ckfree(here_delim); + ckfree(here_pfx); + here_delim = NULL; + here_pfx = NULL; + return T_STR_LITERAL; + } + /* + * It's a data line. It must begin with + * here_pfx or else it's an error. + */ + p = strstr(L_text, here_pfx); + if (p == L_text) { + p += strlen(here_pfx); + } else { + L_err("bad here-document prefix"); + p = L_text; + } + STRBUF_ADD(p, L_leng - (p - L_text)); + } + YY_BREAK +case 189: +YY_RULE_SETUP +#line 1088 "../generic/Lscanner.l" +{ + char *p = strstr(L_text, here_pfx); + if (p == L_text) { + p += strlen(here_pfx); + STRBUF_ADD(p, L_leng - (p - L_text)); + } else { + L_err("bad here-document prefix"); + p = L_text; + } + } + YY_BREAK +case 190: +/* rule 190 can match eol */ +YY_RULE_SETUP +#line 1098 "../generic/Lscanner.l" +STRBUF_ADD(L_text, 1); + YY_BREAK + + +case 191: +/* rule 191 can match eol */ +YY_RULE_SETUP +#line 1102 "../generic/Lscanner.l" + + YY_BREAK +case 192: +YY_RULE_SETUP +#line 1103 "../generic/Lscanner.l" + + YY_BREAK +case 193: +YY_RULE_SETUP +#line 1104 "../generic/Lscanner.l" +yy_pop_state(); + YY_BREAK + + +case 194: +YY_RULE_SETUP +#line 1108 "../generic/Lscanner.l" +{ + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL_RE; + } + YY_BREAK +case 195: +YY_RULE_SETUP +#line 1114 "../generic/Lscanner.l" +{ + if ((L_text[1] == re_end_delim) || + (L_text[1] == re_start_delim)) { + STRBUF_ADD(L_text+1, 1); + } else { + STRBUF_ADD(L_text, L_leng); + } + } + YY_BREAK +case 196: +/* rule 196 can match eol */ +YY_RULE_SETUP +#line 1122 "../generic/Lscanner.l" +{ + --L->line; // since \n already scanned + L_err("run-away regular expression"); + ++L->line; + STRBUF_ADD(L_text, L_leng); + yy_pop_state(); + if (YYSTATE == re_modifier) yy_pop_state(); + return T_RE; + } + YY_BREAK +case 197: +YY_RULE_SETUP +#line 1131 "../generic/Lscanner.l" +{ + // Convert $3 to \3 (regexp capture reference). + STRBUF_ADD("\\", 1); + STRBUF_ADD(L_text+1, L_leng-1); + } + YY_BREAK +case 198: +YY_RULE_SETUP +#line 1136 "../generic/Lscanner.l" +{ + if (*L_text == re_end_delim) { + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + if (YYSTATE == subst_re) { + yy_pop_state(); + return T_SUBST; + } else { + yy_pop_state(); + if (YYSTATE == subst_re) { + STRBUF_START(L_lloc.end); + if (re_start_delim != + re_end_delim) { + yy_push_state( + re_delim); + } + } + return T_RE; + } + } else if (*L_text == re_start_delim) { + L_err("regexp delimiter must be quoted " + "inside the regexp"); + STRBUF_ADD(L_text+1, 1); + } else { + STRBUF_ADD(L_text, L_leng); + } + } + YY_BREAK + + +case 199: +/* rule 199 can match eol */ +YY_RULE_SETUP +#line 1167 "../generic/Lscanner.l" +{ + --L->line; // since \n already scanned + L_err("run-away regular expression"); + ++L->line; + STRBUF_ADD(L_text, L_leng); + yy_pop_state(); + } + YY_BREAK +case 200: +YY_RULE_SETUP +#line 1174 "../generic/Lscanner.l" +{ + extract_re_delims(*L_text); + yy_pop_state(); + } + YY_BREAK + + +case 201: +YY_RULE_SETUP +#line 1181 "../generic/Lscanner.l" +{ + L_lval.s = ckstrdup(L_text); + yy_pop_state(); + return T_RE_MODIFIER; + } + YY_BREAK +case 202: +/* rule 202 can match eol */ +YY_RULE_SETUP +#line 1186 "../generic/Lscanner.l" +{ + unput(L_text[0]); + undo_yy_user_action(); + yy_pop_state(); + L_lval.s = ckstrdup(""); + return T_RE_MODIFIER; + } + YY_BREAK + + +case 203: +YY_RULE_SETUP +#line 1196 "../generic/Lscanner.l" + + YY_BREAK +case 204: +/* rule 204 can match eol */ +YY_RULE_SETUP +#line 1197 "../generic/Lscanner.l" +yy_pop_state(); + YY_BREAK + +case 205: +YY_RULE_SETUP +#line 1200 "../generic/Lscanner.l" +{ + /* This rule matches a char if no other does. */ + L_synerr("illegal character"); + yyterminate(); + } + YY_BREAK +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(re_delim): +case YY_STATE_EOF(re_modifier): +case YY_STATE_EOF(re_arg_split): +case YY_STATE_EOF(re_arg_case): +case YY_STATE_EOF(glob_re): +case YY_STATE_EOF(subst_re): +case YY_STATE_EOF(comment): +case YY_STATE_EOF(str_double): +case YY_STATE_EOF(str_single): +case YY_STATE_EOF(str_backtick): +case YY_STATE_EOF(interpol): +case YY_STATE_EOF(here_doc_interp): +case YY_STATE_EOF(here_doc_nointerp): +case YY_STATE_EOF(eat_through_eol): +case YY_STATE_EOF(lhtml_expr_start): +#line 1205 "../generic/Lscanner.l" +{ + if (in_lhtml) { + yy_user_action(); // for line #s + L_synerr("premature EOF"); + } + unless (include_pop()) yyterminate(); + } + YY_BREAK +case 206: +YY_RULE_SETUP +#line 1212 "../generic/Lscanner.l" +ECHO; + YY_BREAK +#line 3605 "<stdout>" + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed L_in at a new source and called + * L_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = L_in; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( L_wrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * L_text, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of L_lex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + L_restart(L_in ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) L_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + (yy_state_ptr) = (yy_state_buf); + *(yy_state_ptr)++ = yy_current_state; + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 583 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *(yy_state_ptr)++ = yy_current_state; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + + register YY_CHAR yy_c = 1; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 583 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 582); + if ( ! yy_is_jam ) + *(yy_state_ptr)++ = yy_current_state; + + return yy_is_jam ? 0 : yy_current_state; +} + + static void yyunput (int c, register char * yy_bp ) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up L_text */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register yy_size_t number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + L_restart(L_in ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( L_wrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve L_text */ + (yy_hold_char) = *++(yy_c_buf_p); + + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void L_restart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + L_ensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + L__create_buffer(L_in,YY_BUF_SIZE ); + } + + L__init_buffer(YY_CURRENT_BUFFER,input_file ); + L__load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void L__switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * L_pop_buffer_state(); + * L_push_buffer_state(new_buffer); + */ + L_ensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + L__load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (L_wrap()) processing, but the only time this flag + * is looked at is after L_wrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void L__load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + L_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE L__create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) L_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in L__create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) L_alloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in L__create_buffer()" ); + + b->yy_is_our_buffer = 1; + + L__init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with L__create_buffer() + * + */ + void L__delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + L_free((void *) b->yy_ch_buf ); + + L_free((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a L_restart() or at EOF. + */ + static void L__init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + L__flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then L__init_buffer was _probably_ + * called from L_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void L__flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + L__load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void L_push_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + L_ensure_buffer_stack(); + + /* This block is copied from L__switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from L__switch_to_buffer. */ + L__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void L_pop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + L__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + L__load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void L_ensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)L_alloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in L_ensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)L_realloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in L_ensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE L__scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) L_alloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in L__scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + L__switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to L_lex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * L__scan_bytes() instead. + */ +YY_BUFFER_STATE L__scan_string (yyconst char * yystr ) +{ + + return L__scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to L_lex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE L__scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) L_alloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in L__scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = L__scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in L__scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + + static void yy_push_state (int new_state ) +{ + if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) + { + yy_size_t new_size; + + (yy_start_stack_depth) += YY_START_STACK_INCR; + new_size = (yy_start_stack_depth) * sizeof( int ); + + if ( ! (yy_start_stack) ) + (yy_start_stack) = (int *) L_alloc(new_size ); + + else + (yy_start_stack) = (int *) L_realloc((void *) (yy_start_stack),new_size ); + + if ( ! (yy_start_stack) ) + YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); + } + + (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; + + BEGIN(new_state); +} + + static void yy_pop_state (void) +{ + if ( --(yy_start_stack_ptr) < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up L_text. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + L_text[L_leng] = (yy_hold_char); \ + (yy_c_buf_p) = L_text + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + L_leng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int L_get_lineno (void) +{ + + return L_lineno; +} + +/** Get the input stream. + * + */ +FILE *L_get_in (void) +{ + return L_in; +} + +/** Get the output stream. + * + */ +FILE *L_get_out (void) +{ + return L_out; +} + +/** Get the length of the current token. + * + */ +yy_size_t L_get_leng (void) +{ + return L_leng; +} + +/** Get the current token. + * + */ + +char *L_get_text (void) +{ + return L_text; +} + +/** Set the current line number. + * @param line_number + * + */ +void L_set_lineno (int line_number ) +{ + + L_lineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see L__switch_to_buffer + */ +void L_set_in (FILE * in_str ) +{ + L_in = in_str ; +} + +void L_set_out (FILE * out_str ) +{ + L_out = out_str ; +} + +int L_get_debug (void) +{ + return L__flex_debug; +} + +void L_set_debug (int bdebug ) +{ + L__flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from L_lex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + + (yy_start_stack_ptr) = 0; + (yy_start_stack_depth) = 0; + (yy_start_stack) = NULL; + + (yy_state_buf) = 0; + (yy_state_ptr) = 0; + (yy_full_match) = 0; + (yy_lp) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + L_in = stdin; + L_out = stdout; +#else + L_in = (FILE *) 0; + L_out = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * L_lex_init() + */ + return 0; +} + +/* L_lex_destroy is for both reentrant and non-reentrant scanners. */ +int L_lex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + L__delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + L_pop_buffer_state(); + } + + /* Destroy the stack itself. */ + L_free((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Destroy the start condition stack. */ + L_free((yy_start_stack) ); + (yy_start_stack) = NULL; + + L_free ( (yy_state_buf) ); + (yy_state_buf) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * L_lex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *L_alloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *L_realloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void L_free (void * ptr ) +{ + free( (char *) ptr ); /* see L_realloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 1211 "../generic/Lscanner.l" + + +void +L_lex_start() +{ + include_top = -1; + if (in_lhtml) { + STRBUF_START(0); + BEGIN(lhtml); + } else { + BEGIN(INITIAL); + } +} + +void +L_lex_begReArg(int kind) +{ + switch (kind) { + case 0: + yy_push_state(re_arg_split); + break; + case 1: + yy_push_state(re_arg_case); + break; + default: + break; + } +} + +private void +extract_re_delims(char c) +{ + re_start_delim = c; + if (c == '{') { + re_end_delim = '}'; + } else { + re_end_delim = c; + } +} + +void +L_lex_begLhtml() +{ + in_lhtml = 1; +} + +void +L_lex_endLhtml() +{ + in_lhtml = 0; +} + +/* + * These functions are declared down here because they reference + * things that flex has not yet declared in the prelogue (like + * unput() or yyterminate() etc). + */ + +/* + * Unput a single character. This function is declared down here + * because it calls flex's unput() which is not declared before + * the prelogue code earlier. + */ +private void +put_back(char c) +{ + unput(c); + --L_lloc.end; + --L->prev_token_len; + tally_newlines(&c, 1, -1); + --L->script_len; + Tcl_SetObjLength(L->script, L->script_len); +} + +/* + * API for scanning string interpolations: + * interpol_push() - call when starting an interpolation; returns 1 + * on interpolation stack overflow + * interpol_pop() - call when finishing an interpolation + * interpol_lbrace() - call when "{" seen + * interpol_rbrace() - call when "}" seen; returns non-0 if this brace + * ends the current interpolation + */ + +private int +interpol_push() +{ + if (interpol_top >= INTERPOL_STACK_SZ) { + L_err("string interpolation nesting too deep -- aborting"); + interpol_top = -1; + return (1); + } + interpol_stk[++interpol_top] = 0; + yy_push_state(interpol); + return (0); +} + +private void +interpol_pop() +{ + ASSERT((interpol_top >= 0) && (interpol_top <= INTERPOL_STACK_SZ)); + --interpol_top; + yy_pop_state(); +} + +private void +interpol_lbrace() +{ + if (interpol_top >= 0) { + ASSERT(interpol_top <= INTERPOL_STACK_SZ); + ++interpol_stk[interpol_top]; + } +} + +private int +interpol_rbrace() +{ + if (interpol_top >= 0) { + ASSERT(interpol_top <= INTERPOL_STACK_SZ); + return (interpol_stk[interpol_top]-- == 0); + } else { + return (0); + } +} + diff --git a/generic/Lscanner.l b/generic/Lscanner.l new file mode 100644 index 0000000..126b019 --- /dev/null +++ b/generic/Lscanner.l @@ -0,0 +1,1334 @@ +%option noyywrap +%option noyy_top_state +%option stack +%option noinput +%x re_delim +%x re_modifier +%x re_arg_split +%x re_arg_case +%x glob_re +%x subst_re +%x comment +%x str_double +%x str_single +%x str_backtick +%x interpol +%x here_doc_interp +%x here_doc_nointerp +%x eat_through_eol +%x lhtml +%x lhtml_expr_start +ID ([a-zA-Z_]|::)([0-9a-zA-Z_]|::)* +HEX [a-fA-F0-9] +%{ +/* + * Copyright (c) 2006-2008 BitMover, Inc. + */ +#include <string.h> +#define _PWD_H // Some solaris9 conflict, we don't need pwd.h +#include "tclInt.h" +#include "Lcompile.h" +#include "Lgrammar.h" +#include "tommath.h" + +private void extract_re_delims(char c); +private int include_pop(); +private int include_push(Tcl_Channel chan, char *name); +private Tcl_Channel include_search(char *file, char **path, int cwdOnly); +private Tcl_Channel include_try(Tcl_Obj *fileObj, int *found); +private void inject(char *s); +private void interpol_lbrace(); +private void interpol_pop(); +private int interpol_push(); +private int interpol_rbrace(); +private void put_back(char c); +private void tally_newlines(char *s, int len, int tally); + +// Max nesting depth of string interpolations. +#define INTERPOL_STACK_SZ 10 + +// Stack for tracking include() statements. +#define INCLUDE_STACK_SZ 10 +typedef struct { + char *name; + char *dir; + int line; + YY_BUFFER_STATE buf; +} Include; + +private char re_start_delim; // delimiters for m|regexp| form +private char re_end_delim; +private Tcl_Obj *str; // string collection buffer +private int str_beg; // source offset of string +private char *here_delim = NULL; +private char *here_pfx = NULL; +private int include_top; +private Include include_stk[INCLUDE_STACK_SZ+1]; +private Tcl_HashTable *include_table = NULL; +private int interpol_top = -1; +private int interpol_stk[INTERPOL_STACK_SZ+1]; +private int in_lhtml = 0; // Lhtml mode + +#define STRBUF_START(beg) \ + do { \ + str = Tcl_NewObj(); \ + Tcl_IncrRefCount(str); \ + str_beg = (beg); \ + } while (0) + + +#define STRBUF_STRING() Tcl_GetString(str) + +#define STRBUF_STARTED() (str != NULL) + +#define STRBUF_ADD(s, len) Tcl_AppendToObj(str, s, len) + +#define STRBUF_STOP(e) \ + do { \ + Tcl_DecrRefCount(str); \ + str = NULL; \ + L_lloc.beg = str_beg; \ + L_lloc.end = (e); \ + } while (0) + +/* + * Keep track of the current offset in the input string. + * YY_USER_ACTION is run before each action. Note that some actions + * further modify L_lloc. + */ + +#define YY_USER_ACTION yy_user_action(); + +private void +yy_user_action() +{ + L->prev_token_off = L->token_off; + L->token_off += L->prev_token_len; + L->prev_token_len = yyleng; + + L_lloc.beg = L->token_off; + L_lloc.end = L->token_off + yyleng; + + tally_newlines(yytext, yyleng, 1); + L_lloc.line = L->line; + + L_lloc.file = L->file; + + /* + * Build up in L->script the text that the scanner scans. + * The compiler later passes this on to tcl as the script + * source. This allows include() stmts to be handled properly. + */ + Tcl_AppendToObj(L->script, yytext, yyleng); + L->script_len += yyleng; +} + +/* + * Un-do the effects of the YY_USER_ACTION on the token offset + * tracking. This is useful in include() processing where the + * characters in the '#include "file"' must be ignored. + */ +private void +undo_yy_user_action() +{ + L->prev_token_len = L->token_off - L->prev_token_off; + L->token_off = L->prev_token_off; + + L_lloc.beg = L->prev_token_off; + L_lloc.end = L->prev_token_off + L->prev_token_len; + + tally_newlines(yytext, yyleng, -1); + L_lloc.line = L->line; + + L->script_len -= yyleng; + Tcl_SetObjLength(L->script, L->script_len); +} + +/* + * Inject the given string into the L script text, but do not give it + * to the scanner. This is useful for inserting #line directives (for + * #include's) which need to remain in the script so Tcl can see them + * but which aren't parsed. + */ +private void +inject(char *s) +{ + int len = strlen(s); + + L->prev_token_len += len; + + Tcl_AppendToObj(L->script, s, len); + L->script_len += len; +} + +/* + * Count the newlines in a string and add the number to L->line. Pass + * in tally == 1 to count them and tally == -1 to undo it. + */ +private void +tally_newlines(char *s, int len, int tally) +{ + char *end, *p; + + for (p = s, end = p + len; p < end; p++) { + if (*p == '\n') { + L->line += tally; + } else if ((*p == '\r') && ((p+1) < end) && (*(p+1) != '\n')) { + /* Mac line endings. */ + L->line += tally; + } + } +} + +private Tcl_Channel +include_try(Tcl_Obj *fileObj, int *found) +{ + int new; + Tcl_Channel chan; + char *file = Tcl_GetString(fileObj); + char *path; + Tcl_Obj *pathObj; + + /* + * See if the normalized path has been included before. If the path + * isn't absolute, consider it to be relative to where L->file is. + */ + if (Tcl_FSGetPathType(fileObj) == TCL_PATH_ABSOLUTE) { + if ((pathObj = Tcl_FSGetNormalizedPath(NULL, fileObj)) == NULL){ + L_err("unable to normalize include file %s", file); + return (NULL); + } + } else { + pathObj = Tcl_ObjPrintf("%s/%s", L->dir, file); + } + Tcl_IncrRefCount(pathObj); + + path = Tcl_GetString(pathObj); + Tcl_CreateHashEntry(include_table, path, &new); + if (new) { + chan = Tcl_FSOpenFileChannel(L->interp, pathObj, "r", 0666); + *found = (chan != NULL); + return (chan); + } else { + *found = 1; // already included + return (NULL); + } + Tcl_DecrRefCount(pathObj); +} + +/* + * Search for an include file. If the path is absolute, use it. + * Else, for #include <file> (cwdOnly == 0) try + * $BIN/include (where BIN is where the running tclsh lives) + * /usr/local/include/L + * /usr/include/L + * For #include "file" (cwdOnly == 1) look only in the directory + * where the script doing the #include resides. + */ +private Tcl_Channel +include_search(char *file, char **path, int cwdOnly) +{ + int found, len; + Tcl_Channel chan; + Tcl_Obj *binObj = NULL; + Tcl_Obj *fileObj; + + unless (include_table) { + include_table = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable)); + Tcl_InitHashTable(include_table, TCL_STRING_KEYS); + } + + fileObj = Tcl_NewStringObj(file, -1); + Tcl_IncrRefCount(fileObj); + if ((Tcl_FSGetPathType(fileObj) == TCL_PATH_ABSOLUTE) || cwdOnly) { + chan = include_try(fileObj, &found); + } else { + /* Try $BIN/include */ + binObj = TclGetObjNameOfExecutable(); + Tcl_GetStringFromObj(binObj, &len); + if (len > 0) { + Tcl_DecrRefCount(fileObj); + /* TclPathPart bumps the ref count. */ + fileObj = TclPathPart(L->interp, binObj, + TCL_PATH_DIRNAME); + Tcl_AppendPrintfToObj(fileObj, "/include/%s", file); + chan = include_try(fileObj, &found); + if (found) goto done; + } + /* Try /usr/local/include/L */ + Tcl_DecrRefCount(fileObj); + fileObj = Tcl_ObjPrintf("/usr/local/include/L/%s", file); + Tcl_IncrRefCount(fileObj); + chan = include_try(fileObj, &found); + if (found) goto done; + /* Try /usr/include/L */ + Tcl_DecrRefCount(fileObj); + fileObj = Tcl_ObjPrintf("/usr/include/L/%s", file); + Tcl_IncrRefCount(fileObj); + chan = include_try(fileObj, &found); + } + done: + unless (found) { + L_err("cannot find include file %s", file); + } + if (path) *path = ckstrdup(Tcl_GetString(fileObj)); + Tcl_DecrRefCount(fileObj); + return (chan); +} + +private int +include_push(Tcl_Channel chan, char *name) +{ + YY_BUFFER_STATE buf; + Tcl_Obj *objPtr; + char *dec = NULL, *script; + int len, ret; + + /* Read the file into memory. */ + objPtr = Tcl_NewObj(); + Tcl_IncrRefCount(objPtr); + if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) { + Tcl_Close(L->interp, chan); + L_err("error reading include file %s", name); + return (0); + } + Tcl_Close(L->interp, chan); + + /* If it is encrypted, decrypt it. */ + script = Tcl_GetStringFromObj(objPtr, &len); + + /* Create a new flex buffer with the file contents. */ + if (include_top >= INCLUDE_STACK_SZ) { + L_err("include file nesting too deep -- aborting"); + while (include_pop()) ; + ret = 0; + } else { + ++include_top; + include_stk[include_top].name = L->file; + include_stk[include_top].dir = L->dir; + include_stk[include_top].line = L->line; + include_stk[include_top].buf = YY_CURRENT_BUFFER; + buf = yy_scan_bytes(script, len); + L->file = name; + L->dir = L_dirname(L->file); + L->line = 1; + inject("#line 1\n"); + ret = 1; + } + Tcl_DecrRefCount(objPtr); + if (dec) ckfree(dec); + return (ret); +} + +private int +include_pop() +{ + char *s; + + if (include_top >= 0) { + L->file = include_stk[include_top].name; + L->dir = include_stk[include_top].dir; + L->line = include_stk[include_top].line; + yy_delete_buffer(YY_CURRENT_BUFFER); + yy_switch_to_buffer(include_stk[include_top].buf); + --include_top; + s = cksprintf("#line %d\n", L->line); + inject(s); + ckfree(s); + return (1); + } else { + return (0); + } +} + +/* + * Given a decimal, hex, or octal integer constant of arbitrary + * precision, return a canonical string representation. This is done + * by converting it to a bignum and then taking its string rep. + */ +private char * +canonical_num(char *num) +{ + char *ret; + Tcl_Obj *obj; + mp_int big; + + obj = Tcl_NewStringObj(num, -1); + Tcl_IncrRefCount(obj); + Tcl_TakeBignumFromObj(NULL, obj, &big); + Tcl_SetBignumObj(obj, &big); + ret = ckstrdup(Tcl_GetString(obj)); + Tcl_DecrRefCount(obj); + return (ret); +} + +/* + * Work around a Windows problem where our getopt type conficts + * with the system's. + */ +#undef getopt +#undef optarg +#undef optind + +%} +%% +<INITIAL,interpol>{ + "(" return T_LPAREN; + ")" return T_RPAREN; + "{" interpol_lbrace(); return T_LBRACE; + "[" return T_LBRACKET; + "]" return T_RBRACKET; + "," return T_COMMA; + "!" return T_BANG; + "+" return T_PLUS; + "-" return T_MINUS; + "*" return T_STAR; + "/" return T_SLASH; + "%" return T_PERC; + "+=" return T_EQPLUS; + "-=" return T_EQMINUS; + "*=" return T_EQSTAR; + "/=" return T_EQSLASH; + "%=" return T_EQPERC; + "&=" return T_EQBITAND; + "|=" return T_EQBITOR; + "^=" return T_EQBITXOR; + "<<=" return T_EQLSHIFT; + ">>=" return T_EQRSHIFT; + ".=" return T_EQDOT; + "++" return T_PLUSPLUS; + "--" return T_MINUSMINUS; + "&&" return T_ANDAND; + "||" return T_OROR; + "&" return T_BITAND; + "|" return T_BITOR; + "^" return T_BITXOR; + "~" return T_BITNOT; + "<<" return T_LSHIFT; + ">>" return T_RSHIFT; + "=" return T_EQUALS; + ";" return T_SEMI; + "." return T_DOT; + [ \t\n\r]+"."[ \t\n\r]+ return T_STRCAT; + ".." return T_DOTDOT; + "..." return T_ELLIPSIS; + "class" return T_CLASS; + "extern" return T_EXTERN; + "return" return T_RETURN; + "void" return T_VOID; + "string" return T_STRING; + "widget" return T_WIDGET; + "int" return T_INT; + "float" return T_FLOAT; + "poly" return T_POLY; + "split" return T_SPLIT; + "if" return T_IF; + "else" return T_ELSE; + "unless" return T_UNLESS; + "while" return T_WHILE; + "do" return T_DO; + "for" return T_FOR; + "struct" return T_STRUCT; + "typedef" return T_TYPEDEF; + "defined" return T_DEFINED; + "foreach" return T_FOREACH; + "break" return T_BREAK; + "continue" return T_CONTINUE; + "instance" return T_INSTANCE; + "private" return T_PRIVATE; + "public" return T_PUBLIC; + "constructor" return T_CONSTRUCTOR; + "destructor" return T_DESTRUCTOR; + "expand" return T_EXPAND; + "_argused" return T_ARGUSED; + "_attribute" return T_ATTRIBUTE; + "_attributes" return T_ATTRIBUTE; + "_optional" return T_OPTIONAL; + "_mustbetype" return T_MUSTBETYPE; + "goto" return T_GOTO; + "switch" return T_SWITCH; + "case" return T_CASE; + "default" return T_DEFAULT; + "try" return T_TRY; + "=>" return T_ARROW; + "eq" return T_EQ; + "ne" return T_NE; + "lt" return T_LT; + "le" return T_LE; + "gt" return T_GT; + "ge" return T_GE; + "==" return T_EQUALEQUAL; + "!=" return T_NOTEQUAL; + ">" return T_GREATER; + ">=" return T_GREATEREQ; + "<" return T_LESSTHAN; + "<=" return T_LESSTHANEQ; + "->" return T_POINTS; + ":" return T_COLON; + "?" return T_QUESTION; + "?>" { + /* + * ?> marks the end of a script or expr + * inside of an lhtml document but is a + * syntax error otherwise. + */ + unless (in_lhtml) { + undo_yy_user_action(); + REJECT; + } + yy_pop_state(); + STRBUF_START(L_lloc.end); + if (YYSTATE == lhtml_expr_start) { + yy_pop_state(); // pop back to lhtml + ASSERT(YYSTATE == lhtml); + return T_LHTML_EXPR_END; + } + } + "and" { + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_ANDAND; + } + "not" { + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_BANG; + } + "or" { + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_OROR; + } + "xor" { + L_err("'and','or','xor','not' are " + "unimplemented reserved words"); + return T_BITXOR; + } + {ID} { + Type *t = L_typedef_lookup(yytext); + if (t) { + L_lval.Typename.s = ckstrdup(yytext); + L_lval.Typename.t = t; + return T_TYPE; + } else { + L_lval.s = ckstrdup(yytext); + return T_ID; + } + } + {ID}: { + /* + * Push back the : and return a T_ID + * unless it's "default". The grammar relies + * on this to avoid a nasty conflict. + */ + put_back(':'); + if (!strncmp(yytext, "default", 7)) { + return T_DEFAULT; + } + L_lval.s = ckstrdup(yytext); + L_lval.s[yyleng-1] = 0; + return T_ID; + } + ([A-Z]|::)([0-9a-zA-Z]|::)*_\* { + L_lval.s = ckstrdup(yytext); + return T_PATTERN; + } + $[0-9]+ { + /* Regular expression submatches */ + L_lval.s = ckstrdup(yytext); + return T_ID; + } + [0-9]+ { + /* + * Skip any leading 0's which would + * make it look like octal to Tcl. + */ + size_t z = strspn(yytext, "0"); + if (z == yyleng) z = 0; // number is all 0's + L_lval.s = canonical_num(yytext+z); + return T_INT_LITERAL; + } + 0o[0-7]+ { + /* + * Create a leading 0 so it looks like + * octal to Tcl. + */ + yytext[1] = '0'; + L_lval.s = canonical_num(yytext+1); + return T_INT_LITERAL; + } + 0x[0-9a-fA-F]+ { + L_lval.s = canonical_num(yytext); + return T_INT_LITERAL; + } + [0-9]*\.[0-9]+ { + L_lval.s = ckstrdup(yytext); + return T_FLOAT_LITERAL; + } + ^#line[ \t]+[0-9]+\n { + int line = strtoul(yytext+5, NULL, 10); + + if (line <= 0) { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } else { + L->line = line; + } + } + ^#line[ \t]+[0-9]+[ \t]+\"[^\"\n]*\"\n { + int line = strtoul(yytext+5, NULL, 10); + char *beg = strchr(yytext, '"') + 1; + char *end = strrchr(yytext, '"'); + char *name = ckstrndup(beg, end-beg); + + if (line <= 0) { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } else { + L->file = name; + L->line = line; + } + } + ^#line.*\n { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } + ^#include[ \t]*\"[^\"\n]+\" { + char *beg = strchr(yytext, '"') + 1; + char *end = strrchr(yytext, '"'); + char *name = ckstrndup(beg, end-beg); + Tcl_Channel chan; + + chan = include_search(name, NULL, 1); + + undo_yy_user_action(); + if (chan && !include_push(chan, name)) { + /* Bail if includes nest too deeply. */ + yyterminate(); + } + } + ^#include[ \t]*<[^>\n]+> { + char *beg = strchr(yytext, '<') + 1; + char *end = strrchr(yytext, '>'); + char *name = ckstrndup(beg, end-beg); + char *path = NULL; + Tcl_Channel chan; + + chan = include_search(name, &path, 0); + ckfree(name); + + undo_yy_user_action(); + if (chan && !include_push(chan, path)) { + /* Bail if includes nest too deeply. */ + yyterminate(); + } + } + ^#include { + L_err("malformed #include"); + yy_push_state(eat_through_eol); + } + ^#pragma[ \t]+ return T_PRAGMA; + ^#.*("\r"|"\n"|"\r\n") { + /* + * Rather than using a start condition + * to separate out all the ^# patterns + * that don't end in \n, this is + * simpler. If it's not a comment, + * REJECT it so that flex then takes + * the second best rule (those above). + */ + if (!strncmp(yytext, "#pragma ", 8) || + !strncmp(yytext, "#pragma\t", 8)) { + undo_yy_user_action(); + REJECT; + } else if (!strncmp(yytext, "#include", 8)) { + undo_yy_user_action(); + REJECT; + } else unless (L->line == 2) { + --L->line; // since \n already scanned + L_err("# comment valid only on line 1"); + ++L->line; + } + } + [ \t]+#.*("\r"|"\n"|"\r\n") { + --L->line; // since \n already scanned + unless (L->line == 1) { + L_err("# comment valid only on line 1"); + } else { + L_err("# comment must start at " + "first column"); + } + ++L->line; + } + "//".*("\r"|"\n"|"\r\n") + [ \t]+ + \n|\r|\f + \" yy_push_state(str_double); STRBUF_START(L->token_off); + \' yy_push_state(str_single); STRBUF_START(L->token_off); + \` yy_push_state(str_backtick); STRBUF_START(L->token_off); + "/*" yy_push_state(comment); + [!=]~[ \t\r\n]*"m". { + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 2); // next token starts at the "m" + extract_re_delims(yytext[yyleng-1]); + L_lloc.end = L_lloc.beg + 2; // this token spans the "=~" + return ((yytext[0] == '=') ? T_EQTWID : T_BANGTWID); + } + /* if / is used to delimit the regexp, the m can be omitted */ + [!=]~[ \t\r\n]*"/" { + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the "/" + extract_re_delims('/'); + L_lloc.end = L_lloc.beg + 2; // this token spans the "=~" + return ((yytext[0] == '=') ? T_EQTWID : T_BANGTWID); + } + /* a substitution pattern */ + "=~"[ \t\r\n]*"s". { + yy_push_state(re_modifier); + yy_push_state(subst_re); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 2); // next token starts at the "s" + extract_re_delims(yytext[yyleng-1]); + L_lloc.end = L_lloc.beg + 2; // this token spans the "=~" + return T_EQTWID; + } + /* here document (interpolated), valid only on rhs of an assignment */ + =[ \t\r\n]*<<[a-zA-Z_][a-zA-Z_0-9]*\n { + char *p, *q; + + if (here_delim) { + L_err("nested here documents illegal"); + } + p = strchr(yytext, '<') + 2; // the < is guaranteed to exist + for (q = p; (q > yytext) && (*q != '\n'); --q) ; + if ((q > yytext) && (*q == '\n')) { + // \n then <<; the in-between whitespace is the here_pfx + here_pfx = ckstrndup(q+1, p-q-3); + } else { + // non-indented here document + here_pfx = ckstrdup(""); + } + here_delim = ckstrndup(p, yyleng - (p-yytext) - 1); + STRBUF_START(L->token_off); + L_lloc.end = L_lloc.beg + 1; + yy_push_state(here_doc_interp); + return T_EQUALS; + } + /* here document (uninterpolated), valid only on rhs of an assignment */ + =[ \t\r\n]*<<\'[a-zA-Z_][a-zA-Z_0-9]*\'\n { + char *p, *q; + + if (here_delim) { + L_err("nested here documents illegal"); + } + p = strchr(yytext, '<') + 2; // the < is guaranteed to exist + for (q = p; (q > yytext) && (*q != '\n'); --q) ; + if ((q > yytext) && (*q == '\n')) { + // \n then <<; the in-between whitespace is the here_pfx + here_pfx = ckstrndup(q+1, p-q-3); + } else { + // non-indented here document + here_pfx = ckstrdup(""); + } + here_delim = ckstrndup(p+1, yyleng - (p-yytext) - 3); + STRBUF_START(L->token_off); + L_lloc.end = L_lloc.beg + 1; + yy_push_state(here_doc_nointerp); + return T_EQUALS; + } + /* illegal here documents (bad stuff before or after the delim) */ + =[ \t\r\n]*<<-[a-zA-Z_][a-zA-Z_0-9]* | + =[ \t\r\n]*<<-\'[a-zA-Z_][a-zA-Z_0-9]*\' { + L_synerr("<<- unsupported, use =\\n\\t<<END to strip one " + "leading tab"); + } + =[ \t\r\n]*<<[a-zA-Z_][a-zA-Z_0-9]*[^\n] { + L_synerr("illegal characters after here-document delimeter"); + } + =[ \t\r\n]*<<[^a-zA-Z_][a-zA-Z_][a-zA-Z_0-9]* { + L_synerr("illegal characters before here-document delimeter"); + } + =[ \t\r\n]*<<\'[a-zA-Z_][a-zA-Z_0-9]*\'[^\n] { + L_synerr("illegal characters after here-document delimeter"); + } + =[ \t\r\n]*<<\'[^a-zA-Z_][a-zA-Z_][a-zA-Z_0-9]*\' { + L_synerr("illegal characters before here-document delimeter"); + } +} + +<lhtml>{ + /* + * The compiler prepends a #line directive to Lhtml source. + * This communicates the correct line number to the Tcl + * code that prints run-time error messages. + */ + ^#line[ \t]+[0-9]+\n { + int line = strtoul(yytext+5, NULL, 10); + + if (line <= 0) { + --L->line; // since \n already scanned + L_err("malformed #line"); + ++L->line; + } else { + L->line = line; + } + } + "<?"=? { + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + if (yyleng == 2) { + yy_push_state(INITIAL); + } else { + yy_push_state(lhtml_expr_start); + } + return T_HTML; + } + .|\n STRBUF_ADD(yytext, yyleng); + <<EOF>> { + unless (STRBUF_STARTED()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_HTML; + } +} + +<lhtml_expr_start>{ + /* + * This start condition is here only so the rule for ?> can + * know whether we previously scanned <? or <?=. + */ + .|\n { + unput(yytext[0]); + undo_yy_user_action(); + yy_push_state(INITIAL); + return T_LHTML_EXPR_START; + } +} + +<re_arg_split>{ + /* + * A regexp in the context of the first arg to split(). If + * it's not an RE, pop the start-condition stack and push it + * back, so we can continue as normal. + */ + [ \t\r\n]* + /* / starts an RE */ + "/" { + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the "/" + extract_re_delims('/'); + } + /* + * m<punctuation> starts an RE, except for "m)" so that + * "split(m)" works. + */ + "m"[^a-zA-Z() \t\r\n] { + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the delim + extract_re_delims(yytext[yyleng-1]); + } + /* nothing else starts an RE */ + . { + unput(yytext[0]); + undo_yy_user_action(); + yy_pop_state(); + } +} + +<re_arg_case>{ + /* + * A regexp in the context of a case statement. If it's not + * an RE, pop the start-condition stack and push it back, so + * we can continue as normal. + */ + [ \t\r\n]* + /* / starts an RE */ + "/" { + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the "/" + extract_re_delims('/'); + } + /* + * m<punctuation> starts an RE except for "m:" which we scan + * as the variable m (so that "case m:" works) or "m(" which + * is the start of a call to the function m (so that "case m():" + * or "case m(arg):" etc work). + */ + m[^a-zA-Z:( \t\r\n] { + yy_push_state(re_modifier); + yy_push_state(glob_re); + STRBUF_START(L_lloc.end - 1); // next token starts at the delim + extract_re_delims(yytext[yyleng-1]); + } + /* nothing else starts an RE */ + . { + unput(yytext[0]); + undo_yy_user_action(); + yy_pop_state(); + } +} + +<INITIAL>{ + "}" return T_RBRACE; +} + +<interpol>{ + "}" { + if (interpol_rbrace()) { + STRBUF_START(L_lloc.end); + interpol_pop(); + if ((YYSTATE == glob_re) || + (YYSTATE == subst_re)) { + return T_RIGHT_INTERPOL_RE; + } else { + return T_RIGHT_INTERPOL; + } + } else { + return T_RBRACE; + } + } + . { + L_synerr("illegal character"); + } +} + +<str_double>{ + \\r STRBUF_ADD("\r", 1); + \\n STRBUF_ADD("\n", 1); + \\t STRBUF_ADD("\t", 1); + \\u{HEX} | + \\u{HEX}{HEX} | + \\u{HEX}{HEX}{HEX} | + \\u{HEX}{HEX}{HEX}{HEX} { + char buf[TCL_UTF_MAX]; + int ch; + TclParseHex(yytext+2, 4, &ch); + STRBUF_ADD(buf, Tcl_UniCharToUtf(ch, buf)); + } + \\(.|\n) STRBUF_ADD(yytext+1, 1); + "$" STRBUF_ADD("$", 1); + \n { + L_err("missing string terminator \""); + STRBUF_ADD("\n", 1); + } + [^\\\"$\n]+ STRBUF_ADD(yytext, yyleng); + "${" { + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL; + } + \"[ \t\r\n]*\" + \" { + yy_pop_state(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + return T_STR_LITERAL; + } +} + +<str_single>{ + \\\\ STRBUF_ADD("\\", 1); + \\\' STRBUF_ADD("'", 1); + \\\n STRBUF_ADD("\n", 1); + \n { + L_err("missing string terminator \'"); + STRBUF_ADD("\n", 1); + } + \\. | + [^\\\'\n]+ STRBUF_ADD(yytext, yyleng); + \'[ \t\r\n]*\' + \' { + yy_pop_state(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + return T_STR_LITERAL; + } +} + +<str_backtick>{ + \\("$"|`|\\) STRBUF_ADD(yytext+1, 1); + \\\n /* ignore \<newline> */ + \\. | + "$" | + [^\\`$\n]+ STRBUF_ADD(yytext, yyleng); + \n { + L_err("missing string terminator `"); + STRBUF_ADD("\n", 1); + } + "${" { + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL; + } + ` { + yy_pop_state(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + if (YYSTATE == here_doc_interp) { + STRBUF_START(L_lloc.end); + } + return T_STR_BACKTICK; + } +} + +<here_doc_nointerp>{ + ^[ \t]*[a-zA-Z_][a-zA-Z_0-9]*;?$ { + int len; + char *p = yytext; + + /* + * Look for whitespace-prefixed here_delim. + * Any amount of white space is allowed. + */ + while (isspace(*p)) ++p; + len = yyleng - (p - yytext); + if (p[len-1] == ';') --len; + if ((len == strlen(here_delim)) && + !strncmp(p, here_delim, len)) { + yy_pop_state(); + unput(';'); // for the parser + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + ckfree(here_delim); + ckfree(here_pfx); + here_delim = NULL; + here_pfx = NULL; + return T_STR_LITERAL; + } + /* + * It's a data line. It must begin with + * here_pfx or else it's an error. + */ + p = strstr(yytext, here_pfx); + if (p == yytext) { + p += strlen(here_pfx); + } else { + L_err("bad here-document prefix"); + p = yytext; + } + STRBUF_ADD(p, yyleng - (p - yytext)); + } + ^[ \t]+ { + char *p = strstr(yytext, here_pfx); + if (p == yytext) { + p += strlen(here_pfx); + STRBUF_ADD(p, yyleng - (p - yytext)); + } else { + L_err("bad here-document prefix"); + p = yytext; + } + } + .|\n STRBUF_ADD(yytext, 1); +} + +<here_doc_interp>{ + \\\\ STRBUF_ADD("\\", 1); + \\\$ STRBUF_ADD("$", 1); + \\` STRBUF_ADD("`", 1); + \\\n // ignore \<newline> + "${" { + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL; + } + ` { + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + yy_push_state(str_backtick); + STRBUF_START(L->token_off); + return T_START_BACKTICK; + } + ^[ \t]*[a-zA-Z_][a-zA-Z_0-9]*;?$ { + int len; + char *p = yytext; + + /* + * Look for whitespace-prefixed here_delim. + * Any amount of white space is allowed. + */ + while (isspace(*p)) ++p; + len = yyleng - (p - yytext); + if (p[len-1] == ';') --len; + if ((len == strlen(here_delim)) && + !strncmp(p, here_delim, len)) { + yy_pop_state(); + unput(';'); // for the parser + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + ckfree(here_delim); + ckfree(here_pfx); + here_delim = NULL; + here_pfx = NULL; + return T_STR_LITERAL; + } + /* + * It's a data line. It must begin with + * here_pfx or else it's an error. + */ + p = strstr(yytext, here_pfx); + if (p == yytext) { + p += strlen(here_pfx); + } else { + L_err("bad here-document prefix"); + p = yytext; + } + STRBUF_ADD(p, yyleng - (p - yytext)); + } + ^[ \t]+ { + char *p = strstr(yytext, here_pfx); + if (p == yytext) { + p += strlen(here_pfx); + STRBUF_ADD(p, yyleng - (p - yytext)); + } else { + L_err("bad here-document prefix"); + p = yytext; + } + } + .|\n STRBUF_ADD(yytext, 1); +} + +<comment>{ + [^*]+ + "*" + "*/" yy_pop_state(); +} + +<glob_re,subst_re>{ + "${" { + if (interpol_push()) yyterminate(); + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.beg); + return T_LEFT_INTERPOL_RE; + } + \\. { + if ((yytext[1] == re_end_delim) || + (yytext[1] == re_start_delim)) { + STRBUF_ADD(yytext+1, 1); + } else { + STRBUF_ADD(yytext, yyleng); + } + } + \n { + --L->line; // since \n already scanned + L_err("run-away regular expression"); + ++L->line; + STRBUF_ADD(yytext, yyleng); + yy_pop_state(); + if (YYSTATE == re_modifier) yy_pop_state(); + return T_RE; + } + "$"[0-9] { + // Convert $3 to \3 (regexp capture reference). + STRBUF_ADD("\\", 1); + STRBUF_ADD(yytext+1, yyleng-1); + } + . { + if (*yytext == re_end_delim) { + L_lval.s = ckstrdup(STRBUF_STRING()); + STRBUF_STOP(L_lloc.end); + if (YYSTATE == subst_re) { + yy_pop_state(); + return T_SUBST; + } else { + yy_pop_state(); + if (YYSTATE == subst_re) { + STRBUF_START(L_lloc.end); + if (re_start_delim != + re_end_delim) { + yy_push_state( + re_delim); + } + } + return T_RE; + } + } else if (*yytext == re_start_delim) { + L_err("regexp delimiter must be quoted " + "inside the regexp"); + STRBUF_ADD(yytext+1, 1); + } else { + STRBUF_ADD(yytext, yyleng); + } + } + +} + +<re_delim>{ + \n { + --L->line; // since \n already scanned + L_err("run-away regular expression"); + ++L->line; + STRBUF_ADD(yytext, yyleng); + yy_pop_state(); + } + . { + extract_re_delims(*yytext); + yy_pop_state(); + } +} + +<re_modifier>{ + [iglt]+ { + L_lval.s = ckstrdup(yytext); + yy_pop_state(); + return T_RE_MODIFIER; + } + .|\n { + unput(yytext[0]); + undo_yy_user_action(); + yy_pop_state(); + L_lval.s = ckstrdup(""); + return T_RE_MODIFIER; + } +} + +<eat_through_eol>{ + . + \n yy_pop_state(); +} + + . { + /* This rule matches a char if no other does. */ + L_synerr("illegal character"); + yyterminate(); + } + <<EOF>> { + if (in_lhtml) { + yy_user_action(); // for line #s + L_synerr("premature EOF"); + } + unless (include_pop()) yyterminate(); + } +%% +void +L_lex_start() +{ + include_top = -1; + if (in_lhtml) { + STRBUF_START(0); + BEGIN(lhtml); + } else { + BEGIN(INITIAL); + } +} + +void +L_lex_begReArg(int kind) +{ + switch (kind) { + case 0: + yy_push_state(re_arg_split); + break; + case 1: + yy_push_state(re_arg_case); + break; + default: + break; + } +} + +private void +extract_re_delims(char c) +{ + re_start_delim = c; + if (c == '{') { + re_end_delim = '}'; + } else { + re_end_delim = c; + } +} + +void +L_lex_begLhtml() +{ + in_lhtml = 1; +} + +void +L_lex_endLhtml() +{ + in_lhtml = 0; +} + +/* + * These functions are declared down here because they reference + * things that flex has not yet declared in the prelogue (like + * unput() or yyterminate() etc). + */ + +/* + * Unput a single character. This function is declared down here + * because it calls flex's unput() which is not declared before + * the prelogue code earlier. + */ +private void +put_back(char c) +{ + unput(c); + --L_lloc.end; + --L->prev_token_len; + tally_newlines(&c, 1, -1); + --L->script_len; + Tcl_SetObjLength(L->script, L->script_len); +} + +/* + * API for scanning string interpolations: + * interpol_push() - call when starting an interpolation; returns 1 + * on interpolation stack overflow + * interpol_pop() - call when finishing an interpolation + * interpol_lbrace() - call when "{" seen + * interpol_rbrace() - call when "}" seen; returns non-0 if this brace + * ends the current interpolation + */ + +private int +interpol_push() +{ + if (interpol_top >= INTERPOL_STACK_SZ) { + L_err("string interpolation nesting too deep -- aborting"); + interpol_top = -1; + return (1); + } + interpol_stk[++interpol_top] = 0; + yy_push_state(interpol); + return (0); +} + +private void +interpol_pop() +{ + ASSERT((interpol_top >= 0) && (interpol_top <= INTERPOL_STACK_SZ)); + --interpol_top; + yy_pop_state(); +} + +private void +interpol_lbrace() +{ + if (interpol_top >= 0) { + ASSERT(interpol_top <= INTERPOL_STACK_SZ); + ++interpol_stk[interpol_top]; + } +} + +private int +interpol_rbrace() +{ + if (interpol_top >= 0) { + ASSERT(interpol_top <= INTERPOL_STACK_SZ); + return (interpol_stk[interpol_top]-- == 0); + } else { + return (0); + } +} diff --git a/generic/Ltypecheck.c b/generic/Ltypecheck.c new file mode 100644 index 0000000..a1bf86a --- /dev/null +++ b/generic/Ltypecheck.c @@ -0,0 +1,498 @@ +/* + * Type-checking helpers for the L programming language. + * + * Copyright (c) 2006-2008 BitMover, Inc. + */ +#include <stdio.h> +#include "tclInt.h" +#include "Lcompile.h" +#include "Lgrammar.h" + +private int typeck_declType(Type *type, VarDecl *decl, int nameof_ok); +private int typeck_decls(VarDecl *a, VarDecl *b); +private void typeck_fmt(Expr *actuals); +private int typeck_list(Type *a, Type *b); + +/* Create the pre-defined types. */ +void +L_typeck_init() +{ + L_int = type_mkScalar(L_INT); + L_float = type_mkScalar(L_FLOAT); + L_string = type_mkScalar(L_STRING); + L_widget = type_mkScalar(L_WIDGET); + L_void = type_mkScalar(L_VOID); + L_poly = type_mkScalar(L_POLY); +} + +private Tcl_Obj *typenmObj = NULL; + +private void +str_add(char *s) +{ + if (typenmObj) { + Tcl_AppendPrintfToObj(typenmObj, " or %s", s); + } else { + typenmObj = Tcl_NewStringObj(s, -1); + Tcl_IncrRefCount(typenmObj); + } +} + +char * +L_type_str(Type_k kind) +{ + if (typenmObj) { + Tcl_DecrRefCount(typenmObj); + typenmObj = NULL; + } + if (kind & L_INT) str_add("int"); + if (kind & L_FLOAT) str_add("float"); + if (kind & L_STRING) str_add("string"); + if (kind & L_WIDGET) str_add("widget"); + if (kind & L_VOID) str_add("void"); + if (kind & L_POLY) str_add("poly"); + if (kind & L_HASH) str_add("hash"); + if (kind & L_STRUCT) str_add("struct"); + if (kind & L_ARRAY) str_add("array"); + if (kind & L_LIST) str_add("list"); + if (kind & L_FUNCTION) str_add("function"); + if (kind & L_NAMEOF) str_add("nameof"); + if (kind & L_CLASS ) str_add("class"); + return (Tcl_GetString(typenmObj)); +} + +private void +pr_err(Type_k got, Type_k want, char *bef, char *aft, void *node) +{ + Tcl_Obj *obj = Tcl_NewObj(); + + Tcl_IncrRefCount(obj); + if (bef) Tcl_AppendPrintfToObj(obj, "%s, ", bef); + Tcl_AppendPrintfToObj(obj, "expected type %s", L_type_str(want)); + Tcl_AppendPrintfToObj(obj, " but got %s", L_type_str(got)); + if (aft) Tcl_AppendPrintfToObj(obj, " %s", aft); + L_errf(node, Tcl_GetString(obj)); + Tcl_DecrRefCount(obj); +} + +void +L_typeck_deny(Type_k deny, Expr *expr) +{ + ASSERT(expr->type); + + if (hash_get(L->options, "poly")) return; + + if (expr->type->kind & deny) { + L_errf(expr, "type %s illegal", L_type_str(expr->type->kind)); + expr->type = L_poly; // minimize cascading errors + } +} + +void +L_typeck_expect(Type_k want, Expr *expr, char *msg) +{ + ASSERT(expr->type); + + if (hash_get(L->options, "poly") || + ((expr->type->kind | want) & L_POLY)) return; + + unless (expr->type->kind & want) { + pr_err(expr->type->kind, want, NULL, msg, expr); + expr->type = L_poly; // minimize cascading errors + } +} + +int +L_typeck_compat(Type *lhs, Type *rhs) +{ + if ((lhs->kind == L_POLY) || (rhs->kind == L_POLY)) { + return (TRUE); + } + if (lhs->kind == L_FLOAT) { + return (rhs->kind & (L_INT|L_FLOAT)); + } else { + return (L_typeck_same(lhs, rhs)); + } +} + +void +L_typeck_assign(Expr *lhs, Type *rhs) +{ + if (hash_get(L->options, "poly")) return; + unless (lhs && rhs) return; + + if ((rhs->kind == L_VOID) || (lhs->type->kind == L_VOID)) { + L_errf(lhs, "type void illegal"); + } + unless (L_typeck_compat(lhs->type, rhs)) { + L_errf(lhs, "assignment of incompatible types"); + } +} + +void +L_typeck_fncall(VarDecl *formals, Expr *call) +{ + int i, type_ok; + int rest_arg = 0; + Expr *actuals = call->b; + + if (hash_get(L->options, "poly")) return; + + for (i = 1; actuals && formals; ++i) { + if (isexpand(actuals)) return; + rest_arg = formals->flags & DECL_REST_ARG; // is it "...id"? + if (formals->flags & DECL_NAME_EQUIV) { + type_ok = (formals->type == actuals->type); + } else { + type_ok = L_typeck_compat(formals->type, actuals->type); + } + unless (type_ok || rest_arg) { + L_errf(call, "parameter %d has incompatible type", i); + } + if (typeis(formals->type, "FMT")) { + typeck_fmt(actuals); + } + actuals = actuals->next; + formals = formals->next; + } + if (actuals && !rest_arg) { + L_errf(call, "too many arguments for function %s", + call->a->str); + } + if (formals) { + unless ((formals->flags & DECL_REST_ARG) || + (!formals->next && (formals->flags & DECL_OPTIONAL))) { + L_errf(call, "not enough arguments for function %s", + call->a->str); + } + } +} + +/* + * Type check a FMT arg, like + * printf(FMT format, ...args) + * by checking that the number of % format specifiers in "format" matches the + * number of actuals in ...args. We can do this only if "format" is a + * string constant and there are no (expand) operators in the args list. + */ +private void +typeck_fmt(Expr *actuals) +{ + int i, nargs = 0; + Expr *a; + Tcl_Obj *obj, **objv; + + unless (isconst(actuals) && isstring(actuals)) return; + + for (a = actuals->next; a; a = a->next) { + if (a->op == L_OP_EXPAND) return; + ++nargs; + } + + obj = Tcl_NewObj(); + objv = (Tcl_Obj **)ckalloc(nargs * sizeof(Tcl_Obj *)); + for (i = 0; i < nargs; ++i) { + objv[i] = Tcl_NewIntObj(1); + Tcl_IncrRefCount(objv[i]); + } + if (Tcl_AppendFormatToObj(L->interp, obj, actuals->str, + nargs, objv) == TCL_ERROR) { + Tcl_ResetResult(L->interp); + L_warnf(actuals, "bad format specifier"); + } + Tcl_DecrRefCount(obj); + for (i = 0; i < nargs; ++i) { + Tcl_DecrRefCount(objv[i]); + } + ckfree((char *)objv); +} + +/* + * Typecheck the declaration of main() against the allowable forms: + * + * void|int main() + * void|int main(void) + * void|int main(string av[]) + * void|int main(int ac, string av[]) + * void|int main(int ac, string av[], string env{string}) + */ +void +L_typeck_main(VarDecl *decl) +{ + int n; + Type *type = decl->type; + VarDecl *v; + + unless (isinttype(type->base_type) || isvoidtype(type->base_type)) { + L_errf(decl, "main must have int or void return type"); + } + + /* + * Avoid later unused-variable errors on the argc, argv, or + * env formals by marking them as used. + */ + for (n = 0, v = type->u.func.formals; v; v = v->next, ++n) { + v->flags |= DECL_ARGUSED; + } + + v = type->u.func.formals; + switch (n) { + case 0: + break; + case 1: + unless (isvoidtype(v->type) || + isarrayoftype(v->type, L_STRING)) { + L_errf(v, "invalid parameter types for main()"); + } + break; + case 2: + unless (isinttype(v->type) && + isarrayoftype(v->next->type, L_STRING)) { + L_errf(v, "invalid parameter types for main()"); + } + break; + case 3: + unless (isinttype(v->type) && + isarrayoftype(v->next->type, L_STRING) && + ishashoftype(v->next->next->type, L_STRING, L_STRING)) { + L_errf(v, "invalid parameter types for main()"); + } + break; + default: + L_errf(v, "too many formal parameters for main()"); + break; + } +} + +/* + * Check that a declaration uses legal types. This basically checks + * for voids and name-of anywhere in the type where they aren't allowed. + */ +int +L_typeck_declType(VarDecl *decl) +{ + return (typeck_declType(decl->type, decl, FALSE)); +} +private int +typeck_declType(Type *type, VarDecl *decl, int nameof_ok) +{ + int ret = 1; + char *s = NULL; + VarDecl *v; + + switch (type->kind) { + case L_VOID: + s = "void"; + ret = 0; + break; + case L_FUNCTION: + /* First check the return type. Void is legal here. */ + unless (isvoidtype(type->base_type)) { + ret = typeck_declType(type->base_type, decl, FALSE); + } + /* Now look at the formals. */ + v = type->u.func.formals; + for (v = type->u.func.formals; v; v = v->next) { + /* To type-check all formals, don't short-circuit. */ + ret = typeck_declType(v->type, v, TRUE) && ret; + } + break; + case L_NAMEOF: + if (nameof_ok) { + /* Pass FALSE since name-of of a name-of is illegal. */ + ret = typeck_declType(type->base_type, decl, FALSE); + } else { + s = "name-of"; + ret = 0; + } + break; + case L_ARRAY: + ret = typeck_declType(type->base_type, decl, FALSE); + break; + case L_HASH: + ret = typeck_declType(type->base_type, decl, FALSE) && + typeck_declType(type->u.hash.idx_type, decl, FALSE); + break; + case L_STRUCT: + for (v = type->u.struc.members; v; v = v->next) { + /* To type-check all members, don't short-circuit. */ + ret = typeck_declType(v->type, v, FALSE) && ret; + } + break; + default: + break; + } + if (s) { + if (decl->id) { + L_errf(decl->id, + "type %s illegal in declaration of '%s'", + s, decl->id->str); + } else { + L_errf(decl, "type %s illegal", s); + } + } + return (ret); +} + +/* + * Determine if two declaration lists have structurally equivalent + * type declarations. + */ +private int +typeck_decls(VarDecl *a, VarDecl *b) +{ + for (; a && b; a = a->next, b = b->next) { + unless (L_typeck_same(a->type, b->type) && + ((a->flags & (DECL_OPTIONAL | DECL_NAME_EQUIV)) == + (b->flags & (DECL_OPTIONAL | DECL_NAME_EQUIV)))) { + return (0); + } + } + /* Not the same if one has more declarations. */ + return !(a || b); +} + +/* + * Check that a variable type is compatible with the element type of + * an array type or a list type (which can be compatible with an array + * type). + */ +int +L_typeck_arrElt(Type *var, Type *array) +{ + switch (array->kind) { + case L_ARRAY: + // Var must be compat with array element type. + return (L_typeck_compat(var, array->base_type)); + case L_LIST: + // Var must be compat with all list elements. + for (; array; array = array->next) { + unless (L_typeck_compat(var, array->base_type)) { + return (0); + } + } + return (1); + default: + return (0); + } +} + +/* + * Determine if something is structurally compatible with a list type. + */ +private int +typeck_list(Type *a, Type *b) +{ + Type *l, *t; + VarDecl *m; + + ASSERT((a->kind == L_LIST) || (b->kind == L_LIST)); + + /* If only one of a,b is a list, put that in "l". */ + if (a->kind == L_LIST) { + l = a; + t = b; + } else { + l = b; + t = a; + } + + switch (t->kind) { + case L_ARRAY: + /* + * A list type is compatible with an array type iff all the + * list elements have the same type as the array base type. + */ + for (; l; l = l->next) { + ASSERT(l->kind == L_LIST); + unless (L_typeck_compat(t->base_type, l->base_type)) { + return (0); + } + } + return (1); + case L_STRUCT: + /* + * A list type is compatible with a struct type iff the list + * element types match up with the struct member types. + */ + m = t->u.struc.members; + while (m && l) { + ASSERT(l->kind == L_LIST); + unless (L_typeck_compat(l->base_type, m->type)) { + return (0); + } + m = m->next; + l = l->next; + } + return !(l || m); // not the same if one has more elements + case L_LIST: + /* + * Two list types are compatible iff element types + * match up, although one can have more. + */ + for (; t && l; t = t->next, l = l->next) { + unless (L_typeck_same(l->base_type, t->base_type)) { + return (0); + } + } + return (1); + default: + return (0); + } +} + +/* + * Determine if two types are structurally equivalent. Note that + * polys match anything and strings and widgets are compatible. + */ +int +L_typeck_same(Type *a, Type *b) +{ + unless (a && b) return (0); + + /* Polys match anything. */ + if ((a->kind == L_POLY) || (b->kind == L_POLY)) return (1); + + /* Strings and widgets are compatible. */ + if ((a->kind & (L_STRING|L_WIDGET)) && (b->kind & (L_STRING|L_WIDGET))){ + return (1); + } + + if ((a->kind == L_LIST) || (b->kind == L_LIST)) { + return (typeck_list(a, b)); + } + + unless (a->kind == b->kind) return (0); + + switch (a->kind) { + case L_INT: + case L_FLOAT: + case L_STRING: + case L_WIDGET: + case L_VOID: + return (1); + case L_ARRAY: + /* Element types must match (array sizes are ignored). */ + return (L_typeck_same(a->base_type, b->base_type)); + case L_HASH: + /* Element types must match and index types must match. */ + return (L_typeck_same(a->base_type, b->base_type) && + L_typeck_same(a->u.hash.idx_type, b->u.hash.idx_type)); + case L_STRUCT: + /* Struct members must match in type and number + * but member names can be different. */ + return (typeck_decls(a->u.struc.members, b->u.struc.members)); + case L_NAMEOF: + return (L_typeck_same(a->base_type, b->base_type)); + case L_FUNCTION: + /* Return types must match and all arg types must match. */ + return (L_typeck_same(a->base_type, b->base_type) && + typeck_decls(a->u.func.formals, b->u.func.formals)); + case L_CLASS: + /* Must be the same class. */ + return (a->u.class.clsdecl == b->u.class.clsdecl); + default: + L_bomb("bad type kind in L_typeck_same"); + return (0); + } +} diff --git a/generic/blowfish.c b/generic/blowfish.c new file mode 100644 index 0000000..c5ccecb --- /dev/null +++ b/generic/blowfish.c @@ -0,0 +1,446 @@ +#include "blowfish.h" + +static u32 bfp[] = +{ + 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, + 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, + 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, + 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, + 0x9216d5d9, 0x8979fb1b, +}; + +static u32 ks0[] = +{ + 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, + 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, + 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, + 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, + 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, + 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, + 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, + 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, + 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, + 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, + 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, + 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, + 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, + 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, + 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, + 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, + 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, + 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, + 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, + 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, + 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, + 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, + 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, + 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, + 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, + 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, + 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, + 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, + 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, + 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, + 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, + 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, + 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, + 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, + 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, + 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, + 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, + 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, + 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, + 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, + 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, + 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, + 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, + 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, + 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, + 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, + 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, + 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, + 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, + 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, + 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, + 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, + 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, + 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, + 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, + 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, + 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, + 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, + 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, + 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, + 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, + 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, + 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, + 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a + }; + + static u32 ks1[]= + { + 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, + 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, + 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, + 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, + 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, + 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, + 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, + 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, + 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, + 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, + 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, + 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, + 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, + 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, + 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, + 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, + 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, + 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, + 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, + 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, + 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, + 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, + 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, + 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, + 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, + 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, + 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, + 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, + 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, + 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, + 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, + 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, + 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, + 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, + 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, + 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, + 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, + 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, + 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, + 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, + 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, + 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, + 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, + 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, + 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, + 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, + 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, + 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, + 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, + 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, + 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, + 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, + 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, + 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, + 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, + 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, + 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, + 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, + 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, + 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, + 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, + 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, + 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, + 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 +}; + +static u32 ks2[] = +{ + 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, + 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, + 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, + 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, + 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, + 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, + 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, + 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, + 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, + 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, + 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, + 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, + 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, + 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, + 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, + 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, + 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, + 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, + 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, + 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, + 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, + 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, + 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, + 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, + 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, + 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, + 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, + 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, + 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, + 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, + 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, + 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, + 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, + 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, + 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, + 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, + 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, + 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, + 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, + 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, + 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, + 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, + 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, + 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, + 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, + 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, + 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, + 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, + 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, + 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, + 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, + 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, + 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, + 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, + 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, + 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, + 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, + 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, + 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, + 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, + 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, + 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, + 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, + 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 +}; + +static u32 ks3[] = +{ + 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, + 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, + 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, + 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, + 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, + 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, + 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, + 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, + 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, + 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, + 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, + 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, + 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, + 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, + 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, + 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, + 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, + 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, + 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, + 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, + 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, + 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, + 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, + 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, + 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, + 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, + 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, + 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, + 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, + 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, + 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, + 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, + 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, + 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, + 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, + 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, + 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, + 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, + 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, + 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, + 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, + 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, + 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, + 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, + 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, + 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, + 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, + 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, + 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, + 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, + 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, + 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, + 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, + 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, + 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, + 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, + 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, + 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, + 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, + 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, + 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, + 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, + 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, + 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 +}; + +#define N 16 + +static u32 +F(blf_ctx *bc, u32 x) +{ + u32 a, b, c, d, y; + + d = x & 0x00FF; + x >>= 8; + c = x & 0x00FF; + x >>= 8; + b = x & 0x00FF; + x >>= 8; + a = x & 0x00FF; + y = bc->S[0][a] + bc->S[1][b]; + y = y ^ bc->S[2][c]; + y = y + bc->S[3][d]; + + return y; +} + +static void +Blowfish_encipher(blf_ctx *bc, u32 *xl, u32 *xr) +{ + u32 Xl, Xr; + u32 temp; + short i; + + Xl = *xl; + Xr = *xr; + + for (i = 0; i < N; ++i) { + Xl = Xl ^ bc->P[i]; + Xr = F(bc, Xl) ^ Xr; + + temp = Xl; + Xl = Xr; + Xr = temp; + } + + temp = Xl; + Xl = Xr; + Xr = temp; + + Xr = Xr ^ bc->P[N]; + Xl = Xl ^ bc->P[N + 1]; + + *xl = Xl; + *xr = Xr; +} + +static void +Blowfish_decipher(blf_ctx *bc, u32 *xl, u32 *xr) +{ + u32 Xl, Xr; + u32 temp; + short i; + + Xl = *xl; + Xr = *xr; + + for (i = N + 1; i > 1; --i) { + Xl = Xl ^ bc->P[i]; + Xr = F(bc, Xl) ^ Xr; + + /* Exchange Xl and Xr */ + temp = Xl; + Xl = Xr; + Xr = temp; + } + + /* Exchange Xl and Xr */ + temp = Xl; + Xl = Xr; + Xr = temp; + + Xr = Xr ^ bc->P[1]; + Xl = Xl ^ bc->P[0]; + + *xl = Xl; + *xr = Xr; +} + +static short +InitializeBlowfish(blf_ctx *bc, u8 key[], int keybytes) +{ + short i, j, k; + u32 data, datal, datar; + + /* initialise p & s-boxes without file read */ + for (i = 0; i < N+2; i++) { + bc->P[i] = bfp[i]; + } + for (i = 0; i < 256; i++) { + bc->S[0][i] = ks0[i]; + bc->S[1][i] = ks1[i]; + bc->S[2][i] = ks2[i]; + bc->S[3][i] = ks3[i]; + } + + j = 0; + for (i = 0; i < N + 2; ++i) { + data = 0x00000000; + for (k = 0; k < 4; ++k) { + data = (data << 8) | key[j]; + j = j + 1; + if (j >= keybytes) j = 0; + } + bc->P[i] = bc->P[i] ^ data; + } + + datal = 0x00000000; + datar = 0x00000000; + + for (i = 0; i < N + 2; i += 2) { + Blowfish_encipher(bc, &datal, &datar); + + bc->P[i] = datal; + bc->P[i + 1] = datar; + } + + for (i = 0; i < 4; ++i) { + for (j = 0; j < 256; j += 2) { + Blowfish_encipher(bc, &datal, &datar); + + bc->S[i][j] = datal; + bc->S[i][j + 1] = datar; + } + } + return 0; +} + +void +blf_key (blf_ctx *c, u8 *k, int len) +{ + InitializeBlowfish(c, k, len); +} + +void +blf_enc(blf_ctx *c, u32 *data, int blocks) +{ + u32 *d; + int i; + + d = data; + for (i = 0; i < blocks; i++) { + Blowfish_encipher(c, d, d+1); + d += 2; + } +} + +void +blf_dec(blf_ctx *c, u32 *data, int blocks) +{ + u32 *d; + int i; + + d = data; + for (i = 0; i < blocks; i++) { + Blowfish_decipher(c, d, d+1); + d += 2; + } +} diff --git a/generic/blowfish.h b/generic/blowfish.h new file mode 100644 index 0000000..c6b4396 --- /dev/null +++ b/generic/blowfish.h @@ -0,0 +1,12 @@ +typedef unsigned int u32; +typedef unsigned char u8; + +typedef struct { + u32 S[4][256]; + u32 P[18]; +} blf_ctx; + +void blf_enc(blf_ctx *c, u32 *data, int blocks); +void blf_dec(blf_ctx *c, u32 *data, int blocks); +void blf_key(blf_ctx *c, unsigned char *key, int len); + diff --git a/generic/keydecode.c b/generic/keydecode.c new file mode 100644 index 0000000..0ca011e --- /dev/null +++ b/generic/keydecode.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +char * +keydecode(char *key) +{ + unsigned int len, half, i, j; + char *newkey; + + if (key == NULL) { +err: return (key); + } + len = strlen(key); + half = len / 2; + if ((len %2) != 0) goto err; /* len must be even */ + + newkey = malloc(len); + + /* unpack the old bytes */ + for (j = 1, i = 0; i < half; i++, j +=2) newkey[j] = key[i]; + + /* unpack the even bytes */ + for (j = 0, i = half; i < len; i++, j +=2) newkey[j] = key[i]; + + memcpy(key, newkey, len); + free(newkey); + return (key); +} diff --git a/generic/tcl.h b/generic/tcl.h index a08edde..7280b03 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -9,6 +9,7 @@ * Copyright (c) 1994-1998 Sun Microsystems, Inc. * Copyright (c) 1998-2000 by Scriptics Corporation. * Copyright (c) 2002 by Kevin B. Kenny. All rights reserved. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -611,6 +612,10 @@ typedef void (Tcl_ThreadCreateProc) (ClientData clientData); #define TCL_REG_NEWLINE 000300 /* Newlines are line terminators. */ #define TCL_REG_CANMATCH 001000 /* Report details on partial/limited * matches. */ +#define TCL_REG_BYTEOFFSET 002000 /* Use byte offsets instead of + character offsets. */ +#define TCL_REG_PCRE 0x08000000 /* Make sure it doesn't conflict with + * existing TCL_REG_* or PCRE_* bits */ /* * Flags values passed to Tcl_RegExpExecObj. @@ -807,7 +812,16 @@ typedef struct Tcl_ObjType { */ typedef struct Tcl_Obj { - int refCount; /* When 0 the object will be freed. */ +#ifndef TCL_MEM_DEBUG + unsigned int undef:1; /* Used by L to mark an object as having + * the undef value. Steal a bit from + * refCount to avoid increasing the + * Tcl_Obj memory footprint. */ + int refCount:31; /* When 0 the object will be freed. */ +#else + int refCount; + int undef; +#endif char *bytes; /* This points to the first byte of the * object's string representation. The array * must be followed by a null byte (i.e., at @@ -1997,6 +2011,9 @@ typedef struct Tcl_Token { * literal character prefix "{*}". This word is * marked to be expanded - that is, broken into * words after substitution is complete. + * TCL_TOKEN_PRAGMA - This token handles pragma directives that might + * switch the parser used. Currently only the L + * language is supported. */ #define TCL_TOKEN_WORD 1 @@ -2008,6 +2025,7 @@ typedef struct Tcl_Token { #define TCL_TOKEN_SUB_EXPR 64 #define TCL_TOKEN_OPERATOR 128 #define TCL_TOKEN_EXPAND_WORD 256 +#define TCL_TOKEN_PRAGMA 512 /* * Parsing error types. On any parsing error, one of these values will be diff --git a/generic/tclBasic.c b/generic/tclBasic.c index a09bf10..0cb278b 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -12,6 +12,7 @@ * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2006-2008 by Joe Mistachkin. All rights reserved. * Copyright (c) 2008 Miguel Sofer <msofer@users.sourceforge.net> + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -262,6 +263,23 @@ static const CmdInfo builtInCmds[] = { {"yieldto", NULL, TclCompileYieldToCmd, TclNRYieldToObjCmd, CMD_IS_SAFE}, /* + * L Commands + */ + + {"L", Tcl_LObjCmd, NULL, NULL, 1}, + {"shsplit", Tcl_ShSplitObjCmd, NULL, NULL, 1}, + {"fgetline", Tcl_FGetlineObjCmd, NULL, NULL, 1}, + {"angle_read_", Tcl_LAngleReadObjCmd, NULL, NULL, 1}, + {"Lread_", Tcl_LReadCmd, NULL, NULL, 1}, + {"Lwrite_", Tcl_LWriteCmd, NULL, NULL, 1}, + {"Lrefcnt", Tcl_LRefCnt, NULL, NULL, 1}, + {"defined", Tcl_LDefined, NULL, NULL, 1}, + {"Lhtml", Tcl_LHtmlObjCmd, NULL, NULL, 1}, + {"LgetNextLine_", Tcl_LGetNextLine, NULL, NULL, 1}, + {"LgetNextLineInit_", Tcl_LGetNextLineInit, NULL, NULL, 1}, + {"getdirx", Tcl_LGetDirX, NULL, NULL, 1}, + + /* * Commands in the OS-interface. Note that many of these are unsafe. */ @@ -277,6 +295,8 @@ static const CmdInfo builtInCmds[] = { {"fcopy", Tcl_FcopyObjCmd, NULL, NULL, CMD_IS_SAFE}, {"fileevent", Tcl_FileEventObjCmd, NULL, NULL, CMD_IS_SAFE}, {"flush", Tcl_FlushObjCmd, NULL, NULL, CMD_IS_SAFE}, + {"getopt", Tcl_GetOptObjCmd, NULL, NULL, 0}, + {"getoptReset", Tcl_GetOptResetObjCmd, NULL, NULL, 0}, {"gets", Tcl_GetsObjCmd, NULL, NULL, CMD_IS_SAFE}, {"glob", Tcl_GlobObjCmd, NULL, NULL, 0}, {"load", Tcl_LoadObjCmd, NULL, NULL, 0}, @@ -597,6 +617,13 @@ Tcl_CreateInterp(void) iPtr->evalFlags = 0; iPtr->scriptFile = NULL; iPtr->flags = 0; +#ifdef HAVE_PCRE +#ifdef USE_DEFAULT_PCRE + if (getenv("TCL_REGEXP_CLASSIC") == NULL) { iPtr->flags |= INTERP_PCRE; } +#else + if (getenv("TCL_REGEXP_PCRE") != NULL) { iPtr->flags |= INTERP_PCRE; } +#endif +#endif iPtr->tracePtr = NULL; iPtr->tracesForbiddingInline = 0; iPtr->activeCmdTracePtr = NULL; @@ -5181,6 +5208,23 @@ TclEvalEx( TclContinuationsEnterDerived(objv[objectsUsed], wordStart - outerScript, wordCLNext); } + + /* + * If this is the L command and we just processed the first + * command word (i.e., the "L"), inject an argument --line=%d + * before the next command word. This communicates the source + * line # to the L compiler. + */ + if (!objectsUsed && + (!strncmp("L", tokenPtr->start, tokenPtr->size) || + !strncmp("Lhtml", tokenPtr->start, tokenPtr->size))) { + ++numWords; + ++objectsUsed; + ++objectsNeeded; + objv[objectsUsed] = Tcl_ObjPrintf("--line=%d", lines[0]+1); + Tcl_IncrRefCount(objv[objectsUsed]); + expand[objectsUsed] = 0; + } } /* for loop */ iPtr->cmdFramePtr = eeFramePtr; if (code != TCL_OK) { diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index d723e4b..d08ac02 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -12,6 +12,7 @@ * Copyright (c) 1998-1999 by Scriptics Corporation. * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. * Copyright (c) 2005 Donal K. Fellows. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 13f9e7d..c30bce2 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -130,24 +130,34 @@ Tcl_RegexpObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int i, indices, match, about, offset, all, doinline, numMatchesSaved; - int cflags, eflags, stringLength, matchLength; + int i, indices, about, offset, all, doinline; + int cflags, iflags, re_type; + Tcl_Obj *startIndex = NULL; Tcl_RegExp regExpr; - Tcl_Obj *objPtr, *startIndex = NULL, *resultPtr = NULL; - Tcl_RegExpInfo info; static const char *const options[] = { "-all", "-about", "-indices", "-inline", "-expanded", "-line", "-linestop", "-lineanchor", - "-nocase", "-start", "--", NULL + "-nocase", "-start", "-type", "--", NULL }; enum options { REGEXP_ALL, REGEXP_ABOUT, REGEXP_INDICES, REGEXP_INLINE, REGEXP_EXPANDED,REGEXP_LINE, REGEXP_LINESTOP,REGEXP_LINEANCHOR, - REGEXP_NOCASE, REGEXP_START, REGEXP_LAST + REGEXP_NOCASE,REGEXP_START, REGEXP_TYPE, REGEXP_LAST + }; + static CONST char *re_type_opts[] = { + "classic", "pcre", NULL + }; + enum re_type_opts { + RETYPE_CLASSIC, RETYPE_PCRE, }; indices = 0; about = 0; +#ifdef USE_DEFAULT_PCRE + re_type = RETYPE_PCRE; +#else + re_type = RETYPE_CLASSIC; +#endif cflags = TCL_REG_ADVANCED; offset = 0; all = 0; @@ -208,6 +218,15 @@ Tcl_RegexpObjCmd( Tcl_IncrRefCount(startIndex); break; } + case REGEXP_TYPE: + if (++i >= objc) { + goto endOfForLoop; + } + if (Tcl_GetIndexFromObj(interp, objv[i], re_type_opts, "type", + 0, &re_type) != TCL_OK) { + goto optionError; + } + break; case REGEXP_LAST: i++; goto endOfForLoop; @@ -233,22 +252,16 @@ Tcl_RegexpObjCmd( "regexp match variables not allowed when using -inline", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "REGEXP", "MIX_VAR_INLINE", NULL); - goto optionError; + optionError: + if (startIndex) { + Tcl_DecrRefCount(startIndex); + } + return TCL_ERROR; } - /* - * Handle the odd about case separately. - */ - - if (about) { - regExpr = Tcl_GetRegExpFromObj(interp, objv[0], cflags); - if ((regExpr == NULL) || (TclRegAbout(interp, regExpr) < 0)) { - optionError: - if (startIndex) { - Tcl_DecrRefCount(startIndex); - } - return TCL_ERROR; - } + /* L undef never matches anything. */ + if (objv[1]->undef) { + Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); return TCL_OK; } @@ -258,10 +271,19 @@ Tcl_RegexpObjCmd( * regexp to avoid shimmering problems. */ - objPtr = objv[1]; - stringLength = Tcl_GetCharLength(objPtr); - if (startIndex) { + int stringLength; + + if ((enum re_type_opts) re_type == RETYPE_CLASSIC) { + stringLength = Tcl_GetCharLength(objv[1]); + } else { + if (objv[1]->typePtr == &tclByteArrayType) { + (void) Tcl_GetByteArrayFromObj(objv[1], &stringLength); + } else { + /* XXX validate offset by char length */ + (void) Tcl_GetStringFromObj(objv[1], &stringLength); + } + } TclGetIntForIndexM(NULL, startIndex, stringLength, &offset); Tcl_DecrRefCount(startIndex); if (offset < 0) { @@ -269,201 +291,43 @@ Tcl_RegexpObjCmd( } } + /* + * Handle the odd about case separately, otherwise pass of to appropriate + * RE engine. + */ + + iflags = ((Interp *)interp)->flags; + if ((enum re_type_opts) re_type == RETYPE_PCRE) { + cflags |= TCL_REG_PCRE; + } else if (iflags & INTERP_PCRE) { + /* Prevent -type classic from being overridden compiling RE */ + ((Interp *)interp)->flags &= ~(INTERP_PCRE); + } regExpr = Tcl_GetRegExpFromObj(interp, objv[0], cflags); + ((Interp *)interp)->flags = iflags; if (regExpr == NULL) { return TCL_ERROR; } - objc -= 2; - objv += 2; - - if (doinline) { - /* - * Save all the subexpressions, as we will return them as a list - */ - - numMatchesSaved = -1; - } else { - /* - * Save only enough subexpressions for matches we want to keep, expect - * in the case of -all, where we need to keep at least one to know - * where to move the offset. - */ - - numMatchesSaved = (objc == 0) ? all : objc; - } - - /* - * The following loop is to handle multiple matches within the same source - * string; each iteration handles one match. If "-all" hasn't been - * specified then the loop body only gets executed once. We terminate the - * loop when the starting offset is past the end of the string. - */ - - while (1) { - /* - * Pass either 0 or TCL_REG_NOTBOL in the eflags. Passing - * TCL_REG_NOTBOL indicates that the character at offset should not be - * considered the start of the line. If for example the pattern {^} is - * passed and -start is positive, then the pattern will not match the - * start of the string unless the previous character is a newline. - */ - - if (offset == 0) { - eflags = 0; - } else if (offset > stringLength) { - eflags = TCL_REG_NOTBOL; - } else if (Tcl_GetUniChar(objPtr, offset-1) == (Tcl_UniChar)'\n') { - eflags = 0; - } else { - eflags = TCL_REG_NOTBOL; - } - - match = Tcl_RegExpExecObj(interp, regExpr, objPtr, offset, - numMatchesSaved, eflags); - if (match < 0) { - return TCL_ERROR; - } - - if (match == 0) { - /* - * We want to set the value of the intepreter result only when - * this is the first time through the loop. - */ - - if (all <= 1) { - /* - * If inlining, the interpreter's object result remains an - * empty list, otherwise set it to an integer object w/ value - * 0. - */ - - if (!doinline) { - Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); - } - return TCL_OK; - } - break; - } - - /* - * If additional variable names have been specified, return index - * information in those variables. - */ - - Tcl_RegExpGetInfo(regExpr, &info); - if (doinline) { - /* - * It's the number of substitutions, plus one for the matchVar at - * index 0 - */ - - objc = info.nsubs + 1; - if (all <= 1) { - resultPtr = Tcl_NewObj(); - } - } - for (i = 0; i < objc; i++) { - Tcl_Obj *newPtr; - - if (indices) { - int start, end; - Tcl_Obj *objs[2]; - - /* - * Only adjust the match area if there was a match for that - * area. (Scriptics Bug 4391/SF Bug #219232) - */ - - if (i <= info.nsubs && info.matches[i].start >= 0) { - start = offset + info.matches[i].start; - end = offset + info.matches[i].end; - - /* - * Adjust index so it refers to the last character in the - * match instead of the first character after the match. - */ - - if (end >= offset) { - end--; - } - } else { - start = -1; - end = -1; - } - - objs[0] = Tcl_NewLongObj(start); - objs[1] = Tcl_NewLongObj(end); - - newPtr = Tcl_NewListObj(2, objs); - } else { - if (i <= info.nsubs) { - newPtr = Tcl_GetRange(objPtr, - offset + info.matches[i].start, - offset + info.matches[i].end - 1); - } else { - newPtr = Tcl_NewObj(); - } - } - if (doinline) { - if (Tcl_ListObjAppendElement(interp, resultPtr, newPtr) - != TCL_OK) { - Tcl_DecrRefCount(newPtr); - Tcl_DecrRefCount(resultPtr); - return TCL_ERROR; - } - } else { - if (Tcl_ObjSetVar2(interp, objv[i], NULL, newPtr, - TCL_LEAVE_ERR_MSG) == NULL) { - return TCL_ERROR; - } + if ((enum re_type_opts) re_type == RETYPE_CLASSIC) { + if (about) { + if (TclRegAbout(interp, regExpr) < 0) { + return TCL_ERROR; } + return TCL_OK; } - if (all == 0) { - break; - } - - /* - * Adjust the offset to the character just after the last one in the - * matchVar and increment all to count how many times we are making a - * match. We always increment the offset by at least one to prevent - * endless looping (as in the case: regexp -all {a*} a). Otherwise, - * when we match the NULL string at the end of the input string, we - * will loop indefinately (because the length of the match is 0, so - * offset never changes). - */ - - matchLength = (info.matches[0].end - info.matches[0].start); - - offset += info.matches[0].end; - - /* - * A match of length zero could happen for {^} {$} or {.*} and in - * these cases we always want to bump the index up one. - */ - - if (matchLength == 0) { - offset++; - } - all++; - if (offset >= stringLength) { - break; + return TclRegexpClassic(interp, objc, objv, regExpr, + all, indices, doinline, offset); + } else { + if (about) { + /* XXX: implement PCRE about */ + return TCL_OK; } - } - - /* - * Set the interpreter's object result to an integer object with value 1 - * if -all wasn't specified, otherwise it's all-1 (the number of times - * through the while - 1). - */ - if (doinline) { - Tcl_SetObjResult(interp, resultPtr); - } else { - Tcl_SetObjResult(interp, Tcl_NewIntObj(all ? all-1 : 1)); + return TclRegexpPCRE(interp, objc, objv, regExpr, + all, indices, doinline, offset); } - return TCL_OK; } /* @@ -490,27 +354,41 @@ Tcl_RegsubObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int idx, result, cflags, all, wlen, wsublen, numMatches, offset; - int start, end, subStart, subEnd, match; + int idx, result, cflags, iflags, all, wlen, wsublen, numMatches, offset; + int start, end, subStart, subEnd, match, re_type, prevOffset; + int subMatchVarsElemc = 0; Tcl_RegExp regExpr; Tcl_RegExpInfo info; Tcl_Obj *resultPtr, *subPtr, *objPtr, *startIndex = NULL; + Tcl_Obj **subMatchVarsElemv = NULL; Tcl_UniChar ch, *wsrc, *wfirstChar, *wstring, *wsubspec, *wend; static const char *const options[] = { "-all", "-nocase", "-expanded", "-line", "-linestop", "-lineanchor", "-start", - "--", NULL + "-submatches", "-type", "--", NULL }; enum options { REGSUB_ALL, REGSUB_NOCASE, REGSUB_EXPANDED, REGSUB_LINE, REGSUB_LINESTOP, REGSUB_LINEANCHOR, REGSUB_START, - REGSUB_LAST + REGSUB_SUBMATCHES, REGSUB_TYPE, REGSUB_LAST + }; + static CONST char *re_type_opts[] = { + "classic", "pcre", NULL + }; + enum re_type_opts { + RETYPE_CLASSIC, RETYPE_PCRE, }; +#ifdef USE_DEFAULT_PCRE + re_type = RETYPE_PCRE; +#else + re_type = RETYPE_CLASSIC; +#endif cflags = TCL_REG_ADVANCED; all = 0; offset = 0; + prevOffset = 0; resultPtr = NULL; for (idx = 1; idx < objc; idx++) { @@ -559,9 +437,27 @@ Tcl_RegsubObjCmd( Tcl_IncrRefCount(startIndex); break; } + case REGSUB_TYPE: + if (++idx >= objc) { + goto endOfForLoop; + } + if (Tcl_GetIndexFromObj(interp, objv[idx], re_type_opts, "type", + 0, &re_type) != TCL_OK) { + goto optionError; + } + break; case REGSUB_LAST: idx++; goto endOfForLoop; + case REGSUB_SUBMATCHES: + if (++idx >= objc) { + goto endOfForLoop; + } + if (TclListObjGetElements(interp, objv[idx], &subMatchVarsElemc, + &subMatchVarsElemv) != TCL_OK) { + goto optionError; + } + break; } } @@ -580,8 +476,18 @@ Tcl_RegsubObjCmd( objv += idx; if (startIndex) { - int stringLength = Tcl_GetCharLength(objv[1]); + int stringLength; + if ((enum re_type_opts) re_type == RETYPE_CLASSIC) { + stringLength = Tcl_GetCharLength(objv[1]); + } else { + if (objv[1]->typePtr == &tclByteArrayType) { + (void) Tcl_GetByteArrayFromObj(objv[1], &stringLength); + } else { + /* XXX validate offset by char length */ + (void) Tcl_GetStringFromObj(objv[1], &stringLength); + } + } TclGetIntForIndexM(NULL, startIndex, stringLength, &offset); Tcl_DecrRefCount(startIndex); if (offset < 0) { @@ -660,7 +566,15 @@ Tcl_RegsubObjCmd( goto regsubDone; } + iflags = ((Interp *)interp)->flags; + if ((enum re_type_opts) re_type == RETYPE_PCRE) { + cflags |= TCL_REG_PCRE; + } else if (iflags & INTERP_PCRE) { + /* Prevent -type classic from being overridden compiling RE */ + ((Interp *)interp)->flags &= ~(INTERP_PCRE); + } regExpr = Tcl_GetRegExpFromObj(interp, objv[0], cflags); + ((Interp *)interp)->flags = iflags; if (regExpr == NULL) { return TCL_ERROR; } @@ -716,6 +630,7 @@ Tcl_RegsubObjCmd( if (match == 0) { break; } + prevOffset = offset; if (numMatches == 0) { resultPtr = Tcl_NewUnicodeObj(wstring, 0); Tcl_IncrRefCount(resultPtr); @@ -764,6 +679,22 @@ Tcl_RegsubObjCmd( wfirstChar = wsrc + 2; wsrc++; continue; + } else if (re_type == RETYPE_PCRE) { + switch (ch) { + case 'a': *wsrc = '\a'; break; + case 'e': *wsrc = '\e'; break; + case 'f': *wsrc = '\f'; break; + case 'n': *wsrc = '\n'; break; + case 'r': *wsrc = '\r'; break; + case 't': *wsrc = '\t'; break; + default: *wsrc = ch; break; + } + Tcl_AppendUnicodeToObj(resultPtr, wfirstChar, + wsrc - wfirstChar + 1); + *wsrc = '\\'; + wfirstChar = wsrc + 2; + wsrc++; + continue; } else { continue; } @@ -825,6 +756,25 @@ Tcl_RegsubObjCmd( } /* + * Return the regexp submatches in the requested variables. + */ + if (numMatches && subMatchVarsElemc) { + for (idx = 0; (idx <= info.nsubs) && (idx < subMatchVarsElemc); ++idx) { + subStart = info.matches[idx].start; + subEnd = info.matches[idx].end; + Tcl_Obj *obj = Tcl_NewUnicodeObj(wstring + prevOffset + subStart, + subEnd - subStart); + Tcl_IncrRefCount(obj); + if (Tcl_ObjSetVar2(interp, subMatchVarsElemv[idx], NULL, obj, + TCL_LEAVE_ERR_MSG) == NULL) { + Tcl_DecrRefCount(obj); + return (TCL_ERROR); + } + Tcl_DecrRefCount(obj); + } + } + + /* * Copy the portion of the source string after the last match to the * result variable. */ diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index 18da741..436be2a 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -8,6 +8,7 @@ * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. * Copyright (c) 2002 ActiveState Corporation. * Copyright (c) 2004-2013 by Donal K. Fellows. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. diff --git a/generic/tclCompile.c b/generic/tclCompile.c index f62ec14..2d959c0 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -7,6 +7,7 @@ * * Copyright (c) 1996-1998 Sun Microsystems, Inc. * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -662,6 +663,51 @@ InstructionDesc const tclInstructionTable[] = { {"lappendListStk", 1, -1, 0, {OPERAND_NONE}}, /* Lappend list to general variable. * Stack: ... varName list => ... listVarContents */ + {"rot", 2, 0, 1, {OPERAND_UINT1}}, + /* Rotate the top opnd elements in the stack */ + {"l-index", 5, -1, 1, {OPERAND_UINT4}}, + /* Index into a nested struct/array/hash. opnd contains flags, + * index is stktop, object to index into is stknext. */ + {"l-deep-write", 9, -1, 2, {OPERAND_UINT4, OPERAND_UINT4}}, + /* Write via L deep pointer pushed by l-index above. opnd1 is a local + * var index of a var that points to the top-level object being + * indexed; it will be written if the top-level object needed to be + * copied by l-index for copy-on-write. opnd2 contains flags + * indicating whether to leave old or new value on stack top. + * stktop is the L deep pointer, stknext is the value to write. */ + {"lsplit", 2, 0, 1, {OPERAND_UINT4}}, + /* Perl-like string split. opnd is a flags word (see Expr_f), + * stack contains the limit (optional), then the delimeter + * (optional) then the string to split. */ + {"l-defined", 1, 0, 0, {OPERAND_NONE}}, + /* Test whether value at stackTop is the L undefined value. */ + {"l-push-list-size", 1, 0, 0, {OPERAND_NONE}}, + /* Store the size of the list at stktop in the internal L + * sizes stack. Sizes are used to implement the L END keyword. */ + {"l-push-string-size", 1, 0, 0, {OPERAND_NONE}}, + /* Store the length of the string at stktop in the internal L + * sizes stack. */ + {"l-read-size", 1, 1, 0, {OPERAND_NONE}}, + /* Push what's on the top of the internal L sizes stack. */ + {"l-pop-size", 1, 0, 0, {OPERAND_NONE}}, + /* Pop the internal L sizes stack. */ + {"l-push-undef", 1, 1, 0, {OPERAND_NONE}}, + /* Push the L undef object. */ + {"expandRot", 2, 0, 1, {OPERAND_UINT1}}, + /* Rotate the top opnd1 stack elements with those after + * the expand marker (see expandStart). */ + {"l-lindex-stk", 2, 1, 1, {OPERAND_UINT1}}, + /* push(listindex stktop opnd) except if opnd is <0 or + * > # list elements then push the L undef object. */ + {"l-list-insert", 9, 0, 3, {OPERAND_LVT4, OPERAND_UINT4}}, + /* Insert into list local var. Operands are local slot index, + * flags, and list index to insert before (0 means prepend, + * -1 means append). */ + {"unsetLocal", 5, 0, 1, {OPERAND_LVT4}}, + /* Unset the local variable at index op1. */ + {"different-obj", 5, 0, 1, {OPERAND_LVT4}}, + /* Determine whether the variable whose name is at stktop + * points to a different object as the given local. */ {NULL, 0, 0, 0, {OPERAND_NONE}} }; @@ -1809,13 +1855,29 @@ TclCompileInvocation( int numWords, CompileEnv *envPtr) { - int wordIdx = 0, depth = TclGetStackDepth(envPtr); + int adjust = 0, wordIdx = 0, depth = TclGetStackDepth(envPtr); + char *cmd, *s; + Tcl_Obj *obj; DefineLineInformation; if (cmdObj) { CompileCmdLiteral(interp, cmdObj, envPtr); wordIdx = 1; tokenPtr = TokenAfter(tokenPtr); + cmd = Tcl_GetString(cmdObj); + if (!strcmp("L", cmd) || !strcmp("Lhtml", cmd)) { + /* + * If this is the L or Lhtml command, push the argument --line=%d + * to it now. This communicates the source line # to the L + * compiler. + */ + obj = Tcl_ObjPrintf("--line=%d", envPtr->line+1); + Tcl_IncrRefCount(obj); + s = TclGetString(obj); + adjust = TclRegisterNewLiteral(envPtr, s, strlen(s)); + Tcl_DecrRefCount(obj); + TclEmitPush(adjust, envPtr); + } } for (; wordIdx < numWords; wordIdx++, tokenPtr = TokenAfter(tokenPtr)) { @@ -1837,6 +1899,14 @@ TclCompileInvocation( TclEmitPush(objIdx, envPtr); } + /* + * Possible adjust for L-command argument injection (see comment + * above). + */ + if (adjust) { + ++wordIdx; + } + if (wordIdx <= 255) { TclEmitInvoke(envPtr, INST_INVOKE_STK1, wordIdx); } else { @@ -1853,7 +1923,8 @@ CompileExpanded( int numWords, CompileEnv *envPtr) { - int wordIdx = 0; + int adjust = 0, wordIdx = 0; + char *cmd; DefineLineInformation; int depth = TclGetStackDepth(envPtr); @@ -1862,6 +1933,23 @@ CompileExpanded( CompileCmdLiteral(interp, cmdObj, envPtr); wordIdx = 1; tokenPtr = TokenAfter(tokenPtr); + cmd = Tcl_GetString(cmdObj); + if (!strcmp("L", cmd) || !strcmp("Lhtml", cmd)) { + /* + * If this is the L or Lhtml command, push the argument --line=%d + * to it now. This communicates the source line # to the L + * compiler. + */ + char *s; + Tcl_Obj *obj; + + obj = Tcl_ObjPrintf("--line=%d", envPtr->line+1); + Tcl_IncrRefCount(obj); + s = TclGetString(obj); + adjust = TclRegisterNewLiteral(envPtr, s, strlen(s)); + Tcl_DecrRefCount(obj); + TclEmitPush(adjust, envPtr); + } } for (; wordIdx < numWords; wordIdx++, tokenPtr = TokenAfter(tokenPtr)) { @@ -1888,6 +1976,14 @@ CompileExpanded( } /* + * Possible adjust for L-command argument injection (see comment + * above). + */ + if (adjust) { + ++wordIdx; + } + + /* * The stack depth during argument expansion can only be managed at * runtime, as the number of elements in the expanded lists is not known * at compile time. We adjust here the stack depth estimate so that it is diff --git a/generic/tclCompile.h b/generic/tclCompile.h index b89346d..ce20f4a 100644 --- a/generic/tclCompile.h +++ b/generic/tclCompile.h @@ -5,6 +5,7 @@ * Copyright (c) 1998-2000 by Scriptics Corporation. * Copyright (c) 2001 by Kevin B. Kenny. All rights reserved. * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -821,8 +822,25 @@ typedef struct ByteCode { #define INST_LAPPEND_LIST_ARRAY_STK 187 #define INST_LAPPEND_LIST_STK 188 +/* L stuff */ +#define INST_ROT 189 +#define INST_L_INDEX 190 +#define INST_L_DEEP_WRITE 191 +#define INST_L_SPLIT 192 +#define INST_L_DEFINED 193 +#define INST_L_PUSH_LIST_SIZE 194 +#define INST_L_PUSH_STR_SIZE 195 +#define INST_L_READ_SIZE 196 +#define INST_L_POP_SIZE 197 +#define INST_L_PUSH_UNDEF 198 +#define INST_EXPAND_ROT 199 +#define INST_L_LINDEX_STK 200 +#define INST_L_LIST_INSERT 201 +#define INST_UNSET_LOCAL 202 +#define INST_DIFFERENT_OBJ 203 + /* The last opcode */ -#define LAST_INST_OPCODE 188 +#define LAST_INST_OPCODE 203 /* * Table describing the Tcl bytecode instructions: their name (for displaying diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index 86f0e1d..027b2c4 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -794,7 +794,6 @@ PrintSourceToObj( { register const char *p; register int i = 0, len; - Tcl_UniChar ch = 0; if (stringPtr == NULL) { Tcl_AppendToObj(appendObj, "\"\"", -1); @@ -803,65 +802,38 @@ PrintSourceToObj( Tcl_AppendToObj(appendObj, "\"", -1); p = stringPtr; - for (; (*p != '\0') && (i < maxChars); p+=len) { + for (; (*p != '\0') && (i < maxChars); ++i, p+=len) { + Tcl_UniChar ch; len = TclUtfToUniChar(p, &ch); switch (ch) { case '"': Tcl_AppendToObj(appendObj, "\\\"", -1); - i += 2; continue; case '\f': Tcl_AppendToObj(appendObj, "\\f", -1); - i += 2; continue; case '\n': Tcl_AppendToObj(appendObj, "\\n", -1); - i += 2; continue; case '\r': Tcl_AppendToObj(appendObj, "\\r", -1); - i += 2; continue; case '\t': Tcl_AppendToObj(appendObj, "\\t", -1); - i += 2; continue; case '\v': Tcl_AppendToObj(appendObj, "\\v", -1); - i += 2; continue; default: -#if TCL_UTF_MAX > 4 - if (ch > 0xffff) { - Tcl_AppendPrintfToObj(appendObj, "\\U%08x", ch); - i += 10; - } else -#elif TCL_UTF_MAX > 3 - /* If len == 0, this means we have a char > 0xffff, resulting in - * TclUtfToUniChar producing a surrogate pair. We want to output - * this pair as a single Unicode character. - */ - if (len == 0) { - int upper = ((ch & 0x3ff) + 1) << 10; - len = TclUtfToUniChar(p, &ch); - Tcl_AppendPrintfToObj(appendObj, "\\U%08x", upper + (ch & 0x3ff)); - i += 10; - } else -#endif if (ch < 0x20 || ch >= 0x7f) { Tcl_AppendPrintfToObj(appendObj, "\\u%04x", ch); - i += 6; } else { Tcl_AppendPrintfToObj(appendObj, "%c", ch); - i++; } continue; } } - if (*p != '\0') { - Tcl_AppendToObj(appendObj, "...", -1); - } Tcl_AppendToObj(appendObj, "\"", -1); } @@ -1395,13 +1367,6 @@ Tcl_DisassembleObjCmd( * Do the actual disassembly. */ - if (BYTECODE(codeObjPtr)->flags & TCL_BYTECODE_PRECOMPILED) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "may not disassemble prebuilt bytecode", -1)); - Tcl_SetErrorCode(interp, "TCL", "OPERATION", "DISASSEMBLE", - "BYTECODE", NULL); - return TCL_ERROR; - } if (PTR2INT(clientData)) { Tcl_SetObjResult(interp, DisassembleByteCodeAsDicts(codeObjPtr)); } else { diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 7f65262..1510453 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -10,6 +10,7 @@ * Copyright (c) 2005-2007 by Donal K. Fellows. * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2006-2008 by Joe Mistachkin. All rights reserved. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -18,7 +19,9 @@ #include "tclInt.h" #include "tclCompile.h" #include "tclOOInt.h" +#include "tclRegexp.h" #include "tommath.h" +#include "Lcompile.h" #include <math.h> #if NRE_ENABLE_ASSERTS @@ -76,7 +79,7 @@ int tclTraceExec = 0; * expression opcodes (e.g., INST_LOR) in tclCompile.h. * * Does not include the string for INST_EXPON (and beyond), as that is - * disjoint for backward-compatability reasons. + * disjoint for backward-compatibility reasons. */ static const char *const operatorStrings[] = { @@ -840,6 +843,290 @@ ReleaseDictIterator( objPtr->typePtr = NULL; } + +/* + * The L "sizes stack" is a separate run-time stack managed by the + * INST_L_PUSH_LIST_SIZE, INST_L_PUSH_STR_SIZE, INST_L_READ_SIZE, and + * INST_L_POP_SIZE opcodes. The first two push onto this stack the length + * (size) of the list (string) at stktop. INST_L_READ_SIZE pushes onto the + * regular stack the size at the top of L sizes stack, and INST_L_POP_SIZE + * pops the L stack. These are used to implement the L END keyword with + * minimal overhead. + */ +static int *L_sizes_stack = NULL; +static int L_sizes_stack_top = -1; +static int L_sizes_stack_size = 0; + +/* + *---------------------------------------------------------------------- + * + * L_sizes_push -- + * + * Push a size onto the internal L sizes stack. + * + *---------------------------------------------------------------------- + */ + +static inline void +L_sizes_push(int size) +{ + if ((L_sizes_stack_top+1) >= L_sizes_stack_size) { + if (L_sizes_stack_size == 0) { + L_sizes_stack_size = 32; + } else { + L_sizes_stack_size *= 2; + } + L_sizes_stack = (int *)ckrealloc((void *)L_sizes_stack, + L_sizes_stack_size * sizeof(int)); + } + L_sizes_stack[++L_sizes_stack_top] = size; +} + +/* + *---------------------------------------------------------------------- + * + * L_sizes_top -- + * + * Return the stack top of the L internal sizes stack. The + * stack must not be empty when called. + * + *---------------------------------------------------------------------- + */ + +static inline int +L_sizes_top() +{ + if (L_sizes_stack_top < 0) Tcl_Panic("topped empty L sizes stack"); + return (L_sizes_stack[L_sizes_stack_top]); +} + +/* + *---------------------------------------------------------------------- + * + * L_sizes_pop -- + * + * Pop the L internal sizes stack. The stack must not be empty when + * called. + * + *---------------------------------------------------------------------- + */ + +static inline void +L_sizes_pop() +{ + if (L_sizes_stack_top < 0) Tcl_Panic("popped empty L sizes stack"); + --L_sizes_stack_top; +} + +/* + * Special object types for the L language to store object pointers. These are + * created only by L bytecodes (INST_L_INDEX) and are left on the run-time + * stack only transiently to be consumed by other L bytecodes + * (INST_L_DEEP_WRITE). L_deepPtr1Type is used when indexing an array or + * hash. L_deepPtr2Type is used when indexing a string or doing a delete. + */ + +static Tcl_ObjType L_deepPtr1Type = { + "l-deepType1", + NULL, /* freeIntRepProc */ + NULL, /* dupIntRepProc */ + NULL, /* updateStringProc */ + NULL /* setFromAnyProc */ +}; +static Tcl_ObjType L_deepPtr2Type = { + "l-deepType2", + NULL, /* freeIntRepProc */ + NULL, /* dupIntRepProc */ + NULL, /* updateStringProc */ + NULL /* setFromAnyProc */ +}; + +/* + * For a L_deepPtr1Type, the internal rep fits into the Tcl_Obj internalRep + * field (two pointers). For a L_deepPtr2Type, we allocate a struct and point + * to it from the Tcl_Obj internalRep. The struct below is overlayed onto one + * of these two pieces of memory. + */ +typedef struct { + Tcl_Obj *topLevObj; // outer-most enclosing object + Tcl_Obj **elemPtrPtr; // ptr to the object being pointed to + // The following exist only in a L_deepPtr2Type. + Tcl_Obj *parentObj; // enclosing object + Tcl_Obj *idxObj; // index of array/hash/string + int flags; +} L_DeepPtr; + +static inline int +L_isDeepPtr(Tcl_Obj *objPtr) +{ + return ((objPtr->typePtr == &L_deepPtr1Type) || + (objPtr->typePtr == &L_deepPtr2Type)); +} + +static inline L_DeepPtr * +L_deepPtrGet(Tcl_Obj *objPtr) +{ + ASSERT(L_isDeepPtr(objPtr)); + if (objPtr->typePtr == &L_deepPtr1Type) { + return (L_DeepPtr *)&objPtr->internalRep.otherValuePtr; + } else { + return (L_DeepPtr *)objPtr->internalRep.otherValuePtr; + } +} + +/* + * Allocate an L deep-pointer object. flags tells us whether a small or large + * one is needed: a large one for an L_DELETE operation or a string index, and + * a small one for everything else. + */ +static inline Tcl_Obj * +L_deepPtrNew(int flags, Tcl_Obj *objPtr, Tcl_Obj *idxObj, Tcl_Obj **elemPtrPtr) +{ + Tcl_Obj *deepPtrObj = Tcl_NewObj(); + L_DeepPtr *deepPtr; + + if (flags & (L_DELETE | L_IDX_STRING)) { + deepPtr = (L_DeepPtr *)ckalloc(sizeof(L_DeepPtr)); + + deepPtr->parentObj = objPtr; + Tcl_IncrRefCount(objPtr); + + deepPtr->idxObj = idxObj; + Tcl_IncrRefCount(idxObj); + + deepPtr->flags = flags; + + deepPtrObj->typePtr = &L_deepPtr2Type; + deepPtrObj->internalRep.otherValuePtr = deepPtr; + } else { + ASSERT(flags & (L_IDX_ARRAY | L_IDX_HASH)); + deepPtr = (L_DeepPtr *)&deepPtrObj->internalRep.otherValuePtr; + + deepPtrObj->typePtr = &L_deepPtr1Type; + } + + deepPtr->elemPtrPtr = elemPtrPtr; + Tcl_IncrRefCount(*elemPtrPtr); + + deepPtr->topLevObj = objPtr; + Tcl_IncrRefCount(objPtr); + + return (deepPtrObj); +} + +/* + * Re-use the given deepPtr object. Note that once the compiler needs a large + * one, it never goes back to asking for a small one. + */ +static inline void +L_deepPtrSet(Tcl_Obj *deepPtrObj, int flags, Tcl_Obj *objPtr, Tcl_Obj *idxObj, + Tcl_Obj **elemPtrPtr) +{ + L_DeepPtr *deepPtr = L_deepPtrGet(deepPtrObj); + + // Ensured by caller. + ASSERT(*deepPtr->elemPtrPtr == objPtr); + + // Assert !(flags & (L_DELETE|L_IDX_STRING)) => already a L_deepPtr1Type. + ASSERT((flags & (L_DELETE|L_IDX_STRING)) || + (deepPtrObj->typePtr == &L_deepPtr1Type)); + + if (flags & (L_DELETE | L_IDX_STRING)) { + if (deepPtrObj->typePtr == &L_deepPtr1Type) { + // Have L_deepPtr1Type, need L_deepPtr2Type. + L_DeepPtr *newDeepPtr = (L_DeepPtr *)ckalloc(sizeof(L_DeepPtr)); + + newDeepPtr->topLevObj = deepPtr->topLevObj; + + newDeepPtr->parentObj = objPtr; + Tcl_IncrRefCount(objPtr); + + newDeepPtr->idxObj = idxObj; + Tcl_IncrRefCount(idxObj); + + newDeepPtr->flags = flags; + + deepPtrObj->typePtr = &L_deepPtr2Type; + deepPtrObj->internalRep.otherValuePtr = newDeepPtr; + deepPtr = newDeepPtr; + } else { + Tcl_Obj *oldParentObj = deepPtr->parentObj; + Tcl_Obj *oldIdxObj = deepPtr->idxObj; + + deepPtr->parentObj = objPtr; + Tcl_IncrRefCount(objPtr); + + deepPtr->idxObj = idxObj; + Tcl_IncrRefCount(idxObj); + + deepPtr->flags = flags; + + Tcl_DecrRefCount(oldParentObj); + Tcl_DecrRefCount(oldIdxObj); + } + } + + deepPtr->elemPtrPtr = elemPtrPtr; + Tcl_IncrRefCount(*elemPtrPtr); + + deepPtrObj->refCount = 0; +} + +static inline void +L_deepPtrFree(Tcl_Obj *deepPtrObj) +{ + L_DeepPtr *deepPtr; + + unless (deepPtrObj) return; + if (deepPtrObj->typePtr == &L_deepPtr1Type) { + deepPtr = (L_DeepPtr *)&deepPtrObj->internalRep.otherValuePtr; + Tcl_DecrRefCount(deepPtr->topLevObj); + } else { + deepPtr = (L_DeepPtr *)deepPtrObj->internalRep.otherValuePtr; + Tcl_DecrRefCount(deepPtr->parentObj); + Tcl_DecrRefCount(deepPtr->idxObj); + Tcl_DecrRefCount(deepPtr->topLevObj); + ckfree((char *)deepPtr); + } + ASSERT(deepPtrObj->refCount == 1); + Tcl_DecrRefCount(deepPtrObj); +} + +/* + * The following two functions save and set an object's refCount to 1 so that + * it can be modified, and restore it to its original value. This facilitates + * the L deep-dive bytecodes where we know an object is unshared but we may + * have stack or deepPtr refs to it. Experience has shown that the code is + * simpler if we just do this ugly hack. + */ + +static inline int +refCnt_save(Tcl_Obj *objPtr) +{ + int old = objPtr->refCount; + objPtr->refCount = 1; + return (old); +} + +static inline void +refCnt_restore(Tcl_Obj *objPtr, int old) +{ + ASSERT(objPtr->refCount == 1); + objPtr->refCount = old; +} + +/* + * Duplicate part of struct Dict from tclDictObj.c; all we need is the + * first member. The deep-dive execution code uses it to traverse + * hashes. WARNING: this may break if dicts change their internal + * rep! + */ +typedef struct Dict { + Tcl_HashTable table; /* Object hash table to store mapping in. */ +} Dict; + +static Tcl_Obj **L_deepDive(Tcl_Interp *interp, Tcl_Obj *obj, Tcl_Obj *idxObj, + Expr_f flags); /* *---------------------------------------------------------------------- @@ -2666,6 +2953,25 @@ TEBCresume( TRACE_WITH_OBJ(("%u => ", opnd), objResultPtr); NEXT_INST_F(5, 0, 1); + case INST_ROT: { + int opnd; + + opnd = TclGetInt1AtPtr(pc+1); + if (opnd > 0) { + objResultPtr = OBJ_AT_DEPTH(opnd); + memmove(&OBJ_AT_DEPTH(opnd), &OBJ_AT_DEPTH(opnd-1), opnd*sizeof(Tcl_Obj *)); + OBJ_AT_TOS = objResultPtr; + TRACE_WITH_OBJ(("=> "), objResultPtr); + } else if (opnd < 0) { + opnd = -opnd; + objResultPtr = OBJ_AT_TOS; + memmove(&OBJ_AT_DEPTH(opnd-1), &OBJ_AT_DEPTH(opnd), opnd*sizeof(Tcl_Obj *)); + OBJ_AT_DEPTH(opnd) = objResultPtr; + TRACE_WITH_OBJ(("=> "), objResultPtr); + } + NEXT_INST_F(2, 0, 0); + } + case INST_REVERSE: { Tcl_Obj **a, **b; @@ -2941,6 +3247,28 @@ TEBCresume( NEXT_INST_F(5, 0, 0); } + case INST_EXPAND_ROT: { + int depth; + int opnd = TclGetUInt1AtPtr(pc+1); + Tcl_Obj *objPtr = auxObjList; + char *save; + + if (objPtr == NULL) { + TRACE(("%u => error: aux stack empty", opnd)); + result = TCL_ERROR; + goto checkForCatch; + } + depth = CURR_DEPTH - PTR2INT(objPtr->internalRep.twoPtrValue.ptr1); + save = ckalloc(opnd * sizeof(Tcl_Obj *)); + memmove(save, &OBJ_AT_DEPTH(opnd-1), opnd*sizeof(Tcl_Obj *)); + memmove(&OBJ_AT_DEPTH(depth-opnd-1), &OBJ_AT_DEPTH(depth-1), + (depth-opnd)*sizeof(Tcl_Obj *)); + memmove(&OBJ_AT_DEPTH(depth-1), save, opnd*sizeof(Tcl_Obj *)); + ckfree(save); + TRACE(("%u %u =>", opnd, depth)); + NEXT_INST_F(2, 0, 0); + } + case INST_EXPR_STK: { ByteCode *newCodePtr; @@ -3192,7 +3520,7 @@ TEBCresume( * Start of INST_LOAD instructions. * * WARNING: more 'goto' here than your doctor recommended! The different - * instructions set the value of some variables and then jump to some + * instructions set the value of some variables and then jump to somme * common execution code. */ @@ -3756,7 +4084,7 @@ TEBCresume( * Start of INST_INCR instructions. * * WARNING: more 'goto' here than your doctor recommended! The different - * instructions set the value of some variables and then jump to somme + * instructions set the value of some variables and then jump to some * common execution code. */ @@ -5029,7 +5357,9 @@ TEBCresume( case INST_LIST_LENGTH: TRACE(("\"%.30s\" => ", O2S(OBJ_AT_TOS))); - if (TclListObjLength(interp, OBJ_AT_TOS, &length) != TCL_OK) { + if ((OBJ_AT_TOS)->undef) { + length = 0; + } else if (TclListObjLength(interp, OBJ_AT_TOS, &length) != TCL_OK) { TRACE_ERROR(interp); goto gotError; } @@ -5392,7 +5722,26 @@ TEBCresume( value2Ptr = OBJ_AT_TOS; valuePtr = OBJ_UNDER_TOS; - if (valuePtr == value2Ptr) { + if (valuePtr->undef ^ value2Ptr->undef) { + /* L undef never equals anything that's defined. */ + switch (*pc) { + case INST_EQ: + case INST_STR_EQ: + case INST_LT: + case INST_LE: + case INST_NEQ: + case INST_STR_NEQ: + match = 1; + break; + case INST_GT: + case INST_GE: + match = -1; + break; + case INST_STR_CMP: + match = 0; + break; + } + } else if (valuePtr == value2Ptr) { match = 0; } else { /* @@ -5426,8 +5775,8 @@ TEBCresume( && (valuePtr->bytes != NULL) && (s2len == value2Ptr->length) && (value2Ptr->bytes != NULL)) { - s1 = valuePtr->bytes; - s2 = value2Ptr->bytes; + s1 = TclGetString(valuePtr); + s2 = TclGetString(value2Ptr); memCmpFn = memcmp; } else { s1 = (char *) Tcl_GetUnicode(valuePtr); @@ -5516,7 +5865,11 @@ TEBCresume( case INST_STR_LEN: valuePtr = OBJ_AT_TOS; - length = Tcl_GetCharLength(valuePtr); + if (valuePtr->undef) { + length = 0; + } else { + length = Tcl_GetCharLength(valuePtr); + } TclNewIntObj(objResultPtr, length); TRACE(("\"%.20s\" => %d\n", O2S(valuePtr), length)); NEXT_INST_F(1, 1, 1); @@ -5998,7 +6351,10 @@ TEBCresume( * both. */ - if ((valuePtr->typePtr == &tclStringType) + /* L undef never equals anything that's defined. */ + if (valuePtr->undef ^ value2Ptr->undef) { + match = 0; + } else if ((valuePtr->typePtr == &tclStringType) || (value2Ptr->typePtr == &tclStringType)) { Tcl_UniChar *ustring1, *ustring2; @@ -6101,6 +6457,15 @@ TEBCresume( TRACE(("\"%.30s\" \"%.30s\" => ", O2S(valuePtr), O2S(value2Ptr))); /* + * cflags won't use PCRE flag indicator during compilation + * XXX may use TCL_REG_ADVANCED to indicate -type classic for + * XXX compilation, but currently -type isn't compiled + */ + if (((Interp *)interp)->flags & INTERP_PCRE) { + cflags |= TCL_REG_PCRE; + } + + /* * Compile and match the regular expression. */ @@ -6111,8 +6476,12 @@ TEBCresume( if (regExpr == NULL) { TRACE_ERROR(interp); goto gotError; + } else if (valuePtr->undef ^ value2Ptr->undef) { + /* L undef never equals anything that's defined. */ + match = 0; + } else { + match = Tcl_RegExpExecObj(interp, regExpr, valuePtr, 0, 0, 0); } - match = Tcl_RegExpExecObj(interp, regExpr, valuePtr, 0, 0, 0); if (match < 0) { TRACE_ERROR(interp); goto gotError; @@ -6123,7 +6492,7 @@ TEBCresume( /* * Peep-hole optimisation: if you're about to jump, do jump from here. - * Adjustment is 2 due to the nocase byte. + * Adjustment is 2 due to the cflags byte. */ JUMP_PEEPHOLE_F(match, 2, 2); @@ -6184,6 +6553,11 @@ TEBCresume( value2Ptr = OBJ_AT_TOS; valuePtr = OBJ_UNDER_TOS; + /* L undef never equals anything that's defined. */ + if (valuePtr->undef ^ value2Ptr->undef) { + iResult = (*pc == INST_NEQ); + goto foundResult; + } if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) { /* * At least one non-numeric argument - compare as strings. @@ -6992,6 +7366,7 @@ TEBCresume( for (j = 0; j < numVars; j++) { if (valIndex >= listLen) { TclNewObj(valuePtr); + valuePtr->undef = 1; } else { valuePtr = elements[valIndex]; } @@ -7908,6 +8283,651 @@ TEBCresume( * ----------------------------------------------------------------- */ + /* + * Opcodes for the L language. + */ + + case INST_L_INDEX: { + /* + * Index into an L array, hash, struct, or string, and return either + * the indexed value or an L "deep pointer". On entry, the stack is + * (the stack top is on the right): + * + * <obj | deep-ptr> <idx> + * + * <obj> is the object being indexed in to. An L deep pointer + * <deep-ptr> from a previous instance of this instruction also can be + * used; this is how multiple levels are indexed. + * + * On exit, the stack configuration depends on what flags are in + * the instruction: + * + * <elem-val> if flags & L_PUSH_VAL + * <deep-ptr> if flags & L_PUSH_PTR + * <elem-val> <deep-ptr> if flags & L_PUSH_VALPTR + * <deep-ptr> <elem-val> if flags & L_PUSH_PTRVAL + * (nothing) if flags & L_DISCARD + * + * where <elem-val> is the object in <obj> referenced by the given + * index and <deep-ptr> is an object of L_deepPtrType type that only + * this code and the INST_L_DEEP_WRITE bytecode know about. It is + * basically a pointer to <elem-val> that can be used to index or + * modify the element in-place later. + * + * If flags & L_VALUE, it is assumed that the element is going to be + * written later by INST_L_DEEP_WRITE, so if any part of the path to + * that element is shared, an unshared copy is made. If this results + * in the top-level object itself getting copied, the new obj gets + * written back into the local variable when the INST_L_DEEP_WRITE is + * done later. This is possible since the <deep-ptr> encapsulates a + * back-pointer to the top-level object. + */ + + Tcl_Obj **elemPtrPtr; + Tcl_Obj *idxObj, *objPtr; + Tcl_Obj *deepPtrObj = NULL; + L_DeepPtr *deepPtr = NULL; + int dropRefCnt = 0; + unsigned int flags = TclGetUInt4AtPtr(pc+1); + int lvalue = (flags & L_LVALUE); + int needPtr = (flags & (L_PUSH_PTR | L_PUSH_PTRVAL | L_PUSH_VALPTR)); + + // needPtr => L_PUSH_VAL not set + ASSERT(!needPtr || !(flags & L_PUSH_VAL)); + + /* + * Get the bytecode arguments -- the index and object being indexed in + * to. If the object is a deep pointer from an earlier instance of + * this bytecode, de-reference it and get the object from inside it. + */ + idxObj = POP_OBJECT(); + objPtr = POP_OBJECT(); + if (L_isDeepPtr(objPtr)) { + deepPtrObj = objPtr; + deepPtr = L_deepPtrGet(deepPtrObj); + objPtr = *(deepPtr->elemPtrPtr); + /* + * Enclosing obj ref + deepPtr ref == 2. Not >2 because in + * previous iterations through here we already ensured the + * sub-object is an un-shared copy. + */ + ASSERT (!lvalue || (objPtr->refCount == 2)); + ASSERT (!Tcl_IsShared(deepPtrObj)); + } + + /* + * Drop the stack ref to the object being indexed. We have to do this + * now, because we might need to modify the object (e.g., to extend an + * array) and list operations on shared objects will fail. But if the + * stack ref is the only ref (which happens when you index a constant + * or a function's return value), we have to delay it or else the + * object will get deleted. A little ugly, but there's no way around + * this. + */ + if (objPtr->refCount == 1) { + ASSERT(deepPtrObj == NULL); + dropRefCnt = 1; + } else { + /* + * This drops either the stack ref (deepPtrObj==NULL) or the + * deepPtr ref (objPtr=*elemPtrPtr in that case; this is why + * L_deepPtrSet() and L_deepPtrFree() do not drop the *elemPtrPtr + * ref). + */ + Tcl_DecrRefCount(objPtr); + } + + /* + * Special handling for l-values: ensure we have an un-shared copy. + * Note that only the top-level object, i.e., the target of the first + * index of a sequence of indices into a nested object, will get + * copied here. Sub-objects inside the top-level also need to be + * un-shared, but L_deepDive() copies those, so by the time we get + * back around here in the next iteration to index into *them*, they + * won't be shared (the ASSERT below verifies this). + */ + if (lvalue && Tcl_IsShared(objPtr)) { + ASSERT(deepPtrObj == NULL); + objPtr = Tcl_DuplicateObj(objPtr); + Tcl_IncrRefCount(objPtr); + /* + * We're going to modify an element of this list in-place later, + * so also create an unshared copy of the internal list + * representation. Tcl_DuplicateObj() does not do this. + */ + if (objPtr->typePtr == &tclListType) { + TclDuplicateListRep(objPtr); + } + dropRefCnt = 1; + } + + /* + * Index into the object. + */ + elemPtrPtr = L_deepDive(interp, objPtr, idxObj, flags); + if (!elemPtrPtr) { + if (dropRefCnt) Tcl_DecrRefCount(objPtr); // drop stack/deepPtr ref + Tcl_DecrRefCount(idxObj); // drop stack ref + result = TCL_ERROR; + goto checkForCatch; + } + + /* + * If flags indicate a deep-ptr is needed, make an L_deepPtrType object + * that refers to the indexed element and stash the top-level object + * pointer and other bookkeeping in there. The top-level object is + * needed in the INST_L_DEEP_WRITE coming later to update the variable + * being written. If a deep ptr was already on the stack, recycle it + * (and note that it already points to the top-level object). + */ + if (needPtr) { + if (deepPtrObj) { + L_deepPtrSet(deepPtrObj, flags, objPtr, idxObj, elemPtrPtr); + } else { + deepPtrObj = L_deepPtrNew(flags, objPtr, idxObj, elemPtrPtr); + } + } + + /* + * Leave the value, deep-pointer, or both on the stack as requested by + * the input flags. + */ + switch (flags & + (L_PUSH_VAL|L_PUSH_PTR|L_PUSH_PTRVAL|L_PUSH_VALPTR|L_DISCARD)) { + case L_PUSH_VAL: + PUSH_OBJECT(*elemPtrPtr); + L_deepPtrFree(deepPtrObj); + TRACE_WITH_OBJ(("L_PUSH_VAL => "), OBJ_AT_TOS); + break; + case L_PUSH_PTR: + PUSH_OBJECT(deepPtrObj); + TRACE_WITH_OBJ(("L_PUSH_PTR => "), OBJ_AT_TOS); + break; + case L_PUSH_PTRVAL: + PUSH_OBJECT(deepPtrObj); + PUSH_OBJECT(*elemPtrPtr); + TRACE(("L_PUSH_PTRVAL => \"%.30s\" \"%.30s\"", + O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS))); + break; + case L_PUSH_VALPTR: + PUSH_OBJECT(*elemPtrPtr); + PUSH_OBJECT(deepPtrObj); + TRACE(("L_PUSH_VALPTR => \"%.30s\" \"%.30s\"", + O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS))); + break; + case L_DISCARD: + L_deepPtrFree(deepPtrObj); + TRACE(("L_DISCARD => \n")); + break; + default: + Tcl_Panic("illegal operand to INST_L_INDEX"); + break; + } + + /* Drop the stack refs. */ + if (dropRefCnt) Tcl_DecrRefCount(objPtr); + Tcl_DecrRefCount(idxObj); + + NEXT_INST_F(5, 0, 0); + } + + case INST_L_DEEP_WRITE: { + /* + * Write to, or delete, an element of a hash/array/struct/string and + * store the top-level hash/array/struct/string object in a local. + * Leave on the stack the old element value, the new element value, or + * nothing, as requested. + * + * Stack on entry (the stack top is on the right): + * + * [<rval>] <l-deep-ptr> [<arrayIdx>] + * + * <l-deep-ptr> L deep pointer that is created only by + * INST_L_INDEX (above). This "points" to what + * we're indexing in to or deleting. + * <rval> Object to assign to the object pointed + * to by <l-deep-ptr>. Not present for L_DELETE. + * <arrayIdx> Array index. Preset only for L_INSERT_ELT + * and L_INSERT_LIST. An index of -1 means + * append. + * + * Instruction arguments: + * + * opnd1 (one byte): A local index. The top-level array/hash/struct/ + * string object that is encapsulated in the <l-deep-ptr> is + * stored in this local. In older versions of deep dive, + * this used to be done with an extra bytecode. + * + * opnd2 (four bytes): flags, as follows: + * + * L_IDX_STRING, L_IDX_ARRAY, L_IDX_HASH, L_INSERT_ELT, + * L_INSERT_LIST, L_DELETE + * Indicates what kind of object we're indexing in to and whether + * we're writing a single element, deleting an element, or + * inserting an element or another list into a list (array). + * Mutually exclusive. + * + * L_PUSH_NEW, L_PUSH_OLD, L_DISCARD + * Whether to leave the new value, old value, or nothing on the + * stack. Mutually exclusive. + */ + + int arrayIdx = 0, ret, save; + Tcl_Obj *arrayIdxObj, *deepPtrObj, *oldvalObj, *rvalObj = NULL; + Tcl_Obj *currTopLevObj, *newTopLevObj; + Var *varPtr; + L_DeepPtr *deepPtr; + unsigned int flags, idx; + + idx = TclGetUInt4AtPtr(pc+1); + flags = TclGetUInt4AtPtr(pc+5); + // assert flags & L_DELETE => !(flags & L_PUSH_NEW) + ASSERT(!(flags & L_DELETE) || !(flags & L_PUSH_NEW)); + + /* Pop the array index, if present. */ + if (flags & (L_INSERT_ELT | L_INSERT_LIST)) { + arrayIdxObj = POP_OBJECT(); + if (TclGetIntFromObj(NULL, arrayIdxObj, &arrayIdx) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert index to integer", + NULL); + result = TCL_ERROR; + goto checkForCatch; + } + Tcl_DecrRefCount(arrayIdxObj); + if (arrayIdx == -1) arrayIdx = INT_MAX; + } + /* Pop the other instruction arguments. */ + deepPtrObj = POP_OBJECT(); + unless (flags & L_DELETE) rvalObj = POP_OBJECT(); + deepPtr = L_deepPtrGet(deepPtrObj); + ASSERT (!Tcl_IsShared(deepPtrObj)); + if (deepPtrObj->typePtr == &L_deepPtr2Type) flags |= deepPtr->flags; + + /* + * currTopLevObj is what the local currently points to. If it was + * shared, newTopLevObj got an unshared copy (made by INST_L_INDEX). + * We will write into the unshared copy in-place and set the var to it + * below. + */ + varPtr = &(compiledLocals[idx]); + while (TclIsVarLink(varPtr)) { + varPtr = varPtr->value.linkPtr; + } + currTopLevObj = varPtr->value.objPtr; + newTopLevObj = deepPtr->topLevObj; + + /* + * Write or append the new value to the indexed element, or delete the + * indexed element, as requested. + */ + oldvalObj = *(deepPtr->elemPtrPtr); + switch (flags & (L_IDX_STRING|L_INSERT_ELT|L_INSERT_LIST|L_DELETE)) { + case L_IDX_STRING: + case L_IDX_STRING | L_DELETE: { + int len, str_idx; + Tcl_UniChar *tmp; + Tcl_Obj *newStr; + Tcl_Obj *target = deepPtr->parentObj; + + /* Check for writing to index beyond string's end. */ + TclGetIntFromObj(NULL, deepPtr->idxObj, &str_idx); + len = Tcl_GetCharLength(target); + if (str_idx > len) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, + "index is more than one past end of string", + NULL); + result = TCL_ERROR; + goto checkForCatch; + } + /* Copy to newStr chars up to but skipping the given index. */ + newStr = Tcl_GetRange(target, 0, str_idx-1); + Tcl_IncrRefCount(newStr); + unless (flags & L_DELETE) { + /* Append the rval obj. */ + Tcl_AppendObjToObj(newStr, rvalObj); + } + /* Append to newStr all chars after the given index. */ + if (str_idx < len) { + Tcl_Obj *r = Tcl_GetRange(target, str_idx+1, len-1); + Tcl_IncrRefCount(r); + Tcl_AppendObjToObj(newStr, r); + Tcl_DecrRefCount(r); + } + /* + * Assign newStr to target. Possible target ref counts: + * If a one-level index like s[2] = "x" and s unshared: + * deepPtr->topLevObj + deepPtr->parentObj + var ref (s) + * If a one-level index like s[2] = "x" and s was shared: + * deepPtr->topLevObj + deepPtr->parentObj + * (because INST_L_INDEX dup'd but s isn't pointing to it yet) + * Note that a multi-level index like s[0][2] = "x" is + * disallowed by the compiler. + */ + ASSERT((target->refCount == 2) || (target->refCount == 3)); + tmp = Tcl_GetUnicodeFromObj(newStr, &len); + save = refCnt_save(target); + Tcl_SetUnicodeObj(target, tmp, len); + refCnt_restore(target, save); + Tcl_DecrRefCount(newStr); + break; + } + case L_INSERT_ELT: + case L_INSERT_LIST: { + int objc; + Tcl_Obj **objv; + + /* + * oldvalObj has a stack ref and a deepPtr ref, so drop one so + * we can append to it (it must be unshared), then restore it + * (since it's dropped later by L_deepPtrFree()). + */ + ASSERT(oldvalObj->refCount == 2); + ASSERT(rvalObj); + Tcl_DecrRefCount(oldvalObj); + if (flags & L_INSERT_ELT) { + Tcl_ListObjReplace(interp, oldvalObj, arrayIdx, 0, + 1, &rvalObj); + } else { + Tcl_ListObjGetElements(interp, rvalObj, &objc, &objv); + Tcl_ListObjReplace(interp, oldvalObj, arrayIdx, 0, + objc, objv); + } + Tcl_IncrRefCount(oldvalObj); + Tcl_IncrRefCount(oldvalObj); + break; + } + case L_DELETE: + save = refCnt_save(deepPtr->parentObj); + if (deepPtr->flags & L_IDX_HASH) { + ret = Tcl_DictObjRemove(interp, deepPtr->parentObj, + deepPtr->idxObj); + } else if (deepPtr->flags & L_IDX_ARRAY) { + int i; + TclGetIntFromObj(NULL, deepPtr->idxObj, &i); + ret = Tcl_ListObjReplace(interp, deepPtr->parentObj, + i, 1, 0, NULL); + } else { + /* Not array or hash? error! */ + ret = TCL_ERROR; + } + refCnt_restore(deepPtr->parentObj, save); + if (ret != TCL_OK) { + Tcl_Panic("err deleting element in INST_L_DEEP_WRITE"); + } + break; + default: + *(deepPtr->elemPtrPtr) = rvalObj; + Tcl_IncrRefCount(rvalObj); // add parent obj ref + ASSERT(oldvalObj->refCount >= 2); + Tcl_DecrRefCount(oldvalObj); // drop old parent obj ref + break; + } + + /* + * If the local pointed to a shared object when it was indexed, the + * INST_L_INDEX code made an un-shared copy of the obj and cached it + * in deepPtr. In that case, update the local to point to the + * un-shared copy. + */ + if (currTopLevObj != newTopLevObj) { // update only if needed + if (TclIsVarDirectWritable(varPtr)) { + varPtr->value.objPtr = newTopLevObj; + Tcl_IncrRefCount(newTopLevObj); // add new var ref + Tcl_DecrRefCount(currTopLevObj); // lose old var ref + } else { + DECACHE_STACK_INFO(); + if (!TclPtrSetVar(interp, varPtr, NULL, NULL, NULL, + newTopLevObj, TCL_LEAVE_ERR_MSG, idx)) { + Tcl_Panic("could not set var in INST_L_DEEP_WRITE"); + } + CACHE_STACK_INFO(); + } + } + + switch (flags & (L_PUSH_OLD|L_PUSH_NEW|L_DISCARD)) { + case L_PUSH_OLD: + PUSH_OBJECT(oldvalObj); + TRACE_WITH_OBJ(("L_PUSH_OLD => "), OBJ_AT_TOS); + break; + case L_PUSH_NEW: + PUSH_OBJECT(rvalObj); + TRACE_WITH_OBJ(("L_PUSH_NEW => "), OBJ_AT_TOS); + break; + case L_DISCARD: + TRACE(("L_DISCARD =>\n")); + break; + default: + Tcl_Panic("Bad flags to INST_L_DEEP_WRITE"); + break; + } + + Tcl_DecrRefCount(oldvalObj); // drop old deepPtr ref + if (rvalObj) Tcl_DecrRefCount(rvalObj); // drop stack ref + L_deepPtrFree(deepPtrObj); + + ASSERT(!Tcl_IsShared(newTopLevObj)); + +#ifndef TCL_COMPILE_DEBUG + /* Peephole optimization. */ + if (*(pc+6) == INST_POP) { + tosPtr--; + NEXT_INST_F(10, 0, 0); + } +#endif + NEXT_INST_F(9, 0, 0); + } + + case INST_L_SPLIT: { + int n; + Tcl_Obj *strObj = NULL; + Tcl_Obj *delimObj = NULL; + Tcl_Obj *limitObj = NULL; + unsigned int opnd = TclGetUInt4AtPtr(pc+1); + + if (opnd & L_SPLIT_LIM) { + ASSERT(opnd & (L_SPLIT_RE | L_SPLIT_STR)); + delimObj = OBJ_AT_DEPTH(2); + strObj = OBJ_AT_DEPTH(1); + limitObj = OBJ_AT_DEPTH(0); + n = 3; + } else if (opnd & (L_SPLIT_RE | L_SPLIT_STR)) { + delimObj = OBJ_AT_DEPTH(1); + strObj = OBJ_AT_DEPTH(0); + n = 2; + } else { + strObj = OBJ_AT_DEPTH(0); + n = 1; + } + objResultPtr = L_split(interp, strObj, delimObj, limitObj, opnd); + if (!objResultPtr) { + result = TCL_ERROR; + goto checkForCatch; + } + TRACE_WITH_OBJ(("0x%x => ", opnd), objResultPtr); + NEXT_INST_V(5, n, 1); + } + + case INST_L_DEFINED: { + objResultPtr = constants[(OBJ_AT_TOS)->undef == 0]; + TRACE_WITH_OBJ(("=> "), objResultPtr); + NEXT_INST_F(1, 1, 1); + } + + case INST_L_PUSH_LIST_SIZE: { + int length; + Tcl_Obj *valuePtr; + L_DeepPtr *deepPtr; + + valuePtr = OBJ_AT_TOS; + + if (L_isDeepPtr(valuePtr)) { + deepPtr = L_deepPtrGet(valuePtr); + valuePtr = *deepPtr->elemPtrPtr; + } + + result = TclListObjLength(interp, valuePtr, &length); + if (result == TCL_OK) { + L_sizes_push(length - 1); + TRACE(("%.20s => %d on L sizes stack\n", O2S(valuePtr), length)); + NEXT_INST_F(1, 0, 0); + } else { + TRACE_WITH_OBJ(("%.30s => ERROR: ", O2S(valuePtr)), + Tcl_GetObjResult(interp)); + goto checkForCatch; + } + } + + case INST_L_PUSH_STR_SIZE: { + int length; + Tcl_Obj *valuePtr; + L_DeepPtr *deepPtr; + + valuePtr = OBJ_AT_TOS; + + if (L_isDeepPtr(valuePtr)) { + deepPtr = L_deepPtrGet(valuePtr); + valuePtr = *deepPtr->elemPtrPtr; + } + + Tcl_GetUnicodeFromObj(valuePtr, &length); + L_sizes_push(length - 1); + TRACE(("%.20s => %d on L sizes stack\n", O2S(valuePtr), length)); + NEXT_INST_F(1, 0, 0); + } + + case INST_L_READ_SIZE: { + int length = L_sizes_top(); + objResultPtr = Tcl_NewIntObj(length); + TRACE(("=> %d\n", length)); + NEXT_INST_F(1, 0, 1); + } + + case INST_L_POP_SIZE: { + L_sizes_pop(); + NEXT_INST_F(1, 0, 0); + } + + case INST_L_PUSH_UNDEF: { + objResultPtr = *L_undefObjPtrPtr(); + NEXT_INST_F(1, 0, 1); + } + + case INST_L_LINDEX_STK: { + int listc; + Tcl_Obj *list = OBJ_AT_TOS; + Tcl_Obj **listv; + unsigned int i = TclGetUInt1AtPtr(pc+1); + + result = TclListObjGetElements(interp, list, &listc, &listv); + if (result != TCL_OK) { + goto checkForCatch; + } + if ((i >= 0) && (i < listc)) { + objResultPtr = listv[i]; + } else { + objResultPtr = *L_undefObjPtrPtr(); + } + NEXT_INST_F(2, 0, 1); + } + + case INST_L_LIST_INSERT: { + int index, objc; + Tcl_Obj **objv; + Tcl_Obj *listPtr; + Tcl_Obj *indexPtr = POP_OBJECT(); + Tcl_Obj *elemPtr = OBJ_AT_TOS; + unsigned int opnd = TclGetUInt4AtPtr(pc+1); + unsigned int flags = TclGetUInt4AtPtr(pc+5); + Var *varPtr = &(compiledLocals[opnd]); + + while (TclIsVarLink(varPtr)) { + varPtr = varPtr->value.linkPtr; + } + listPtr = varPtr->value.objPtr; + if (Tcl_IsShared(listPtr)) { + listPtr = Tcl_DuplicateObj(listPtr); + TclPtrSetVar(interp, varPtr, NULL, NULL, NULL, listPtr, 0, opnd); + } + if (TclGetIntFromObj(NULL, indexPtr, &index) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert index to integer", NULL); + result = TCL_ERROR; + goto checkForCatch; + } + Tcl_DecrRefCount(indexPtr); + if (index == -1) index = INT_MAX; // -1 means append + if (flags & L_INSERT_ELT) { + result = Tcl_ListObjReplace(interp, listPtr, index, 0, 1, &elemPtr); + } else { + ASSERT(flags & L_INSERT_LIST); + Tcl_ListObjGetElements(interp, elemPtr, &objc, &objv); + result = Tcl_ListObjReplace(interp, listPtr, index, 0, objc, objv); + } + if (result != TCL_OK) { + goto checkForCatch; + } + NEXT_INST_F(9, 1, 0); + } + + case INST_UNSET_LOCAL: { + unsigned int opnd = TclGetUInt4AtPtr(pc+1); + Var *varPtr = &compiledLocals[opnd]; + Var *linkPtr; + + /* + * This is intended to delete L's local temp variables, which are + * always scalars and never traced. + */ + if (TclIsVarLink(varPtr)) { + linkPtr = varPtr->value.linkPtr; + if (TclIsVarInHash(linkPtr)) { + VarHashRefCount(linkPtr)--; + if (TclIsVarUndefined(linkPtr)) { + TclCleanupVar(linkPtr, NULL); + } + } + TclSetVarScalar(varPtr); + varPtr->value.linkPtr = NULL; + } else unless (TclIsVarUndefined(varPtr)) { + TclDecrRefCount(varPtr->value.objPtr); + TclSetVarUndefined(varPtr); + } + NEXT_INST_F(5, 0, 0); + } + + case INST_DIFFERENT_OBJ: { + unsigned int opnd = TclGetUInt4AtPtr(pc+1); + Var *localVarPtr = &compiledLocals[opnd]; + Var *otherVarPtr, *varPtr; + Tcl_Obj *varName = OBJ_AT_TOS; + Tcl_Obj *localObjPtr, *otherObjPtr; + + otherVarPtr = TclObjLookupVar(interp, varName, NULL, TCL_GLOBAL_ONLY, + NULL, 0, 0, &varPtr); + if (otherVarPtr == NULL) { + Tcl_SetResult(interp, "variable not found", TCL_STATIC); + result = TCL_ERROR; + goto checkForCatch; + } + while (TclIsVarLink(otherVarPtr)) { + otherVarPtr = otherVarPtr->value.linkPtr; + } + while (TclIsVarLink(localVarPtr)) { + localVarPtr = localVarPtr->value.linkPtr; + } + if (!TclIsVarUndefined(localVarPtr) && !TclIsVarUndefined(otherVarPtr)) { + localObjPtr = localVarPtr->value.objPtr; + otherObjPtr = otherVarPtr->value.objPtr; + objResultPtr = constants[localObjPtr != otherObjPtr]; + } else { + objResultPtr = constants[1]; + } + + NEXT_INST_F(5, 1, 1); + } + default: Tcl_Panic("TclNRExecuteByteCode: unrecognized opCode %u", *pc); } /* end of switch on opCode */ @@ -10750,6 +11770,373 @@ StringForResultCode( #endif /* TCL_COMPILE_DEBUG */ /* + *---------------------------------------------------------------------- + * + * L_deepDiveArray -- + * + * Index one level into an L array or struct (represented as a Tcl list), + * using L semantics. + * + * Results: + * If flags & L_PUSH_VAL, the array is being indexed as an r-value. + * Otherwise, it is assumed that the indexed value will be written + * in-place later (i.e., used as an l-value), and this function does + * the magic necessary to allow that. + * + * For an r-value, this function returns a pointer to the indexed object + * pointer (i.e., a Tcl_Obj ** pointer into the lists's internal element + * array). If the index is < 0 or beyond the last element, a pointer to + * the L undef object is returned instead. If the index has the value + * undef, always return the undef object as the element value. + * + * For an l-value, if the indexed element is shared, an un-shared copy is + * made so that the indexed object later can be written in-place. Also, + * if the index is beyond the last element, the list is padded out with + * copies of the L undef object. + * + * Side effects: + * See above. The lists's string representation also is invalidated. + * + *---------------------------------------------------------------------- + */ + +static Tcl_Obj ** +L_deepDiveArray( + Tcl_Interp *interp, + Tcl_Obj *obj, /* object being indexed */ + Tcl_Obj *idxObj, /* index (array subscript) into obj */ + Expr_f flags) +{ + int i, idx, len, result; + Tcl_Obj **elemPtrs, **pad; + Tcl_Obj *subObj; + int lvalue = (flags & L_LVALUE); + + if (L_isUndef(idxObj)) { + if (lvalue) { + Tcl_SetResult(interp, "cannot write to undefined array index", + NULL); + return (NULL); + } else { + Tcl_SetResult(interp, "cannot read from undefined array index", + NULL); + return (NULL); + } + } + if (TclGetIntFromObj(NULL, idxObj, &idx) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert index to integer", NULL); + return (NULL); + } + if (TclListObjGetElements(NULL, obj, &len, &elemPtrs) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert object to list", NULL); + return (NULL); + } + + if (lvalue) { + if (idx < 0) { + if (flags & L_NEG_OK) { + return (L_undefObjPtrPtr()); + } else { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot write to negative array index", + NULL); + return (NULL); + } + } else if (idx >= len) { + /* Auto extend the array. */ + int n = idx - len + 1; + pad = (Tcl_Obj **)ckalloc(n * sizeof(Tcl_Obj *)); + for (i = 0; i < n; ++i) { + pad[i] = *L_undefObjPtrPtr(); + } + result = Tcl_ListObjReplace(interp, obj, len, 0, n, pad); + ckfree((char *)pad); + if (result != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert object to list", NULL); + return (NULL); + } + } + if (TclListObjGetElements(interp, obj, &len, &elemPtrs) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert object to list", NULL); + return (NULL); + } + if (Tcl_IsShared(elemPtrs[idx])) { + /* + * Make an un-shared copy of the element. Because we're going to + * later modify it in place, if the element is itself a list, we + * have to also duplicate its internal list representation because + * Tcl_DuplicateObj() does not (it shares the internal list rep + * between the old and new Tcl_Objs). + */ + subObj = Tcl_DuplicateObj(elemPtrs[idx]); + if (subObj->typePtr == &tclListType) { + TclDuplicateListRep(subObj); + } + TclListObjSetElement(NULL, obj, idx, subObj); + if (Tcl_IsShared(subObj)) { + subObj = Tcl_DuplicateObj(subObj); + } + if (TclListObjGetElements(interp, obj, &len, &elemPtrs) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert object to list", NULL); + return (NULL); + } + } + Tcl_InvalidateStringRep(obj); + return (&elemPtrs[idx]); + } else { + if ((idx < 0) || (idx >= len)) { + return (L_undefObjPtrPtr()); + } else { + return (&elemPtrs[idx]); + } + } +} + +/* + *---------------------------------------------------------------------- + * + * L_deepDiveHash -- + * + * Index one level into an L hash (represented as a Tcl dict), + * using L semantics. + * + * Results: + * If flags & L_PUSH_VAL, the hash is being indexed as an r-value. + * Otherwise, it is assumed that the indexed value will be written + * in-place later (i.e., used as an l-value), and this function does + * the magic necessary to allow that. + * + * For an r-value, this function returns a pointer to the indexed object + * pointer (i.e., a Tcl_Obj ** that points to the hash bucket). If the + * key does not exist, a pointer to the L undef object is returned + * instead. + * + * For an l-value, if the indexed element is shared, an un-shared copy is + * made so that the indexed object later can be written in-place. Also, + * if the key does not exist, it is added to the hash with a value of + * the L undef object. + * + * Side effects: + * See above. The hash's string representation also is invalidated. + * + *---------------------------------------------------------------------- + */ + +static Tcl_Obj ** +L_deepDiveHash( + Tcl_Interp *interp, + Tcl_Obj *obj, /* object being indexed */ + Tcl_Obj *idxObj, /* index (key) into obj */ + Expr_f flags) +{ + int result, tmp; + Tcl_Obj *objPtr; + Tcl_Obj **elt; + Dict *dict; + Tcl_HashEntry *hPtr; + int lvalue = (flags & L_LVALUE); + + ASSERT(!lvalue || !Tcl_IsShared(obj)); // lvalue => obj is unshared + + unless (Tcl_DictObjSize(NULL, obj, &tmp) == TCL_OK) { + /* Obj is not a dict and can't be converted to one. */ + if (lvalue) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "not a hash", NULL); + return (NULL); + } else { + return (L_undefObjPtrPtr()); + } + } + + if (L_isUndef(idxObj)) { + static int undef_idx_ok = -1; + + if (undef_idx_ok == -1) { + undef_idx_ok = getenv("BK_L_ALLOW_UNDEF_HASH_INDEX") != NULL; + } + if (undef_idx_ok == 1) { + unless (flags & L_LVALUE) { + return (L_undefObjPtrPtr()); + } + } else { + if (flags & L_LVALUE) { + Tcl_SetResult(interp, "cannot write to undefined hash index", + NULL); + return (NULL); + } else { + Tcl_SetResult(interp, "cannot read from undefined hash index", + NULL); + return (NULL); + } + } + } + + dict = (Dict *)obj->internalRep.otherValuePtr; + hPtr = Tcl_FindHashEntry(&dict->table, (char *)idxObj); + unless (hPtr) { + unless (lvalue) return (L_undefObjPtrPtr()); + TclNewObj(objPtr); + Tcl_IncrRefCount(objPtr); + result = Tcl_DictObjPut(interp, obj, idxObj, objPtr); + Tcl_DecrRefCount(objPtr); +#ifdef TCL_COMPILE_DEBUG + unless (result == TCL_OK) L_bomb("L deep-dive hash err"); +#else + (void)result; // quiet compiler warning +#endif + hPtr = Tcl_FindHashEntry(&dict->table, (char *)idxObj); + } + elt = (Tcl_Obj **)(void *)&Tcl_GetHashValue(hPtr); + ASSERT(elt); + if (lvalue && Tcl_IsShared(*elt)) { + Tcl_DecrRefCount(*elt); + *elt = Tcl_DuplicateObj(*elt); + Tcl_IncrRefCount(*elt); + } + if (lvalue) Tcl_InvalidateStringRep(obj); + return (elt); +} + +/* + *---------------------------------------------------------------------- + * + * L_deepDiveString -- + * + * Index into a string for the L INST_L_INDEX bytecode. + * + * Results: + * Creates a new Tcl_Obj that contains a substring of obj. To be + * compatible with the other L_deepDive* functions, this function returns + * a Tcl_Obj** by stashing the Tcl_Obj* into the object itself and + * returning a pointer to that pointer. + * + * If the given index is negative, a run-time error is generated. + * If the index is beyond the end of the string, a pointer the L + * undefined object pointer is returned. If the index is undef, + * return undef if the string is being read else throw a run-time + * error. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static Tcl_Obj ** +L_deepDiveString( + Tcl_Interp *interp, + Tcl_Obj *obj, /* object being indexed */ + Tcl_Obj *idxObj, /* index into obj */ + Expr_f flags) +{ + int idx, len; + Tcl_Obj *newObj; + Tcl_UniChar ch; + + if (L_isUndef(idxObj)) { + if (flags & L_LVALUE) { + Tcl_SetResult(interp, "cannot write to undefined string index", + NULL); + return (NULL); + } else { + Tcl_SetResult(interp, "cannot read from undefined string index", + NULL); + return (NULL); + } + } + if (TclGetIntFromObj(NULL, idxObj, &idx) != TCL_OK) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "cannot convert index to integer", NULL); + return (NULL); + } + + if (idx < 0) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "negative string index illegal", NULL); + return (NULL); + } else if (idx < Tcl_GetCharLength(obj)) { + ch = Tcl_GetUniChar(obj, idx); + if (obj->typePtr == &tclByteArrayType) { + unsigned char uch = (unsigned char) ch; + + newObj = Tcl_NewByteArrayObj(&uch, 1); + } else { + char buf[TCL_UTF_MAX]; + + len = Tcl_UniCharToUtf(ch, buf); + newObj = Tcl_NewStringObj(buf, len); + } + newObj->internalRep.twoPtrValue.ptr2 = newObj; + return (Tcl_Obj **)(void *)&(newObj->internalRep.twoPtrValue.ptr2); + } else { + return (L_undefObjPtrPtr()); + } +} + +/* + *---------------------------------------------------------------------- + * + * L_deepDive -- + * + * Index one level into an L array, hash, struct, or string, + * using L semantics. + * + * Results: + * If flags & L_PUSH_VAL, the object is being indexed as an r-value. + * Otherwise, it is assumed that the indexed value will be written + * in-place later (i.e., used as an l-value), and this function does + * the magic necessary to allow that. + * + * This function returns a pointer to the indexed object pointer (i.e., a + * Tcl_Obj **) that later can be used to modify the element in-place. If + * the indexed element does not exist, a pointer to the L undef object is + * returned instead. + * + * For an l-value, if the indexed element is shared, an un-shared copy is + * made so that the indexed object later can be written in-place. + * + * Side effects: + * See comments for L_deepDiveArray() and L_deepDiveHash(). The + * object's string representation also is invalidated. + * + *---------------------------------------------------------------------- + */ + +static Tcl_Obj ** +L_deepDive( + Tcl_Interp *interp, + Tcl_Obj *obj, + Tcl_Obj *idxObj, + Expr_f flags) +{ + Tcl_Obj **ret = NULL; + + switch (flags & (L_IDX_ARRAY | L_IDX_HASH | L_IDX_STRING)) { + case L_IDX_ARRAY: + ret = L_deepDiveArray(interp, obj, idxObj, flags); + break; + case L_IDX_HASH: + ret = L_deepDiveHash(interp, obj, idxObj, flags); + break; + case L_IDX_STRING: + ret = L_deepDiveString(interp, obj, idxObj, flags); + break; + default: + L_bomb("L_deepDive internal error"); + break; + } + /* If we're going to write to obj, mark it as defined now. */ + if (ret && (flags & L_LVALUE)) obj->undef = 0; + return (ret); +} + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/generic/tclIO.c b/generic/tclIO.c index 8e9e346..15b37b0 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -15,6 +15,9 @@ #include "tclInt.h" #include "tclIO.h" #include <assert.h> +#ifndef MIN +# define MIN(x,y) ((x)<(y)?(x):(y)) +#endif /* * For each channel handler registered in a call to Tcl_CreateChannelHandler, @@ -4168,6 +4171,48 @@ WillRead( } /* + *--------------------------------------------------------------------------- + * + * Tcl_WriteObjN -- + * + * Same as Tcl_WriteObj but takes the number of bytes to write. + * + *---------------------------------------------------------------------- + */ + +int +Tcl_WriteObjN( + Tcl_Channel chan, /* The channel to buffer output for. */ + Tcl_Obj *objPtr, /* The object to write. */ + int numBytes) /* The number of bytes to write. */ +{ + /* + * Always use the topmost channel of the stack + */ + + Channel *chanPtr; + ChannelState *statePtr; /* State info for channel */ + const char *src; + int srcLen; + + statePtr = ((Channel *) chan)->state; + chanPtr = statePtr->topChanPtr; + + if (CheckChannelErrors(statePtr, TCL_WRITABLE) != 0) { + return -1; + } + if (statePtr->encoding == NULL) { + src = (char *) Tcl_GetByteArrayFromObj(objPtr, &srcLen); + numBytes = MIN(numBytes, srcLen); + return WriteBytes(chanPtr, src, numBytes); + } else { + src = TclGetStringFromObj(objPtr, &srcLen); + numBytes = MIN(numBytes, srcLen); + return WriteChars(chanPtr, src, numBytes); + } +} + +/* *---------------------------------------------------------------------- * * Write -- @@ -7777,6 +7822,16 @@ Tcl_GetChannelOption( return TCL_OK; } } + if (len == 0 || HaveOpt(2, "-epipe")) { + if (len == 0) { + Tcl_DStringAppendElement(dsPtr, "-epipe"); + } + Tcl_DStringAppendElement(dsPtr, + (flags & CHANNEL_EXIT_ON_EPIPE) ? "exit" : "error"); + if (len > 0) { + return TCL_OK; + } + } if (len == 0 || HaveOpt(1, "-translation")) { if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-translation"); @@ -8030,6 +8085,29 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; + } else if (HaveOpt(2, "-epipe")) { + if (Tcl_SplitList(interp, newValue, &argc, &argv) == TCL_ERROR) { + return TCL_ERROR; + } + if (argc == 1) { + len = strlen(newValue); + if (strncmp(newValue, "exit", len) == 0) { + SetFlag(statePtr, CHANNEL_EXIT_ON_EPIPE); + ckfree((char *) argv); + return TCL_OK; + } else if (strncmp(newValue, "error", len) == 0) { + ResetFlag(statePtr, CHANNEL_EXIT_ON_EPIPE); + ckfree((char *) argv); + return TCL_OK; + } + } + if (interp) { + Tcl_AppendResult(interp, + "bad value for -epipe: must be one of exit or error", + NULL); + } + ckfree((char *) argv); + return TCL_ERROR; } else if (HaveOpt(1, "-translation")) { const char *readMode, *writeMode; diff --git a/generic/tclIO.h b/generic/tclIO.h index b799375..f7ce677 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -282,6 +282,8 @@ typedef struct ChannelState { #define CHANNEL_CLOSEDWRITE (1<<21) /* Channel write side has been closed. * No further Tcl-level write IO on * the channel is allowed. */ +#define CHANNEL_EXIT_ON_EPIPE (1<<22) /* Exit on EPIPE (broken pipe) error + * on the stdout channel. */ /* * The length of time to wait between synthetic timer events. Must be zero or diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index 834f225..1a0a2f9 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -10,6 +10,7 @@ */ #include "tclInt.h" +#include "tclIO.h" /* * Callback structure for accept callback in a TCP server. @@ -203,6 +204,11 @@ Tcl_PutsObjCmd( */ error: + if ((chan == Tcl_GetStdChannel(TCL_STDOUT)) && + (((Channel *)chan)->state->flags & CHANNEL_EXIT_ON_EPIPE)) { + Tcl_Exit(0); + /*NOTREACHED*/ + } if (!TclChanCaughtErrorBypass(interp, chan)) { Tcl_SetObjResult(interp, Tcl_ObjPrintf("error writing \"%s\": %s", TclGetString(chanObjPtr), Tcl_PosixError(interp))); diff --git a/generic/tclIOSock.c b/generic/tclIOSock.c index d578d19..8d8ee67 100644 --- a/generic/tclIOSock.c +++ b/generic/tclIOSock.c @@ -288,6 +288,35 @@ TclCreateSocketAddress( } /* + * Work around an omission in earlier versions of MinGW. + */ +#ifdef __MINGW32__ +char* WSAAPI +gai_strerrorA(int ecode) +{ + static char message[1024+1]; + DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_MAX_WIDTH_MASK; + DWORD dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); + FormatMessageA(dwFlags, NULL, ecode, dwLanguageId, (LPSTR)message, 1024, NULL); + return message; +} + +WCHAR* WSAAPI +gai_strerrorW(int ecode) +{ + static WCHAR message[1024+1]; + DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_IGNORE_INSERTS + | FORMAT_MESSAGE_MAX_WIDTH_MASK; + DWORD dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); + FormatMessageW(dwFlags, NULL, ecode, dwLanguageId, (LPWSTR)message, 1024, NULL); + return message; +} +#endif + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index 1330c02..af544c3 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -13,6 +13,7 @@ * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright (c) 2001-2004 Vincent Darley. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -23,6 +24,7 @@ # include "tclWinInt.h" #endif #include "tclFileSystem.h" +#include "Lcompile.h" #ifdef TCL_TEMPLOAD_NO_UNLINK #ifndef NO_FSTATFS @@ -80,6 +82,8 @@ static void FsAddMountsToGlobResult(Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types); static void FsUpdateCwd(Tcl_Obj *cwdObj, ClientData clientData); +static Tcl_Obj * FsMaybeWrapInLLang(Tcl_Interp *interp, + Tcl_Obj *fileContents, const char *path); static void FsRecacheFilesystemList(void); static void Claim(void); static void Disclaim(void); @@ -1817,15 +1821,14 @@ Tcl_FSEvalFileEx( oldScriptFile = iPtr->scriptFile; iPtr->scriptFile = pathPtr; Tcl_IncrRefCount(iPtr->scriptFile); - string = Tcl_GetStringFromObj(objPtr, &length); - /* - * TIP #280 Force the evaluator to open a frame for a sourced file. - */ + objPtr = FsMaybeWrapInLLang(interp, objPtr, Tcl_GetString(pathPtr)); + string = Tcl_GetStringFromObj(objPtr, &length); + /* TIP #280 Force the evaluator to open a frame for a sourced + * file. */ iPtr->evalFlags |= TCL_EVAL_FILE; result = TclEvalEx(interp, string, length, 0, 1, NULL, string); - /* * Now we have to be careful; the script may have changed the * iPtr->scriptFile value, so we must reset it without assuming it still @@ -1955,6 +1958,8 @@ TclNREvalFile( iPtr->scriptFile = pathPtr; Tcl_IncrRefCount(iPtr->scriptFile); + objPtr = FsMaybeWrapInLLang(interp, objPtr, Tcl_GetString(pathPtr)); + /* * TIP #280: Force the evaluator to open a frame for a sourced file. */ @@ -1975,7 +1980,6 @@ EvalFileCallback( Tcl_Obj *oldScriptFile = data[0]; Tcl_Obj *pathPtr = data[1]; Tcl_Obj *objPtr = data[2]; - /* * Now we have to be careful; the script may have changed the * iPtr->scriptFile value, so we must reset it without assuming it still @@ -2010,6 +2014,47 @@ EvalFileCallback( } /* + * Handle L and html/L code. + * + * If the path ends in .l, precede the file contents with #lang L. + * If the path ends in .lhtml, with #lang Lhtml. + * + * Return a Tcl_Obj containing the potentially wrapped string. + */ +static Tcl_Obj * +FsMaybeWrapInLLang( + Tcl_Interp *interp, + Tcl_Obj *fileContents, + const char *path) +{ + int flen; + int plen = strlen(path); + char *s = Tcl_GetStringFromObj(fileContents, &flen); + char *append = ""; + Tcl_Obj *newContents; + + /* Append a newline if not already there. */ + if (flen && (s[flen-1] != '\n')) append = "\n"; + + if (((plen >= 2) && (path[plen-2] == '.') && (path[plen-1] == 'l')) || + (L && L->global->forceL)) { + newContents = Tcl_ObjPrintf("#lang L --lineadj=-1\n%s%s#lang tcl", + s, append); + Tcl_DecrRefCount(fileContents); + Tcl_IncrRefCount(newContents); + fileContents = newContents; + if (L) L->global->forceL = 0; + } else if ((plen >= 6) && !strcmp(path+plen-6, ".lhtml")) { + newContents = Tcl_ObjPrintf("#lang Lhtml --lineadj=-1\n%s%s#lang tcl", + s, append); + Tcl_DecrRefCount(fileContents); + Tcl_IncrRefCount(newContents); + fileContents = newContents; + } + return fileContents; +} + +/* *---------------------------------------------------------------------- * * Tcl_GetErrno -- diff --git a/generic/tclInt.h b/generic/tclInt.h index 356d250..d90fb99 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -11,6 +11,7 @@ * Copyright (c) 2007 Daniel A. Steffen <das@users.sourceforge.net> * Copyright (c) 2006-2008 by Joe Mistachkin. All rights reserved. * Copyright (c) 2008 by Miguel Sofer. All rights reserved. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -48,6 +49,9 @@ #else #include <string.h> #endif +#ifdef HAVE_STRINGS_H +#include <strings.h> +#endif #ifdef STDC_HEADERS #include <stddef.h> #else @@ -2252,6 +2256,7 @@ typedef struct Interp { * script in progress has been canceled thereby allowing * the evaluation stack for the interp to be fully * unwound. + * INTERP_PCRE Non-zero means use PCRE engine by default for REs * * WARNING: For the sake of some extensions that have made use of former * internal values, do not re-use the flag values 2 (formerly ERR_IN_PROGRESS) @@ -2264,6 +2269,7 @@ typedef struct Interp { #define DONT_COMPILE_CMDS_INLINE 0x20 #define RAND_SEED_INITIALIZED 0x40 #define SAFE_INTERP 0x80 +#define INTERP_PCRE 0x100 #define INTERP_TRACE_IN_PROGRESS 0x200 #define INTERP_ALTERNATE_WRONG_ARGS 0x400 #define ERR_LEGACY_COPY 0x800 @@ -2484,7 +2490,7 @@ typedef struct List { * * DICT_PATH_UPDATE indicates that we are going to be doing an update at the * tip of the path, so duplication of shared objects should be done along the - * way. + * way. * * DICT_PATH_EXISTS indicates that we are performing an existance test and a * lookup failure should therefore not be an error. If (and only if) this flag @@ -2883,6 +2889,7 @@ MODULE_SCOPE void TclContinuationsCopy(Tcl_Obj *objPtr, MODULE_SCOPE int TclConvertElement(const char *src, int length, char *dst, int flags); MODULE_SCOPE void TclDeleteNamespaceVars(Namespace *nsPtr); +MODULE_SCOPE void TclDuplicateListRep(Tcl_Obj *objPtr); MODULE_SCOPE int TclFindDictElement(Tcl_Interp *interp, const char *dict, int dictLength, const char **elementPtr, const char **nextPtr, @@ -2989,6 +2996,9 @@ MODULE_SCOPE int TclIsSpaceProc(char byte); MODULE_SCOPE int TclIsBareword(char byte); MODULE_SCOPE Tcl_Obj * TclJoinPath(int elements, Tcl_Obj * const objv[]); MODULE_SCOPE int TclJoinThread(Tcl_ThreadId id, int *result); +MODULE_SCOPE void TclLInitCompiler(Tcl_Interp *interp); +MODULE_SCOPE void TclLCleanupCompiler(ClientData clientData, + Tcl_Interp *interp); MODULE_SCOPE void TclLimitRemoveAllHandlers(Tcl_Interp *interp); MODULE_SCOPE Tcl_Obj * TclLindexList(Tcl_Interp *interp, Tcl_Obj *listPtr, Tcl_Obj *argPtr); @@ -3269,6 +3279,9 @@ MODULE_SCOPE int Tcl_FconfigureObjCmd( MODULE_SCOPE int Tcl_FcopyObjCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_FGetlineObjCmd(ClientData dummy, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE Tcl_Command TclInitFileCmd(Tcl_Interp *interp); MODULE_SCOPE int TclMakeFileCommandSafe(Tcl_Interp *interp); MODULE_SCOPE int Tcl_FileEventObjCmd(ClientData clientData, @@ -3286,6 +3299,12 @@ MODULE_SCOPE int Tcl_ForeachObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_FormatObjCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_GetOptObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_GetOptResetObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_GetsObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -3311,9 +3330,24 @@ MODULE_SCOPE int Tcl_JoinObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_LappendObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LAngleReadObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_LassignObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LDefined(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LGetNextLine(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LGetNextLineInit(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LGetDirX(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_LindexObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -3335,6 +3369,12 @@ MODULE_SCOPE int Tcl_LoadObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_LrangeObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LReadCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LRefCnt(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_LrepeatObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -3353,6 +3393,9 @@ MODULE_SCOPE int Tcl_LsetObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_LsortObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LWriteCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE Tcl_Command TclInitNamespaceCmd(Tcl_Interp *interp); MODULE_SCOPE int TclNamespaceEnsembleCmd(ClientData dummy, Tcl_Interp *interp, int objc, @@ -3400,6 +3443,9 @@ MODULE_SCOPE int Tcl_SeekObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_SetObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_ShSplitObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_SplitObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -3454,6 +3500,16 @@ MODULE_SCOPE int Tcl_VwaitObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_WhileObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LHtmlObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_PtrObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); + /* *---------------------------------------------------------------- @@ -3959,6 +4015,17 @@ MODULE_SCOPE int TclObjCallVarTraces(Interp *iPtr, Var *arrayPtr, int flags, int leaveErrMsg, int index); /* + * The variant RE engines + */ + +MODULE_SCOPE int TclRegexpClassic(Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[], Tcl_RegExp regExpr, + int all, int indices, int doinline, int offset); +MODULE_SCOPE int TclRegexpPCRE(Tcl_Interp *interp, int objc, + Tcl_Obj *CONST objv[], Tcl_RegExp regExpr, + int all, int indices, int doinline, int offset); + +/* * So tclObj.c and tclDictObj.c can share these implementations. */ @@ -4064,7 +4131,8 @@ typedef const char *TclDTraceStr; */ # define TclAllocObjStorageEx(interp, objPtr) \ - (objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj)) + (objPtr) = (Tcl_Obj *) ckalloc(sizeof(Tcl_Obj)); \ + (objPtr)->undef = 0 # define TclFreeObjStorageEx(interp, objPtr) \ ckfree((char *) (objPtr)) @@ -4109,6 +4177,7 @@ MODULE_SCOPE void TclpFreeAllocCache(void *); cachePtr->firstObjPtr = (objPtr)->internalRep.twoPtrValue.ptr1; \ --cachePtr->numObjects; \ } \ + (objPtr)->undef = 0; \ } while (0) # define TclFreeObjStorageEx(interp, objPtr) \ @@ -4150,6 +4219,7 @@ MODULE_SCOPE Tcl_Mutex tclObjMutex; tclFreeObjList = (Tcl_Obj *) \ tclFreeObjList->internalRep.twoPtrValue.ptr1; \ Tcl_MutexUnlock(&tclObjMutex); \ + (objPtr)->undef = 0; \ } while (0) # define TclFreeObjStorageEx(interp, objPtr) \ diff --git a/generic/tclInterp.c b/generic/tclInterp.c index 0da5d47..8929102 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -489,6 +489,7 @@ TclInterpInit( Tcl_NRCreateCommand(interp, "interp", Tcl_InterpObjCmd, NRInterpCmd, NULL, NULL); + TclLInitCompiler(interp); Tcl_CallWhenDeleted(interp, InterpInfoDeleteProc, NULL); return TCL_OK; @@ -615,7 +616,8 @@ NRInterpCmd( "eval", "exists", "expose", "hide", "hidden", "issafe", "invokehidden", "limit", "marktrusted", "recursionlimit", - "slaves", "share", "target", "transfer", + "regexp", "slaves", "share", "target", + "transfer", NULL }; enum option { @@ -624,7 +626,8 @@ NRInterpCmd( OPT_EVAL, OPT_EXISTS, OPT_EXPOSE, OPT_HIDE, OPT_HIDDEN, OPT_ISSAFE, OPT_INVOKEHID, OPT_LIMIT, OPT_MARKTRUSTED,OPT_RECLIMIT, - OPT_SLAVES, OPT_SHARE, OPT_TARGET, OPT_TRANSFER + OPT_REGEXP, OPT_SLAVES, OPT_SHARE, OPT_TARGET, + OPT_TRANSFER }; if (objc < 2) { @@ -1034,6 +1037,41 @@ NRInterpCmd( Tcl_SetObjResult(interp, resultPtr); return TCL_OK; } + case OPT_REGEXP: { + int re_type; + Interp *slaveInterp; + static CONST char *re_type_opts[] = { + "classic", "pcre", NULL + }; + enum re_type_opts { + RETYPE_CLASSIC, RETYPE_PCRE, + }; + if (objc != 3 && objc != 4) { + Tcl_WrongNumArgs(interp, 2, objv, "path ?type?"); + return TCL_ERROR; + } + slaveInterp = (Interp *) GetInterp(interp, objv[2]); + if (slaveInterp == NULL) { + return TCL_ERROR; + } + if (objc == 4) { + if (Tcl_GetIndexFromObj(interp, objv[3], re_type_opts, "type", + 0, &re_type) != TCL_OK) { + return TCL_ERROR; + } + if ((enum re_type_opts) re_type == RETYPE_PCRE) { + slaveInterp->flags |= INTERP_PCRE; + } else { + slaveInterp->flags &= ~(INTERP_PCRE); + } + } + if (slaveInterp->flags & INTERP_PCRE) { + Tcl_SetObjResult(interp, Tcl_NewStringObj("pcre", -1)); + } else { + Tcl_SetObjResult(interp, Tcl_NewStringObj("classic", -1)); + } + return TCL_OK; + } case OPT_TRANSFER: case OPT_SHARE: { Tcl_Interp *masterInterp; /* The master of the slave. */ diff --git a/generic/tclListObj.c b/generic/tclListObj.c index fa67ee6..72bc6da 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -577,6 +577,7 @@ Tcl_ListObjAppendElement( if (listPtr->bytes == tclEmptyStringRep) { Tcl_SetListObj(listPtr, 1, &objPtr); + listPtr->undef = 0; return TCL_OK; } result = SetListFromAny(interp, listPtr); @@ -691,6 +692,7 @@ Tcl_ListObjAppendElement( *(&listRepPtr->elements + listRepPtr->elemCount) = objPtr; Tcl_IncrRefCount(objPtr); listRepPtr->elemCount++; + listPtr->undef = 0; /* * Invalidate any old string representation since the list's internal @@ -865,6 +867,7 @@ Tcl_ListObjReplace( if (listPtr->typePtr != &tclListType) { if (listPtr->bytes == tclEmptyStringRep) { if (!objc) { + listPtr->undef = 0; return TCL_OK; } Tcl_SetListObj(listPtr, objc, NULL); @@ -1058,6 +1061,7 @@ Tcl_ListObjReplace( */ TclInvalidateStringRep(listPtr); + listPtr->undef = 0; return TCL_OK; } @@ -2000,6 +2004,48 @@ UpdateStringOfList( } /* + *---------------------------------------------------------------------- + * + * TclDuplicateListRep -- + * + * Create an unshared copy of a list's internal representation. + * + * Results: + * None. + * + * Side effects: + * The object's internal representation is changed to point to + * a newly allocated copy of its old representation. + * + *---------------------------------------------------------------------- + */ + +void +TclDuplicateListRep(Tcl_Obj *objPtr) +{ + int i, numElems; + List *listRepPtr, *oldListRepPtr; + Tcl_Obj **elemPtrs, **oldElems; + + listRepPtr = (List *)objPtr->internalRep.twoPtrValue.ptr1; + if (listRepPtr->refCount > 1) { + oldListRepPtr = listRepPtr; + numElems = listRepPtr->elemCount; + listRepPtr = NewListIntRep(listRepPtr->maxElemCount, NULL, 1); + oldElems = &oldListRepPtr->elements; + elemPtrs = &listRepPtr->elements; + for (i=0; i<numElems; i++) { + elemPtrs[i] = oldElems[i]; + Tcl_IncrRefCount(elemPtrs[i]); + } + listRepPtr->elemCount = numElems; + listRepPtr->refCount++; + oldListRepPtr->refCount--; + objPtr->internalRep.twoPtrValue.ptr1 = (void *) listRepPtr; + } +} + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/generic/tclMain.c b/generic/tclMain.c index 927de7e..8c3888e 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -11,6 +11,7 @@ * Copyright (c) 1988-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright (c) 2000 Ajuba Solutions. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -32,6 +33,7 @@ # endif #endif +#include "Lcompile.h" #include "tclInt.h" /* @@ -309,9 +311,11 @@ Tcl_MainEx( * but before starting to execute commands. */ Tcl_Interp *interp) { - Tcl_Obj *path, *resultPtr, *argvPtr, *appName; + Tcl_Obj *path, *resultPtr, *argvPtr, *appName, *LObj; + int commandLen; + char *commandStr; const char *encodingName = NULL; - int code, exitCode = 0; + int code, exitCode = 0, isL = 0; Tcl_MainLoopProc *mainLoopProc; Tcl_Channel chan; InteractiveState is; @@ -333,12 +337,18 @@ Tcl_MainEx( if (NULL == Tcl_GetStartupScript(NULL)) { /* - * Check whether first 3 args (argv[1] - argv[3]) look like + * Check whether initial args (argv[1] and beyond) look like * -encoding ENCODING FILENAME * or like - * FILENAME + * [-opt1] [-opt2] ... [-optn] FILENAME */ + /* Create argv list obj for L. */ + L->global->tclsh_argc = 1; + L->global->tclsh_argv = Tcl_NewObj(); + Tcl_ListObjAppendElement(NULL, L->global->tclsh_argv, + NewNativeObj(argv[0], -1)); + if ((argc > 3) && (0 == _tcscmp(TEXT("-encoding"), argv[1])) && ('-' != argv[3][0])) { Tcl_Obj *value = NewNativeObj(argv[2], -1); @@ -347,10 +357,21 @@ Tcl_MainEx( Tcl_DecrRefCount(value); argc -= 3; argv += 3; - } else if ((argc > 1) && ('-' != argv[1][0])) { - Tcl_SetStartupScript(NewNativeObj(argv[1], -1), NULL); - argc--; - argv++; + } else if (argc > 1) { + /* Pass over all options to look for a file name. */ + int i; + Tcl_Obj *argObj; + for (i = 1; i < argc; ++i) { + argObj = NewNativeObj(argv[i], -1); + Tcl_ListObjAppendElement(NULL, L->global->tclsh_argv, argObj); + ++L->global->tclsh_argc; + if ('-' != argv[i][0]) { + Tcl_SetStartupScript(argObj, NULL); + argc -= i; + argv += i; + break; + } + } } } @@ -365,12 +386,15 @@ Tcl_MainEx( argv++; Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(argc), TCL_GLOBAL_ONLY); + L->global->script_argc = argc; argvPtr = Tcl_NewListObj(0, NULL); while (argc--) { Tcl_ListObjAppendElement(NULL, argvPtr, NewNativeObj(*argv++, -1)); } Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY); + L->global->script_argv = argvPtr; + Tcl_IncrRefCount(argvPtr); /* * Set the "tcl_interactive" variable. @@ -416,6 +440,31 @@ Tcl_MainEx( path = Tcl_GetStartupScript(&encodingName); if (path != NULL) { + int argc, i; + char *av0path; + Tcl_Obj **argvObjs, *pathObj; + + /* + * Set L->global->forceL if argv[0] is "L", or "-L" or "--L" was given + * as a cmd-line option. This causes Tcl_FSEvalFileEx() to wrap the + * input file in a #lang L regardless of its extension. + */ + if (L->global->tclsh_argv) { + Tcl_ListObjGetElements(interp, L->global->tclsh_argv, &argc, + &argvObjs); + pathObj = Tcl_FSGetNormalizedPath(interp, argvObjs[0]); + av0path = Tcl_GetString(pathObj); + if (av0path) { + L->global->forceL = (!strcmp(av0path+strlen(av0path)-2, "/L")); + } + for (i = 1; i < argc; ++i) { + if (!strcmp(Tcl_GetString(argvObjs[i]), "--L") || + !strcmp(Tcl_GetString(argvObjs[i]), "-L")) { + L->global->forceL = 1; + } + } + } + Tcl_ResetResult(interp); code = Tcl_FSEvalFileEx(interp, path, encodingName); if (code != TCL_OK) { @@ -462,6 +511,7 @@ Tcl_MainEx( * Get a new value for tty if anyone writes to ::tcl_interactive */ + Tcl_LinkVar(interp, "L", (char *) &isL, TCL_LINK_BOOLEAN); Tcl_LinkVar(interp, "tcl_interactive", (char *) &is.tty, TCL_LINK_BOOLEAN); is.input = Tcl_GetStdChannel(TCL_STDIN); while ((is.input != NULL) && !Tcl_InterpDeleted(interp)) { @@ -509,6 +559,17 @@ Tcl_MainEx( } /* + * Check for the #lang comments and sub them out for + * meaningful commands. + */ + commandStr = Tcl_GetStringFromObj(is.commandPtr, &commandLen); + if (!isL && strncasecmp(commandStr, "#lang l", 7) == 0) { + Tcl_SetStringObj(is.commandPtr, "set ::L 1", -1); + } else if (isL && strncasecmp(commandStr, "#lang tcl", 9) == 0) { + Tcl_SetStringObj(is.commandPtr, "set('::L',0);", -1); + } + + /* * Add the newline removed by Tcl_GetsObj back to the string. Have * to add it back before testing completeness, because it can make * a difference. [Bug 1775878] @@ -527,6 +588,18 @@ Tcl_MainEx( is.prompt = PROMPT_START; + if (isL) { + LObj = Tcl_NewStringObj("L {", -1); + Tcl_AppendObjToObj(LObj, is.commandPtr); + if (commandStr[commandLen-1] != ';') { + Tcl_AppendToObj(LObj, ";", -1); + } + Tcl_AppendToObj(LObj, "}\n", -1); + Tcl_DecrRefCount(is.commandPtr); + is.commandPtr = LObj; + Tcl_IncrRefCount(is.commandPtr); + } + /* * The final newline is syntactically redundant, and causes some * error messages troubles deeper in, so lop it back off. diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index dfab185..65d4f39 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -4853,7 +4853,7 @@ TclLogCommandInfo( { register const char *p; Interp *iPtr = (Interp *) interp; - int overflow, limit = 150; + int overflow, limit = 150, line; Var *varPtr, *arrayPtr; if (iPtr->flags & ERR_ALREADY_LOGGED) { @@ -4867,12 +4867,18 @@ TclLogCommandInfo( if (command != NULL) { /* - * Compute the line number where the error occurred. + * Compute the line number where the error occurred, honoring #line + * directives generated by the L compiler. */ iPtr->errorLine = 1; + if (!strncmp(script,"#line ",6) && ((line = strtoul(script+6,NULL,10)) > 0)) { + iPtr->errorLine = line - 1; + } for (p = script; p != command; p++) { - if (*p == '\n') { + if (!strncmp(p,"\n#line ",7) && ((line = strtoul(p+7,NULL,10)) > 0)) { + iPtr->errorLine = line - 1; + } else if (*p == '\n') { iPtr->errorLine++; } } diff --git a/generic/tclObj.c b/generic/tclObj.c index c641152..452160d 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -1064,6 +1064,7 @@ TclDbInitNewObj( objPtr->bytes = tclEmptyStringRep; objPtr->length = 0; objPtr->typePtr = NULL; + objPtr->undef = 0; #ifdef TCL_THREADS /* @@ -1576,6 +1577,7 @@ TclObjBeingDeleted( (dupPtr)->typePtr = typePtr; \ } \ } \ + (dupPtr)->undef = (objPtr)->undef; \ } Tcl_Obj * @@ -1886,6 +1888,10 @@ Tcl_GetBooleanFromObj( register Tcl_Obj *objPtr, /* The object from which to get boolean. */ register int *boolPtr) /* Place to store resulting boolean. */ { + if (objPtr->undef) { + *boolPtr = 0; + return TCL_OK; + } do { if (objPtr->typePtr == &tclIntType) { *boolPtr = (objPtr->internalRep.longValue != 0); diff --git a/generic/tclParse.c b/generic/tclParse.c index 95abc45..1a83df4 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -8,6 +8,7 @@ * Copyright (c) 1997 Sun Microsystems, Inc. * Copyright (c) 1998-2000 Ajuba Solutions. * Contributions from Don Porter, NIST, 2002. (not subject to US copyright) + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -16,6 +17,7 @@ #include "tclInt.h" #include "tclParse.h" #include <assert.h> +#include "Last.h" /* * The following table provides parsing information about each possible 8-bit @@ -160,6 +162,8 @@ const char tclCharTypeTable[] = { * Prototypes for local functions defined in this file: */ +static int ParseLang(Tcl_Interp *interp, const char *src, + int numBytes, Tcl_Parse *parsePtr, int *scanned); static inline int CommandComplete(const char *script, int numBytes); static int ParseComment(const char *src, int numBytes, Tcl_Parse *parsePtr); @@ -171,6 +175,105 @@ static int ParseWhiteSpace(const char *src, int numBytes, /* *---------------------------------------------------------------------- * + * ParseLang -- + * Scans up to numBytes bytes starting at src, consuming a Tcl lang + * directive. + * + * Results: + * Records in parsePtr information about the parse. Returns either + * TCL_BREAK, meaning the parsing should continue, TCL_OK meaning + * a Language directive was succesfully consumed, or TCL_ERROR meaning + * the lang directive was incomplete (missing end #lang or missing EOF) + * or there was some kind of an error + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +static int +ParseLang( + Tcl_Interp *interp, /* Tcl interpreter */ + CONST char *src, /* First character to parse. */ + register int numBytes, /* Max number of bytes to scan. */ + Tcl_Parse *parsePtr, /* Information about parse in progress. + * Updated if parsing indicates an incomplete + * command. */ + int *scanned) /* How many bytes we used */ +{ + register CONST char *p = src; + char *eol, *end; + Tcl_Token *tokenPtr; + Tcl_Parse optsParse; + int wordIdx; + char *message = "malformed pragma"; + + p += 5; + eol = strchr(p, '\n') + 1; + /* in case there's no \n, use the end of the string instead */ + if (eol == (char *)1) { + eol = (char *)src + numBytes; + } + if (Tcl_ParseCommand(interp, p, eol - p, 0, &optsParse) != TCL_OK) { + goto error; + } + if (optsParse.numWords < 1) goto error; + tokenPtr = optsParse.tokenPtr; + if (tokenPtr->type != TCL_TOKEN_SIMPLE_WORD) goto error; + tokenPtr++; + if (!strncasecmp("tcl", tokenPtr->start, tokenPtr->size)) { + /* treat #lang tcl as a comment */ + if (!parsePtr->commentStart) { + parsePtr->commentStart = src; + } + parsePtr->commentSize = eol - src; + parsePtr->commandStart = NULL; + parsePtr->commandSize = 0; + *scanned = eol - src; + return TCL_BREAK; + } + if (!strncmp("L", tokenPtr->start, tokenPtr->size) || + !strncmp("Lhtml", tokenPtr->start, tokenPtr->size)) { + /* it's L code, so do the parse again, but side-effect the parsePtr + * this time */ + Tcl_ParseCommand(interp, p, eol - p, 0, parsePtr); + /* now tack on one more word for the L code */ + /* XXX strstr is not safe -- it expects a NULL on the end. */ + end = strstr(eol, "\n#lang"); + if (!end) { + end = (char *)src + numBytes - 1; + } + TclGrowParseTokenArray(parsePtr, 2); + wordIdx = parsePtr->numTokens; + tokenPtr = &parsePtr->tokenPtr[wordIdx]; + tokenPtr->type = TCL_TOKEN_SIMPLE_WORD; + tokenPtr->start = eol; + tokenPtr->size = end - tokenPtr->start + 1; + tokenPtr->numComponents = 1; + parsePtr->numTokens++; + parsePtr->numWords++; + + tokenPtr = &parsePtr->tokenPtr[wordIdx+1]; + *tokenPtr = parsePtr->tokenPtr[wordIdx]; + tokenPtr->type = TCL_TOKEN_TEXT; + tokenPtr->numComponents = 0; + parsePtr->numTokens++; + parsePtr->commandSize = end - p; + return TCL_OK; + } + error: + parsePtr->commandStart = src; + parsePtr->commandSize = eol - src; + if (interp) { + Tcl_SetResult(interp, message, TCL_STATIC); + } + Tcl_FreeParse(parsePtr); + return TCL_ERROR; +} + +/* + *---------------------------------------------------------------------- + * * TclParseInit -- * * Initialize the fields of a Tcl_Parse struct. @@ -282,9 +385,10 @@ Tcl_ParseCommand( * Parse any leading space and comments before the first word of the * command. */ - - scanned = ParseComment(start, numBytes, parsePtr); - src = (start + scanned); + src = start; +comments: + scanned = ParseComment(src, numBytes, parsePtr); + src += scanned; numBytes -= scanned; if (numBytes == 0) { if (nested) { @@ -293,6 +397,19 @@ Tcl_ParseCommand( } /* + * Check for lang + */ + + if (strncmp(src, "#lang", 5) == 0) { + int rc = ParseLang(interp, src, numBytes, parsePtr, &scanned); + if (rc != TCL_BREAK) return rc; + src += scanned; + numBytes -= scanned; + if (numBytes > 0) + goto comments; + } + + /* * The following loop parses the words of the command, one word in each * iteration through the loop. */ @@ -1033,7 +1150,7 @@ ParseComment( numBytes -= scanned; } while (numBytes && (*p == '\n') && (p++,numBytes--)); - if ((numBytes == 0) || (*p != '#')) { + if ((numBytes == 0) || (*p != '#') || (strncmp(p, "#lang", 5) == 0)) { break; } if (parsePtr->commentStart == NULL) { diff --git a/generic/tclPipe.c b/generic/tclPipe.c index 83fb818..1339d24 100644 --- a/generic/tclPipe.c +++ b/generic/tclPipe.c @@ -5,6 +5,7 @@ * as well as various utility routines used in managing subprocesses. * * Copyright (c) 1997 by Sun Microsystems, Inc. + * Copyright (c) 2007 BitMover, Inc. * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index ea25d4b..978316a 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -75,6 +75,12 @@ typedef struct ThreadSpecificData { struct TclRegexp *regexps[NUM_REGEXPS]; /* Compiled forms of above strings. Also * malloc-ed, or NULL if not in use yet. */ +#ifdef HAVE_PCRE + Tcl_RegExpIndices *matches; /* To support PCRE in Tcl_RegExpGetInfo, we + * need a classic info matches area to store + * data in. */ + int matchelems; /* length of matches */ +#endif } ThreadSpecificData; static Tcl_ThreadDataKey dataKey; @@ -253,8 +259,21 @@ Tcl_RegExpRange( } else { string = regexpPtr->string; } - *startPtr = Tcl_UtfAtIndex(string, regexpPtr->matches[index].rm_so); - *endPtr = Tcl_UtfAtIndex(string, regexpPtr->matches[index].rm_eo); + if (regexpPtr->flags & TCL_REG_PCRE) { +#ifdef HAVE_PCRE + /* XXX We could check for tclByteArrayType objPtr */ + int last = regexpPtr->details.rm_extend.rm_so; /* last offset */ + *startPtr = Tcl_UtfAtIndex(string, + regexpPtr->matches[index].rm_so - last); + *endPtr = Tcl_UtfAtIndex(string, + regexpPtr->matches[index].rm_eo - last); +#else + Tcl_Panic("Cannot get info for PCRE match"); +#endif + } else { + *startPtr = Tcl_UtfAtIndex(string, regexpPtr->matches[index].rm_so); + *endPtr = Tcl_UtfAtIndex(string, regexpPtr->matches[index].rm_eo); + } } } @@ -432,9 +451,9 @@ Tcl_RegExpExecObj( int flags) /* Regular expression execution flags. */ { TclRegexp *regexpPtr = (TclRegexp *) re; - Tcl_UniChar *udata; - int length; + int i, length; int reflags = regexpPtr->flags; + /* We could allow TCL_REG_PCRE to accept glob-fallback as well */ #define TCL_REG_GLOBOK_FLAGS \ (TCL_REG_ADVANCED | TCL_REG_NOSUB | TCL_REG_NOCASE) @@ -464,15 +483,109 @@ Tcl_RegExpExecObj( regexpPtr->string = NULL; regexpPtr->objPtr = textObj; - udata = Tcl_GetUnicodeFromObj(textObj, &length); + if (reflags & TCL_REG_PCRE) { +#ifdef HAVE_PCRE + const char *matchstr; + int match, pcreeflags, nm = (regexpPtr->re.re_nsub + 1) * 3; + int byteOffset, wlen; + unsigned long pcreopts; - if (offset > length) { - offset = length; - } - udata += offset; - length -= offset; + if (!(flags & TCL_REG_BYTEOFFSET)) { + wlen = Tcl_GetCharLength(textObj); + } + if (textObj->typePtr == &tclByteArrayType) { + matchstr = (const char*)Tcl_GetByteArrayFromObj(textObj, &length); + } else { + matchstr = (const char*)Tcl_GetStringFromObj(textObj, &length); + } + + pcreeflags = 0; + if (flags & TCL_REG_NOTBOL) { + pcreeflags |= PCRE_NOTBOL; + } + pcre_fullinfo(regexpPtr->pcre, NULL, PCRE_INFO_OPTIONS, &pcreopts); - return RegExpExecUniChar(interp, re, udata, length, nmatches, flags); + if (!(flags & TCL_REG_BYTEOFFSET)) { + /* To handle UTF8, convert offset from a char index to a byte offset. */ + if (offset > wlen) { + offset = wlen; + } + byteOffset = Tcl_UtfAtIndex(matchstr, offset) - matchstr; + if (byteOffset > length) { + byteOffset = length; + } + } else { + if (offset > length) { + offset = length; + } + byteOffset = offset; + } + + match = pcre_exec(regexpPtr->pcre, regexpPtr->study, + matchstr, length, byteOffset, pcreeflags, + (int *) regexpPtr->matches, nm); + + if (!(flags & TCL_REG_BYTEOFFSET)) { + /* + * For UTF8, we need the matches array as char offsets, but pcre + * returns byte offsets. Do the conversion. + * This could be sped up for lots of matches. + */ + for (i = 0; i < 2*match; ++i) { + int *p = &((int *)regexpPtr->matches)[i]; + *p = Tcl_NumUtfChars(matchstr, *p); + } + } + + /* + * Store last offset to support Tcl_RegExpGetInfo translation. + */ + if (match == PCRE_ERROR_NOMATCH) { + regexpPtr->details.rm_extend.rm_so = -1; + } else { + regexpPtr->details.rm_extend.rm_so = offset; + } + + /* + * Check for errors. + */ + + if (match == PCRE_ERROR_NOMATCH) { + return 0; + } else if (match == 0) { + if (interp != NULL) { + Tcl_AppendResult(interp, + "pcre_exec had insufficient capture space", NULL); + } + return -1; + } else if (match < -1) { + if (interp != NULL) { + char buf[32 + TCL_INTEGER_SPACE]; + sprintf(buf, "pcre_exec returned error code %d", match); + Tcl_AppendResult(interp, buf, NULL); + } + return -1; + } + return 1; +#else + if (interp != NULL) { + Tcl_AppendResult(interp, "PCRE not available", NULL); + } + return -1; +#endif + } else { + Tcl_UniChar *udata; + + udata = Tcl_GetUnicodeFromObj(textObj, &length); + + if (offset > length) { + offset = length; + } + udata += offset; + length -= offset; + + return RegExpExecUniChar(interp, re, udata, length, nmatches, flags); + } } /* @@ -535,7 +648,32 @@ Tcl_RegExpGetInfo( TclRegexp *regexpPtr = (TclRegexp *) regexp; infoPtr->nsubs = regexpPtr->re.re_nsub; - infoPtr->matches = (Tcl_RegExpIndices *) regexpPtr->matches; + if (regexpPtr->flags & TCL_REG_PCRE) { +#ifdef HAVE_PCRE + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + int i, last, *matches = (int *) regexpPtr->matches; + + /* + * This works both to initialize and extend matches as necessary + */ + if (tsdPtr->matchelems <= infoPtr->nsubs) { + tsdPtr->matchelems = infoPtr->nsubs + 1; + tsdPtr->matches = (Tcl_RegExpIndices *) + ckrealloc((char *) tsdPtr->matches, + sizeof(Tcl_RegExpIndices) * tsdPtr->matchelems); + } + last = regexpPtr->details.rm_extend.rm_so; /* last offset */ + for (i = 0; i <= infoPtr->nsubs; i++) { + tsdPtr->matches[i].start = matches[i*2] - last; + tsdPtr->matches[i].end = matches[i*2+1] - last; + } + infoPtr->matches = tsdPtr->matches; +#else + Tcl_Panic("Cannot get info for PCRE match"); +#endif + } else { + infoPtr->matches = (Tcl_RegExpIndices *) regexpPtr->matches; + } infoPtr->extendStart = regexpPtr->details.rm_extend.rm_so; } @@ -580,6 +718,10 @@ Tcl_GetRegExpFromObj( regexpPtr = objPtr->internalRep.twoPtrValue.ptr1; + /* XXX Need to have case where -type classic isn't ignored in regexp/sub */ + if ((interp != NULL) && (((Interp *)interp)->flags & INTERP_PCRE)) { + flags |= TCL_REG_PCRE; + } if ((objPtr->typePtr != &tclRegexpType) || (regexpPtr->flags != flags)) { pattern = TclGetStringFromObj(objPtr, &length); @@ -906,38 +1048,126 @@ CompileRegexp( */ regexpPtr = ckalloc(sizeof(TclRegexp)); - regexpPtr->objPtr = NULL; - regexpPtr->string = NULL; + memset(regexpPtr, 0, sizeof(TclRegexp)); + + regexpPtr->flags = flags; regexpPtr->details.rm_extend.rm_so = -1; regexpPtr->details.rm_extend.rm_eo = -1; - /* - * Get the up-to-date string representation and map to unicode. - */ + if (flags & TCL_REG_PCRE) { +#ifdef HAVE_PCRE + pcre *pcre; + char *p, *cstring = (char *) string; + const char *errstr; + int erroffset, rc, nsubs, pcrecflags; - Tcl_DStringInit(&stringBuf); - uniString = Tcl_UtfToUniCharDString(string, length, &stringBuf); - numChars = Tcl_DStringLength(&stringBuf) / sizeof(Tcl_UniChar); + /* + * Convert from Tcl classic to PCRE cflags + */ - /* - * Compile the string and check for errors. - */ + /* XXX Should enable PCRE_UTF8 selectively on non-ByteArray Tcl_Obj */ + pcrecflags = PCRE_NO_UTF8_CHECK | PCRE_DOLLAR_ENDONLY | PCRE_DOTALL; + for (i = 0, p = cstring; i < length; i++) { + if (UCHAR(*p++) > 0x80) { + pcrecflags |= PCRE_UTF8; + break; + } + } + if (flags & TCL_REG_NOCASE) { + pcrecflags |= PCRE_CASELESS; + } + if (flags & TCL_REG_EXPANDED) { + pcrecflags |= PCRE_EXTENDED; + } + /* TCL_REG_NLSTOP|TCL_REG_NLANCH == TCL_REG_NEWLINE */ + if (flags & TCL_REG_NLSTOP) { + pcrecflags &= ~(PCRE_DOTALL); + } + if (flags & TCL_REG_NLANCH) { + pcrecflags |= PCRE_MULTILINE; + pcrecflags &= ~(PCRE_DOLLAR_ENDONLY); + } - regexpPtr->flags = flags; - status = TclReComp(®expPtr->re, uniString, (size_t) numChars, flags); - Tcl_DStringFree(&stringBuf); + if (cstring[length] != 0) { + cstring = (char *) ckalloc(length + 1); + memcpy(cstring, string, length); + cstring[length] = 0; + } + pcre = pcre_compile(cstring, pcrecflags, &errstr, &erroffset, NULL); + regexpPtr->pcre = pcre; + if (cstring != (char *) string) { + ckfree(cstring); + } + + if (pcre == NULL) { + ckfree((char *)regexpPtr); + Tcl_AppendResult(interp, + "couldn't compile pcre pattern: ", errstr, NULL); + return NULL; + } + + regexpPtr->study = pcre_study(pcre, 0, &errstr); + if (errstr != NULL) { + pcre_free(pcre); + ckfree((char *)regexpPtr); + Tcl_AppendResult(interp, + "error studying pcre pattern: ", errstr, NULL); + return NULL; + } - if (status != REG_OKAY) { /* - * Clean up and report errors in the interpreter, if possible. + * Allocate enough space for all of the subexpressions, plus one extra + * for the entire pattern. */ - ckfree(regexpPtr); - if (interp) { - TclRegError(interp, - "couldn't compile regular expression pattern: ", status); + rc = pcre_fullinfo(pcre, NULL, PCRE_INFO_CAPTURECOUNT, &nsubs); + if (rc == 0) { + regexpPtr->re.re_nsub = nsubs; + regexpPtr->matches = (regmatch_t *) + ckalloc(sizeof(int) * (nsubs+1)*3); } +#else + Tcl_AppendResult(interp, + "couldn't compile pcre pattern: pcre unavailabe", NULL); return NULL; +#endif + } else { + /* + * Get the up-to-date string representation and map to unicode. + */ + + Tcl_DStringInit(&stringBuf); + uniString = Tcl_UtfToUniCharDString(string, length, &stringBuf); + numChars = Tcl_DStringLength(&stringBuf) / sizeof(Tcl_UniChar); + + /* + * Compile the string and check for errors. + */ + + status = TclReComp(®expPtr->re, uniString, (size_t) numChars, flags); + Tcl_DStringFree(&stringBuf); + + if (status != REG_OKAY) { + /* + * Clean up and report errors in the interpreter, if possible. + */ + + ckfree((char *)regexpPtr); + if (interp) { + TclRegError(interp, + "couldn't compile regular expression pattern: ", + status); + } + return NULL; + } + + /* + * Allocate enough space for all of the subexpressions, plus one extra + * for the entire pattern. + */ + + regexpPtr->matches = (regmatch_t *) ckalloc( + sizeof(regmatch_t) * (regexpPtr->re.re_nsub + 1)); } /* @@ -955,14 +1185,6 @@ CompileRegexp( } /* - * Allocate enough space for all of the subexpressions, plus one extra for - * the entire pattern. - */ - - regexpPtr->matches = - ckalloc(sizeof(regmatch_t) * (regexpPtr->re.re_nsub + 1)); - - /* * Initialize the refcount to one initially, since it is in the cache. */ @@ -1014,6 +1236,14 @@ static void FreeRegexp( TclRegexp *regexpPtr) /* Compiled regular expression to free. */ { +#ifdef HAVE_PCRE + if (regexpPtr->flags & TCL_REG_PCRE) { + pcre_free(regexpPtr->pcre); + if (regexpPtr->study) { + pcre_free(regexpPtr->study); + } + } else +#endif TclReFree(®expPtr->re); if (regexpPtr->globObjPtr) { TclDecrRefCount(regexpPtr->globObjPtr); @@ -1057,6 +1287,11 @@ FinalizeRegexp( tsdPtr->patterns[i] = NULL; } +#ifdef HAVE_PCRE + if (tsdPtr->matches != NULL) { + ckfree((char *) tsdPtr->matches); + } +#endif /* * We may find ourselves reinitialized if another finalization routine * invokes regexps. @@ -1066,6 +1301,448 @@ FinalizeRegexp( } /* + *---------------------------------------------------------------------- + * + * TclRegexpClassic -- + * + * This procedure processes a classic "regexp". + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +int +TclRegexpClassic( + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[], /* Argument objects. */ + Tcl_RegExp regExpr, + int all, + int indices, + int doinline, + int offset) +{ + int i, match, numMatchesSaved, matchLength; + int eflags, stringLength; + Tcl_Obj *objPtr, *resultPtr = NULL; + Tcl_RegExpInfo info; + + objPtr = objv[1]; + stringLength = Tcl_GetCharLength(objPtr); + + objc -= 2; + objv += 2; + + if (doinline) { + /* + * Save all the subexpressions, as we will return them as a list + */ + + numMatchesSaved = -1; + } else { + /* + * Save only enough subexpressions for matches we want to keep, expect + * in the case of -all, where we need to keep at least one to know + * where to move the offset. + */ + + numMatchesSaved = (objc == 0) ? all : objc; + } + + /* + * The following loop is to handle multiple matches within the same source + * string; each iteration handles one match. If "-all" hasn't been + * specified then the loop body only gets executed once. We terminate the + * loop when the starting offset is past the end of the string. + */ + + while (1) { + /* + * Pass either 0 or TCL_REG_NOTBOL in the eflags. Passing + * TCL_REG_NOTBOL indicates that the character at offset should not be + * considered the start of the line. If for example the pattern {^} is + * passed and -start is positive, then the pattern will not match the + * start of the string unless the previous character is a newline. + */ + + if (offset == 0) { + eflags = 0; + } else if (offset > stringLength) { + eflags = TCL_REG_NOTBOL; + } else if (Tcl_GetUniChar(objPtr, offset-1) == (Tcl_UniChar)'\n') { + eflags = 0; + } else { + eflags = TCL_REG_NOTBOL; + } + + match = Tcl_RegExpExecObj(interp, regExpr, objPtr, offset, + numMatchesSaved, eflags); + if (match < 0) { + return TCL_ERROR; + } + + if (match == 0) { + /* + * We want to set the value of the intepreter result only when + * this is the first time through the loop. + */ + + if (all <= 1) { + /* + * If inlining, the interpreter's object result remains an + * empty list, otherwise set it to an integer object w/ value + * 0. + */ + + if (!doinline) { + Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + } + return TCL_OK; + } + break; + } + + /* + * If additional variable names have been specified, return index + * information in those variables. + */ + + Tcl_RegExpGetInfo(regExpr, &info); + if (doinline) { + /* + * It's the number of substitutions, plus one for the matchVar at + * index 0 + */ + + objc = info.nsubs + 1; + if (all <= 1) { + resultPtr = Tcl_NewObj(); + } + } + for (i = 0; i < objc; i++) { + Tcl_Obj *newPtr; + + if (indices) { + int start, end; + Tcl_Obj *objs[2]; + + /* + * Only adjust the match area if there was a match for that + * area. (Scriptics Bug 4391/SF Bug #219232) + */ + + if (i <= info.nsubs && info.matches[i].start >= 0) { + start = offset + info.matches[i].start; + end = offset + info.matches[i].end; + + /* + * Adjust index so it refers to the last character in the + * match instead of the first character after the match. + */ + + if (end >= offset) { + end--; + } + } else { + start = -1; + end = -1; + } + + objs[0] = Tcl_NewLongObj(start); + objs[1] = Tcl_NewLongObj(end); + + newPtr = Tcl_NewListObj(2, objs); + } else { + if (i <= info.nsubs) { + newPtr = Tcl_GetRange(objPtr, + offset + info.matches[i].start, + offset + info.matches[i].end - 1); + } else { + newPtr = Tcl_NewObj(); + } + } + if (doinline) { + if (Tcl_ListObjAppendElement(interp, resultPtr, newPtr) + != TCL_OK) { + Tcl_DecrRefCount(newPtr); + Tcl_DecrRefCount(resultPtr); + return TCL_ERROR; + } + } else { + if (Tcl_ObjSetVar2(interp, objv[i], NULL, newPtr, + TCL_LEAVE_ERR_MSG) == NULL) { + return TCL_ERROR; + } + } + } + + if (all == 0) { + break; + } + + /* + * Adjust the offset to the character just after the last one in the + * matchVar and increment all to count how many times we are making a + * match. We always increment the offset by at least one to prevent + * endless looping (as in the case: regexp -all {a*} a). Otherwise, + * when we match the NULL string at the end of the input string, we + * will loop indefinately (because the length of the match is 0, so + * offset never changes). + */ + + matchLength = (info.matches[0].end - info.matches[0].start); + + offset += info.matches[0].end; + + /* + * A match of length zero could happen for {^} {$} or {.*} and in + * these cases we always want to bump the index up one. + */ + + if (matchLength == 0) { + offset++; + } + offset += info.matches[0].end; + all++; + eflags |= TCL_REG_NOTBOL; + if (offset >= stringLength) { + break; + } + } + + /* + * Set the interpreter's object result to an integer object with value 1 + * if -all wasn't specified, otherwise it's all-1 (the number of times + * through the while - 1). + */ + + if (doinline) { + Tcl_SetObjResult(interp, resultPtr); + } else { + Tcl_SetObjResult(interp, Tcl_NewIntObj(all ? all-1 : 1)); + } + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * TclRegexpPCRE -- + * + * This procedure processes a PCRE "regexp". + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +int +TclRegexpPCRE( + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[], /* Argument objects. */ + Tcl_RegExp regExpr, + int all, + int indices, + int doinline, + int offset) +{ +#ifdef HAVE_PCRE + int i, match, eflags, stringLength, matchelems, *matches; + Tcl_Obj *objPtr, *resultPtr = NULL; + const char *matchstr; + pcre *re; + pcre_extra *study; + TclRegexp *regexpPtr = (TclRegexp *) regExpr; + + objPtr = objv[1]; + if (objPtr->typePtr == &tclByteArrayType) { + matchstr = (const char*)Tcl_GetByteArrayFromObj(objPtr, &stringLength); + } else { + matchstr = (const char*)Tcl_GetStringFromObj(objPtr, &stringLength); + } + + eflags = PCRE_NO_UTF8_CHECK; + if (offset > 0) { + /* + * Translate offset into correct placement for utf-8 chars. + * Add flag if using offset (string is part of a larger string), so + * that "^" won't match. + */ + + if (objPtr->typePtr != &tclByteArrayType) { + /* XXX: probably needs length restriction */ + offset = Tcl_UtfAtIndex(matchstr, offset) - matchstr; + } + eflags |= PCRE_NOTBOL; + } + + objc -= 2; + objv += 2; + + /* + * The following loop is to handle multiple matches within the same source + * string; each iteration handles one match. If "-all" hasn't been + * specified then the loop body only gets executed once. We terminate the + * loop when the starting offset is past the end of the string. + */ + + re = regexpPtr->pcre; + study = regexpPtr->study; + matches = (int *) regexpPtr->matches; + matchelems = (int) (regexpPtr->re.re_nsub + 1) * 3; + while (1) { + match = pcre_exec(re, study, matchstr, stringLength, + offset, eflags, matches, matchelems); + + if (match < -1) { + char buf[32 + TCL_INTEGER_SPACE]; + sprintf(buf, "pcre_exec returned error code %d", match); + Tcl_AppendResult(interp, buf, NULL); + return TCL_ERROR; + } + + if (match == 0) { + Tcl_AppendResult(interp, + "pcre_exec had insufficient capture space", NULL); + return TCL_ERROR; + } + + if (match == PCRE_ERROR_NOMATCH) { + /* + * We want to set the value of the intepreter result only when + * this is the first time through the loop. + */ + + if (all <= 1) { + /* + * If inlining, the interpreter's object result remains an + * empty list, otherwise set it to an integer object w/ value + * 0. + */ + + if (!doinline) { + Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); + } + return TCL_OK; + } + break; + } + + /* + * If additional variable names have been specified, return index + * information in those variables. + */ + + if (doinline) { + /* + * It's the number of substitutions, plus one for the matchVar at + * index 0 + */ + + objc = match; + if (all <= 1) { + resultPtr = Tcl_NewObj(); + } + } + for (i = 0; i < objc; i++) { + Tcl_Obj *newPtr; + int start, end; + + if (i < match) { + start = matches[i*2]; + end = matches[i*2 + 1]; + } else { + start = -1; + end = -1; + } + if (indices) { + Tcl_Obj *objs[2]; + + objs[0] = Tcl_NewLongObj(start); + objs[1] = Tcl_NewLongObj((end < 0) ? end : end - 1); + + newPtr = Tcl_NewListObj(2, objs); + } else { + if (i < match) { + newPtr = Tcl_NewStringObj(matchstr + start, end - start); + } else { + newPtr = Tcl_NewObj(); + } + } + if (doinline) { + if (Tcl_ListObjAppendElement(interp, resultPtr, newPtr) + != TCL_OK) { + Tcl_DecrRefCount(newPtr); + Tcl_DecrRefCount(resultPtr); + return TCL_ERROR; + } + } else { + Tcl_Obj *valuePtr; + valuePtr = Tcl_ObjSetVar2(interp, objv[i], NULL, newPtr, 0); + if (valuePtr == NULL) { + Tcl_AppendResult(interp, "couldn't set variable \"", + TclGetString(objv[i]), "\"", NULL); + return TCL_ERROR; + } + } + } + + if (all == 0) { + break; + } + + /* + * Adjust the offset to the character just after the last one in the + * matchVar and increment all to count how many times we are making a + * match. We always increment the offset by at least one to prevent + * endless looping (as in the case: regexp -all {a*} a). Otherwise, + * when we match the NULL string at the end of the input string, we + * will loop indefinately (because the length of the match is 0, so + * offset never changes). + * matches[1] is the match end point of the full RE match. + */ + + if (matches[0] == matches[1]) { + offset++; + } else { + offset = matches[1]; + } + all++; + eflags |= PCRE_NOTBOL; + if (offset >= stringLength) { + break; + } + } + + /* + * Set the interpreter's object result to an integer object with value 1 + * if -all wasn't specified, otherwise it's all-1 (the number of times + * through the while - 1). + */ + + if (doinline) { + Tcl_SetObjResult(interp, resultPtr); + } else { + Tcl_SetObjResult(interp, Tcl_NewIntObj(all ? all-1 : 1)); + } + return TCL_OK; +#else /* !HAVE_PCRE */ + Tcl_AppendResult(interp, "PCRE not available", NULL); + return TCL_ERROR; +#endif +} + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/generic/tclRegexp.h b/generic/tclRegexp.h index 3b2433e..8ee674f 100644 --- a/generic/tclRegexp.h +++ b/generic/tclRegexp.h @@ -16,6 +16,10 @@ #include "regex.h" +#ifdef HAVE_PCRE +#include <pcre.h> +#endif + /* * The TclRegexp structure encapsulates a compiled regex_t, the flags that * were used to compile it, and an array of pointers that are used to indicate @@ -28,6 +32,10 @@ typedef struct TclRegexp { int flags; /* Regexp compile flags. */ regex_t re; /* Compiled re, includes number of * subexpressions. */ +#ifdef HAVE_PCRE + pcre *pcre; /* PCRE compile re */ + pcre_extra *study; /* study of PCRE */ +#endif const char *string; /* Last string passed to Tcl_RegExpExec. */ Tcl_Obj *objPtr; /* Last object passed to Tcl_RegExpExecObj. */ Tcl_Obj *globObjPtr; /* Glob pattern rep of RE or NULL if none. */ |