e576bb2002-10-11Martin Nilsson /* -*- c -*- || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
afbd442004-10-22Andreas (Kaos) Stenius || $Id: language.yacc,v 1.343 2004/10/22 14:42:16 grubba Exp $
e576bb2002-10-11Martin Nilsson */
1b10db2002-10-08Martin Nilsson 
215bed1996-09-28Fredrik Hübinette (Hubbe) %pure_parser
f76b4c2000-05-11Henrik Grubbström (Grubba)  %token TOK_ARROW
215bed1996-09-28Fredrik Hübinette (Hubbe)  /* * Basic value pushing */
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_CONSTANT TOK_FLOAT TOK_STRING %token TOK_NUMBER
215bed1996-09-28Fredrik Hübinette (Hubbe) /* * These are the predefined functions that can be accessed from Pike. */
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_INC TOK_DEC %token TOK_RETURN
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_EQ TOK_GE TOK_LE TOK_NE %token TOK_NOT %token TOK_LSH TOK_RSH %token TOK_LAND TOK_LOR %token TOK_SWITCH TOK_SSCANF TOK_CATCH %token TOK_FOREACH
215bed1996-09-28Fredrik Hübinette (Hubbe) 
db271d1998-04-27Henrik Grubbström (Grubba) /* This is the end of file marker used by the lexer * to enable nicer EOF in error handling. */
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_LEX_EOF %token TOK_ADD_EQ %token TOK_AND_EQ %token TOK_ARRAY_ID %token TOK_BREAK %token TOK_CASE %token TOK_CLASS %token TOK_COLON_COLON %token TOK_CONTINUE %token TOK_DEFAULT %token TOK_DIV_EQ %token TOK_DO %token TOK_DOT_DOT %token TOK_DOT_DOT_DOT %token TOK_ELSE
76e7f92001-03-18Henrik Grubbström (Grubba) %token TOK_ENUM
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_EXTERN %token TOK_FLOAT_ID %token TOK_FOR %token TOK_FUNCTION_ID %token TOK_GAUGE
3604362002-05-05Martin Stjernholm %token TOK_GLOBAL
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_IDENTIFIER %token TOK_IF %token TOK_IMPORT %token TOK_INHERIT %token TOK_INLINE %token TOK_LOCAL_ID %token TOK_FINAL_ID %token TOK_INT_ID %token TOK_LAMBDA %token TOK_MULTISET_ID %token TOK_MULTISET_END %token TOK_MULTISET_START %token TOK_LSH_EQ %token TOK_MAPPING_ID %token TOK_MIXED_ID %token TOK_MOD_EQ %token TOK_MULT_EQ %token TOK_NO_MASK %token TOK_OBJECT_ID %token TOK_OR_EQ %token TOK_PRIVATE %token TOK_PROGRAM_ID %token TOK_PROTECTED %token TOK_PREDEF %token TOK_PUBLIC %token TOK_RSH_EQ %token TOK_STATIC %token TOK_STRING_ID %token TOK_SUB_EQ
5e3aa52001-04-01Henrik Grubbström (Grubba) %token TOK_TYPEDEF
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_TYPEOF
8f733e2000-07-12Henrik Grubbström (Grubba) %token TOK_VARIANT
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_VOID_ID %token TOK_WHILE %token TOK_XOR_EQ %token TOK_OPTIONAL
215bed1996-09-28Fredrik Hübinette (Hubbe)  %right '=' %right '?'
f76b4c2000-05-11Henrik Grubbström (Grubba) %left TOK_LOR %left TOK_LAND
215bed1996-09-28Fredrik Hübinette (Hubbe) %left '|' %left '^' %left '&'
f76b4c2000-05-11Henrik Grubbström (Grubba) %left TOK_EQ TOK_NE %left '>' TOK_GE '<' TOK_LE /* nonassoc? */ %left TOK_LSH TOK_RSH
215bed1996-09-28Fredrik Hübinette (Hubbe) %left '+' '-'
413c8e1996-11-01Fredrik Hübinette (Hubbe) %left '*' '%' '/'
f76b4c2000-05-11Henrik Grubbström (Grubba) %right TOK_NOT '~' %nonassoc TOK_INC TOK_DEC
215bed1996-09-28Fredrik Hübinette (Hubbe)  %{ /* This is the grammar definition of Pike. */ #include "global.h" #ifdef HAVE_MEMORY_H #include <memory.h> #endif #include "interpret.h" #include "array.h" #include "object.h" #include "stralloc.h" #include "las.h" #include "interpret.h" #include "program.h" #include "pike_types.h" #include "constants.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
bb8a782000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) #include "docode.h"
4868db1997-05-07Per Hedbor #include "machine.h"
b9188f1999-12-13Henrik Grubbström (Grubba) #include "main.h"
f76b4c2000-05-11Henrik Grubbström (Grubba) #include "opcodes.h"
a418ce2001-03-31Henrik Grubbström (Grubba) #include "operators.h"
96c3932002-08-27Henrik Grubbström (Grubba) #include "bignum.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) #define YYMAXDEPTH 1000
215bed1996-09-28Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
8c77b61998-04-13Henrik Grubbström (Grubba) #ifndef YYDEBUG /* May also be defined by machine.h */
189fd01997-01-28Fredrik Hübinette (Hubbe) #define YYDEBUG 1
8c77b61998-04-13Henrik Grubbström (Grubba) #endif /* YYDEBUG */
189fd01997-01-28Fredrik Hübinette (Hubbe) #endif
4492b12002-01-03Henrik Grubbström (Grubba) /* Get verbose parse error reporting. */ #define YYERROR_VERBOSE 1
c68a292001-06-10Henrik Grubbström (Grubba) /* #define LAMBDA_DEBUG 1 */
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3699402001-02-20Henrik Grubbström (Grubba) int add_local_name(struct pike_string *, struct pike_type *, node *);
97f6282000-03-07Fredrik Hübinette (Hubbe) int low_add_local_name(struct compiler_frame *,
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_string *, struct pike_type *, node *);
4218011999-01-31Fredrik Hübinette (Hubbe) static node *lexical_islocal(struct pike_string *);
6cde992001-04-03Henrik Grubbström (Grubba) static void safe_inc_enum(void);
9036e82001-08-16Martin Stjernholm static int call_handle_import(struct pike_string *s);
215bed1996-09-28Fredrik Hübinette (Hubbe) 
8c64232000-06-26Henrik Grubbström (Grubba) static int inherit_depth; static struct program_state *inherit_state = NULL;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
cd89d71997-09-10Henrik Grubbström (Grubba) /* * Kludge for Bison not using prototypes. */ #ifndef __GNUC__ #ifndef __cplusplus
d5fa6a2002-09-24Henrik Grubbström (Grubba) static void __yy_memcpy(char *to, YY_FROM_CONST char *from, YY_COUNT_TYPE count);
cd89d71997-09-10Henrik Grubbström (Grubba) #endif /* !__cplusplus */ #endif /* !__GNUC__ */
215bed1996-09-28Fredrik Hübinette (Hubbe) %}
e2acf71997-04-23Henrik Grubbström (Grubba) 
215bed1996-09-28Fredrik Hübinette (Hubbe) %union { int number; FLOAT_TYPE fnum; struct node_s *n;
315aa81999-12-17Fredrik Hübinette (Hubbe)  char *str;
a993572002-10-12Henrik Grubbström (Grubba)  void *ptr;
215bed1996-09-28Fredrik Hübinette (Hubbe) }
e2acf71997-04-23Henrik Grubbström (Grubba) %{
4b974c1999-02-20Henrik Grubbström (Grubba) /* Needs to be included after YYSTYPE is defined. */
00dc302004-03-23Martin Stjernholm #define INCLUDED_FROM_LANGUAGE_YACC
4b974c1999-02-20Henrik Grubbström (Grubba) #include "lex.h" %} %{
7ee3801998-11-10Henrik Grubbström (Grubba) /* Include <stdio.h> our selves, so that we can do our magic * without being disturbed... */ #include <stdio.h>
e2acf71997-04-23Henrik Grubbström (Grubba) int yylex(YYSTYPE *yylval);
7ee3801998-11-10Henrik Grubbström (Grubba) /* Bison is stupid, and tries to optimize for space... */ #ifdef YYBISON #define short int #endif /* YYBISON */
a993572002-10-12Henrik Grubbström (Grubba) 
e2acf71997-04-23Henrik Grubbström (Grubba) %}
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <fnum> TOK_FLOAT %type <number> TOK_ARRAY_ID %type <number> TOK_BREAK %type <number> TOK_CASE %type <number> TOK_CATCH %type <number> TOK_CONTINUE %type <number> TOK_DEFAULT %type <number> TOK_DO %type <number> TOK_ELSE %type <number> TOK_FLOAT_ID %type <number> TOK_FOR %type <number> TOK_FOREACH %type <number> TOK_FUNCTION_ID %type <number> TOK_GAUGE %type <number> TOK_IF %type <number> TOK_INHERIT %type <number> TOK_INLINE %type <number> TOK_INT_ID %type <number> TOK_LAMBDA %type <number> TOK_LOCAL_ID %type <number> TOK_MAPPING_ID %type <number> TOK_MIXED_ID %type <number> TOK_MULTISET_ID %type <number> TOK_NO_MASK %type <number> TOK_OBJECT_ID %type <number> TOK_PREDEF %type <number> TOK_PRIVATE %type <number> TOK_PROGRAM_ID %type <number> TOK_PROTECTED %type <number> TOK_PUBLIC %type <number> TOK_RETURN %type <number> TOK_SSCANF %type <number> TOK_STATIC %type <number> TOK_STRING_ID %type <number> TOK_SWITCH %type <number> TOK_VOID_ID %type <number> TOK_WHILE
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> arguments %type <number> arguments2
febbc81997-04-22Fredrik Hübinette (Hubbe) %type <number> func_args
c20a522000-07-08Henrik Grubbström (Grubba) %type <number> optional_create_arguments %type <number> create_arguments %type <number> create_arguments2 %type <number> create_arg
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> assign %type <number> modifier %type <number> modifier_list %type <number> modifiers
8c64232000-06-26Henrik Grubbström (Grubba) %type <number> inherit_specifier
cbae7e2000-03-30Henrik Grubbström (Grubba) %type <number> function_type_list %type <number> function_type_list2
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> optional_dot_dot_dot
cbae7e2000-03-30Henrik Grubbström (Grubba) %type <number> optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <number> optional_stars
215bed1996-09-28Fredrik Hübinette (Hubbe) 
315aa81999-12-17Fredrik Hübinette (Hubbe) %type <str> magic_identifiers %type <str> magic_identifiers1 %type <str> magic_identifiers2 %type <str> magic_identifiers3
8c77b61998-04-13Henrik Grubbström (Grubba) /* The following symbols return type information */
215bed1996-09-28Fredrik Hübinette (Hubbe) 
011ad31999-10-22Fredrik Hübinette (Hubbe) %type <n> number_or_minint %type <n> number_or_maxint
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> cast
1d73ef1999-11-23Henrik Grubbström (Grubba) %type <n> soft_cast
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> simple_type
6bc9281998-04-10Fredrik Hübinette (Hubbe) %type <n> simple_type2 %type <n> simple_identifier_type
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> string_constant %type <n> string
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <n> TOK_STRING %type <n> TOK_NUMBER
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> optional_rename_inherit %type <n> optional_identifier
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <n> TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> assoc_pair
9b39022003-03-27Martin Stjernholm %type <n> line_number_info
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> block
a30f092000-07-12Fredrik Hübinette (Hubbe) %type <n> optional_block
01d3e21997-04-23Fredrik Hübinette (Hubbe) %type <n> failsafe_block
10fe602003-10-01Martin Stjernholm %type <n> open_paren_with_line_info
bb213c1999-12-27Henrik Grubbström (Grubba) %type <n> close_paren_or_missing
10fe602003-10-01Martin Stjernholm %type <n> open_bracket_with_line_info
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> block_or_semi %type <n> break %type <n> case %type <n> catch %type <n> catch_arg %type <n> class
a418ce2001-03-31Henrik Grubbström (Grubba) %type <n> enum
4d21331998-04-14Henrik Grubbström (Grubba) %type <n> safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> comma_expr %type <n> comma_expr2 %type <n> comma_expr_or_maxint %type <n> comma_expr_or_zero %type <n> cond %type <n> continue %type <n> default %type <n> do
998e1f1998-04-15Henrik Grubbström (Grubba) %type <n> safe_expr0
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> expr00 %type <n> expr01 %type <n> expr1 %type <n> expr2 %type <n> expr3 expr0 %type <n> expr4 %type <n> expr_list %type <n> expr_list2 %type <n> for %type <n> for_expr %type <n> foreach %type <n> gauge
d2c6081996-11-07Fredrik Hübinette (Hubbe) %type <n> idents
71d9702000-06-21Henrik Grubbström (Grubba) %type <n> idents2
5a0fd52001-01-10Martin Stjernholm %type <n> labeled_statement
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> lambda %type <n> local_name_list
6bc9281998-04-10Fredrik Hübinette (Hubbe) %type <n> local_name_list2
591c0c1997-01-19Fredrik Hübinette (Hubbe) %type <n> low_idents
998e1f1998-04-15Henrik Grubbström (Grubba) %type <n> safe_lvalue
3ddb531996-11-02Fredrik Hübinette (Hubbe) %type <n> lvalue
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> lvalue_list
2a32691998-01-31Fredrik Hübinette (Hubbe) %type <n> low_lvalue_list
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> m_expr_list %type <n> m_expr_list2 %type <n> new_local_name
6bc9281998-04-10Fredrik Hübinette (Hubbe) %type <n> new_local_name2
5a0fd52001-01-10Martin Stjernholm %type <n> normal_label_statement
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> optional_else_part
5a0fd52001-01-10Martin Stjernholm %type <n> optional_label
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> return %type <n> sscanf %type <n> statement %type <n> statements
71bde82001-03-16Fredrik Hübinette (Hubbe) %type <n> statement_with_semicolon
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> switch %type <n> typeof %type <n> unused %type <n> unused2 %type <n> while
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) %type <n> optional_comma_expr
61e9a01998-01-25Fredrik Hübinette (Hubbe) %type <n> low_program_ref
2ebdad2004-03-16Henrik Grubbström (Grubba) %type <n> inherit_ref
a566ca1999-12-14Fredrik Hübinette (Hubbe) %type <n> local_function %type <n> local_function2
315aa81999-12-17Fredrik Hübinette (Hubbe) %type <n> magic_identifier
5e3aa52001-04-01Henrik Grubbström (Grubba) %type <n> simple_identifier
4cdb802001-02-23Fredrik Hübinette (Hubbe) %type <n> foreach_lvalues %type <n> foreach_optional_lvalue
215bed1996-09-28Fredrik Hübinette (Hubbe) %%
db271d1998-04-27Henrik Grubbström (Grubba) all: program { YYACCEPT; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | program TOK_LEX_EOF { YYACCEPT; } /* | error TOK_LEX_EOF { YYABORT; } */
8c77b61998-04-13Henrik Grubbström (Grubba)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
9ce6b62000-09-20Henrik Grubbström (Grubba) program: program def | program ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3c0c281998-01-26Fredrik Hübinette (Hubbe) string_constant: string | string_constant '+' string
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *a,*b; copy_shared_string(a,$1->u.sval.u.string); copy_shared_string(b,$3->u.sval.u.string); free_node($1); free_node($3); a=add_and_free_shared_strings(a,b); $$=mkstrnode(a); free_string(a);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) optional_rename_inherit: ':' TOK_IDENTIFIER { $$=$2; }
8c77b61998-04-13Henrik Grubbström (Grubba)  | ':' bad_identifier { $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | ':' error { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | { $$=0; } ;
d2c6081996-11-07Fredrik Hübinette (Hubbe) 
66c2361998-08-29Henrik Grubbström (Grubba) /* NOTE: This rule pushes a string "name" on the stack in addition * to resolving the program reference. */
61e9a01998-01-25Fredrik Hübinette (Hubbe) low_program_ref: string_constant
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
a993572002-10-12Henrik Grubbström (Grubba)  STACK_LEVEL_START(0);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  ref_push_string($1->u.sval.u.string);
9036e82001-08-16Martin Stjernholm  if (call_handle_inherit($1->u.sval.u.string)) { $$=mksvaluenode(Pike_sp-1); pop_stack();
10e16f1999-11-04Henrik Grubbström (Grubba)  }
9036e82001-08-16Martin Stjernholm  else $$=mknewintnode(0);
43fc171999-09-19Fredrik Hübinette (Hubbe)  if($$->name) free_string($$->name);
9036e82001-08-16Martin Stjernholm  add_ref( $$->name=Pike_sp[-1].u.string ); free_node($1);
a993572002-10-12Henrik Grubbström (Grubba)  STACK_LEVEL_DONE(1);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } | idents {
a993572002-10-12Henrik Grubbström (Grubba)  STACK_LEVEL_START(0);
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier)
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  {
de1d7d2000-07-10Henrik Grubbström (Grubba)  ref_push_string(Pike_compiler->last_identifier);
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  }else{
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  push_constant_text("");
8d7bda1997-02-10Fredrik Hübinette (Hubbe)  }
61e9a01998-01-25Fredrik Hübinette (Hubbe)  $$=$1;
a993572002-10-12Henrik Grubbström (Grubba)  STACK_LEVEL_DONE(1);
61e9a01998-01-25Fredrik Hübinette (Hubbe)  } ;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
66c2361998-08-29Henrik Grubbström (Grubba) /* NOTE: Pushes the resolved program on the stack. */
61e9a01998-01-25Fredrik Hübinette (Hubbe) program_ref: low_program_ref {
a993572002-10-12Henrik Grubbström (Grubba)  STACK_LEVEL_START(0);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  resolv_program($1); free_node($1);
a993572002-10-12Henrik Grubbström (Grubba)  STACK_LEVEL_DONE(1);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } ;
2ebdad2004-03-16Henrik Grubbström (Grubba)  inherit_ref: { SET_FORCE_RESOLVE($<number>$); } low_program_ref { UNSET_FORCE_RESOLVE($<number>1); $$ = $2; } ; inheritance: modifiers TOK_INHERIT inherit_ref optional_rename_inherit ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (($1 & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared inherit."); }
2ebdad2004-03-16Henrik Grubbström (Grubba)  if($3 && !(Pike_compiler->new_program->flags & PROGRAM_PASS_1_DONE))
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
f077582000-07-06Fredrik Hübinette (Hubbe)  struct pike_string *s=Pike_sp[-1].u.string;
2ebdad2004-03-16Henrik Grubbström (Grubba)  if($4) s=$4->u.sval.u.string; compiler_do_inherit($3,$1,s);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
2ebdad2004-03-16Henrik Grubbström (Grubba)  if($4) free_node($4);
a993572002-10-12Henrik Grubbström (Grubba)  pop_stack();
2ebdad2004-03-16Henrik Grubbström (Grubba)  if ($3) free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
2ebdad2004-03-16Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT inherit_ref error ';'
8c77b61998-04-13Henrik Grubbström (Grubba)  {
2ebdad2004-03-16Henrik Grubbström (Grubba)  if ($3) free_node($3);
48e4102001-12-20Martin Stjernholm  pop_stack(); yyerrok;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
2ebdad2004-03-16Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT inherit_ref error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
2ebdad2004-03-16Henrik Grubbström (Grubba)  if ($3) free_node($3);
48e4102001-12-20Martin Stjernholm  pop_stack();
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
2ebdad2004-03-16Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT inherit_ref error '}'
db271d1998-04-27Henrik Grubbström (Grubba)  {
2ebdad2004-03-16Henrik Grubbström (Grubba)  if ($3) free_node($3);
48e4102001-12-20Martin Stjernholm  pop_stack(); yyerror("Missing ';'.");
db271d1998-04-27Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT error ';' { yyerrok; } | modifiers TOK_INHERIT error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_INHERIT error '}' { yyerror("Missing ';'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) import: TOK_IMPORT idents ';'
591c0c1997-01-19Fredrik Hübinette (Hubbe)  {
97358e1998-04-23Fredrik Hübinette (Hubbe)  resolv_constant($2); free_node($2);
f077582000-07-06Fredrik Hübinette (Hubbe)  use_module(Pike_sp-1);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  pop_stack();
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT string ';'
eb5c901998-04-19Fredrik Hübinette (Hubbe)  {
9036e82001-08-16Martin Stjernholm  if (call_handle_import($2->u.sval.u.string)) { use_module(Pike_sp-1); pop_stack();
10e16f1999-11-04Henrik Grubbström (Grubba)  }
9036e82001-08-16Martin Stjernholm  free_node($2);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT error ';' { yyerrok; } | TOK_IMPORT error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT error '}' { yyerror("Missing ';'."); }
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) constant_name: TOK_IDENTIFIER '=' safe_expr0
d2c6081996-11-07Fredrik Hübinette (Hubbe)  { /* This can be made more lenient in the future */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  /* Ugly hack to make sure that $3 is optimized */
b5c9052000-08-19Henrik Grubbström (Grubba)  { int tmp=Pike_compiler->compiler_pass; $3=mknode(F_COMMA_EXPR,$3,0); Pike_compiler->compiler_pass=tmp; }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
019b3d2000-07-09Henrik Grubbström (Grubba)  if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared constant."); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!is_const($3))
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass==2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  yyerror("Constant definition is not constant.");
a786431999-11-18Martin Stjernholm  else
019b3d2000-07-09Henrik Grubbström (Grubba)  add_constant($1->u.sval.u.string, 0, Pike_compiler->current_modifiers & ~ID_EXTERN);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } else {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->num_parse_error)
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  {
9f85c32002-10-25Marcus Comstedt  ptrdiff_t tmp=eval_low($3,1);
57cddc1998-04-19Per Hedbor  if(tmp < 1) { yyerror("Error in constant definition.");
f23f062004-03-12Henrik Grubbström (Grubba)  push_undefined();
57cddc1998-04-19Per Hedbor  }else{
84f8952000-08-16Henrik Grubbström (Grubba)  pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1)));
57cddc1998-04-19Per Hedbor  }
f23f062004-03-12Henrik Grubbström (Grubba)  } else { push_undefined();
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  }
f23f062004-03-12Henrik Grubbström (Grubba)  add_constant($1->u.sval.u.string, Pike_sp-1, Pike_compiler->current_modifiers & ~ID_EXTERN); pop_stack();
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if($3) free_node($3);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
998e1f1998-04-15Henrik Grubbström (Grubba)  | bad_identifier '=' safe_expr0 { if ($3) free_node($3); } | error '=' safe_expr0 { if ($3) free_node($3); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ; constant_list: constant_name | constant_list ',' constant_name ;
f76b4c2000-05-11Henrik Grubbström (Grubba) constant: modifiers TOK_CONSTANT constant_list ';' {} | modifiers TOK_CONSTANT error ';' { yyerrok; } | modifiers TOK_CONSTANT error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers TOK_CONSTANT error '}' { yyerror("Missing ';'."); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) block_or_semi: block {
498ec11999-11-12Henrik Grubbström (Grubba)  $$ = check_node_hash(mknode(F_COMMA_EXPR,$1,mknode(F_RETURN,mkintnode(0),0)));
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
76b4491999-12-09Henrik Grubbström (Grubba)  | ';' { $$ = NULL; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Expected ';'."); $$ = NULL; }
76b4491999-12-09Henrik Grubbström (Grubba)  | error { $$ = NULL; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  type_or_error: simple_type
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
3699402001-02-20Henrik Grubbström (Grubba)  check_type_string(check_node_hash($1)->u.sval.u.type);
498ec11999-11-12Henrik Grubbström (Grubba) #endif /* PIKE_DEBUG */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_type)
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(Pike_compiler->compiler_frame->current_type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_type, $1->u.sval.u.type);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
76b4491999-12-09Henrik Grubbström (Grubba) 
10fe602003-10-01Martin Stjernholm open_paren_with_line_info: '(' { /* Used to hold line-number info */ $$ = mkintnode(0); } ;
76b4491999-12-09Henrik Grubbström (Grubba) close_paren_or_missing: ')'
bb213c1999-12-27Henrik Grubbström (Grubba)  { /* Used to hold line-number info */ $$ = mkintnode(0); }
76b4491999-12-09Henrik Grubbström (Grubba)  | /* empty */ { yyerror("Missing ')'.");
bb213c1999-12-27Henrik Grubbström (Grubba)  /* Used to hold line-number info */ $$ = mkintnode(0);
76b4491999-12-09Henrik Grubbström (Grubba)  } ; close_brace_or_missing: '}' | /* empty */ { yyerror("Missing '}'."); } ;
d4c3e02002-05-02Henrik Grubbström (Grubba) close_brace_or_eof: '}' | TOK_LEX_EOF { yyerror("Missing '}'."); } ;
10fe602003-10-01Martin Stjernholm open_bracket_with_line_info: '[' { /* Used to hold line-number info */ $$ = mkintnode(0); } ;
76b4491999-12-09Henrik Grubbström (Grubba) close_bracket_or_missing: ']' | /* empty */ { yyerror("Missing ']'."); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba) push_compiler_frame0: /* empty */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8322b62000-05-08Fredrik Hübinette (Hubbe)  push_compiler_frame(SCOPE_LOCAL);
b5aa651999-12-16Henrik Grubbström (Grubba) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->compiler_frame->previous || !Pike_compiler->compiler_frame->previous->current_type)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Internal compiler fault.");
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_type,
d68a072001-02-20Henrik Grubbström (Grubba)  mixed_type_string);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_type,
d68a072001-02-20Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->previous->current_type);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }
3ec3df1999-12-16Henrik Grubbström (Grubba)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) def: modifiers type_or_error optional_stars TOK_IDENTIFIER push_compiler_frame0
76b4491999-12-09Henrik Grubbström (Grubba)  '(' arguments close_paren_or_missing
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int e; /* construct the function type */
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($3 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
febbc81997-04-22Fredrik Hübinette (Hubbe)  while(--$3>=0) push_type(T_ARRAY);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_return_type)
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(Pike_compiler->compiler_frame->current_return_type);
babd872001-02-23Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->current_return_type = compiler_pop_type();
7e50571996-11-02Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
3ec3df1999-12-16Henrik Grubbström (Grubba)  e=$7-1;
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--;
5b368e2001-03-31Henrik Grubbström (Grubba)  pop_type_stack(T_ARRAY);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
dfed932001-03-03Henrik Grubbström (Grubba)  push_type(T_FUNCTION);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s=compiler_pop_type();
be57ea2000-07-14Henrik Grubbström (Grubba)  int i = isidentifier($4->u.sval.u.string); if (Pike_compiler->compiler_pass == 1) { if ($1 & ID_VARIANT) { /* FIXME: Lookup the type of any existing variant */ /* Or the types. */ fprintf(stderr, "Pass %d: Identifier %s:\n", Pike_compiler->compiler_pass, $4->u.sval.u.string->str); if (i >= 0) { struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, i); if (id) {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *new_type;
be57ea2000-07-14Henrik Grubbström (Grubba)  fprintf(stderr, "Defined, type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(id->type);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  new_type = or_pike_types(s, id->type, 1);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
be57ea2000-07-14Henrik Grubbström (Grubba)  s = new_type; fprintf(stderr, "Resulting type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(s);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  } else {
ce060e2004-06-30Martin Nilsson  my_yyerror("Lost identifier %O (%d).", $4->u.sval, i);
be57ea2000-07-14Henrik Grubbström (Grubba)  } } else { fprintf(stderr, "Not defined.\n"); } fprintf(stderr, "New type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(s);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  } } else { /* FIXME: Second pass reuses the type from the end of * the first pass if this is a variant function. */ if (i >= 0) { if (Pike_compiler->new_program->identifier_references[i].id_flags & ID_VARIANT) { struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, i); fprintf(stderr, "Pass %d: Identifier %s:\n", Pike_compiler->compiler_pass, $4->u.sval.u.string->str);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(s, id->type);
be57ea2000-07-14Henrik Grubbström (Grubba)  fprintf(stderr, "Resulting type:\n");
57198b2000-07-18Martin Stjernholm #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  simple_describe_type(s);
57198b2000-07-18Martin Stjernholm #endif
be57ea2000-07-14Henrik Grubbström (Grubba)  } } else {
ce060e2004-06-30Martin Nilsson  my_yyerror("Identifier %S lost after first pass.", $4->u.sval);
be57ea2000-07-14Henrik Grubbström (Grubba)  } }
3699402001-02-20Henrik Grubbström (Grubba)  $<n>$ = mktypenode(s);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
be57ea2000-07-14Henrik Grubbström (Grubba) 
bad5162000-06-23Fredrik Hübinette (Hubbe) /* if(Pike_compiler->compiler_pass==1) */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
6fd5172000-04-25Fredrik Hübinette (Hubbe)  /* FIXME: * set current_function_number for local functions as well */
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->current_function_number=
6fd5172000-04-25Fredrik Hübinette (Hubbe)  define_function(check_node_hash($4)->u.sval.u.string,
3699402001-02-20Henrik Grubbström (Grubba)  check_node_hash($<n>$)->u.sval.u.type,
6fd5172000-04-25Fredrik Hübinette (Hubbe)  $1 & (~ID_EXTERN),
3116ce2002-11-22Henrik Grubbström (Grubba)  IDENTIFIER_PIKE_FUNCTION | (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),
1ef5572000-08-30Henrik Grubbström (Grubba)  0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);
be57ea2000-07-14Henrik Grubbström (Grubba) 
3116ce2002-11-22Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
be57ea2000-07-14Henrik Grubbström (Grubba)  if ($1 & ID_VARIANT) { fprintf(stderr, "Function number: %d\n", Pike_compiler->compiler_frame->current_function_number); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } block_or_semi { int e;
3ec3df1999-12-16Henrik Grubbström (Grubba)  if($10)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
22edc21998-01-29Fredrik Hübinette (Hubbe)  int f;
b9188f1999-12-13Henrik Grubbström (Grubba)  node *check_args = NULL;
f639a52003-02-04Martin Stjernholm  struct pike_string *save_file = lex.current_file;
bb213c1999-12-27Henrik Grubbström (Grubba)  int save_line = lex.current_line;
9039702000-08-15Henrik Grubbström (Grubba)  int num_required_args = 0;
1ef5572000-08-30Henrik Grubbström (Grubba)  struct identifier *i;
d4f23b2001-08-10Martin Stjernholm  lex.current_file = $4->current_file; lex.current_line = $4->line_number;
b9188f1999-12-13Henrik Grubbström (Grubba) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (($1 & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared function definition."); }
3ec3df1999-12-16Henrik Grubbström (Grubba)  for(e=0; e<$7; e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!Pike_compiler->compiler_frame->variable[e].name || !Pike_compiler->compiler_frame->variable[e].name->len)
b9188f1999-12-13Henrik Grubbström (Grubba)  { my_yyerror("Missing name for argument %d.",e); } else {
9039702000-08-15Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) { if ($1 & ID_VARIANT) {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *arg_type =
9039702000-08-15Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[e].type; /* FIXME: Generate code that checks the arguments. */ /* If there is a bad argument, call the fallback, and return. */ if (! pike_types_le(void_type_string, arg_type)) { /* Argument my not be void. * ie it's required. */ num_required_args++; } } else { /* FIXME: Should probably use some other flag. */ if ((runtime_options & RUNTIME_CHECK_TYPES) &&
babd872001-02-23Henrik Grubbström (Grubba)  (Pike_compiler->compiler_frame->variable[e].type != mixed_type_string)) {
9039702000-08-15Henrik Grubbström (Grubba)  node *local_node; /* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/ local_node = mklocalnode(e, 0); /* The following is needed to go around the optimization in * mksoftcastnode(). */
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(local_node->type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(local_node->type, mixed_type_string);
9039702000-08-15Henrik Grubbström (Grubba)  check_args = mknode(F_COMMA_EXPR, check_args, mksoftcastnode(Pike_compiler->compiler_frame->variable[e].type, local_node)); }
8f733e2000-07-12Henrik Grubbström (Grubba)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
b9188f1999-12-13Henrik Grubbström (Grubba)  } }
9039702000-08-15Henrik Grubbström (Grubba)  if ($1 & ID_VARIANT) { struct pike_string *bad_arg_str;
de56ec2003-02-08Martin Stjernholm  MAKE_CONST_STRING(bad_arg_str, "Bad number of arguments!\n");
9039702000-08-15Henrik Grubbström (Grubba)  fprintf(stderr, "Required args: %d\n", num_required_args); check_args = mknode('?', mkopernode("`<", mkefuncallnode("query_num_arg", NULL), mkintnode(num_required_args)), mknode(':', mkefuncallnode("throw", mkefuncallnode("aggregate", mkstrnode(bad_arg_str))), NULL)); }
587c6a2001-06-30Martin Stjernholm  { int l = $10->line_number;
635fce2001-07-01Martin Stjernholm  struct pike_string *f = $10->current_file;
587c6a2001-06-30Martin Stjernholm  if (check_args) { /* Prepend the arg checking code. */ $10 = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, check_args, NULL), $10); } lex.current_line = l; lex.current_file = f;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
329cc01997-02-17Fredrik Hübinette (Hubbe) 
6fd5172000-04-25Fredrik Hübinette (Hubbe)  f=dooptcode(check_node_hash($4)->u.sval.u.string, check_node_hash($10),
3699402001-02-20Henrik Grubbström (Grubba)  check_node_hash($<n>9)->u.sval.u.type,
6fd5172000-04-25Fredrik Hübinette (Hubbe)  $1);
be57ea2000-07-14Henrik Grubbström (Grubba) 
1ef5572000-08-30Henrik Grubbström (Grubba)  i = ID_FROM_INT(Pike_compiler->new_program, f); i->opt_flags = Pike_compiler->compiler_frame->opt_flags;
be57ea2000-07-14Henrik Grubbström (Grubba)  if ($1 & ID_VARIANT) { fprintf(stderr, "Function number: %d\n", f); }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
be57ea2000-07-14Henrik Grubbström (Grubba)  if(Pike_interpreter.recoveries && ((Pike_sp - Pike_interpreter.evaluator_stack) < Pike_interpreter.recoveries->stack_pointer))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack error (underflow)\n");
ae95031999-04-07Fredrik Hübinette (Hubbe) 
be57ea2000-07-14Henrik Grubbström (Grubba)  if((Pike_compiler->compiler_pass == 1) &&
d4c3e02002-05-02Henrik Grubbström (Grubba)  (f != Pike_compiler->compiler_frame->current_function_number)) { fprintf(stderr, "define_function()/do_opt_code() failed for symbol %s\n", $4->u.sval.u.string->str); dump_program_desc(Pike_compiler->new_program);
5aad932002-08-15Marcus Comstedt  Pike_fatal("define_function screwed up! %d != %d\n",
be57ea2000-07-14Henrik Grubbström (Grubba)  f, Pike_compiler->compiler_frame->current_function_number);
d4c3e02002-05-02Henrik Grubbström (Grubba)  }
294dc51997-08-03Fredrik Hübinette (Hubbe) #endif
c3453f2001-06-30Martin Stjernholm  lex.current_line = save_line; lex.current_file = save_file;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($4);
bb213c1999-12-27Henrik Grubbström (Grubba)  free_node($8);
3ec3df1999-12-16Henrik Grubbström (Grubba)  free_node($<n>9);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | modifiers type_or_error optional_stars TOK_IDENTIFIER push_compiler_frame0
b5aa651999-12-16Henrik Grubbström (Grubba)  error { pop_compiler_frame(); free_node($4);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | modifiers type_or_error optional_stars bad_identifier {
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(compiler_pop_type());
8c77b61998-04-13Henrik Grubbström (Grubba)  }
33b82c1999-12-19Henrik Grubbström (Grubba)  '(' arguments ')' block_or_semi { if ($9) free_node($9); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | modifiers type_or_error name_list ';' {} | inheritance {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  | import {}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | constant {}
121d491996-11-27Fredrik Hübinette (Hubbe)  | class { free_node($1); }
a418ce2001-03-31Henrik Grubbström (Grubba)  | enum { free_node($1); }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | typedef {}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { reset_type_stack(); yyerror("Missing ';'."); yyerror("Unexpected end of file"); }
07f33e1998-11-05Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); yyerrok;
bad5162000-06-23Fredrik Hübinette (Hubbe) /* if(Pike_compiler->num_parse_error>5) YYACCEPT; */
07f33e1998-11-05Henrik Grubbström (Grubba)  }
2968361998-04-14Henrik Grubbström (Grubba)  | error '}' { reset_type_stack();
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Missing ';'.");
eb5c901998-04-19Fredrik Hübinette (Hubbe)  /* yychar = '}'; */ /* Put the '}' back on the input stream */
2968361998-04-14Henrik Grubbström (Grubba)  }
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | modifiers '{' { $<number>$=lex.pragmas; lex.pragmas|=$1; } program
d4c3e02002-05-02Henrik Grubbström (Grubba)  close_brace_or_eof
21b2c91999-12-17Fredrik Hübinette (Hubbe)  { lex.pragmas=$<number>3; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) optional_dot_dot_dot: TOK_DOT_DOT_DOT { $$=1; }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | TOK_DOT_DOT { yyerror("Range indicator ('..') where elipsis ('...') expected."); $$=1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) optional_identifier: TOK_IDENTIFIER
97358e1998-04-23Fredrik Hübinette (Hubbe)  | bad_identifier { $$=0; }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) new_arg_name: type7 optional_dot_dot_dot optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs) yyerror("Can't define more arguments after ...");
215bed1996-09-28Fredrik Hübinette (Hubbe) 
7e50571996-11-02Fredrik Hübinette (Hubbe)  if($2) { push_type(T_ARRAY);
c3cfe92000-07-10Henrik Grubbström (Grubba)  Pike_compiler->varargs=1;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!$3)
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
de56ec2003-02-08Martin Stjernholm  $3=mkstrnode(empty_pike_string);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
96ab241998-02-28Fredrik Hübinette (Hubbe)  if($3->u.sval.u.string->len &&
fe80612000-09-05Henrik Grubbström (Grubba)  islocal($3->u.sval.u.string) >= 0)
ce060e2004-06-30Martin Nilsson  my_yyerror("Variable %O appears twice in argument list.", $3->u.sval);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
a566ca1999-12-14Fredrik Hübinette (Hubbe)  add_local_name($3->u.sval.u.string, compiler_pop_type(),0);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
bb213c1999-12-27Henrik Grubbström (Grubba) func_args: '(' arguments close_paren_or_missing { free_node($3); $$=$2; } ;
febbc81997-04-22Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) arguments: /* empty */ optional_comma { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | arguments2 optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  arguments2: new_arg_name { $$ = 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | arguments2 ',' new_arg_name { $$ = $1 + 1; }
76b4491999-12-09Henrik Grubbström (Grubba)  | arguments2 ':' new_arg_name { yyerror("Unexpected ':' in argument list."); $$ = $1 + 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
a7c3a42000-07-10Henrik Grubbström (Grubba) modifier: TOK_NO_MASK { $$ = ID_NOMASK; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FINAL_ID { $$ = ID_NOMASK; } | TOK_STATIC { $$ = ID_STATIC; } | TOK_EXTERN { $$ = ID_EXTERN; } | TOK_OPTIONAL { $$ = ID_OPTIONAL; } | TOK_PRIVATE { $$ = ID_PRIVATE | ID_STATIC; } | TOK_LOCAL_ID { $$ = ID_INLINE; } | TOK_PUBLIC { $$ = ID_PUBLIC; } | TOK_PROTECTED { $$ = ID_PROTECTED; } | TOK_INLINE { $$ = ID_INLINE; }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT { $$ = ID_VARIANT; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
315aa81999-12-17Fredrik Hübinette (Hubbe) magic_identifiers1:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_NO_MASK { $$ = "nomask"; } | TOK_FINAL_ID { $$ = "final"; } | TOK_STATIC { $$ = "static"; }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | TOK_EXTERN { $$ = "extern"; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PRIVATE { $$ = "private"; } | TOK_LOCAL_ID { $$ = "local"; } | TOK_PUBLIC { $$ = "public"; } | TOK_PROTECTED { $$ = "protected"; } | TOK_INLINE { $$ = "inline"; } | TOK_OPTIONAL { $$ = "optional"; }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT { $$ = "variant"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ; magic_identifiers2:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_VOID_ID { $$ = "void"; } | TOK_MIXED_ID { $$ = "mixed"; } | TOK_ARRAY_ID { $$ = "array"; } | TOK_MAPPING_ID { $$ = "mapping"; } | TOK_MULTISET_ID { $$ = "multiset"; } | TOK_OBJECT_ID { $$ = "object"; } | TOK_FUNCTION_ID { $$ = "function"; } | TOK_PROGRAM_ID { $$ = "program"; } | TOK_STRING_ID { $$ = "string"; } | TOK_FLOAT_ID { $$ = "float"; } | TOK_INT_ID { $$ = "int"; }
76e7f92001-03-18Henrik Grubbström (Grubba)  | TOK_ENUM { $$ = "enum"; }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | TOK_TYPEDEF { $$ = "typedef"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ; magic_identifiers3:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_IF { $$ = "if"; } | TOK_DO { $$ = "do"; } | TOK_FOR { $$ = "for"; } | TOK_WHILE { $$ = "while"; } | TOK_ELSE { $$ = "else"; } | TOK_FOREACH { $$ = "foreach"; } | TOK_CATCH { $$ = "catch"; } | TOK_GAUGE { $$ = "gauge"; } | TOK_CLASS { $$ = "class"; } | TOK_BREAK { $$ = "break"; } | TOK_CASE { $$ = "case"; } | TOK_CONSTANT { $$ = "constant"; } | TOK_CONTINUE { $$ = "continue"; } | TOK_DEFAULT { $$ = "default"; } | TOK_IMPORT { $$ = "import"; } | TOK_INHERIT { $$ = "inherit"; } | TOK_LAMBDA { $$ = "lambda"; } | TOK_PREDEF { $$ = "predef"; } | TOK_RETURN { $$ = "return"; } | TOK_SSCANF { $$ = "sscanf"; } | TOK_SWITCH { $$ = "switch"; } | TOK_TYPEOF { $$ = "typeof"; }
1977e22002-08-18Martin Stjernholm  | TOK_GLOBAL { $$ = "global"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ;
21b2c91999-12-17Fredrik Hübinette (Hubbe) magic_identifiers: magic_identifiers1 | magic_identifiers2 | magic_identifiers3 ;
f76b4c2000-05-11Henrik Grubbström (Grubba) magic_identifier: TOK_IDENTIFIER
21b2c91999-12-17Fredrik Hübinette (Hubbe)  | magic_identifiers
315aa81999-12-17Fredrik Hübinette (Hubbe)  { struct pike_string *tmp=make_shared_string($1); $$=mkstrnode(tmp); free_string(tmp); } ;
1d73ef1999-11-23Henrik Grubbström (Grubba) modifiers: modifier_list {
019b3d2000-07-09Henrik Grubbström (Grubba)  $$=Pike_compiler->current_modifiers=$1 | (lex.pragmas & ID_MODIFIER_MASK);
1d73ef1999-11-23Henrik Grubbström (Grubba)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  modifier_list: /* empty */ { $$ = 0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | modifier modifier_list { $$ = $1 | $2; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  optional_stars: optional_stars '*' { $$=$1 + 1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | /* empty */ { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
10fe602003-10-01Martin Stjernholm cast: open_paren_with_line_info type ')'
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s = compiler_pop_type(); $$ = mktypenode(s);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
10fe602003-10-01Martin Stjernholm  free_node ($1);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  }
2e4e451997-02-13Fredrik Hübinette (Hubbe)  ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) 
10fe602003-10-01Martin Stjernholm soft_cast: open_bracket_with_line_info type ']'
1d73ef1999-11-23Henrik Grubbström (Grubba)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s = compiler_pop_type(); $$ = mktypenode(s);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
10fe602003-10-01Martin Stjernholm  free_node ($1);
1d73ef1999-11-23Henrik Grubbström (Grubba)  } ;
0ebfc82001-04-01Henrik Grubbström (Grubba) full_type: type4
a6062c2001-04-01Henrik Grubbström (Grubba)  | full_type '*'
5e3aa52001-04-01Henrik Grubbström (Grubba)  { if (Pike_compiler->compiler_pass == 2) { yywarning("The *-syntax in types is obsolete. Use array instead."); } push_type(T_ARRAY); } ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) type6: type | identifier_type ;
2e4e451997-02-13Fredrik Hübinette (Hubbe) 
66f7712000-02-17Henrik Grubbström (Grubba) type: type '*' {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass == 2) {
67abdc2000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
66f7712000-02-17Henrik Grubbström (Grubba)  push_type(T_ARRAY); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | type2 ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
66f7712000-02-17Henrik Grubbström (Grubba) type7: type7 '*' {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass == 2) {
67abdc2000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
66f7712000-02-17Henrik Grubbström (Grubba)  push_type(T_ARRAY); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | type4 ; simple_type: type4 {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s = compiler_pop_type(); $$ = mktypenode(s);
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
3699402001-02-20Henrik Grubbström (Grubba)  if ($$->u.sval.u.type != s) {
5aad932002-08-15Marcus Comstedt  Pike_fatal("mktypenode(%p) created node with %p\n", s, $$->u.sval.u.type);
498ec11999-11-12Henrik Grubbström (Grubba)  } #endif /* PIKE_DEBUG */
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
6bc9281998-04-10Fredrik Hübinette (Hubbe)  } ; simple_type2: type2 {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s = compiler_pop_type(); $$ = mktypenode(s);
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
3699402001-02-20Henrik Grubbström (Grubba)  if ($$->u.sval.u.type != s) {
5aad932002-08-15Marcus Comstedt  Pike_fatal("mktypenode(%p) created node with %p\n", s, $$->u.sval.u.type);
498ec11999-11-12Henrik Grubbström (Grubba)  } #endif /* PIKE_DEBUG */
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
6bc9281998-04-10Fredrik Hübinette (Hubbe)  } ; simple_identifier_type: identifier_type
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s = compiler_pop_type(); $$ = mktypenode(s);
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
3699402001-02-20Henrik Grubbström (Grubba)  if ($$->u.sval.u.type != s) {
5aad932002-08-15Marcus Comstedt  Pike_fatal("mktypenode(%p) created node with %p\n", s, $$->u.sval.u.type);
498ec11999-11-12Henrik Grubbström (Grubba)  } #endif /* PIKE_DEBUG */
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(s);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
1220212001-05-08Henrik Grubbström (Grubba) type4: type4 '|' type8 { push_type(T_OR); } | type8 ; type2: type2 '|' type8 { push_type(T_OR); } | basic_type ; type8: basic_type | identifier_type ; basic_type: TOK_FLOAT_ID { push_type(T_FLOAT); } | TOK_VOID_ID { push_type(T_VOID); } | TOK_MIXED_ID { push_type(T_MIXED); } | TOK_STRING_ID { push_type(T_STRING); } | TOK_INT_ID opt_int_range {} | TOK_MAPPING_ID opt_mapping_type {} | TOK_FUNCTION_ID opt_function_type {} | TOK_OBJECT_ID opt_object_type {} | TOK_PROGRAM_ID opt_object_type { push_type(T_PROGRAM); } | TOK_ARRAY_ID opt_array_type { push_type(T_ARRAY); } | TOK_MULTISET_ID opt_array_type { push_type(T_MULTISET); } ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) identifier_type: idents
7a08f32000-01-25Henrik Grubbström (Grubba)  { resolv_constant($1);
f077582000-07-06Fredrik Hübinette (Hubbe)  if (Pike_sp[-1].type == T_TYPE) {
7a08f32000-01-25Henrik Grubbström (Grubba)  /* "typedef" */
3699402001-02-20Henrik Grubbström (Grubba)  push_finished_type(Pike_sp[-1].u.type);
7a08f32000-01-25Henrik Grubbström (Grubba)  } else { /* object type */ struct program *p = NULL;
f077582000-07-06Fredrik Hübinette (Hubbe)  if (Pike_sp[-1].type == T_OBJECT) { if(!Pike_sp[-1].u.object->prog)
7a08f32000-01-25Henrik Grubbström (Grubba)  { pop_stack(); push_int(0); yyerror("Destructed object used as program identifier."); }else{
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  int f=FIND_LFUN(Pike_sp[-1].u.object->prog,LFUN_CALL); if(f!=-1) { Pike_sp[-1].subtype=f; Pike_sp[-1].type=T_FUNCTION; }else{
3a77fb2003-02-26Henrik Grubbström (Grubba)  extern void f_object_program(INT32);
e2091d2004-08-16Martin Stjernholm  if (Pike_compiler->compiler_pass == 2 && !TEST_COMPAT (7, 4)) {
1a19e42003-01-13Henrik Grubbström (Grubba)  yywarning("Using object as program identifier."); }
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  f_object_program(1); }
7a08f32000-01-25Henrik Grubbström (Grubba)  } }
f077582000-07-06Fredrik Hübinette (Hubbe)  switch(Pike_sp[-1].type) {
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  case T_FUNCTION: if((p = program_from_function(Pike_sp-1))) push_object_type(0, p?(p->id):0); else { struct pike_type *a,*b; a=get_type_of_svalue(Pike_sp-1); b=check_call(function_type_string,a,0); push_finished_type(b); free_type(a); free_type(b); } break;
7a08f32000-01-25Henrik Grubbström (Grubba)  default:
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass!=1)
721e4f2002-05-12Martin Stjernholm  my_yyerror("Illegal program identifier (type: %s).",
af4e112002-03-21Henrik Grubbström (Grubba)  get_name_of_type(Pike_sp[-1].type));
7a08f32000-01-25Henrik Grubbström (Grubba)  pop_stack(); push_int(0);
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  push_object_type(0, 0);
7a08f32000-01-25Henrik Grubbström (Grubba)  break; case T_PROGRAM:
f077582000-07-06Fredrik Hübinette (Hubbe)  p = Pike_sp[-1].u.program;
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  push_object_type(0, p?(p->id):0);
7a08f32000-01-25Henrik Grubbström (Grubba)  break; } }
f62c412001-03-05Henrik Grubbström (Grubba)  /* Attempt to name the type. */ if (Pike_compiler->last_identifier) { push_type_name(Pike_compiler->last_identifier); }
7a08f32000-01-25Henrik Grubbström (Grubba)  pop_stack(); free_node($1); } ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) 
f5fd531999-03-29Henrik Grubbström (Grubba) number_or_maxint: /* Empty */
8c77b61998-04-13Henrik Grubbström (Grubba)  {
69aa4b2003-01-26Mirar (Pontus Hagland)  $$ = mkintnode(MAX_INT_TYPE);
f5fd531999-03-29Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NUMBER | '-' TOK_NUMBER
3dc8561999-12-30Henrik Grubbström (Grubba)  { #ifdef PIKE_DEBUG if (($2->token != F_CONSTANT) || ($2->u.sval.type != T_INT)) {
5aad932002-08-15Marcus Comstedt  Pike_fatal("Unexpected number in negative int-range.\n");
3dc8561999-12-30Henrik Grubbström (Grubba)  } #endif /* PIKE_DEBUG */ $$ = mkintnode(-($2->u.sval.u.integer)); free_node($2); }
f5fd531999-03-29Henrik Grubbström (Grubba)  ; number_or_minint: /* Empty */ {
69aa4b2003-01-26Mirar (Pontus Hagland)  $$ = mkintnode(MIN_INT_TYPE);
f5fd531999-03-29Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NUMBER | '-' TOK_NUMBER
3dc8561999-12-30Henrik Grubbström (Grubba)  { #ifdef PIKE_DEBUG if (($2->token != F_CONSTANT) || ($2->u.sval.type != T_INT)) {
5aad932002-08-15Marcus Comstedt  Pike_fatal("Unexpected number in negative int-range.\n");
3dc8561999-12-30Henrik Grubbström (Grubba)  } #endif /* PIKE_DEBUG */ $$ = mkintnode(-($2->u.sval.u.integer)); free_node($2); }
f5fd531999-03-29Henrik Grubbström (Grubba)  ;
a7c3a42000-07-10Henrik Grubbström (Grubba) expected_dot_dot: TOK_DOT_DOT | TOK_DOT_DOT_DOT { yyerror("Elipsis ('...') where range indicator ('..') expected."); } ;
f5fd531999-03-29Henrik Grubbström (Grubba) opt_int_range: /* Empty */ {
69aa4b2003-01-26Mirar (Pontus Hagland)  push_int_type(MIN_INT_TYPE, MAX_INT_TYPE);
f5fd531999-03-29Henrik Grubbström (Grubba)  }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | '(' number_or_minint expected_dot_dot number_or_maxint ')'
f5fd531999-03-29Henrik Grubbström (Grubba)  {
69aa4b2003-01-26Mirar (Pontus Hagland)  INT_TYPE min = MIN_INT_TYPE; INT_TYPE max = MAX_INT_TYPE;
3611422001-02-20Henrik Grubbström (Grubba) 
f5fd531999-03-29Henrik Grubbström (Grubba)  /* FIXME: Check that $4 is >= $2. */
96c3932002-08-27Henrik Grubbström (Grubba)  if($4->token == F_CONSTANT) { if ($4->u.sval.type == T_INT) { max = $4->u.sval.u.integer; #ifdef AUTO_BIGNUM } else if (is_bignum_object_in_svalue(&$4->u.sval)) { push_int(0); if (is_lt(&$4->u.sval, Pike_sp-1)) {
69aa4b2003-01-26Mirar (Pontus Hagland)  max = MIN_INT_TYPE;
96c3932002-08-27Henrik Grubbström (Grubba)  } pop_stack(); #endif /* AUTO_BIGNUM */ }
011ad31999-10-22Fredrik Hübinette (Hubbe)  }
96c3932002-08-27Henrik Grubbström (Grubba)  if($2->token == F_CONSTANT) { if ($2->u.sval.type == T_INT) { min = $2->u.sval.u.integer; #ifdef AUTO_BIGNUM
5cad762002-08-27Henrik Grubbström (Grubba)  } else if (is_bignum_object_in_svalue(&$2->u.sval)) {
96c3932002-08-27Henrik Grubbström (Grubba)  push_int(0);
5cad762002-08-27Henrik Grubbström (Grubba)  if (is_lt(Pike_sp-1, &$2->u.sval)) {
69aa4b2003-01-26Mirar (Pontus Hagland)  min = MAX_INT_TYPE;
96c3932002-08-27Henrik Grubbström (Grubba)  } pop_stack(); #endif /* AUTO_BIGNUM */ }
011ad31999-10-22Fredrik Hübinette (Hubbe)  }
3611422001-02-20Henrik Grubbström (Grubba)  push_int_type(min, max);
011ad31999-10-22Fredrik Hübinette (Hubbe)  free_node($2); free_node($4);
8c77b61998-04-13Henrik Grubbström (Grubba)  }
3803c21998-11-11Henrik Grubbström (Grubba)  ;
8c77b61998-04-13Henrik Grubbström (Grubba) 
3611422001-02-20Henrik Grubbström (Grubba) opt_object_type: /* Empty */ { push_object_type(0, 0); }
a993572002-10-12Henrik Grubbström (Grubba)  | { #ifdef PIKE_DEBUG $<ptr>$ = Pike_sp; #endif /* PIKE_DEBUG */ } '(' program_ref ')'
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
66c2361998-08-29Henrik Grubbström (Grubba)  /* NOTE: On entry, there are two items on the stack:
f077582000-07-06Fredrik Hübinette (Hubbe)  * Pike_sp-2: Name of the program reference (string). * Pike_sp-1: The resolved program (program|function|zero).
66c2361998-08-29Henrik Grubbström (Grubba)  */
f077582000-07-06Fredrik Hübinette (Hubbe)  struct program *p=program_from_svalue(Pike_sp-1);
3611422001-02-20Henrik Grubbström (Grubba) 
a993572002-10-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if ($<ptr>1 != (Pike_sp - 2)) { Pike_fatal("Unexpected stack depth: %p != %p\n", $<n>1, Pike_sp-2); } #endif /* PIKE_DEBUG */
3611422001-02-20Henrik Grubbström (Grubba)  if(!p) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass!=1) {
f077582000-07-06Fredrik Hübinette (Hubbe)  if ((Pike_sp[-2].type == T_STRING) && (Pike_sp[-2].u.string->len > 0) && (Pike_sp[-2].u.string->len < 256)) {
ce060e2004-06-30Martin Nilsson  my_yyerror("Not a valid program specifier: %S", Pike_sp[-2]);
a786431999-11-18Martin Stjernholm  } else { yyerror("Not a valid program specifier."); }
66c2361998-08-29Henrik Grubbström (Grubba)  }
1532e61996-11-16Fredrik Hübinette (Hubbe)  }
3611422001-02-20Henrik Grubbström (Grubba)  push_object_type(0, p?(p->id):0);
f62c412001-03-05Henrik Grubbström (Grubba)  /* Attempt to name the type. */ if (Pike_sp[-2].type == T_STRING) { push_type_name(Pike_sp[-2].u.string); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  pop_n_elems(2); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) opt_function_type: '('
7e50571996-11-02Fredrik Hübinette (Hubbe)  { type_stack_mark(); } function_type_list optional_dot_dot_dot ':' {
0aa4ba2001-02-25Henrik Grubbström (Grubba)  /* Add the many type if there is none. */
7e50571996-11-02Fredrik Hübinette (Hubbe)  if ($4) {
0aa4ba2001-02-25Henrik Grubbström (Grubba)  if (!$3) {
7e71da2000-03-30Henrik Grubbström (Grubba)  /* function_type_list ends with a comma, or is empty. * FIXME: Should this be a syntax error or not? */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass == 1) {
6deabd2000-03-30Henrik Grubbström (Grubba)  yyerror("Missing type before ... .");
85fb3d2000-03-30Henrik Grubbström (Grubba)  }
7e71da2000-03-30Henrik Grubbström (Grubba)  push_type(T_MIXED);
cbae7e2000-03-30Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{ push_type(T_VOID); } }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7 ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
92aeb12001-02-26Henrik Grubbström (Grubba)  push_reverse_type(T_MANY); Pike_compiler->pike_type_mark_stackp--;
dfed932001-03-03Henrik Grubbström (Grubba)  while (*Pike_compiler->pike_type_mark_stackp+1 <
92aeb12001-02-26Henrik Grubbström (Grubba)  Pike_compiler->type_stackp) { push_reverse_type(T_FUNCTION); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } | /* empty */ { push_type(T_MIXED);
327c051999-11-24Fredrik Hübinette (Hubbe)  push_type(T_VOID); push_type(T_OR);
2401c72000-01-03Martin Stjernholm  push_type(T_ZERO);
327c051999-11-24Fredrik Hübinette (Hubbe)  push_type(T_VOID); push_type(T_OR);
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_MANY); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
cbae7e2000-03-30Henrik Grubbström (Grubba) function_type_list: /* Empty */ optional_comma { $$=0; } | function_type_list2 optional_comma { $$=!$2; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
cbae7e2000-03-30Henrik Grubbström (Grubba) function_type_list2: type7 { $$=1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | function_type_list2 ',' { }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) opt_array_type: '(' type7 ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  | { push_type(T_MIXED); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  opt_mapping_type: '('
7e50571996-11-02Fredrik Hübinette (Hubbe)  { }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7 ':'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  type7
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
92aeb12001-02-26Henrik Grubbström (Grubba)  push_reverse_type(T_MAPPING);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ')' | /* empty */ { push_type(T_MIXED); push_type(T_MIXED);
92aeb12001-02-26Henrik Grubbström (Grubba)  push_type(T_MAPPING);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  name_list: new_name
7e50571996-11-02Fredrik Hübinette (Hubbe)  | name_list ',' new_name ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) new_name: optional_stars TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
019b3d2000-07-09Henrik Grubbström (Grubba)  define_variable($2->u.sval.u.string, type, Pike_compiler->current_modifiers);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier {}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '='
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
019b3d2000-07-09Henrik Grubbström (Grubba)  if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared variable has initializer."); } $<number>$=define_variable($2->u.sval.u.string, type,
019b3d2000-07-09Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers & (~ID_EXTERN));
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } expr0 {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->init_node=mknode(F_COMMA_EXPR,Pike_compiler->init_node,
7e50571996-11-02Fredrik Hübinette (Hubbe)  mkcastnode(void_type_string, mknode(F_ASSIGN,$5, mkidentifiernode($<number>4))));
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' error
2968361998-04-14Henrik Grubbström (Grubba)  { free_node($2); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("Unexpected end of file in variable definition."); free_node($2); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier '=' expr0 { free_node($4); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) new_local_name: optional_stars TOK_IDENTIFIER
abdfb62002-09-28Martin Stjernholm  { int id;
3699402001-02-20Henrik Grubbström (Grubba)  push_finished_type($<n>0->u.sval.u.type);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
abdfb62002-09-28Martin Stjernholm  id = add_local_name($2->u.sval.u.string, compiler_pop_type(),0); if (id >= 0) $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(id,0)); else $$ = 0;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  | optional_stars bad_identifier { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' expr0
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
abdfb62002-09-28Martin Stjernholm  int id;
3699402001-02-20Henrik Grubbström (Grubba)  push_finished_type($<n>0->u.sval.u.type);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
abdfb62002-09-28Martin Stjernholm  id = add_local_name($2->u.sval.u.string, compiler_pop_type(),0); if (id >= 0) $$=mknode(F_ASSIGN,$4,mklocalnode(id,0)); else $$ = 0;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | optional_stars bad_identifier '=' expr0 { free_node($4);
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' error
8c77b61998-04-13Henrik Grubbström (Grubba)  { free_node($2); /* No yyerok here since we aren't done yet. */
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER '=' TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("Unexpected end of file in local variable definition."); free_node($2); /* No yyerok here since we aren't done yet. */ $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) new_local_name2: TOK_IDENTIFIER
6bc9281998-04-10Fredrik Hübinette (Hubbe)  {
abdfb62002-09-28Martin Stjernholm  int id;
3699402001-02-20Henrik Grubbström (Grubba)  add_ref($<n>0->u.sval.u.type);
abdfb62002-09-28Martin Stjernholm  id = add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.type, 0); if (id >= 0) $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(id,0)); else $$ = 0;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  free_node($1); }
498ec11999-11-12Henrik Grubbström (Grubba)  | bad_identifier { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '=' safe_expr0
6bc9281998-04-10Fredrik Hübinette (Hubbe)  {
abdfb62002-09-28Martin Stjernholm  int id;
3699402001-02-20Henrik Grubbström (Grubba)  add_ref($<n>0->u.sval.u.type);
abdfb62002-09-28Martin Stjernholm  id = add_local_name($1->u.sval.u.string, $<n>0->u.sval.u.type, 0); if (id >= 0) $$=mknode(F_ASSIGN,$3, mklocalnode(id,0)); else $$ = 0;
6bc9281998-04-10Fredrik Hübinette (Hubbe)  free_node($1); }
998e1f1998-04-15Henrik Grubbström (Grubba)  | bad_identifier '=' safe_expr0 { $$=$3; }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
9b39022003-03-27Martin Stjernholm line_number_info: /* empty */ { /* Used to hold line-number info */ $$ = mkintnode(0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) block:'{'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>1=Pike_compiler->num_used_modules; $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
9b39022003-03-27Martin Stjernholm  line_number_info
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level;
120d842000-11-08Fredrik Hübinette (Hubbe)  if($<number>$ == -1) /* if 'first block' */ Pike_compiler->compiler_frame->last_block_level=0; /* all variables */ else Pike_compiler->compiler_frame->last_block_level=$<number>2;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  }
73a2a11998-04-27Henrik Grubbström (Grubba)  statements end_block
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  unuse_modules(Pike_compiler->num_used_modules - $<number>1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
702ea52002-10-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level=$<number>4;
2917422004-08-25Henrik Grubbström (Grubba)  if ($5) COPY_LINE_NUMBER_INFO($5, $3);
9b39022003-03-27Martin Stjernholm  free_node ($3); $$=$5;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) end_block: '}'
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing '}'."); yyerror("Unexpected end of file."); } ;
01d3e21997-04-23Fredrik Hübinette (Hubbe) failsafe_block: block
73a2a11998-04-27Henrik Grubbström (Grubba)  | error { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
01d3e21997-04-23Fredrik Hübinette (Hubbe)  ;
a30f092000-07-12Fredrik Hübinette (Hubbe) 
01d3e21997-04-23Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) local_name_list: new_local_name
babd872001-02-23Henrik Grubbström (Grubba)  | local_name_list ',' { $<n>$=$<n>0; } new_local_name { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
6bc9281998-04-10Fredrik Hübinette (Hubbe) local_name_list2: new_local_name2
babd872001-02-23Henrik Grubbström (Grubba)  | local_name_list2 ',' { $<n>$=$<n>0; } new_local_name { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); }
6bc9281998-04-10Fredrik Hübinette (Hubbe)  ;
f5df592000-10-25Fredrik Hübinette (Hubbe)  local_constant_name: TOK_IDENTIFIER '=' safe_expr0 {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
f5df592000-10-25Fredrik Hübinette (Hubbe)  /* Ugly hack to make sure that $3 is optimized */ { int tmp=Pike_compiler->compiler_pass; $3=mknode(F_COMMA_EXPR,$3,0);
71bde82001-03-16Fredrik Hübinette (Hubbe)  optimize_node($3);
f5df592000-10-25Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass=tmp; type=$3->u.node.a->type; } if(!is_const($3)) { if(Pike_compiler->compiler_pass==2) yyerror("Constant definition is not constant."); }else{
9f85c32002-10-25Marcus Comstedt  ptrdiff_t tmp=eval_low($3,1);
f5df592000-10-25Fredrik Hübinette (Hubbe)  if(tmp < 1) { yyerror("Error in constant definition."); }else{ pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1))); if($3) free_node($3); $3=mksvaluenode(Pike_sp-1); type=$3->type; pop_stack(); } }
babd872001-02-23Henrik Grubbström (Grubba)  if(!type) type = mixed_type_string;
f5df592000-10-25Fredrik Hübinette (Hubbe)  add_ref(type);
107a0a2001-01-16Fredrik Hübinette (Hubbe)  low_add_local_name(Pike_compiler->compiler_frame, /*->previous,*/
f5df592000-10-25Fredrik Hübinette (Hubbe)  $1->u.sval.u.string, type, $3); free_node($1); } | bad_identifier '=' safe_expr0 { if ($3) free_node($3); } | error '=' safe_expr0 { if ($3) free_node($3); } ; local_constant_list: local_constant_name
1070292000-11-04Henrik Grubbström (Grubba)  | local_constant_list ',' local_constant_name
f5df592000-10-25Fredrik Hübinette (Hubbe)  ;
1070292000-11-04Henrik Grubbström (Grubba) local_constant: TOK_CONSTANT local_constant_list ';' | TOK_CONSTANT error ';' { yyerrok; } | TOK_CONSTANT error TOK_LEX_EOF
f5df592000-10-25Fredrik Hübinette (Hubbe)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); }
1070292000-11-04Henrik Grubbström (Grubba)  | TOK_CONSTANT error '}' { yyerror("Missing ';'."); }
f5df592000-10-25Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) statements: { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | statements statement {
babd872001-02-23Henrik Grubbström (Grubba)  $$ = mknode(F_COMMA_EXPR, $1, mkcastnode(void_type_string, $2));
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
71bde82001-03-16Fredrik Hübinette (Hubbe) statement_with_semicolon: unused2 optional_block { if($2) { $$=recursive_add_call_arg($1,$2); }else{ $$=$1; } } ;
f5df592000-10-25Fredrik Hübinette (Hubbe) 
71bde82001-03-16Fredrik Hübinette (Hubbe) normal_label_statement: statement_with_semicolon
97358e1998-04-23Fredrik Hübinette (Hubbe)  | import { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | cond
71bde82001-03-16Fredrik Hübinette (Hubbe)  | return
f5df592000-10-25Fredrik Hübinette (Hubbe)  | local_constant { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | block
586b8a1998-04-28Henrik Grubbström (Grubba)  | break expected_semicolon | continue expected_semicolon
e2acf71997-04-23Henrik Grubbström (Grubba)  | error ';' { reset_type_stack(); $$=0; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { reset_type_stack(); yyerror("Missing ';'."); yyerror("Unexpected end of file."); $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | error '}' { reset_type_stack();
998e1f1998-04-15Henrik Grubbström (Grubba)  yyerror("Missing ';'.");
eb5c901998-04-19Fredrik Hübinette (Hubbe) /* yychar = '}'; */ /* Put the '}' back on the input stream. */ $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | ';' { $$=0; } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm statement: normal_label_statement { Pike_compiler->compiler_frame->opt_flags &= ~OPT_CUSTOM_LABELS; } | while | do | for | foreach | switch | case | default | labeled_statement ; labeled_statement: TOK_IDENTIFIER { Pike_compiler->compiler_frame->opt_flags &= ~OPT_CUSTOM_LABELS; } ':' statement { $$ = mknode(Pike_compiler->compiler_frame->opt_flags & OPT_CUSTOM_LABELS ? F_CUSTOM_STMT_LABEL : F_NORMAL_STMT_LABEL, $1, $4); /* FIXME: This won't be correct if the node happens to be shared. * That's an issue to be solved with shared nodes in general, * though. */
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
5a0fd52001-01-10Martin Stjernholm  } ; optional_label: TOK_IDENTIFIER | /* empty */ {$$ = 0;} ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm break: TOK_BREAK optional_label { $$=mknode(F_BREAK,$2,0); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) default: TOK_DEFAULT ':' { $$=mknode(F_DEFAULT,0,0); } | TOK_DEFAULT
4d21331998-04-14Henrik Grubbström (Grubba)  { $$=mknode(F_DEFAULT,0,0); yyerror("Expected ':' after default."); } ;
5a0fd52001-01-10Martin Stjernholm continue: TOK_CONTINUE optional_label { $$=mknode(F_CONTINUE,$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba) push_compiler_frame1: /* empty */
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
8322b62000-05-08Fredrik Hübinette (Hubbe)  push_compiler_frame(SCOPE_LOCAL);
b5aa651999-12-16Henrik Grubbström (Grubba)  } ;
9b39022003-03-27Martin Stjernholm lambda: TOK_LAMBDA line_number_info push_compiler_frame1
b5aa651999-12-16Henrik Grubbström (Grubba)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type)
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(Pike_compiler->compiler_frame->current_return_type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_return_type, any_type_string);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
9039702000-08-15Henrik Grubbström (Grubba)  func_args { $<number>$ = Pike_compiler->varargs; Pike_compiler->varargs = 0; } failsafe_block
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
b1aa472001-10-05Fredrik Hübinette (Hubbe)  char buf[80];
329cc01997-02-17Fredrik Hübinette (Hubbe)  int f,e;
7e50571996-11-02Fredrik Hübinette (Hubbe)  struct pike_string *name;
9b39022003-03-27Martin Stjernholm  struct pike_string *save_file = lex.current_file;
d4f23b2001-08-10Martin Stjernholm  int save_line = lex.current_line;
9b39022003-03-27Martin Stjernholm  lex.current_file = $2->current_file; lex.current_line = $2->line_number;
d4f23b2001-08-10Martin Stjernholm 
9b39022003-03-27Martin Stjernholm  debug_malloc_touch($7); $7=mknode(F_COMMA_EXPR,$7,mknode(F_RETURN,mkintnode(0),0));
cbdf332003-03-27Martin Stjernholm  if (Pike_compiler->compiler_pass == 2) /* Doing this in pass 1 might induce too strict checks on types * in cases where we got placeholders. */ type=find_return_type($7); else type = NULL;
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
b0ef311999-12-14Henrik Grubbström (Grubba)  if(type) {
61e9a01998-01-25Fredrik Hübinette (Hubbe)  push_finished_type(type);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
b0ef311999-12-14Henrik Grubbström (Grubba)  } else
61e9a01998-01-25Fredrik Hübinette (Hubbe)  push_type(T_MIXED);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
9b39022003-03-27Martin Stjernholm  e=$5-1; if($<number>6)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--;
5b368e2001-03-31Henrik Grubbström (Grubba)  pop_type_stack(T_ARRAY);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{ push_type(T_VOID); }
9039702000-08-15Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_MANY);
dfed932001-03-03Henrik Grubbström (Grubba)  for(; e>=0; e--) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
dfed932001-03-03Henrik Grubbström (Grubba)  push_type(T_FUNCTION); }
7e50571996-11-02Fredrik Hübinette (Hubbe) 
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
d4f23b2001-08-10Martin Stjernholm  sprintf(buf,"__lambda_%ld_%ld_line_%d",
bad5162000-06-23Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id,
d4f23b2001-08-10Martin Stjernholm  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ (int) lex.current_line);
8267f41998-01-28Fredrik Hübinette (Hubbe)  name=make_shared_string(buf);
c4d4681998-06-06Henrik Grubbström (Grubba)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
c4d4681998-06-06Henrik Grubbström (Grubba) #endif /* LAMBDA_DEBUG */
b1aa472001-10-05Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass == 2) Pike_compiler->compiler_frame->current_function_number=isidentifier(name);
3271182004-03-18Henrik Grubbström (Grubba) 
8267f41998-01-28Fredrik Hübinette (Hubbe)  f=dooptcode(name,
9b39022003-03-27Martin Stjernholm  $7,
8267f41998-01-28Fredrik Hübinette (Hubbe)  type,
c6eb961999-12-14Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
22edc21998-01-29Fredrik Hübinette (Hubbe) 
164d6b2001-11-29Henrik Grubbström (Grubba) #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: lexical_scope: 0x%08x\n", Pike_compiler->compiler_pass, Pike_compiler->compiler_frame->lexical_scope); #endif /* LAMBDA_DEBUG */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED) {
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  $$ = mktrampolinenode(f, Pike_compiler->compiler_frame->previous);
498ec11999-11-12Henrik Grubbström (Grubba)  } else { $$ = mkidentifiernode(f); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_string(name);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
d4f23b2001-08-10Martin Stjernholm  lex.current_line = save_line;
9b39022003-03-27Martin Stjernholm  lex.current_file = save_file; free_node ($2);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3271182004-03-18Henrik Grubbström (Grubba)  | TOK_LAMBDA line_number_info push_compiler_frame1 error
b5aa651999-12-16Henrik Grubbström (Grubba)  { pop_compiler_frame();
3857bd2000-11-04Henrik Grubbström (Grubba)  $$ = mkintnode(0);
3271182004-03-18Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2); free_node($2);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) local_function: TOK_IDENTIFIER push_compiler_frame1 func_args
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
97f6282000-03-07Fredrik Hübinette (Hubbe)  char buf[40];
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_string *name; struct pike_type *type;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  int id,e;
97f6282000-03-07Fredrik Hübinette (Hubbe)  node *n; struct identifier *i=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type)
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(Pike_compiler->compiler_frame->current_return_type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_return_type, $<n>0->u.sval.u.type);
97f6282000-03-07Fredrik Hübinette (Hubbe) 
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  /***/
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  e=$3-1;
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs)
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  e--;
5b368e2001-03-31Henrik Grubbström (Grubba)  pop_type_stack(T_ARRAY);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }else{ push_type(T_VOID); } push_type(T_MANY);
dfed932001-03-03Henrik Grubbström (Grubba)  for(; e>=0; e--) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
dfed932001-03-03Henrik Grubbström (Grubba)  push_type(T_FUNCTION); }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
97f6282000-03-07Fredrik Hübinette (Hubbe)  /***/
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
d4f23b2001-08-10Martin Stjernholm  sprintf(buf,"__lambda_%ld_%ld_line_%d",
bad5162000-06-23Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id,
d4f23b2001-08-10Martin Stjernholm  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ (int) $1->line_number);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */ name=make_shared_string(buf);
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1) { id=isidentifier(name); }else{ id=define_function(name, type,
b1aa472001-10-05Fredrik Hübinette (Hubbe)  ID_INLINE,
3116ce2002-11-22Henrik Grubbström (Grubba)  IDENTIFIER_PIKE_FUNCTION | (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  0, OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); }
3116ce2002-11-22Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
b1aa472001-10-05Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->current_function_number=id;
3271182004-03-18Henrik Grubbström (Grubba) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  n=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1 && (i=ID_FROM_INT(Pike_compiler->new_program, id)))
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  { if(i->identifier_flags & IDENTIFIER_SCOPED) n = mktrampolinenode(id, Pike_compiler->compiler_frame->previous); else
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  n = mkidentifiernode(id);
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  }
5fb9b02000-04-06Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_add_local_name(Pike_compiler->compiler_frame->previous,
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  $1->u.sval.u.string, type, n); $<number>$=id; free_string(name); } failsafe_block { int localid;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct identifier *i=ID_FROM_INT(Pike_compiler->new_program, $<number>4);
d4f23b2001-08-10Martin Stjernholm  struct pike_string *save_file = lex.current_file;
f639a52003-02-04Martin Stjernholm  int save_line = lex.current_line;
d4f23b2001-08-10Martin Stjernholm  lex.current_file = $1->current_file; lex.current_line = $1->line_number;
5fb9b02000-04-06Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  $5=mknode(F_COMMA_EXPR,$5,mknode(F_RETURN,mkintnode(0),0));
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($5);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  dooptcode(i->name,
97f6282000-03-07Fredrik Hübinette (Hubbe)  $5,
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  i->type,
97f6282000-03-07Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
1ef5572000-08-30Henrik Grubbström (Grubba)  i->opt_flags = Pike_compiler->compiler_frame->opt_flags;
d4f23b2001-08-10Martin Stjernholm  lex.current_line = save_line; lex.current_file = save_file;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  pop_compiler_frame(); free_node($1);
97f6282000-03-07Fredrik Hübinette (Hubbe)  /* WARNING: If the local function adds more variables we are screwed */
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /* WARNING2: if add_local_name stops adding local variables at the end, * this has to be fixed. */
bad5162000-06-23Fredrik Hübinette (Hubbe)  localid=Pike_compiler->compiler_frame->current_number_of_locals-1; if(Pike_compiler->compiler_frame->variable[localid].def)
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $$=copy_node(Pike_compiler->compiler_frame->variable[localid].def);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }else{
b6cdf32000-06-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->lexical_scope & (SCOPE_SCOPE_USED | SCOPE_SCOPED))
d187072000-06-20Fredrik Hübinette (Hubbe)  {
3a77fb2003-02-26Henrik Grubbström (Grubba)  $$ = mktrampolinenode($<number>4,Pike_compiler->compiler_frame);
d187072000-06-20Fredrik Hübinette (Hubbe)  }else{
3a77fb2003-02-26Henrik Grubbström (Grubba)  $$ = mkidentifiernode($<number>4);
d187072000-06-20Fredrik Hübinette (Hubbe)  }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IDENTIFIER push_compiler_frame1 error
b5aa651999-12-16Henrik Grubbström (Grubba)  { pop_compiler_frame();
97f6282000-03-07Fredrik Hübinette (Hubbe)  $$=mkintnode(0);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) local_function2: optional_stars TOK_IDENTIFIER push_compiler_frame1 func_args
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
97f6282000-03-07Fredrik Hübinette (Hubbe)  char buf[40];
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_string *name; struct pike_type *type;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  int id,e;
97f6282000-03-07Fredrik Hübinette (Hubbe)  node *n; struct identifier *i=0;
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /***/
bad5162000-06-23Fredrik Hübinette (Hubbe)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
3699402001-02-20Henrik Grubbström (Grubba)  push_finished_type($<n>0->u.sval.u.type);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if ($1 && (Pike_compiler->compiler_pass == 2)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  while($1--) push_type(T_ARRAY);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_return_type)
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(Pike_compiler->compiler_frame->current_return_type);
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->current_return_type=compiler_pop_type();
97f6282000-03-07Fredrik Hübinette (Hubbe) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /***/
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  e=$4-1;
c3cfe92000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->varargs)
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  e--;
5b368e2001-03-31Henrik Grubbström (Grubba)  pop_type_stack(T_ARRAY);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }else{ push_type(T_VOID); } push_type(T_MANY);
dfed932001-03-03Henrik Grubbström (Grubba)  for(; e>=0; e--) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
dfed932001-03-03Henrik Grubbström (Grubba)  push_type(T_FUNCTION); }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  type=compiler_pop_type(); /***/
97f6282000-03-07Fredrik Hübinette (Hubbe) 
d4f23b2001-08-10Martin Stjernholm  sprintf(buf,"__lambda_%ld_%ld_line_%d",
bad5162000-06-23Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id,
d4f23b2001-08-10Martin Stjernholm  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ (int) $2->line_number);
97f6282000-03-07Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
97f6282000-03-07Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */ name=make_shared_string(buf);
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1) { id=isidentifier(name); }else{ id=define_function(name, type,
b1aa472001-10-05Fredrik Hübinette (Hubbe)  ID_INLINE,
3116ce2002-11-22Henrik Grubbström (Grubba)  IDENTIFIER_PIKE_FUNCTION| (Pike_compiler->varargs?IDENTIFIER_VARARGS:0),
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  0, OPT_SIDE_EFFECT|OPT_EXTERNAL_DEPEND); }
3116ce2002-11-22Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
b1aa472001-10-05Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->current_function_number=id;
3271182004-03-18Henrik Grubbström (Grubba) 
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  n=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1 && (i=ID_FROM_INT(Pike_compiler->new_program, id)))
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  { if(i->identifier_flags & IDENTIFIER_SCOPED) n = mktrampolinenode(id, Pike_compiler->compiler_frame->previous); else
97f6282000-03-07Fredrik Hübinette (Hubbe)  n = mkidentifiernode(id);
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  }
97f6282000-03-07Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  low_add_local_name(Pike_compiler->compiler_frame->previous,
97f6282000-03-07Fredrik Hübinette (Hubbe)  $2->u.sval.u.string, type, n); $<number>$=id; free_string(name);
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  failsafe_block
a566ca1999-12-14Fredrik Hübinette (Hubbe)  {
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  int localid;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct identifier *i=ID_FROM_INT(Pike_compiler->new_program, $<number>5);
d4f23b2001-08-10Martin Stjernholm  struct pike_string *save_file = lex.current_file;
f639a52003-02-04Martin Stjernholm  int save_line = lex.current_line;
d4f23b2001-08-10Martin Stjernholm  lex.current_file = $2->current_file; lex.current_line = $2->line_number;
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($6); $6=mknode(F_COMMA_EXPR,$6,mknode(F_RETURN,mkintnode(0),0));
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
b5aa651999-12-16Henrik Grubbström (Grubba)  debug_malloc_touch($6);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  dooptcode(i->name,
97f6282000-03-07Fredrik Hübinette (Hubbe)  $6,
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  i->type,
97f6282000-03-07Fredrik Hübinette (Hubbe)  ID_STATIC | ID_PRIVATE | ID_INLINE);
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
1ef5572000-08-30Henrik Grubbström (Grubba)  i->opt_flags = Pike_compiler->compiler_frame->opt_flags;
d4f23b2001-08-10Martin Stjernholm  lex.current_line = save_line; lex.current_file = save_file;
a566ca1999-12-14Fredrik Hübinette (Hubbe)  pop_compiler_frame(); free_node($2);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  /* WARNING: If the local function adds more variables we are screwed */
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  /* WARNING2: if add_local_name stops adding local variables at the end, * this has to be fixed. */
bad5162000-06-23Fredrik Hübinette (Hubbe)  localid=Pike_compiler->compiler_frame->current_number_of_locals-1; if(Pike_compiler->compiler_frame->variable[localid].def)
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $$=copy_node(Pike_compiler->compiler_frame->variable[localid].def);
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }else{
b6cdf32000-06-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->lexical_scope & (SCOPE_SCOPE_USED | SCOPE_SCOPED))
d187072000-06-20Fredrik Hübinette (Hubbe)  {
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  $$ = mktrampolinenode($<number>5,Pike_compiler->compiler_frame);
d187072000-06-20Fredrik Hübinette (Hubbe)  }else{
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  $$ = mkidentifiernode($<number>5);
d187072000-06-20Fredrik Hübinette (Hubbe)  }
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | optional_stars TOK_IDENTIFIER push_compiler_frame1 error
b5aa651999-12-16Henrik Grubbström (Grubba)  { pop_compiler_frame(); free_node($2);
97f6282000-03-07Fredrik Hübinette (Hubbe)  $$=mkintnode(0);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  ;
e6c0892001-03-30Henrik Grubbström (Grubba) create_arg: modifiers type_or_error optional_stars optional_dot_dot_dot TOK_IDENTIFIER
c20a522000-07-08Henrik Grubbström (Grubba)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
c20a522000-07-08Henrik Grubbström (Grubba) 
e6c0892001-03-30Henrik Grubbström (Grubba)  if (Pike_compiler->varargs) { yyerror("Can't define more variables after ..."); }
c20a522000-07-08Henrik Grubbström (Grubba)  push_finished_type(Pike_compiler->compiler_frame->current_type); if ($3 && (Pike_compiler->compiler_pass == 2)) { yywarning("The *-syntax in types is obsolete. Use array instead."); } while($3--) push_type(T_ARRAY);
e6c0892001-03-30Henrik Grubbström (Grubba)  if ($4) { push_type(T_ARRAY); Pike_compiler->varargs = 1; }
c20a522000-07-08Henrik Grubbström (Grubba)  type=compiler_pop_type();
e6c0892001-03-30Henrik Grubbström (Grubba)  if(islocal($5->u.sval.u.string) >= 0)
ce060e2004-06-30Martin Nilsson  my_yyerror("Variable %O appears twice in create argument list.", $5->u.sval);
c20a522000-07-08Henrik Grubbström (Grubba)  /* Add the identifier both globally and locally. */
e6c0892001-03-30Henrik Grubbström (Grubba)  define_variable($5->u.sval.u.string, type,
019b3d2000-07-09Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers);
e6c0892001-03-30Henrik Grubbström (Grubba)  add_local_name($5->u.sval.u.string, type, 0);
c20a522000-07-08Henrik Grubbström (Grubba) 
d68a072001-02-20Henrik Grubbström (Grubba)  /* free_type(type); */
e6c0892001-03-30Henrik Grubbström (Grubba)  free_node($5);
c20a522000-07-08Henrik Grubbström (Grubba)  $$=0; } | modifiers type_or_error optional_stars bad_identifier { $$=0; } ; create_arguments2: create_arg { $$ = 1; } | create_arguments2 ',' create_arg { $$ = $1 + 1; } | create_arguments2 ':' create_arg { yyerror("Unexpected ':' in create argument list."); $$ = $1 + 1; } ; create_arguments: /* empty */ optional_comma { $$=0; } | create_arguments2 optional_comma ; push_compiler_frame01: /* empty */ { push_compiler_frame(SCOPE_LOCAL); } ; optional_create_arguments: /* empty */ { $$ = 0; } | '(' push_compiler_frame01 create_arguments close_paren_or_missing { int e; node *create_code = NULL;
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type = NULL;
c20a522000-07-08Henrik Grubbström (Grubba)  struct pike_string *create_string = NULL; int f;
de56ec2003-02-08Martin Stjernholm  MAKE_CONST_STRING(create_string, "create");
c20a522000-07-08Henrik Grubbström (Grubba)  /* First: Deduce the type for the create() function. */ push_type(T_VOID); /* Return type. */
e6c0892001-03-30Henrik Grubbström (Grubba)  e = $3-1; if (Pike_compiler->varargs) { /* Varargs */ push_finished_type(Pike_compiler->compiler_frame->variable[e--].type);
5b368e2001-03-31Henrik Grubbström (Grubba)  pop_type_stack(T_ARRAY); /* Pop one level of array. */
e6c0892001-03-30Henrik Grubbström (Grubba)  } else { /* Not varargs. */ push_type(T_VOID); }
c20a522000-07-08Henrik Grubbström (Grubba)  push_type(T_MANY);
e6c0892001-03-30Henrik Grubbström (Grubba)  for(; e >= 0; e--) {
c20a522000-07-08Henrik Grubbström (Grubba)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
dfed932001-03-03Henrik Grubbström (Grubba)  push_type(T_FUNCTION);
c20a522000-07-08Henrik Grubbström (Grubba)  } type = compiler_pop_type(); /* Second: Declare the function. */ Pike_compiler->compiler_frame->current_function_number= define_function(create_string, type,
3116ce2002-11-22Henrik Grubbström (Grubba)  ID_INLINE | ID_STATIC, IDENTIFIER_PIKE_FUNCTION | (Pike_compiler->varargs?IDENTIFIER_VARARGS:0), 0,
1ef5572000-08-30Henrik Grubbström (Grubba)  OPT_SIDE_EFFECT);
c20a522000-07-08Henrik Grubbström (Grubba) 
3116ce2002-11-22Henrik Grubbström (Grubba)  Pike_compiler->varargs = 0;
c20a522000-07-08Henrik Grubbström (Grubba)  /* Third: Generate the initialization code. * * global_arg = [type]local_arg; * [,..] */ for(e=0; e<$3; e++) { if(!Pike_compiler->compiler_frame->variable[e].name || !Pike_compiler->compiler_frame->variable[e].name->len) { my_yyerror("Missing name for argument %d.",e); } else { node *local_node = mklocalnode(e, 0); /* FIXME: Should probably use some other flag. */ if ((runtime_options & RUNTIME_CHECK_TYPES) && (Pike_compiler->compiler_pass == 2) && (Pike_compiler->compiler_frame->variable[e].type != mixed_type_string)) { /* fprintf(stderr, "Creating soft cast node for local #%d\n", e);*/ /* The following is needed to go around the optimization in * mksoftcastnode(). */
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(local_node->type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(local_node->type, mixed_type_string);
c20a522000-07-08Henrik Grubbström (Grubba)  local_node = mksoftcastnode(Pike_compiler->compiler_frame-> variable[e].type, local_node); } create_code = mknode(F_COMMA_EXPR, create_code, mknode(F_ASSIGN, local_node, mkidentifiernode(isidentifier(Pike_compiler-> compiler_frame-> variable[e].name)))); } } /* Fourth: Add a return 0; at the end. */ create_code = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, create_code, NULL), mknode(F_RETURN, mkintnode(0), NULL)); /* Fifth: Define the function. */ f=dooptcode(create_string, check_node_hash(create_code), type, ID_STATIC); #ifdef PIKE_DEBUG if(Pike_interpreter.recoveries && Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack error (underflow)\n");
c20a522000-07-08Henrik Grubbström (Grubba)  if(Pike_compiler->compiler_pass == 1 && f!=Pike_compiler->compiler_frame->current_function_number)
5aad932002-08-15Marcus Comstedt  Pike_fatal("define_function screwed up! %d != %d\n",
c20a522000-07-08Henrik Grubbström (Grubba)  f, Pike_compiler->compiler_frame->current_function_number); #endif /* Done. */ pop_compiler_frame(); free_node($4);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
c20a522000-07-08Henrik Grubbström (Grubba)  } ;
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
586b8a1998-04-28Henrik Grubbström (Grubba) failsafe_program: '{' program end_block
e2acf71997-04-23Henrik Grubbström (Grubba)  | error { yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("End of file where program definition expected."); }
febbc81997-04-22Fredrik Hübinette (Hubbe)  ;
9b39022003-03-27Martin Stjernholm class: modifiers TOK_CLASS line_number_info optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
9b39022003-03-27Martin Stjernholm  if(!$4)
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *s;
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  char buffer[42];
d4f23b2001-08-10Martin Stjernholm  sprintf(buffer,"__class_%ld_%ld_line_%d", (long)Pike_compiler->new_program->id, (long)Pike_compiler->local_class_counter++,
9b39022003-03-27Martin Stjernholm  (int) $3->line_number);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  s=make_shared_string(buffer);
9b39022003-03-27Martin Stjernholm  $4=mkstrnode(s);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_string(s);
c6eb961999-12-14Fredrik Hübinette (Hubbe)  $1|=ID_STATIC | ID_PRIVATE | ID_INLINE;
51ffdb1998-01-19Fredrik Hübinette (Hubbe)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  /* fprintf(stderr, "LANGUAGE.YACC: CLASS start\n"); */
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass==1)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8fd9311999-12-30Henrik Grubbström (Grubba)  if ($1 & ID_EXTERN) { yywarning("Extern declared class definition."); }
e60a362003-06-03Henrik Grubbström (Grubba)  low_start_new_program(0, 1, $4->u.sval.u.string,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
ff88db2000-07-12Henrik Grubbström (Grubba)  /* fprintf(stderr, "Pass 1: Program %s has id %d\n",
9b39022003-03-27Martin Stjernholm  $4->u.sval.u.string->str, Pike_compiler->new_program->id); */
ff88db2000-07-12Henrik Grubbström (Grubba) 
9b39022003-03-27Martin Stjernholm  store_linenumber($3->line_number, $3->current_file); debug_malloc_name(Pike_compiler->new_program, $3->current_file->str, $3->line_number);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ int i; struct identifier *id;
bad5162000-06-23Fredrik Hübinette (Hubbe)  int tmp=Pike_compiler->compiler_pass;
9b39022003-03-27Martin Stjernholm  i=isidentifier($4->u.sval.u.string);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(i<0) {
6c2aad2003-09-01Martin Nilsson  /* Seriously broken... */
25df642003-08-20Henrik Grubbström (Grubba)  yyerror("Pass 2: program not defined!"); low_start_new_program(0, 2, 0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{
bad5162000-06-23Fredrik Hübinette (Hubbe)  id=ID_FROM_INT(Pike_compiler->new_program, i);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(IDENTIFIER_IS_CONSTANT(id->identifier_flags)) { struct svalue *s;
25df642003-08-20Henrik Grubbström (Grubba)  if ((id->func.offset >= 0) && ((s = &PROG_FROM_INT(Pike_compiler->new_program,i)-> constants[id->func.offset].sval)->type == T_PROGRAM))
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
e60a362003-06-03Henrik Grubbström (Grubba)  low_start_new_program(s->u.program, 2,
9b39022003-03-27Martin Stjernholm  $4->u.sval.u.string,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
ff88db2000-07-12Henrik Grubbström (Grubba)  /* fprintf(stderr, "Pass 2: Program %s has id %d\n",
9b39022003-03-27Martin Stjernholm  $4->u.sval.u.string->str, Pike_compiler->new_program->id); */
ff88db2000-07-12Henrik Grubbström (Grubba) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{ yyerror("Pass 2: constant redefined!");
25df642003-08-20Henrik Grubbström (Grubba)  low_start_new_program(0, 2, 0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }else{ yyerror("Pass 2: class constant no longer constant!");
25df642003-08-20Henrik Grubbström (Grubba)  low_start_new_program(0, 2, 0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  $1, &$<number>$);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } }
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_pass=tmp;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
afbd442004-10-22Andreas (Kaos) Stenius  { /* Clear scoped modifiers. */ $<number>$ = lex.pragmas; lex.pragmas &= ~ID_MODIFIER_MASK; }
c20a522000-07-08Henrik Grubbström (Grubba)  optional_create_arguments failsafe_program
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  struct program *p;
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass == 1)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  p=end_first_pass(0); else
97358e1998-04-23Fredrik Hübinette (Hubbe)  p=end_first_pass(1);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
8c77b61998-04-13Henrik Grubbström (Grubba)  /* fprintf(stderr, "LANGUAGE.YACC: CLASS end\n"); */
903dd32004-03-13Henrik Grubbström (Grubba)  if(p) {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  free_program(p);
4eab662004-03-17Henrik Grubbström (Grubba)  } else if (!Pike_compiler->num_parse_error) {
72de5a2004-03-13Henrik Grubbström (Grubba)  /* Make sure code in this class is aware that something went wrong. */
4eab662004-03-17Henrik Grubbström (Grubba)  Pike_compiler->num_parse_error = 1;
2401c72000-01-03Martin Stjernholm  }
9b39022003-03-27Martin Stjernholm  $$=mkidentifiernode($<number>5);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
afbd442004-10-22Andreas (Kaos) Stenius  free_node($3);
9b39022003-03-27Martin Stjernholm  free_node($4);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  check_tree($$,0);
afbd442004-10-22Andreas (Kaos) Stenius  lex.pragmas = $<number>6;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
5e3aa52001-04-01Henrik Grubbström (Grubba) simple_identifier: TOK_IDENTIFIER
a418ce2001-03-31Henrik Grubbström (Grubba)  | bad_identifier { $$ = 0; } ; enum_value: /* EMPTY */ { safe_inc_enum(); } | '=' safe_expr0 { pop_stack(); /* This can be made more lenient in the future */ /* Ugly hack to make sure that $2 is optimized */ { int tmp=Pike_compiler->compiler_pass; $2=mknode(F_COMMA_EXPR,$2,0); Pike_compiler->compiler_pass=tmp; } if(!is_const($2)) { if(Pike_compiler->compiler_pass==2) yyerror("Enum definition is not constant."); push_int(0); } else { if(!Pike_compiler->num_parse_error) {
9f85c32002-10-25Marcus Comstedt  ptrdiff_t tmp=eval_low($2,1);
a418ce2001-03-31Henrik Grubbström (Grubba)  if(tmp < 1) { yyerror("Error in enum definition."); push_int(0); }else{ pop_n_elems(DO_NOT_WARN((INT32)(tmp - 1))); } } else { push_int(0); } } if($2) free_node($2); } ; enum_def: /* EMPTY */
5e3aa52001-04-01Henrik Grubbström (Grubba)  | simple_identifier enum_value
a418ce2001-03-31Henrik Grubbström (Grubba)  { if ($1) { add_constant($1->u.sval.u.string, Pike_sp-1,
9319582001-04-03Henrik Grubbström (Grubba)  (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);
a418ce2001-03-31Henrik Grubbström (Grubba)  } free_node($1); /* Update the type. */ { struct pike_type *current = pop_unfinished_type(); struct pike_type *new = get_type_of_svalue(Pike_sp-1);
5e3aa52001-04-01Henrik Grubbström (Grubba)  struct pike_type *res = or_pike_types(new, current, 1);
a418ce2001-03-31Henrik Grubbström (Grubba)  free_type(current); free_type(new); type_stack_mark(); push_finished_type(res);
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  free_type(res);
a418ce2001-03-31Henrik Grubbström (Grubba)  } } ; enum_list: enum_def | enum_list ',' enum_def
cd69002004-07-23Henrik Grubbström (Grubba)  | error
a418ce2001-03-31Henrik Grubbström (Grubba)  ; enum: modifiers TOK_ENUM { if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) { yywarning("Extern declared enum."); } push_int(-1); /* Last enum-value. */ type_stack_mark(); push_type(T_ZERO); /* Joined type so far. */ } optional_identifier '{' enum_list end_block { struct pike_type *t = pop_unfinished_type(); pop_stack(); if ($4) { ref_push_type_value(t); add_constant($4->u.sval.u.string, Pike_sp-1,
3e13612001-04-03Henrik Grubbström (Grubba)  (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);
a418ce2001-03-31Henrik Grubbström (Grubba)  pop_stack(); free_node($4); } $$ = mktypenode(t); free_type(t); } ;
5e3aa52001-04-01Henrik Grubbström (Grubba) typedef: modifiers TOK_TYPEDEF full_type simple_identifier ';' { struct pike_type *t = compiler_pop_type(); if ((Pike_compiler->current_modifiers & ID_EXTERN) && (Pike_compiler->compiler_pass == 1)) { yywarning("Extern declared typedef."); } if ($4) { ref_push_type_value(t); add_constant($4->u.sval.u.string, Pike_sp-1,
3e13612001-04-03Henrik Grubbström (Grubba)  (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE);
5e3aa52001-04-01Henrik Grubbström (Grubba)  pop_stack(); free_node($4); } free_type(t); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) cond: TOK_IF
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
10fe602003-10-01Martin Stjernholm  line_number_info
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond statement optional_else_part
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
702ea52002-10-11Henrik Grubbström (Grubba)  $$ = mknode('?', $6,
0ef4e02002-05-09Henrik Grubbström (Grubba)  mknode(':',
702ea52002-10-11Henrik Grubbström (Grubba)  mkcastnode(void_type_string, $8), mkcastnode(void_type_string, $9)));
0ef4e02002-05-09Henrik Grubbström (Grubba)  $$ = mkcastnode(void_type_string, $$);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $3);
10fe602003-10-01Martin Stjernholm  free_node ($3);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
702ea52002-10-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level=$<number>4;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) end_cond: ')' | '}' { yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ')'."); yyerror("Unexpected end of file."); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) optional_else_part: { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_ELSE statement { $$=$2; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
998e1f1998-04-15Henrik Grubbström (Grubba) safe_lvalue: lvalue
97358e1998-04-23Fredrik Hübinette (Hubbe)  | error { $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ; safe_expr0: expr0
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
498ec11999-11-12Henrik Grubbström (Grubba)  | error { $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ;
4cdb802001-02-23Fredrik Hübinette (Hubbe)  foreach_optional_lvalue: /* empty */ { $$=0; } | safe_lvalue ; foreach_lvalues: ',' safe_lvalue { $$=$2; } | ';' foreach_optional_lvalue ';' foreach_optional_lvalue { $$=mknode(':',$2,$4); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) foreach: TOK_FOREACH
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
9b39022003-03-27Martin Stjernholm  line_number_info
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
4cdb802001-02-23Fredrik Hübinette (Hubbe)  '(' expr0 foreach_lvalues end_cond statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
702ea52002-10-11Henrik Grubbström (Grubba)  if ($7) {
4cdb802001-02-23Fredrik Hübinette (Hubbe)  $$=mknode(F_FOREACH,
702ea52002-10-11Henrik Grubbström (Grubba)  mknode(F_VAL_LVAL,$6,$7), $9);
998e1f1998-04-15Henrik Grubbström (Grubba)  } else { /* Error in lvalue */
702ea52002-10-11Henrik Grubbström (Grubba)  free_node($6); $$=$9;
998e1f1998-04-15Henrik Grubbström (Grubba)  }
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $3);
9b39022003-03-27Martin Stjernholm  free_node ($3);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
702ea52002-10-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level=$<number>4;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
9b39022003-03-27Martin Stjernholm do: TOK_DO line_number_info statement TOK_WHILE '(' safe_comma_expr end_cond expected_semicolon
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
9b39022003-03-27Martin Stjernholm  $$=mknode(F_DO,$3,$6);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
9b39022003-03-27Martin Stjernholm  free_node ($2);
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
9b39022003-03-27Martin Stjernholm  | TOK_DO line_number_info statement TOK_WHILE TOK_LEX_EOF
07f33e1998-11-05Henrik Grubbström (Grubba)  {
9b39022003-03-27Martin Stjernholm  free_node ($2);
07f33e1998-11-05Henrik Grubbström (Grubba)  $$=0; yyerror("Missing '(' in do-while loop."); yyerror("Unexpected end of file."); }
9b39022003-03-27Martin Stjernholm  | TOK_DO line_number_info statement TOK_LEX_EOF
07f33e1998-11-05Henrik Grubbström (Grubba)  {
9b39022003-03-27Martin Stjernholm  free_node ($2);
07f33e1998-11-05Henrik Grubbström (Grubba)  $$=0; yyerror("Missing 'while' in do-while loop."); yyerror("Unexpected end of file."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) expected_semicolon: ';'
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  { yyerror("Missing ';'."); yyerror("Unexpected end of file."); } ;
f76b4c2000-05-11Henrik Grubbström (Grubba) for: TOK_FOR
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
10fe602003-10-01Martin Stjernholm  line_number_info
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' unused expected_semicolon for_expr expected_semicolon unused end_cond statement
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
702ea52002-10-11Henrik Grubbström (Grubba)  $$=mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $6), mknode(F_FOR,$8,mknode(':',$12,$10)));
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $3);
10fe602003-10-01Martin Stjernholm  free_node ($3);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
702ea52002-10-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level=$<number>4;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) while: TOK_WHILE
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
10fe602003-10-01Martin Stjernholm  line_number_info
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
702ea52002-10-11Henrik Grubbström (Grubba)  $$=mknode(F_FOR,$6,mknode(':',$8,NULL));
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $3);
10fe602003-10-01Martin Stjernholm  free_node ($3);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
702ea52002-10-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level=$<number>4;
5a0fd52001-01-10Martin Stjernholm  Pike_compiler->compiler_frame->opt_flags |= OPT_CUSTOM_LABELS;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  for_expr: /* EMPTY */ { $$=mkintnode(1); }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) switch: TOK_SWITCH
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
9b39022003-03-27Martin Stjernholm  line_number_info
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */ $<number>$=Pike_compiler->compiler_frame->last_block_level; Pike_compiler->compiler_frame->last_block_level=$<number>2; }
73a2a11998-04-27Henrik Grubbström (Grubba)  '(' safe_comma_expr end_cond statement
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
702ea52002-10-11Henrik Grubbström (Grubba)  $$=mknode(F_SWITCH,$6,$8);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $3);
9b39022003-03-27Martin Stjernholm  free_node ($3);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_local_variables($<number>2);
702ea52002-10-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level=$<number>4;
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) case: TOK_CASE safe_comma_expr expected_colon
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_CASE,$2,0); }
a7c3a42000-07-10Henrik Grubbström (Grubba)  | TOK_CASE safe_comma_expr expected_dot_dot optional_comma_expr expected_colon
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
9abda42002-03-02Martin Stjernholm  $$=mknode(F_CASE_RANGE,$2,$4); } | TOK_CASE expected_dot_dot safe_comma_expr expected_colon { $$=mknode(F_CASE_RANGE,0,$3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
73a2a11998-04-27Henrik Grubbström (Grubba) expected_colon: ':'
76b4491999-12-09Henrik Grubbström (Grubba)  | ';' { yyerror("Missing ':'."); } | '}' { yyerror("Missing ':'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF
73a2a11998-04-27Henrik Grubbström (Grubba)  {
3d78821999-11-06Henrik Grubbström (Grubba)  yyerror("Missing ':'.");
73a2a11998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); } ;
71bde82001-03-16Fredrik Hübinette (Hubbe) return: TOK_RETURN expected_semicolon
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
b8cd052000-09-26Fredrik Hübinette (Hubbe)  if(!TEST_COMPAT(0,6) && !match_types(Pike_compiler->compiler_frame->current_return_type,
7e50571996-11-02Fredrik Hübinette (Hubbe)  void_type_string)) {
f23f062004-03-12Henrik Grubbström (Grubba)  yytype_error("Must return a value for a non-void function.", Pike_compiler->compiler_frame->current_return_type, void_type_string, 0);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } $$=mknode(F_RETURN,mkintnode(0),0); }
71bde82001-03-16Fredrik Hübinette (Hubbe)  | TOK_RETURN safe_comma_expr expected_semicolon
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_RETURN,$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  unused: { $$=0; }
babd872001-02-23Henrik Grubbström (Grubba)  | safe_comma_expr { $$=mkcastnode(void_type_string, $1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
babd872001-02-23Henrik Grubbström (Grubba) unused2: comma_expr { $$=mkcastnode(void_type_string, $1); } ;
7e50571996-11-02Fredrik Hübinette (Hubbe) 
ba62cf1997-09-18Fredrik Hübinette (Hubbe) optional_comma_expr: { $$=0; }
4d21331998-04-14Henrik Grubbström (Grubba)  | safe_comma_expr ; safe_comma_expr: comma_expr
498ec11999-11-12Henrik Grubbström (Grubba)  | error { $$=0; }
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) comma_expr: comma_expr2
6bc9281998-04-10Fredrik Hübinette (Hubbe)  | simple_type2 local_name_list { $$=$2; free_node($1); } | simple_identifier_type local_name_list2 { $$=$2; free_node($1); }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  | simple_identifier_type local_function { $$=$2; free_node($1); } | simple_type2 local_function2 { $$=$2; free_node($1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ; comma_expr2: expr0 | comma_expr2 ',' expr0 {
babd872001-02-23Henrik Grubbström (Grubba)  $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr00: expr0
7e50571996-11-02Fredrik Hübinette (Hubbe)  | '@' expr0 { $$=mknode(F_PUSH_ARRAY,$2,0); };
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr0: expr01
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr4 '=' expr0 { $$=mknode(F_ASSIGN,$3,$1); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 '=' error { $$=$1; reset_type_stack(); yyerrok; }
a663191998-04-17Henrik Grubbström (Grubba)  | bad_expr_ident '=' expr0 { $$=$3; }
10fe602003-10-01Martin Stjernholm  | open_bracket_with_line_info low_lvalue_list ']' '=' expr0 { $$=mknode(F_ASSIGN,$5,mknode(F_ARRAY_LVALUE,$2,0));
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
10fe602003-10-01Martin Stjernholm  free_node ($1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr4 assign expr0 { $$=mknode($2,$1,$3); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | expr4 assign error { $$=$1; reset_type_stack(); yyerrok; }
a663191998-04-17Henrik Grubbström (Grubba)  | bad_expr_ident assign expr0 { $$=$3; }
10fe602003-10-01Martin Stjernholm  | open_bracket_with_line_info low_lvalue_list ']' assign expr0 { $$=mknode($4,mknode(F_ARRAY_LVALUE,$2,0),$5);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
10fe602003-10-01Martin Stjernholm  free_node ($1); } | open_bracket_with_line_info low_lvalue_list ']' error { $$=$2; free_node ($1); reset_type_stack(); yyerrok; }
8c77b61998-04-13Henrik Grubbström (Grubba) /* | error { $$=0; reset_type_stack(); } */
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
97358e1998-04-23Fredrik Hübinette (Hubbe) expr01: expr1
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '?' expr01 ':' expr01 { $$=mknode('?',$1,mknode(':',$3,$5)); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) assign: TOK_AND_EQ { $$=F_AND_EQ; } | TOK_OR_EQ { $$=F_OR_EQ; } | TOK_XOR_EQ { $$=F_XOR_EQ; } | TOK_LSH_EQ { $$=F_LSH_EQ; } | TOK_RSH_EQ { $$=F_RSH_EQ; } | TOK_ADD_EQ { $$=F_ADD_EQ; } | TOK_SUB_EQ { $$=F_SUB_EQ; } | TOK_MULT_EQ{ $$=F_MULT_EQ; } | TOK_MOD_EQ { $$=F_MOD_EQ; } | TOK_DIV_EQ { $$=F_DIV_EQ; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
cbae7e2000-03-30Henrik Grubbström (Grubba) optional_comma: { $$=0; } | ',' { $$=1; };
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr_list: { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr_list2 optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr_list2: expr00
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr_list2 ',' expr00 { $$=mknode(F_ARG_LIST,$1,$3); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  m_expr_list: { $$=0; }
97358e1998-04-23Fredrik Hübinette (Hubbe)  | m_expr_list2 optional_comma
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  m_expr_list2: assoc_pair
998e1f1998-04-15Henrik Grubbström (Grubba)  | m_expr_list2 ',' assoc_pair { if ($3) { $$=mknode(F_ARG_LIST,$1,$3); } else { /* Error in assoc_pair */ $$=$1; } } | m_expr_list2 ',' error
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3271182004-03-18Henrik Grubbström (Grubba) assoc_pair: expr0 expected_colon expr0 { $$=mknode(F_ARG_LIST,$1,$3); }
73a2a11998-04-27Henrik Grubbström (Grubba)  | expr0 expected_colon error { free_node($1); $$=0; }
998e1f1998-04-15Henrik Grubbström (Grubba)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr1: expr2
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LOR expr1 { $$=mknode(F_LOR,$1,$3); } | expr1 TOK_LAND expr1 { $$=mknode(F_LAND,$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '|' expr1 { $$=mkopernode("`|",$1,$3); } | expr1 '^' expr1 { $$=mkopernode("`^",$1,$3); } | expr1 '&' expr1 { $$=mkopernode("`&",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_EQ expr1 { $$=mkopernode("`==",$1,$3); } | expr1 TOK_NE expr1 { $$=mkopernode("`!=",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '>' expr1 { $$=mkopernode("`>",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_GE expr1 { $$=mkopernode("`>=",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '<' expr1 { $$=mkopernode("`<",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LE expr1 { $$=mkopernode("`<=",$1,$3); } | expr1 TOK_LSH expr1 { $$=mkopernode("`<<",$1,$3); } | expr1 TOK_RSH expr1 { $$=mkopernode("`>>",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '+' expr1 { $$=mkopernode("`+",$1,$3); } | expr1 '-' expr1 { $$=mkopernode("`-",$1,$3); } | expr1 '*' expr1 { $$=mkopernode("`*",$1,$3); } | expr1 '%' expr1 { $$=mkopernode("`%",$1,$3); } | expr1 '/' expr1 { $$=mkopernode("`/",$1,$3); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LOR error | expr1 TOK_LAND error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '|' error | expr1 '^' error | expr1 '&' error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_EQ error | expr1 TOK_NE error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '>' error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_GE error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '<' error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LE error | expr1 TOK_LSH error | expr1 TOK_RSH error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | expr1 '+' error | expr1 '-' error | expr1 '*' error | expr1 '%' error | expr1 '/' error
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr2: expr3
7e50571996-11-02Fredrik Hübinette (Hubbe)  | cast expr2 {
3699402001-02-20Henrik Grubbström (Grubba)  $$ = mkcastnode($1->u.sval.u.type, $2);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
1d73ef1999-11-23Henrik Grubbström (Grubba)  | soft_cast expr2 {
3699402001-02-20Henrik Grubbström (Grubba)  $$ = mksoftcastnode($1->u.sval.u.type, $2);
1d73ef1999-11-23Henrik Grubbström (Grubba)  free_node($1); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INC expr4 { $$=mknode(F_INC,$2,0); } | TOK_DEC expr4 { $$=mknode(F_DEC,$2,0); } | TOK_NOT expr2 { $$=mkopernode("`!",$2,0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | '~' expr2 { $$=mkopernode("`~",$2,0); } | '-' expr2 { $$=mkopernode("`-",$2,0); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  expr3: expr4
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr4 TOK_INC { $$=mknode(F_POST_INC,$1,0); } | expr4 TOK_DEC { $$=mknode(F_POST_DEC,$1,0); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
a30f092000-07-12Fredrik Hübinette (Hubbe) /* FIXMEs * It would be nice if 'return' would exit from * the surrounding function rather than from the * implicit lambda. (I think) So beware that the * behaviour of 'return' might change some day. * -Hubbe * * It would also be nice if it was possible to send * arguments to the implicit function, but it would * require using ugly implicit variables or extending * the syntax, and if you extend the syntax you might * as well use lambda() instead. * -Hubbe * * We might want to allow having more than block after * a function ( ie. func(args) {} {} {} {} ) * -Hubbe */
71bde82001-03-16Fredrik Hübinette (Hubbe) optional_block: ';' /* EMPTY */ { $$=0; }
9b39022003-03-27Martin Stjernholm  | '{' line_number_info push_compiler_frame0
a30f092000-07-12Fredrik Hübinette (Hubbe)  { debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type)
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(Pike_compiler->compiler_frame->current_return_type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_return_type, any_type_string);
a30f092000-07-12Fredrik Hübinette (Hubbe)  /* block code */ $<number>1=Pike_compiler->num_used_modules;
c68a292001-06-10Henrik Grubbström (Grubba)  $<number>$=Pike_compiler->compiler_frame->current_number_of_locals;
a30f092000-07-12Fredrik Hübinette (Hubbe)  }
74d75d2002-09-16Marcus Comstedt  statements end_block expected_semicolon
a30f092000-07-12Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
a30f092000-07-12Fredrik Hübinette (Hubbe)  char buf[40];
c68a292001-06-10Henrik Grubbström (Grubba)  int f/*, e */;
a30f092000-07-12Fredrik Hübinette (Hubbe)  struct pike_string *name;
9b39022003-03-27Martin Stjernholm  struct pike_string *save_file = lex.current_file;
d4f23b2001-08-10Martin Stjernholm  int save_line = lex.current_line;
9b39022003-03-27Martin Stjernholm  lex.current_file = $2->current_file; lex.current_line = $2->line_number;
a30f092000-07-12Fredrik Hübinette (Hubbe)  /* block code */ unuse_modules(Pike_compiler->num_used_modules - $<number>1);
9b39022003-03-27Martin Stjernholm  pop_local_variables($<number>4);
c68a292001-06-10Henrik Grubbström (Grubba) 
9b39022003-03-27Martin Stjernholm  debug_malloc_touch($5); $5=mknode(F_COMMA_EXPR,$5,mknode(F_RETURN,mkintnode(0),0));
cbdf332003-03-27Martin Stjernholm  if (Pike_compiler->compiler_pass == 2) /* Doing this in pass 1 might induce too strict checks on types * in cases where we got placeholders. */ type=find_return_type($5); else type = NULL;
a30f092000-07-12Fredrik Hübinette (Hubbe)  if(type) { push_finished_type(type);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
a30f092000-07-12Fredrik Hübinette (Hubbe)  } else push_type(T_MIXED); push_type(T_VOID); push_type(T_MANY); /*
9b39022003-03-27Martin Stjernholm  e=$5-1;
a30f092000-07-12Fredrik Hübinette (Hubbe)  for(; e>=0; e--) push_finished_type(Pike_compiler->compiler_frame->variable[e].type); */ type=compiler_pop_type();
d4f23b2001-08-10Martin Stjernholm  sprintf(buf,"__lambda_%ld_%ld_line_%d",
a30f092000-07-12Fredrik Hübinette (Hubbe)  (long)Pike_compiler->new_program->id,
d4f23b2001-08-10Martin Stjernholm  (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */ (int) lex.current_line);
a30f092000-07-12Fredrik Hübinette (Hubbe)  name=make_shared_string(buf); #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: IMPLICIT LAMBDA: %s 0x%08lx 0x%08lx\n", Pike_compiler->compiler_pass, buf, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1); #endif /* LAMBDA_DEBUG */ f=dooptcode(name,
9b39022003-03-27Martin Stjernholm  $5,
a30f092000-07-12Fredrik Hübinette (Hubbe)  type, ID_STATIC | ID_PRIVATE | ID_INLINE); if(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED) {
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  $$ = mktrampolinenode(f,Pike_compiler->compiler_frame->previous);
a30f092000-07-12Fredrik Hübinette (Hubbe)  } else { $$ = mkidentifiernode(f); }
d4f23b2001-08-10Martin Stjernholm  lex.current_line = save_line;
9b39022003-03-27Martin Stjernholm  lex.current_file = save_file; free_node ($2);
a30f092000-07-12Fredrik Hübinette (Hubbe)  free_string(name);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
a30f092000-07-12Fredrik Hübinette (Hubbe)  pop_compiler_frame(); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) expr4: string
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NUMBER | TOK_FLOAT { $$=mkfloatnode((FLOAT_TYPE)$1); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | catch | gauge | typeof | sscanf | lambda | class
a418ce2001-03-31Henrik Grubbström (Grubba)  | enum
71d9702000-06-21Henrik Grubbström (Grubba)  | idents2
10fe602003-10-01Martin Stjernholm  | expr4 open_paren_with_line_info expr_list ')'
a30f092000-07-12Fredrik Hübinette (Hubbe)  { $$=mkapplynode($1,$3);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
10fe602003-10-01Martin Stjernholm  free_node ($2);
a30f092000-07-12Fredrik Hübinette (Hubbe)  }
10fe602003-10-01Martin Stjernholm  | expr4 open_paren_with_line_info error ')'
db271d1998-04-27Henrik Grubbström (Grubba)  {
10fe602003-10-01Martin Stjernholm  $$=mkapplynode($1, NULL); free_node ($2); yyerrok; } | expr4 open_paren_with_line_info error TOK_LEX_EOF { yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file.");
10fe602003-10-01Martin Stjernholm  $$=mkapplynode($1, NULL); free_node ($2); } | expr4 open_paren_with_line_info error ';' { yyerror("Missing ')'."); $$=mkapplynode($1, NULL); free_node ($2); } | expr4 open_paren_with_line_info error '}' { yyerror("Missing ')'."); $$=mkapplynode($1, NULL); free_node ($2); } | expr4 open_bracket_with_line_info '*' ']' { $$=mknode(F_AUTO_MAP_MARKER, $1, 0);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
10fe602003-10-01Martin Stjernholm  free_node ($2); } | expr4 open_bracket_with_line_info expr0 ']' { $$=mknode(F_INDEX,$1,$3);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
10fe602003-10-01Martin Stjernholm  free_node ($2);
db271d1998-04-27Henrik Grubbström (Grubba)  }
10fe602003-10-01Martin Stjernholm  | expr4 open_bracket_with_line_info comma_expr_or_zero expected_dot_dot comma_expr_or_maxint ']'
d2c6081996-11-07Fredrik Hübinette (Hubbe)  { $$=mknode(F_RANGE,$1,mknode(F_ARG_LIST,$3,$5));
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
10fe602003-10-01Martin Stjernholm  free_node ($2);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
10fe602003-10-01Martin Stjernholm  | expr4 open_bracket_with_line_info error ']' { $$=$1; free_node ($2); yyerrok; } | expr4 open_bracket_with_line_info error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  { $$=$1; yyerror("Missing ']'."); yyerror("Unexpected end of file.");
10fe602003-10-01Martin Stjernholm  free_node ($2);
db271d1998-04-27Henrik Grubbström (Grubba)  }
10fe602003-10-01Martin Stjernholm  | expr4 open_bracket_with_line_info error ';' {$$=$1; yyerror("Missing ']'."); free_node ($2);} | expr4 open_bracket_with_line_info error '}' {$$=$1; yyerror("Missing ']'."); free_node ($2);} | expr4 open_bracket_with_line_info error ')' {$$=$1; yyerror("Missing ']'."); free_node ($2);} | open_paren_with_line_info comma_expr2 ')'
0195962004-08-25Henrik Grubbström (Grubba)  {$$=$2; COPY_LINE_NUMBER_INFO($$, $1); free_node ($1);}
10fe602003-10-01Martin Stjernholm  | open_paren_with_line_info '{' expr_list close_brace_or_missing ')' { $$=mkefuncallnode("aggregate",$3);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
10fe602003-10-01Martin Stjernholm  free_node ($1); } | open_paren_with_line_info open_bracket_with_line_info /* Only to avoid shift/reduce conflicts. */ m_expr_list close_bracket_or_missing ')' { $$=mkefuncallnode("aggregate_mapping",$3);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $1);
10fe602003-10-01Martin Stjernholm  free_node ($1); free_node ($2); } | TOK_MULTISET_START line_number_info expr_list TOK_MULTISET_END { $$=mkefuncallnode("aggregate_multiset",$3);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
10fe602003-10-01Martin Stjernholm  free_node ($2); } | TOK_MULTISET_START line_number_info expr_list ')'
76b4491999-12-09Henrik Grubbström (Grubba)  { yyerror("Missing '>'.");
10fe602003-10-01Martin Stjernholm  $$=mkefuncallnode("aggregate_multiset",$3);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $2);
10fe602003-10-01Martin Stjernholm  free_node ($2);
76b4491999-12-09Henrik Grubbström (Grubba)  }
10fe602003-10-01Martin Stjernholm  | open_paren_with_line_info error ')' { $$=$1; yyerrok; } | open_paren_with_line_info error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
10fe602003-10-01Martin Stjernholm  $$=$1; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
10fe602003-10-01Martin Stjernholm  | open_paren_with_line_info error ';' { $$=$1; yyerror("Missing ')'."); } | open_paren_with_line_info error '}' { $$=$1; yyerror("Missing ')'."); } | TOK_MULTISET_START line_number_info error TOK_MULTISET_END { $$=$2; yyerrok; } | TOK_MULTISET_START line_number_info error ')' {
76b4491999-12-09Henrik Grubbström (Grubba)  yyerror("Missing '>'.");
10fe602003-10-01Martin Stjernholm  $$=$2; yyerrok;
76b4491999-12-09Henrik Grubbström (Grubba)  }
10fe602003-10-01Martin Stjernholm  | TOK_MULTISET_START line_number_info error TOK_LEX_EOF
76b4491999-12-09Henrik Grubbström (Grubba)  {
10fe602003-10-01Martin Stjernholm  $$=$2; yyerror("Missing '>)'.");
76b4491999-12-09Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
10fe602003-10-01Martin Stjernholm  | TOK_MULTISET_START line_number_info error ';' { $$=$2; yyerror("Missing '>)'."); } | TOK_MULTISET_START line_number_info error '}' { $$=$2; yyerror("Missing '>)'."); } | expr4 TOK_ARROW line_number_info magic_identifier
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
10fe602003-10-01Martin Stjernholm  $$=mknode(F_ARROW,$1,$4);
0195962004-08-25Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $3);
10fe602003-10-01Martin Stjernholm  free_node ($3);
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
10fe602003-10-01Martin Stjernholm  | expr4 TOK_ARROW line_number_info error {$$=$1; free_node ($3);}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  ;
71d9702000-06-21Henrik Grubbström (Grubba) idents2: idents | TOK_LOCAL_ID TOK_COLON_COLON TOK_IDENTIFIER { int i;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
71d9702000-06-21Henrik Grubbström (Grubba) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  if (((i = find_shared_string_identifier(Pike_compiler->last_identifier,
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->new_program)) >= 0) ||
de1d7d2000-07-10Henrik Grubbström (Grubba)  ((i = really_low_find_shared_string_identifier(Pike_compiler->last_identifier,
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->new_program,
71d9702000-06-21Henrik Grubbström (Grubba)  SEE_STATIC| SEE_PRIVATE)) >= 0)) {
acbe8a2002-09-21Martin Stjernholm  struct reference *ref = Pike_compiler->new_program->identifier_references + i; if (!TEST_COMPAT (7, 2) && IDENTIFIER_IS_VARIABLE ( ID_FROM_PTR (Pike_compiler->new_program, ref)->identifier_flags)) { /* Allowing local:: on variables would lead to pathological * behavior: If a non-local variable in a class is referenced * both with and without local::, both references would * address the same variable in all cases except where an * inheriting program overrides it (c.f. [bug 1252]). * * Furthermore, that's not how it works currently; if this * error is removed then local:: will do nothing on variables * except forcing a lookup in the closest surrounding class * scope. */
c0dec72002-09-21Martin Stjernholm  yyerror ("Cannot make local references to variables.");
acbe8a2002-09-21Martin Stjernholm  $$ = 0; } else { if (!(ref->id_flags & ID_HIDDEN)) { /* We need to generate a new reference. */ int d; struct reference funp = *ref; funp.id_flags = (funp.id_flags & ~ID_INHERITED) | ID_INLINE|ID_HIDDEN; i = -1; for(d = 0; d < (int)Pike_compiler->new_program->num_identifier_references; d++) { struct reference *refp; refp = Pike_compiler->new_program->identifier_references + d; if(!MEMCMP((char *)refp,(char *)&funp,sizeof funp)) { i = d; break; } } if (i < 0) { add_to_identifier_references(funp); i = Pike_compiler->new_program->num_identifier_references - 1;
71d9702000-06-21Henrik Grubbström (Grubba)  } }
acbe8a2002-09-21Martin Stjernholm  $$ = mkidentifiernode(i);
71d9702000-06-21Henrik Grubbström (Grubba)  } } else {
f23f062004-03-12Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) {
ce060e2004-06-30Martin Nilsson  my_yyerror("%S not defined in local scope.", Pike_compiler->last_identifier);
f23f062004-03-12Henrik Grubbström (Grubba)  $$ = 0;
71d9702000-06-21Henrik Grubbström (Grubba)  } else {
f23f062004-03-12Henrik Grubbström (Grubba)  $$ = mknode(F_UNDEFINED, 0, 0);
71d9702000-06-21Henrik Grubbström (Grubba)  } } free_node($3); } | TOK_LOCAL_ID TOK_COLON_COLON bad_identifier { $$=0; } ;
591c0c1997-01-19Fredrik Hübinette (Hubbe) idents: low_idents
f76b4c2000-05-11Henrik Grubbström (Grubba)  | idents '.' TOK_IDENTIFIER
591c0c1997-01-19Fredrik Hübinette (Hubbe)  {
de1d7d2000-07-10Henrik Grubbström (Grubba)  $$=index_node($1, Pike_compiler->last_identifier?Pike_compiler->last_identifier->str:NULL,
fae37d1998-08-30Henrik Grubbström (Grubba)  $3->u.sval.u.string);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  free_node($1);
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3);
591c0c1997-01-19Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | '.' TOK_IDENTIFIER
eb5c901998-04-19Fredrik Hübinette (Hubbe)  {
9036e82001-08-16Martin Stjernholm  struct pike_string *dot;
de56ec2003-02-08Martin Stjernholm  MAKE_CONST_STRING(dot, ".");
9036e82001-08-16Martin Stjernholm  if (call_handle_import(dot)) { node *tmp=mkconstantsvaluenode(Pike_sp-1); pop_stack(); $$=index_node(tmp, ".", $2->u.sval.u.string); free_node(tmp);
10e16f1999-11-04Henrik Grubbström (Grubba)  }
9036e82001-08-16Martin Stjernholm  else $$=mknewintnode(0);
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);
eb5c901998-04-19Fredrik Hübinette (Hubbe)  free_node($2); }
f34f642002-05-05Martin Stjernholm  | TOK_GLOBAL '.' TOK_IDENTIFIER { $$ = resolve_identifier ($3->u.sval.u.string); if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string); free_node ($3); }
8c77b61998-04-13Henrik Grubbström (Grubba)  | idents '.' bad_identifier {}
4d21331998-04-14Henrik Grubbström (Grubba)  | idents '.' error {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ;
82e1b72000-06-22Henrik Grubbström (Grubba) inherit_specifier: TOK_IDENTIFIER TOK_COLON_COLON {
91b0d92002-05-05Martin Stjernholm  int e = -1;
82e1b72000-06-22Henrik Grubbström (Grubba) 
8c64232000-06-26Henrik Grubbström (Grubba)  inherit_state = Pike_compiler;
0ee38f2002-05-11Martin Stjernholm  for (inherit_depth = 0;; inherit_depth++, inherit_state = inherit_state->previous) {
91b0d92002-05-05Martin Stjernholm  int inh = find_inherit(inherit_state->new_program, $1->u.sval.u.string); if (inh) { e = inh;
8c64232000-06-26Henrik Grubbström (Grubba)  break;
91b0d92002-05-05Martin Stjernholm  }
0ee38f2002-05-11Martin Stjernholm  if (inherit_depth == compilation_depth) break;
91b0d92002-05-05Martin Stjernholm  if (!TEST_COMPAT (7, 2) && ID_FROM_INT (inherit_state->previous->new_program, inherit_state->previous->parent_identifier)->name == $1->u.sval.u.string) { e = 0; break; }
8c64232000-06-26Henrik Grubbström (Grubba)  }
91b0d92002-05-05Martin Stjernholm  if (e == -1) { if (TEST_COMPAT (7, 2))
ce060e2004-06-30Martin Nilsson  my_yyerror("No such inherit %O.", $1->u.sval);
e5674c2002-06-07Martin Stjernholm  else { if ($1->u.sval.u.string == this_program_string) { inherit_state = Pike_compiler; inherit_depth = 0; e = 0; } else
ce060e2004-06-30Martin Nilsson  my_yyerror("No inherit or surrounding class %O.", $1->u.sval);
e5674c2002-06-07Martin Stjernholm  }
82e1b72000-06-22Henrik Grubbström (Grubba)  } free_node($1);
8c64232000-06-26Henrik Grubbström (Grubba)  $$ = e;
82e1b72000-06-22Henrik Grubbström (Grubba)  }
3604362002-05-05Martin Stjernholm  | TOK_GLOBAL TOK_COLON_COLON { inherit_state = Pike_compiler; for (inherit_depth = 0; inherit_depth < compilation_depth; inherit_depth++, inherit_state = inherit_state->previous) {} $$ = 0; }
82e1b72000-06-22Henrik Grubbström (Grubba)  | inherit_specifier TOK_IDENTIFIER TOK_COLON_COLON {
91b0d92002-05-05Martin Stjernholm  if ($1 >= 0) {
0b3d0f2000-06-26Henrik Grubbström (Grubba)  int e = 0; #if 0 /* FIXME: The inherit modifiers aren't kept. */ if (!(inherit_state->new_program->inherits[$1].flags & ID_PRIVATE)) { #endif /* 0 */ e = find_inherit(inherit_state->new_program->inherits[$1].prog, $2->u.sval.u.string); #if 0 } #endif /* 0 */
8c64232000-06-26Henrik Grubbström (Grubba)  if (!e) { if (inherit_state->new_program->inherits[$1].name) {
ce060e2004-06-30Martin Nilsson  my_yyerror("No such inherit %S::%O.", inherit_state->new_program->inherits[$1].name, $2->u.sval);
8c64232000-06-26Henrik Grubbström (Grubba)  } else {
ce060e2004-06-30Martin Nilsson  my_yyerror("No such inherit %O.", $2->u.sval);
8c64232000-06-26Henrik Grubbström (Grubba)  }
91b0d92002-05-05Martin Stjernholm  $$ = -1;
82e1b72000-06-22Henrik Grubbström (Grubba)  } else {
8c64232000-06-26Henrik Grubbström (Grubba)  /* We know stuff about the inherit structure... */ $$ = e + $1;
82e1b72000-06-22Henrik Grubbström (Grubba)  } } free_node($2); }
91b0d92002-05-05Martin Stjernholm  | inherit_specifier bad_identifier TOK_COLON_COLON { $$ = -1; }
82e1b72000-06-22Henrik Grubbström (Grubba)  ;
f76b4c2000-05-11Henrik Grubbström (Grubba) low_idents: TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $1->u.sval.u.string);
4218011999-01-31Fredrik Hübinette (Hubbe) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(($$=lexical_islocal(Pike_compiler->last_identifier)))
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
4218011999-01-31Fredrik Hübinette (Hubbe)  /* done, nothing to do here */
0ee38f2002-05-11Martin Stjernholm  }else if(!($$=find_module_identifier(Pike_compiler->last_identifier,1)) && !($$ = program_magic_identifier (Pike_compiler, 0, 0, Pike_compiler->last_identifier, 0))) {
cd2be32004-03-13Henrik Grubbström (Grubba)  if((Pike_compiler->flags & COMPILATION_FORCE_RESOLVE) ||
4eab662004-03-17Henrik Grubbström (Grubba)  (Pike_compiler->compiler_pass==2)) {
ce060e2004-06-30Martin Nilsson  my_yyerror("Undefined identifier %S.", Pike_compiler->last_identifier);
4eab662004-03-17Henrik Grubbström (Grubba)  /* FIXME: Add this identifier as a constant in the current program to * avoid multiple reporting of the same identifier. * NOTE: This should then only be done in the second pass. */
f23f062004-03-12Henrik Grubbström (Grubba)  $$=0;
97358e1998-04-23Fredrik Hübinette (Hubbe)  }else{
f23f062004-03-12Henrik Grubbström (Grubba)  $$=mknode(F_UNDEFINED,0,0);
dffa011997-01-15Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF TOK_COLON_COLON TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
45e8a81997-01-26Fredrik Hübinette (Hubbe)  node *tmp2;
ac87152000-09-25Fredrik Hübinette (Hubbe)  extern dynamic_buffer used_modules;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
ac87152000-09-25Fredrik Hübinette (Hubbe)  tmp2=mkconstantsvaluenode((struct svalue *) used_modules.s.str );
fae37d1998-08-30Henrik Grubbström (Grubba)  $$=index_node(tmp2, "predef", $3->u.sval.u.string);
43fc171999-09-19Fredrik Hübinette (Hubbe)  if(!$$->name) add_ref( $$->name=$3->u.sval.u.string );
45e8a81997-01-26Fredrik Hübinette (Hubbe)  free_node(tmp2);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF TOK_COLON_COLON bad_identifier
8c77b61998-04-13Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
82e1b72000-06-22Henrik Grubbström (Grubba)  | inherit_specifier TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
91b0d92002-05-05Martin Stjernholm  if ($1 >= 0) {
8c64232000-06-26Henrik Grubbström (Grubba)  int id;
fae37d1998-08-30Henrik Grubbström (Grubba) 
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);
a005eb1999-03-04Fredrik Hübinette (Hubbe) 
59e7652002-05-11Martin Stjernholm  if ($1 > 0) id = low_reference_inherited_identifier(inherit_state, $1, Pike_compiler->last_identifier, SEE_STATIC); else id = really_low_find_shared_string_identifier(Pike_compiler->last_identifier, inherit_state->new_program, SEE_STATIC|SEE_PRIVATE);
8c64232000-06-26Henrik Grubbström (Grubba)  if (id != -1) {
0ee38f2002-05-11Martin Stjernholm  if (inherit_depth > 0) {
ff88db2000-07-12Henrik Grubbström (Grubba)  $$ = mkexternalnode(inherit_state->new_program, id);
8c64232000-06-26Henrik Grubbström (Grubba)  } else { $$ = mkidentifiernode(id); }
0ee38f2002-05-11Martin Stjernholm  } else if (($$ = program_magic_identifier (inherit_state, inherit_depth, $1, Pike_compiler->last_identifier, 1))) { /* All done. */ } else {
cd2be32004-03-13Henrik Grubbström (Grubba)  if ((Pike_compiler->flags & COMPILATION_FORCE_RESOLVE) || (Pike_compiler->compiler_pass == 2)) {
59e7652002-05-11Martin Stjernholm  if (inherit_state->new_program->inherits[$1].name) {
ce060e2004-06-30Martin Nilsson  my_yyerror("Undefined identifier %S::%S.", inherit_state->new_program->inherits[$1].name, Pike_compiler->last_identifier);
59e7652002-05-11Martin Stjernholm  } else {
ce060e2004-06-30Martin Nilsson  my_yyerror("Undefined identifier %S.", Pike_compiler->last_identifier);
59e7652002-05-11Martin Stjernholm  } $$=0;
8c64232000-06-26Henrik Grubbström (Grubba)  }
59e7652002-05-11Martin Stjernholm  else $$=mknode(F_UNDEFINED,0,0);
8c64232000-06-26Henrik Grubbström (Grubba)  } } else {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
82e1b72000-06-22Henrik Grubbström (Grubba)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
8c64232000-06-26Henrik Grubbström (Grubba)  | inherit_specifier bad_identifier { $$=0; } | inherit_specifier error { $$=0; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_COLON_COLON TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int e,i;
de1d7d2000-07-10Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string);
fae37d1998-08-30Henrik Grubbström (Grubba) 
7e50571996-11-02Fredrik Hübinette (Hubbe)  $$=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  for(e=1;e<(int)Pike_compiler->new_program->num_inherits;e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->new_program->inherits[e].inherit_level!=1) continue;
8aae6d1999-08-19Fredrik Hübinette (Hubbe)  i=low_reference_inherited_identifier(0,e,$2->u.sval.u.string,SEE_STATIC);
45e8a81997-01-26Fredrik Hübinette (Hubbe)  if(i==-1) continue; if($$) { $$=mknode(F_ARG_LIST,$$,mkidentifiernode(i)); }else{ $$=mkidentifiernode(i); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } if(!$$) {
0ee38f2002-05-11Martin Stjernholm  if (!($$ = program_magic_identifier (Pike_compiler, 0, -1, $2->u.sval.u.string, 1)))
2756c12002-11-27Henrik Grubbström (Grubba)  { if (Pike_compiler->compiler_pass == 2) {
1e5c292002-12-02Henrik Grubbström (Grubba)  if (TEST_COMPAT(7,2)) {
ce060e2004-06-30Martin Nilsson  yywarning("Undefined identifier ::%O.", $2->u.sval);
1e5c292002-12-02Henrik Grubbström (Grubba)  } else {
ce060e2004-06-30Martin Nilsson  my_yyerror("Undefined identifier ::%O.", $2->u.sval);
1e5c292002-12-02Henrik Grubbström (Grubba)  }
2756c12002-11-27Henrik Grubbström (Grubba)  }
0ee38f2002-05-11Martin Stjernholm  $$=mkintnode(0);
2756c12002-11-27Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{
45e8a81997-01-26Fredrik Hübinette (Hubbe)  if($$->token==F_ARG_LIST) $$=mkefuncallnode("aggregate",$$);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_COLON_COLON bad_identifier
8c77b61998-04-13Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
1c858f1999-11-14Henrik Grubbström (Grubba) comma_expr_or_zero: /* empty */ { $$=mkintnode(0); }
55356e1999-05-26Fredrik Hübinette (Hubbe)  | comma_expr
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
7a4a132003-11-07Martin Stjernholm comma_expr_or_maxint: /* empty */ { $$=mkintnode(MAX_INT_TYPE); }
55356e1999-05-26Fredrik Hübinette (Hubbe)  | comma_expr
7a4a132003-11-07Martin Stjernholm  | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$=mkintnode(MAX_INT_TYPE); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) gauge: TOK_GAUGE catch_arg
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
47f9762003-02-08Martin Stjernholm  $$=mkopernode("`/", mkopernode("`-", mkopernode("`-", mkefuncallnode("gethrvtime", mkintnode(1)),
c0637b2001-06-25Henrik Grubbström (Grubba)  mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, $2, NULL),
47f9762003-02-08Martin Stjernholm  mkefuncallnode("gethrvtime", mkintnode(1)))), NULL), mkfloatnode((FLOAT_TYPE)1e9));
4868db1997-05-07Per Hedbor  };
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) typeof: TOK_TYPEOF '(' expr0 ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *t;
7e50571996-11-02Fredrik Hübinette (Hubbe)  node *tmp;
3d78821999-11-06Henrik Grubbström (Grubba)  /* FIXME: Why build the node at all? */
ac87152000-09-25Fredrik Hübinette (Hubbe)  /* Because the optimizer cannot optimize the root node of the * tree properly -Hubbe */
b98c612000-05-17Henrik Grubbström (Grubba)  tmp=mknode(F_COMMA_EXPR, $3, 0);
71bde82001-03-16Fredrik Hübinette (Hubbe)  optimize_node(tmp);
3c0c281998-01-26Fredrik Hübinette (Hubbe) 
3699402001-02-20Henrik Grubbström (Grubba)  t=(tmp && CAR(tmp) && CAR(tmp)->type ? CAR(tmp)->type : mixed_type_string);
ac87152000-09-25Fredrik Hübinette (Hubbe)  if(TEST_COMPAT(7,0)) {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_string *s=describe_type(t);
ac87152000-09-25Fredrik Hübinette (Hubbe)  $$ = mkstrnode(s); free_string(s); }else{
3699402001-02-20Henrik Grubbström (Grubba)  $$ = mktypenode(t);
ac87152000-09-25Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_node(tmp);
4d21331998-04-14Henrik Grubbström (Grubba)  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF '(' error ')' { $$=0; yyerrok; } | TOK_TYPEOF '(' error '}' { $$=0; yyerror("Missing ')'."); } | TOK_TYPEOF '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF '(' error ';' { $$=0; yyerror("Missing ')'."); }
4d21331998-04-14Henrik Grubbström (Grubba)  ;
7e50571996-11-02Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) catch_arg: '(' comma_expr ')' { $$=$2; }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error ')' { $$=0; yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
498ec11999-11-12Henrik Grubbström (Grubba)  | '(' error '}' { $$=0; yyerror("Missing ')'."); } | '(' error ';' { $$=0; yyerror("Missing ')'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | block
4cb7d91999-12-10Henrik Grubbström (Grubba)  | error { $$=0; yyerror("Bad expression for catch."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) catch: TOK_CATCH
9649491998-02-27Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->catch_level++;
9649491998-02-27Fredrik Hübinette (Hubbe)  } catch_arg { $$=mknode(F_CATCH,$3,NULL);
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->catch_level--;
4d21331998-04-14Henrik Grubbström (Grubba)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) sscanf: TOK_SSCANF '(' expr0 ',' expr0 lvalue_list ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  { $$=mknode(F_SSCANF,mknode(F_ARG_LIST,$3,$5),$6); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error ')'
4d21331998-04-14Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error '}'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 ',' expr0 error ';'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); free_node($5); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error ')'
4d21331998-04-14Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
4d21331998-04-14Henrik Grubbström (Grubba)  free_node($3); yyerrok; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error '}'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' expr0 error ';'
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0;
db271d1998-04-27Henrik Grubbström (Grubba)  free_node($3); yyerror("Missing ')'."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' error ')' { $$=0; yyerrok; } | TOK_SSCANF '(' error TOK_LEX_EOF
db271d1998-04-27Henrik Grubbström (Grubba)  {
498ec11999-11-12Henrik Grubbström (Grubba)  $$=0; yyerror("Missing ')'.");
db271d1998-04-27Henrik Grubbström (Grubba)  yyerror("Unexpected end of file."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF '(' error '}' { $$=0; yyerror("Missing ')'."); } | TOK_SSCANF '(' error ';' { $$=0; yyerror("Missing ')'."); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
3ddb531996-11-02Fredrik Hübinette (Hubbe) lvalue: expr4
10fe602003-10-01Martin Stjernholm  | open_bracket_with_line_info low_lvalue_list ']'
0195962004-08-25Henrik Grubbström (Grubba)  { $$=mknode(F_ARRAY_LVALUE, $2,0); COPY_LINE_NUMBER_INFO($$, $1); free_node($1); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | type6 TOK_IDENTIFIER
3ddb531996-11-02Fredrik Hübinette (Hubbe)  {
abdfb62002-09-28Martin Stjernholm  int id = add_local_name($2->u.sval.u.string,compiler_pop_type(),0); if (id >= 0) $$=mklocalnode(id,0); else $$ = 0;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
3ddb531996-11-02Fredrik Hübinette (Hubbe)  }
1d73ef1999-11-23Henrik Grubbström (Grubba)  | bad_expr_ident
498ec11999-11-12Henrik Grubbström (Grubba)  { $$=mknewintnode(0); }
39245b1998-04-17Henrik Grubbström (Grubba)  ;
bdacd91998-04-15Henrik Grubbström (Grubba) low_lvalue_list: lvalue lvalue_list { $$=mknode(F_LVALUE_LIST,$1,$2); }
2a32691998-01-31Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) lvalue_list: /* empty */ { $$ = 0; }
3ddb531996-11-02Fredrik Hübinette (Hubbe)  | ',' lvalue lvalue_list { $$ = mknode(F_LVALUE_LIST,$2,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f76b4c2000-05-11Henrik Grubbström (Grubba) string: TOK_STRING | string TOK_STRING
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3c0c281998-01-26Fredrik Hübinette (Hubbe)  struct pike_string *a,*b; copy_shared_string(a,$1->u.sval.u.string); copy_shared_string(b,$2->u.sval.u.string); free_node($1); free_node($2); a=add_and_free_shared_strings(a,b); $$=mkstrnode(a); free_string(a);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
8c77b61998-04-13Henrik Grubbström (Grubba) /* * Some error-handling */
de1d7d2000-07-10Henrik Grubbström (Grubba) /* FIXME: Should probably set Pike_compiler->last_identifier. */
1d73ef1999-11-23Henrik Grubbström (Grubba) bad_identifier: bad_expr_ident
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_ARRAY_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("array is a reserved word."); }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | TOK_CLASS { yyerror("class is a reserved word."); } | TOK_ENUM { yyerror("enum is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FLOAT_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("float is a reserved word.");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FUNCTION_ID
39245b1998-04-17Henrik Grubbström (Grubba)  { yyerror("function is a reserved word.");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INT_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("int is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MAPPING_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("mapping is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MIXED_ID
39245b1998-04-17Henrik Grubbström (Grubba)  { yyerror("mixed is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("multiset is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_OBJECT_ID
97358e1998-04-23Fredrik Hübinette (Hubbe)  { yyerror("object is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PROGRAM_ID
97358e1998-04-23Fredrik Hübinette (Hubbe)  { yyerror("program is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_STRING_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("string is a reserved word."); }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | TOK_TYPEDEF { yyerror("typedef is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_VOID_ID
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("void is a reserved word."); }
a663191998-04-17Henrik Grubbström (Grubba)  ; bad_expr_ident:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_INLINE
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("inline is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LOCAL_ID
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("local is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NO_MASK
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("nomask is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("predef is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PRIVATE
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("private is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PROTECTED
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("protected is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PUBLIC
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("public is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_OPTIONAL
21b2c91999-12-17Fredrik Hübinette (Hubbe)  { yyerror("optional is a reserved word."); }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT { yyerror("variant is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_STATIC
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("static is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_EXTERN
1c379c1999-12-30Henrik Grubbström (Grubba)  { yyerror("extern is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FINAL_ID
a663191998-04-17Henrik Grubbström (Grubba)  { yyerror("final is a reserved word.");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DO
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("do is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_ELSE
2a7c7c1999-07-18Fredrik Hübinette (Hubbe)  { yyerror("else without if."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_RETURN
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("return is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("import is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INHERIT
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("inherit is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CATCH
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("catch is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_GAUGE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("gauge is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LAMBDA
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("lambda is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("sscanf is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SWITCH
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("switch is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("typeof is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_BREAK
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("break is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CASE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("case is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CONTINUE
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("continue is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DEFAULT
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("default is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FOR
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("for is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FOREACH
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("foreach is a reserved word."); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IF
8c77b61998-04-13Henrik Grubbström (Grubba)  { yyerror("if is a reserved word."); } ;
702ea52002-10-11Henrik Grubbström (Grubba) /* * Kludge for bison 1.50. * * Bison 1.50 doesn't support having multiple action blocks * in a sequence where a block refers to the value of its * immediate predecessor. */
8c77b61998-04-13Henrik Grubbström (Grubba) 
10fe602003-10-01Martin Stjernholm /* empty: ; */ /* line_number_info is now used in these cases. */
8c77b61998-04-13Henrik Grubbström (Grubba) 
215bed1996-09-28Fredrik Hübinette (Hubbe) %% void yyerror(char *str) {
523e641996-12-10David Hedbor  extern int cumulative_parse_error;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
f23f062004-03-12Henrik Grubbström (Grubba)  STACK_LEVEL_START(0);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
f077582000-07-06Fredrik Hübinette (Hubbe)  if(Pike_interpreter.recoveries && Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack error (underflow)\n");
294dc51997-08-03Fredrik Hübinette (Hubbe) #endif
903dd32004-03-13Henrik Grubbström (Grubba)  if (Pike_compiler->num_parse_error > 20) return;
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->num_parse_error++;
c3c7031996-12-04Fredrik Hübinette (Hubbe)  cumulative_parse_error++;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
10e16f1999-11-04Henrik Grubbström (Grubba)  if ((error_handler && error_handler->prog) || get_master())
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
52b45e1999-06-20Henrik Grubbström (Grubba)  if (lex.current_file) { ref_push_string(lex.current_file); } else { /* yyerror() can be called from define_function(), which * can be called by the C module initialization code. */ push_constant_text(""); }
2416d81998-01-27Fredrik Hübinette (Hubbe)  push_int(lex.current_line); push_text(str);
9036e82001-08-16Martin Stjernholm  low_safe_apply_handler("compile_error", error_handler, compat_handler, 3);
215bed1996-09-28Fredrik Hübinette (Hubbe)  pop_stack(); }else{
52b45e1999-06-20Henrik Grubbström (Grubba)  if (lex.current_file) { (void)fprintf(stderr, "%s:%ld: %s\n", lex.current_file->str, (long)lex.current_line, str); } else { (void)fprintf(stderr, "NULL:%ld: %s\n", (long)lex.current_line, str); }
215bed1996-09-28Fredrik Hübinette (Hubbe)  fflush(stderr); }
f23f062004-03-12Henrik Grubbström (Grubba)  STACK_LEVEL_DONE(0);
215bed1996-09-28Fredrik Hübinette (Hubbe) }
120d842000-11-08Fredrik Hübinette (Hubbe) static int low_islocal(struct compiler_frame *f, struct pike_string *str) { int e; for(e=f->current_number_of_locals-1;e>=0;e--) if(f->variable[e].name==str) return e; return -1; }
97f6282000-03-07Fredrik Hübinette (Hubbe)  int low_add_local_name(struct compiler_frame *frame,
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_string *str, struct pike_type *type, node *def)
215bed1996-09-28Fredrik Hübinette (Hubbe) {
ac87152000-09-25Fredrik Hübinette (Hubbe)  if (str->len && !TEST_COMPAT(7,0)) {
120d842000-11-08Fredrik Hübinette (Hubbe)  int tmp=low_islocal(frame,str); if(tmp>=0 && tmp >= frame->last_block_level)
fe80612000-09-05Henrik Grubbström (Grubba)  {
ce060e2004-06-30Martin Nilsson  my_yyerror("Duplicate local variable %S, " "previous declaration on line %d\n", str, frame->variable[tmp].line);
fe80612000-09-05Henrik Grubbström (Grubba)  }
f8a4be2000-10-03Fredrik Hübinette (Hubbe)  if(type == void_type_string) {
ce060e2004-06-30Martin Nilsson  my_yyerror("Local variable %S is void.\n", str);
f8a4be2000-10-03Fredrik Hübinette (Hubbe)  }
02a79a2000-09-04Fredrik Hübinette (Hubbe)  }
a566ca1999-12-14Fredrik Hübinette (Hubbe)  debug_malloc_touch(def); debug_malloc_touch(type); debug_malloc_touch(str);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  reference_shared_string(str);
97f6282000-03-07Fredrik Hübinette (Hubbe)  if (frame->current_number_of_locals == MAX_LOCAL)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
8c77b61998-04-13Henrik Grubbström (Grubba)  yyerror("Too many local variables.");
abdfb62002-09-28Martin Stjernholm  return -1;
215bed1996-09-28Fredrik Hübinette (Hubbe)  }else {
498ec11999-11-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG check_type_string(type); #endif /* PIKE_DEBUG */
df13b71999-12-18Henrik Grubbström (Grubba)  if (pike_types_le(type, void_type_string)) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (Pike_compiler->compiler_pass != 1) {
1191241999-12-18Henrik Grubbström (Grubba)  yywarning("Declaring local variable with type void " "(converted to type zero)."); }
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
be6fec2001-04-01Henrik Grubbström (Grubba)  copy_pike_type(type, zero_type_string);
5fdb4d1999-12-18Henrik Grubbström (Grubba)  }
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->variable[frame->current_number_of_locals].type = type; frame->variable[frame->current_number_of_locals].name = str; frame->variable[frame->current_number_of_locals].def = def;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  frame->variable[frame->current_number_of_locals].line=lex.current_line; frame->variable[frame->current_number_of_locals].file=lex.current_file; add_ref(lex.current_file);
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->current_number_of_locals++; if(frame->current_number_of_locals > frame->max_number_of_locals)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->max_number_of_locals= frame->current_number_of_locals;
215bed1996-09-28Fredrik Hübinette (Hubbe)  }
97f6282000-03-07Fredrik Hübinette (Hubbe)  return frame->current_number_of_locals-1;
215bed1996-09-28Fredrik Hübinette (Hubbe)  } }
97f6282000-03-07Fredrik Hübinette (Hubbe)  /* argument must be a shared string */ /* Note that this function eats a reference to 'type' */ /* If def is nonzero, it also eats a ref to def */ int add_local_name(struct pike_string *str,
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type,
97f6282000-03-07Fredrik Hübinette (Hubbe)  node *def) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  return low_add_local_name(Pike_compiler->compiler_frame,
97f6282000-03-07Fredrik Hübinette (Hubbe)  str, type, def); }
120d842000-11-08Fredrik Hübinette (Hubbe) 
215bed1996-09-28Fredrik Hübinette (Hubbe) int islocal(struct pike_string *str) {
120d842000-11-08Fredrik Hübinette (Hubbe)  return low_islocal(Pike_compiler->compiler_frame, str);
215bed1996-09-28Fredrik Hübinette (Hubbe) }
61e9a01998-01-25Fredrik Hübinette (Hubbe) 
4218011999-01-31Fredrik Hübinette (Hubbe) /* argument must be a shared string */ static node *lexical_islocal(struct pike_string *str) { int e,depth=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct compiler_frame *f=Pike_compiler->compiler_frame;
4218011999-01-31Fredrik Hübinette (Hubbe)  while(1) { for(e=f->current_number_of_locals-1;e>=0;e--) { if(f->variable[e].name==str) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct compiler_frame *q=Pike_compiler->compiler_frame;
164d6b2001-11-29Henrik Grubbström (Grubba) 
4218011999-01-31Fredrik Hübinette (Hubbe)  while(q!=f) {
8322b62000-05-08Fredrik Hübinette (Hubbe)  q->lexical_scope|=SCOPE_SCOPED;
4218011999-01-31Fredrik Hübinette (Hubbe)  q=q->previous; }
8322b62000-05-08Fredrik Hübinette (Hubbe)  if(depth) q->lexical_scope|=SCOPE_SCOPE_USED;
2898e62001-08-02Fredrik Hübinette (Hubbe)  if(q->min_number_of_locals < e+1) q->min_number_of_locals = e+1;
9ed8de2001-12-06Henrik Grubbström (Grubba)  if(f->variable[e].def) { /*fprintf(stderr, "Found prior definition of \"%s\"\n", str->str); */ return copy_node(f->variable[e].def); }
4218011999-01-31Fredrik Hübinette (Hubbe)  return mklocalnode(e,depth); } }
8322b62000-05-08Fredrik Hübinette (Hubbe)  if(!(f->lexical_scope & SCOPE_LOCAL)) return 0;
4218011999-01-31Fredrik Hübinette (Hubbe)  depth++; f=f->previous; } }
a418ce2001-03-31Henrik Grubbström (Grubba) static void safe_inc_enum(void) { JMP_BUF recovery;
c78ead2002-11-24Henrik Grubbström (Grubba)  STACK_LEVEL_START(1);
a418ce2001-03-31Henrik Grubbström (Grubba) 
3601d32002-11-23Martin Stjernholm  if (SETJMP_SP(recovery, 1)) {
37338b2003-11-14Martin Stjernholm  handle_compile_exception ("Bad implicit enum value (failed to add 1).");
3601d32002-11-23Martin Stjernholm  push_int(0);
a418ce2001-03-31Henrik Grubbström (Grubba)  } else { push_int(1); f_add(2); } UNSETJMP(recovery);
3601d32002-11-23Martin Stjernholm  STACK_LEVEL_DONE(1);
a418ce2001-03-31Henrik Grubbström (Grubba) }
9036e82001-08-16Martin Stjernholm  static int call_handle_import(struct pike_string *s) { int args; ref_push_string(s); ref_push_string(lex.current_file); if (error_handler && error_handler->prog) { ref_push_object(error_handler); args = 3; } else args = 2; if (safe_apply_handler("handle_import", error_handler, compat_handler, args, BIT_MAPPING|BIT_OBJECT|BIT_PROGRAM|BIT_ZERO)) if (Pike_sp[-1].type != T_INT) return 1; else { pop_stack();
ce060e2004-06-30Martin Nilsson  my_yyerror("Couldn't find module to import: %S", s);
9036e82001-08-16Martin Stjernholm  }
37338b2003-11-14Martin Stjernholm  else handle_compile_exception ("Error finding module to import");
9036e82001-08-16Martin Stjernholm  return 0; }
61e9a01998-01-25Fredrik Hübinette (Hubbe) void cleanup_compiler(void) { }