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.
884b6f2008-06-17Martin Stjernholm || $Id: language.yacc,v 1.431 2008/06/16 22:16:53 mast 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
d315082008-03-27Henrik Grubbström (Grubba) %token TOK_ATTRIBUTE_ID
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_BREAK %token TOK_CASE %token TOK_CLASS %token TOK_COLON_COLON
c8feb52006-02-27Martin Stjernholm %token TOK_CONTINUE
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_DEFAULT
316e7d2008-04-04Henrik Grubbström (Grubba) %token TOK_DEPRECATED_ID
f76b4c2000-05-11Henrik Grubbström (Grubba) %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
528fe12004-10-23Martin Nilsson %token TOK_FACET
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_INLINE %token TOK_LOCAL_ID %token TOK_FINAL_ID
d315082008-03-27Henrik Grubbström (Grubba) %token TOK_FUNCTION_NAME
f76b4c2000-05-11Henrik Grubbström (Grubba) %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
a0af022006-01-21Henrik Grubbström (Grubba) %token TOK_VERSION
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
0bfbb02004-10-26Henrik Grubbström (Grubba) #include "port.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) #include "interpret.h" #include "array.h" #include "object.h"
c8feb52006-02-27Martin Stjernholm #include "mapping.h"
215bed1996-09-28Fredrik Hübinette (Hubbe) #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"
1a26b22004-12-30Henrik Grubbström (Grubba) #include "pike_embed.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) 
94d66b2008-05-24Henrik Grubbström (Grubba) static void yyerror_reserved(const char *keyword);
b2e7262007-09-15Henrik Grubbström (Grubba) static struct pike_string *get_new_name();
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 *);
6572be2008-01-05Henrik Grubbström (Grubba) static void mark_lvalues_as_used(node *n);
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) %{
e021fe2008-04-14Henrik Grubbström (Grubba) /* Need 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"
e021fe2008-04-14Henrik Grubbström (Grubba) #include "pike_compiler.h"
4b974c1999-02-20Henrik Grubbström (Grubba) %} %{
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... */
beb25e2005-10-14Henrik Grubbström (Grubba) #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
528fe12004-10-23Martin Nilsson %type <number> TOK_FACET
f76b4c2000-05-11Henrik Grubbström (Grubba) %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> 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
2a343f2008-04-04Henrik Grubbström (Grubba) %type <number> implicit_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
6fe35d2007-09-14Henrik Grubbström (Grubba) %type <number> optional_constant
1104c62007-10-08Henrik Grubbström (Grubba) %type <number> optional_create_arguments
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
9aee972008-05-06Henrik Grubbström (Grubba) %type <n> string_segment
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> string
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <n> TOK_STRING %type <n> TOK_NUMBER
316e7d2008-04-04Henrik Grubbström (Grubba) %type <n> optional_attributes
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> optional_rename_inherit %type <n> optional_identifier
ff02322008-05-07Henrik Grubbström (Grubba) %type <n> implicit_identifier
f76b4c2000-05-11Henrik Grubbström (Grubba) %type <n> TOK_IDENTIFIER
a0af022006-01-21Henrik Grubbström (Grubba) %type <n> TOK_VERSION
316e7d2008-04-04Henrik Grubbström (Grubba) %type <n> attribute
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
408a1e2004-10-30Martin Stjernholm %type <n> range_bound
7e50571996-11-02Fredrik Hübinette (Hubbe) %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
55bd772005-02-18Henrik Grubbström (Grubba) %type <n> apply
7e50571996-11-02Fredrik Hübinette (Hubbe) %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
2a343f2008-04-04Henrik Grubbström (Grubba) %type <n> propagated_type
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{
7863d62005-05-06Martin Nilsson  push_empty_string();
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) 
528fe12004-10-23Martin Nilsson facet: TOK_FACET TOK_IDENTIFIER ':' idents ';' {
2c660c2005-12-31Martin Nilsson #ifdef WITH_FACETS
528fe12004-10-23Martin Nilsson  struct object *o; if (Pike_compiler->compiler_pass == 1) { if (Pike_compiler->new_program->facet_class == PROGRAM_IS_FACET_CLASS) {
1fb2de2004-10-23Martin Nilsson  yyerror("A class can only belong to one facet.");
528fe12004-10-23Martin Nilsson  } else { resolv_constant($4); if (Pike_sp[-1].type == T_OBJECT) {
f54c782004-12-22Henrik Grubbström (Grubba)  /* FIXME: Object subtypes! */
528fe12004-10-23Martin Nilsson  o = Pike_sp[-1].u.object;
960cca2004-11-06Martin Nilsson  ref_push_string($2->u.sval.u.string);
528fe12004-10-23Martin Nilsson  push_int(Pike_compiler->new_program->id); push_int(Pike_compiler->new_program->facet_class);
ef9a242006-07-06Henrik Grubbström (Grubba)  safe_apply(o, "add_facet_class", 3);
528fe12004-10-23Martin Nilsson  if (Pike_sp[-1].type == T_INT && Pike_sp[-1].u.integer >= 0) { Pike_compiler->new_program->facet_class = PROGRAM_IS_FACET_CLASS; Pike_compiler->new_program->facet_index = Pike_sp[-1].u.integer; add_ref(Pike_compiler->new_program->facet_group = o); } else yyerror("Could not add facet class to system.");
1a796b2004-10-30Martin Nilsson  pop_stack();
528fe12004-10-23Martin Nilsson  } else
392c792004-11-05Henrik Grubbström (Grubba)  yyerror("Invalid facet group specifier.");
1a796b2004-10-30Martin Nilsson  pop_stack();
528fe12004-10-23Martin Nilsson  } }
1a796b2004-10-30Martin Nilsson  free_node($2); free_node($4);
2c660c2005-12-31Martin Nilsson #else yyerror("No support for facets."); #endif
528fe12004-10-23Martin Nilsson  } ;
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."); }
d165152008-05-03Henrik Grubbström (Grubba)  if($3)
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)  }
528fe12004-10-23Martin Nilsson 
2c660c2005-12-31Martin Nilsson #ifdef WITH_FACETS
528fe12004-10-23Martin Nilsson  /* If this is a product class, check that all product classes in its
392c792004-11-05Henrik Grubbström (Grubba)  * facet-group inherit from all facets */
528fe12004-10-23Martin Nilsson  if($3 && Pike_compiler->compiler_pass == 2) { if (Pike_compiler->new_program->facet_class==PROGRAM_IS_PRODUCT_CLASS){ if (!Pike_compiler->new_program->facet_group)
392c792004-11-05Henrik Grubbström (Grubba)  yyerror("Product class without facet group."); else { safe_apply(Pike_compiler->new_program->facet_group, "product_classes_checked", 0); if (Pike_sp[-1].type == T_INT && Pike_sp[-1].u.integer == 0) { pop_stack();
ef9a242006-07-06Henrik Grubbström (Grubba)  safe_apply(Pike_compiler->new_program->facet_group, "check_product_classes", 0);
392c792004-11-05Henrik Grubbström (Grubba)  }
528fe12004-10-23Martin Nilsson  pop_stack(); } } }
2c660c2005-12-31Martin Nilsson #endif
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)  {
64dd452007-09-29Henrik Grubbström (Grubba)  if(Pike_compiler->compiler_pass==2) { int depth = 0; struct program_state *state = Pike_compiler; node *n = $3; while (((n->token == F_COMMA_EXPR) || (n->token == F_ARG_LIST)) && ((!CAR(n)) ^ (!CDR(n)))) { if (CAR(n)) n = CAR(n); else n = CDR(n); } if (n->token == F_EXTERNAL) { while (state && (state->new_program->id != n->u.integer.a)) { depth++; state = state->previous; } } if (depth && state) { /* Alias for a symbol in a surrounding scope. */ int id = really_low_reference_inherited_identifier(state, 0, n->u.integer.b); define_alias($1->u.sval.u.string, n->type, Pike_compiler->current_modifiers & ~ID_EXTERN, depth, id); } else { yyerror("Constant definition is not constant."); } } 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 {
0b84582007-10-06Henrik Grubbström (Grubba)  $$ = 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
0b84582007-10-06Henrik Grubbström (Grubba)  check_type_string($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)  {
392c792004-11-05Henrik Grubbström (Grubba)  yyerror("Internal compiler error (push_compiler_frame0).");
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)  ;
6fe35d2007-09-14Henrik Grubbström (Grubba) optional_constant: /* empty */ { $$ = OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT; } | TOK_CONSTANT { $$ = 0; } ;
316e7d2008-04-04Henrik Grubbström (Grubba) def: modifiers optional_attributes type_or_error optional_constant optional_stars
6fe35d2007-09-14Henrik Grubbström (Grubba)  TOK_IDENTIFIER push_compiler_frame0
1e9a882007-10-05Henrik Grubbström (Grubba)  '(' { $<number>$ = 0; /* Check for the (very special) case of create and create_args. */ if (Pike_compiler->num_create_args) { struct pike_string *create_string = NULL; int e; MAKE_CONST_STRING(create_string, "create");
316e7d2008-04-04Henrik Grubbström (Grubba)  if ($6->u.sval.u.string == create_string) {
1104c62007-10-08Henrik Grubbström (Grubba)  if (TEST_COMPAT(7, 6)) { yywarning("Having both an implicit and an explicit create() " "was not supported in Pike 7.6 and before."); }
1e9a882007-10-05Henrik Grubbström (Grubba)  /* Prepend the create arguments. */ if (Pike_compiler->num_create_args < 0) { Pike_compiler->varargs = 1; for (e = 0; e < -Pike_compiler->num_create_args; e++) { struct identifier *id = Pike_compiler->new_program->identifiers + e; add_ref(id->type);
1104c62007-10-08Henrik Grubbström (Grubba)  add_local_name(empty_pike_string, id->type, 0);
1e9a882007-10-05Henrik Grubbström (Grubba)  } } else { for (e = 0; e < Pike_compiler->num_create_args; e++) { struct identifier *id = Pike_compiler->new_program->identifiers + e; add_ref(id->type);
1104c62007-10-08Henrik Grubbström (Grubba)  add_local_name(empty_pike_string, id->type, 0);
1e9a882007-10-05Henrik Grubbström (Grubba)  } } $<number>$ = e; } } } arguments close_paren_or_missing
7e50571996-11-02Fredrik Hübinette (Hubbe)  { int e;
6fe35d2007-09-14Henrik Grubbström (Grubba)  /* Adjust opt_flags in case we've got an optional_constant. */
316e7d2008-04-04Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->opt_flags = $4;
6fe35d2007-09-14Henrik Grubbström (Grubba) 
7e50571996-11-02Fredrik Hübinette (Hubbe)  /* construct the function type */
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type);
316e7d2008-04-04Henrik Grubbström (Grubba)  if ($5 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
66f7712000-02-17Henrik Grubbström (Grubba)  yywarning("The *-syntax in types is obsolete. Use array instead."); }
316e7d2008-04-04Henrik Grubbström (Grubba)  while(--$5>=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) 
316e7d2008-04-04Henrik Grubbström (Grubba)  e = $<number>9 + $10 - 1;
1e9a882007-10-05Henrik Grubbström (Grubba)  if(Pike_compiler->varargs &&
316e7d2008-04-04Henrik Grubbström (Grubba)  (!$<number>9 || (Pike_compiler->num_create_args >= 0)))
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) 
316e7d2008-04-04Henrik Grubbström (Grubba)  if ($2) { node *n = $2; while (n) { push_type_attribute(CDR(n)->u.sval.u.string); n = CAR(n); } }
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *s=compiler_pop_type();
316e7d2008-04-04Henrik Grubbström (Grubba)  int i = isidentifier($6->u.sval.u.string);
be57ea2000-07-14Henrik Grubbström (Grubba)  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",
316e7d2008-04-04Henrik Grubbström (Grubba)  Pike_compiler->compiler_pass, $6->u.sval.u.string->str);
be57ea2000-07-14Henrik Grubbström (Grubba)  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 {
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Lost identifier %S (%d).",
316e7d2008-04-04Henrik Grubbström (Grubba)  $6->u.sval.u.string, 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",
316e7d2008-04-04Henrik Grubbström (Grubba)  Pike_compiler->compiler_pass, $6->u.sval.u.string->str);
be57ea2000-07-14Henrik Grubbström (Grubba) 
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 {
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Identifier %S lost after first pass.",
316e7d2008-04-04Henrik Grubbström (Grubba)  $6->u.sval.u.string);
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=
316e7d2008-04-04Henrik Grubbström (Grubba)  define_function($6->u.sval.u.string,
0b84582007-10-06Henrik Grubbström (Grubba)  $<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,
316e7d2008-04-04Henrik Grubbström (Grubba)  $4);
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;
316e7d2008-04-04Henrik Grubbström (Grubba)  if($13)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
22edc21998-01-29Fredrik Hübinette (Hubbe)  int f;
b9188f1999-12-13Henrik Grubbström (Grubba)  node *check_args = NULL;
e021fe2008-04-14Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION; struct pike_string *save_file = c->lex.current_file; int save_line = c->lex.current_line;
9039702000-08-15Henrik Grubbström (Grubba)  int num_required_args = 0;
1ef5572000-08-30Henrik Grubbström (Grubba)  struct identifier *i;
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_file = $6->current_file; c->lex.current_line = $6->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."); }
316e7d2008-04-04Henrik Grubbström (Grubba)  for(e=0; e<$<number>9+$10; e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
316e7d2008-04-04Henrik Grubbström (Grubba)  if((e >= $<number>9) &&
1104c62007-10-08Henrik Grubbström (Grubba)  (!Pike_compiler->compiler_frame->variable[e].name || !Pike_compiler->compiler_frame->variable[e].name->len))
b9188f1999-12-13Henrik Grubbström (Grubba)  {
316e7d2008-04-04Henrik Grubbström (Grubba)  my_yyerror("Missing name for argument %d.", e - $<number>9);
b9188f1999-12-13Henrik Grubbström (Grubba)  } 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)); }
316e7d2008-04-04Henrik Grubbström (Grubba)  if ($<number>9) {
1e9a882007-10-05Henrik Grubbström (Grubba)  /* Hook in the initializers for the create arguments. */
316e7d2008-04-04Henrik Grubbström (Grubba)  for (e = $<number>9; e--;) { $13 = mknode(F_COMMA_EXPR,
1e9a882007-10-05Henrik Grubbström (Grubba)  mknode(F_POP_VALUE, mknode(F_ASSIGN, mklocalnode(e, 0), mkidentifiernode(e)), NULL),
316e7d2008-04-04Henrik Grubbström (Grubba)  $13);
1e9a882007-10-05Henrik Grubbström (Grubba)  } }
587c6a2001-06-30Martin Stjernholm  {
316e7d2008-04-04Henrik Grubbström (Grubba)  int l = $13->line_number; struct pike_string *f = $13->current_file;
587c6a2001-06-30Martin Stjernholm  if (check_args) { /* Prepend the arg checking code. */
316e7d2008-04-04Henrik Grubbström (Grubba)  $13 = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, check_args, NULL), $13);
587c6a2001-06-30Martin Stjernholm  }
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_line = l; c->lex.current_file = f;
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
329cc01997-02-17Fredrik Hübinette (Hubbe) 
316e7d2008-04-04Henrik Grubbström (Grubba)  f=dooptcode($6->u.sval.u.string, $13, $<n>12->u.sval.u.type, $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",
316e7d2008-04-04Henrik Grubbström (Grubba)  $6->u.sval.u.string->str);
d4c3e02002-05-02Henrik Grubbström (Grubba)  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 
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_line = save_line; c->lex.current_file = save_file;
b715a92008-01-04Henrik Grubbström (Grubba)  } else { /* Prototype; don't warn about unused arguments. */
0b7dff2008-01-04Henrik Grubbström (Grubba)  for (e = Pike_compiler->compiler_frame->current_number_of_locals; e--;) {
b715a92008-01-04Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[e].flags |= LOCAL_VAR_IS_USED; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
316e7d2008-04-04Henrik Grubbström (Grubba)  free_node($6); free_node($11); free_node($<n>12); if ($2) free_node($2);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
316e7d2008-04-04Henrik Grubbström (Grubba)  | modifiers optional_attributes type_or_error optional_constant optional_stars TOK_IDENTIFIER push_compiler_frame0
b5aa651999-12-16Henrik Grubbström (Grubba)  error { pop_compiler_frame();
316e7d2008-04-04Henrik Grubbström (Grubba)  free_node($6); if ($2) free_node($2);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
316e7d2008-04-04Henrik Grubbström (Grubba)  | modifiers optional_attributes type_or_error optional_constant optional_stars bad_identifier
8c77b61998-04-13Henrik Grubbström (Grubba)  {
316e7d2008-04-04Henrik Grubbström (Grubba)  if ($2) free_node($2);
884b6f2008-06-17Martin Stjernholm  compiler_discard_type();
8c77b61998-04-13Henrik Grubbström (Grubba)  }
33b82c1999-12-19Henrik Grubbström (Grubba)  '(' arguments ')' block_or_semi {
316e7d2008-04-04Henrik Grubbström (Grubba)  if ($11) free_node($11); } | modifiers optional_attributes type_or_error optional_constant name_list ';' { if ($2) { yyerror("Invalid use of attributes in variable declaration.\n"); free_node($2); }
33b82c1999-12-19Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | inheritance {}
528fe12004-10-23Martin Nilsson  | facet {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  | import {}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | constant {}
2a343f2008-04-04Henrik Grubbström (Grubba)  | modifiers class { free_node($2); } | modifiers enum { free_node($2); }
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 '{' {
e021fe2008-04-14Henrik Grubbström (Grubba)  $<number>$=THIS_COMPILATION->lex.pragmas; THIS_COMPILATION->lex.pragmas|=$1;
21b2c91999-12-17Fredrik Hübinette (Hubbe)  } program
d4c3e02002-05-02Henrik Grubbström (Grubba)  close_brace_or_eof
21b2c91999-12-17Fredrik Hübinette (Hubbe)  {
e021fe2008-04-14Henrik Grubbström (Grubba)  THIS_COMPILATION->lex.pragmas=$<number>3;
21b2c91999-12-17Fredrik Hübinette (Hubbe)  }
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)  {
01e7e52008-01-03Henrik Grubbström (Grubba)  int i;
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)
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Variable %S appears twice in argument list.", $3->u.sval.u.string);
7e50571996-11-02Fredrik Hübinette (Hubbe) 
01e7e52008-01-03Henrik Grubbström (Grubba)  i = add_local_name($3->u.sval.u.string, compiler_pop_type(),0);
b1d40c2008-01-04Henrik Grubbström (Grubba)  if (i >= 0 && (!$3->u.sval.u.string->len ||
e021fe2008-04-14Henrik Grubbström (Grubba)  !(THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES))) {
62f35a2008-01-03Henrik Grubbström (Grubba)  /* Only warn about unused arguments in strict types mode. */
01e7e52008-01-03Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[i].flags |= LOCAL_VAR_IS_USED; }
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:
e97e672007-12-28Henrik Grubbström (Grubba)  TOK_NO_MASK { $$ = ID_FINAL | ID_INLINE; } | TOK_FINAL_ID { $$ = ID_FINAL | ID_INLINE; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | 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"; }
d315082008-03-27Henrik Grubbström (Grubba)  | TOK_ATTRIBUTE_ID { $$ = "__attribute__"; }
316e7d2008-04-04Henrik Grubbström (Grubba)  | TOK_DEPRECATED_ID { $$ = "__deprecated__"; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MAPPING_ID { $$ = "mapping"; } | TOK_MULTISET_ID { $$ = "multiset"; } | TOK_OBJECT_ID { $$ = "object"; } | TOK_FUNCTION_ID { $$ = "function"; }
d315082008-03-27Henrik Grubbström (Grubba)  | TOK_FUNCTION_NAME { $$ = "__FUNCTION__"; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | 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"; }
528fe12004-10-23Martin Nilsson  | TOK_FACET { $$ = "facet"; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | 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 {
e021fe2008-04-14Henrik Grubbström (Grubba)  $$=Pike_compiler->current_modifiers=$1 | (THIS_COMPILATION->lex.pragmas & ID_MODIFIER_MASK);
1d73ef1999-11-23Henrik Grubbström (Grubba)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  modifier_list: /* empty */ { $$ = 0; }
2a343f2008-04-04Henrik Grubbström (Grubba)  | modifier_list modifier { $$ = $1 | $2; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
316e7d2008-04-04Henrik Grubbström (Grubba) attribute: TOK_ATTRIBUTE_ID '(' string_constant optional_comma ')' { $$ = $3; } | TOK_DEPRECATED_ID '(' ')' { struct pike_string *deprecated_string; MAKE_CONST_STRING(deprecated_string, "deprecated"); $$ = mkstrnode(deprecated_string); } | TOK_DEPRECATED_ID { struct pike_string *deprecated_string; MAKE_CONST_STRING(deprecated_string, "deprecated"); $$ = mkstrnode(deprecated_string); } ; optional_attributes: /* empty */ { $$ = 0; } | optional_attributes attribute { $$ = mknode(F_ARG_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)  {
beb25e2005-10-14Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2 && !TEST_COMPAT (0, 6)) {
5e3aa52001-04-01Henrik Grubbström (Grubba)  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 '*' {
beb25e2005-10-14Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2 && !TEST_COMPAT (0, 6)) {
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 '*' {
beb25e2005-10-14Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2 && !TEST_COMPAT (0, 6)) {
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); }
157fc62007-03-03Henrik Grubbström (Grubba)  | TOK_STRING_ID opt_string_width {}
1220212001-05-08Henrik Grubbström (Grubba)  | 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); }
d315082008-03-27Henrik Grubbström (Grubba)  | TOK_ATTRIBUTE_ID '(' string_constant ',' type7 ')' { push_type_attribute($3->u.sval.u.string); free_node($3); } | TOK_ATTRIBUTE_ID '(' string_constant error ')' { push_type(T_MIXED); push_type_attribute($3->u.sval.u.string); free_node($3); } | TOK_ATTRIBUTE_ID error { push_type(T_MIXED); }
316e7d2008-04-04Henrik Grubbström (Grubba)  | TOK_DEPRECATED_ID '(' type7 ')' { struct pike_string *deprecated_string; MAKE_CONST_STRING(deprecated_string, "deprecated"); push_type_attribute(deprecated_string); } | TOK_DEPRECATED_ID '(' error ')' { struct pike_string *deprecated_string; MAKE_CONST_STRING(deprecated_string, "deprecated"); push_type(T_MIXED); push_type_attribute(deprecated_string); }
1220212001-05-08Henrik Grubbström (Grubba)  ;
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) {
f54c782004-12-22Henrik Grubbström (Grubba)  if(!(p = 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{
f54c782004-12-22Henrik Grubbström (Grubba)  int f = FIND_LFUN(p->inherits[Pike_sp[-1].subtype].prog, LFUN_CALL);
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  if(f!=-1) {
f54c782004-12-22Henrik Grubbström (Grubba)  Pike_sp[-1].subtype = f + p->inherits[Pike_sp[-1].subtype].identifier_level;
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  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)
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Illegal program identifier: %O.", Pike_sp-1);
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)  }
4e6c082007-05-02Henrik Grubbström (Grubba)  | '(' error ')'
157fc62007-03-03Henrik Grubbström (Grubba)  {
4e6c082007-05-02Henrik Grubbström (Grubba)  push_int_type(MIN_INT32, MAX_INT32); yyerror("Expected integer range.");
157fc62007-03-03Henrik Grubbström (Grubba)  }
4e6c082007-05-02Henrik Grubbström (Grubba)  ;
157fc62007-03-03Henrik Grubbström (Grubba) 
4e6c082007-05-02Henrik Grubbström (Grubba) opt_string_width: opt_int_range
157fc62007-03-03Henrik Grubbström (Grubba)  {
4e6c082007-05-02Henrik Grubbström (Grubba)  push_type(T_STRING);
157fc62007-03-03Henrik 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) {
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Not a valid program specifier: %S", Pike_sp[-2].u.string);
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);
beb25e2005-10-14Henrik Grubbström (Grubba)  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
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);
beb25e2005-10-14Henrik Grubbström (Grubba)  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
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);
beb25e2005-10-14Henrik Grubbström (Grubba)  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
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);
c981662006-03-02Henrik Grubbström (Grubba)  if (id >= 0) { /* FIXME: Consider using mklocalnode(id, -1). */
abdfb62002-09-28Martin Stjernholm  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(id,0));
c981662006-03-02Henrik Grubbström (Grubba)  } else
abdfb62002-09-28Martin Stjernholm  $$ = 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);
beb25e2005-10-14Henrik Grubbström (Grubba)  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
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);
b1d40c2008-01-04Henrik Grubbström (Grubba)  if (id >= 0) {
e021fe2008-04-14Henrik Grubbström (Grubba)  if (!(THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES)) {
b1d40c2008-01-04Henrik Grubbström (Grubba)  /* Only warn about unused initialized variables in strict types mode. */ Pike_compiler->compiler_frame->variable[id].flags |= LOCAL_VAR_IS_USED; }
abdfb62002-09-28Martin Stjernholm  $$=mknode(F_ASSIGN,$4,mklocalnode(id,0));
b1d40c2008-01-04Henrik Grubbström (Grubba)  } else
abdfb62002-09-28Martin Stjernholm  $$ = 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);
c981662006-03-02Henrik Grubbström (Grubba)  if (id >= 0) { /* FIXME: Consider using mklocalnode(id, -1). */
abdfb62002-09-28Martin Stjernholm  $$=mknode(F_ASSIGN,mkintnode(0),mklocalnode(id,0));
c981662006-03-02Henrik Grubbström (Grubba)  } else
abdfb62002-09-28Martin Stjernholm  $$ = 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);
b1d40c2008-01-04Henrik Grubbström (Grubba)  if (id >= 0) {
e021fe2008-04-14Henrik Grubbström (Grubba)  if (!(THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES)) {
b1d40c2008-01-04Henrik Grubbström (Grubba)  /* Only warn about unused initialized variables in strict types mode. */ Pike_compiler->compiler_frame->variable[id].flags |= LOCAL_VAR_IS_USED; }
abdfb62002-09-28Martin Stjernholm  $$=mknode(F_ASSIGN,$3, mklocalnode(id,0));
b1d40c2008-01-04Henrik Grubbström (Grubba)  } else
abdfb62002-09-28Martin Stjernholm  $$ = 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) 
2a343f2008-04-04Henrik Grubbström (Grubba) /* Type at $-2 */ propagated_type: { $$ = $<n>-2; } ;
01d3e21997-04-23Fredrik Hübinette (Hubbe) 
2a343f2008-04-04Henrik Grubbström (Grubba) /* Type at $0 */
215bed1996-09-28Fredrik Hübinette (Hubbe) local_name_list: new_local_name
2a343f2008-04-04Henrik Grubbström (Grubba)  | local_name_list ',' propagated_type new_local_name
babd872001-02-23Henrik Grubbström (Grubba)  { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $4); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
2a343f2008-04-04Henrik Grubbström (Grubba) /* Type at $0 */
6bc9281998-04-10Fredrik Hübinette (Hubbe) local_name_list2: new_local_name2
2a343f2008-04-04Henrik Grubbström (Grubba)  | local_name_list2 ',' propagated_type new_local_name
babd872001-02-23Henrik Grubbström (Grubba)  { $$ = 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);
147cb72008-01-05Henrik Grubbström (Grubba)  /* Note: Intentionally not marked as used. */
f5df592000-10-25Fredrik Hübinette (Hubbe)  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) 
24af192005-02-18Henrik Grubbström (Grubba) statement_with_semicolon: unused2 expected_semicolon ;
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)  } ;
ff02322008-05-07Henrik Grubbström (Grubba) implicit_identifier: /* empty */ {
2479872008-05-07Henrik Grubbström (Grubba)  struct pike_string *name; $$=mkstrnode(name = get_new_name()); free_string(name);
ff02322008-05-07Henrik Grubbström (Grubba)  } ; lambda: TOK_LAMBDA line_number_info implicit_identifier 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 {
ff02322008-05-07Henrik Grubbström (Grubba)  struct pike_string *name = $3->u.sval.u.string; struct pike_type *type; int e;
9039702000-08-15Henrik Grubbström (Grubba)  $<number>$ = Pike_compiler->varargs; Pike_compiler->varargs = 0;
ff02322008-05-07Henrik Grubbström (Grubba) 
9072562008-05-07Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 1) { /* Define a tentative prototype for the lambda. */ push_finished_type(mixed_type_string); e=$6-1; if($<number>$) { push_finished_type(Pike_compiler->compiler_frame->variable[e].type); e--; pop_type_stack(T_ARRAY); }else{ push_type(T_VOID); } Pike_compiler->varargs=0; push_type(T_MANY); for(; e>=0; e--) { push_finished_type(Pike_compiler->compiler_frame->variable[e].type); push_type(T_FUNCTION); } type=compiler_pop_type(); Pike_compiler->compiler_frame->current_function_number = define_function(name, type, ID_STATIC | ID_PRIVATE | ID_INLINE | ID_USED, IDENTIFIER_PIKE_FUNCTION, NULL, (unsigned INT16) (Pike_compiler->compiler_frame->opt_flags)); free_type(type); } else { /* In pass 2 we just reuse the type from pass 1. */ Pike_compiler->compiler_frame->current_function_number = isidentifier(name);
ff02322008-05-07Henrik Grubbström (Grubba)  }
9039702000-08-15Henrik Grubbström (Grubba)  } failsafe_block
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
329cc01997-02-17Fredrik Hübinette (Hubbe)  int f,e;
7e50571996-11-02Fredrik Hübinette (Hubbe)  struct pike_string *name;
e021fe2008-04-14Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION; struct pike_string *save_file = c->lex.current_file; int save_line = c->lex.current_line; c->lex.current_file = $2->current_file; c->lex.current_line = $2->line_number;
d4f23b2001-08-10Martin Stjernholm 
ff02322008-05-07Henrik Grubbström (Grubba)  debug_malloc_touch($8); $8=mknode(F_COMMA_EXPR,$8,mknode(F_RETURN,mkintnode(0),0));
e3866b2007-09-03Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) {
cbdf332003-03-27Martin Stjernholm  /* Doing this in pass 1 might induce too strict checks on types * in cases where we got placeholders. */
ff02322008-05-07Henrik Grubbström (Grubba)  type=find_return_type($8);
e3866b2007-09-03Henrik Grubbström (Grubba)  if (type) { push_finished_type(type); free_type(type); } else { yywarning("Failed to determine return type for lambda."); push_type(T_ZERO); } } else { /* Tentative return type. */
61e9a01998-01-25Fredrik Hübinette (Hubbe)  push_type(T_MIXED);
e3866b2007-09-03Henrik Grubbström (Grubba)  }
ff02322008-05-07Henrik Grubbström (Grubba)  e=$6-1; if($<number>7)
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) 
ff02322008-05-07Henrik Grubbström (Grubba)  name = $3->u.sval.u.string;
c4d4681998-06-06Henrik Grubbström (Grubba)  #ifdef LAMBDA_DEBUG
e3866b2007-09-03Henrik Grubbström (Grubba)  fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n%d: type: ",
b2e7262007-09-15Henrik Grubbström (Grubba)  Pike_compiler->compiler_pass, name->str, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1, Pike_compiler->compiler_pass);
e3866b2007-09-03Henrik Grubbström (Grubba)  simple_describe_type(type); fprintf(stderr, "\n");
c4d4681998-06-06Henrik Grubbström (Grubba) #endif /* LAMBDA_DEBUG */
3271182004-03-18Henrik Grubbström (Grubba) 
8267f41998-01-28Fredrik Hübinette (Hubbe)  f=dooptcode(name,
ff02322008-05-07Henrik Grubbström (Grubba)  $8,
8267f41998-01-28Fredrik Hübinette (Hubbe)  type,
f14d5f2007-10-11Henrik Grubbström (Grubba)  ID_STATIC | ID_PRIVATE | ID_INLINE | ID_USED);
22edc21998-01-29Fredrik Hübinette (Hubbe) 
9072562008-05-07Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (f != Pike_compiler->compiler_frame->current_function_number) { Pike_fatal("Lost track of lambda %s.\n", name->str); } #endif /* PIKE_DEBUG */
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); }
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_line = save_line; c->lex.current_file = save_file;
ff02322008-05-07Henrik Grubbström (Grubba)  free_node($3);
9b39022003-03-27Martin Stjernholm  free_node ($2);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
ff02322008-05-07Henrik Grubbström (Grubba)  | TOK_LAMBDA line_number_info implicit_identifier 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);
ff02322008-05-07Henrik Grubbström (Grubba)  free_node($3);
3271182004-03-18Henrik Grubbström (Grubba)  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)  {
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) 
b2e7262007-09-15Henrik Grubbström (Grubba)  name = get_new_name();
5fb9b02000-04-06Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
b2e7262007-09-15Henrik Grubbström (Grubba)  Pike_compiler->compiler_pass, name->str, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
5fb9b02000-04-06Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1) { id=isidentifier(name); }else{ id=define_function(name, type,
df58bc2007-10-11Henrik Grubbström (Grubba)  ID_INLINE|ID_USED,
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);
e021fe2008-04-14Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION; struct pike_string *save_file = c->lex.current_file; int save_line = c->lex.current_line; c->lex.current_file = $1->current_file; c->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;
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_line = save_line; c->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)  {
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);
beb25e2005-10-14Henrik Grubbström (Grubba)  if ($1 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
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(); /***/
b2e7262007-09-15Henrik Grubbström (Grubba)  name = get_new_name();
97f6282000-03-07Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: LAMBDA: %s 0x%08lx 0x%08lx\n",
b2e7262007-09-15Henrik Grubbström (Grubba)  Pike_compiler->compiler_pass, name->str, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
97f6282000-03-07Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_pass > 1) { id=isidentifier(name); }else{ id=define_function(name, type,
df58bc2007-10-11Henrik Grubbström (Grubba)  ID_INLINE|ID_USED,
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);
e021fe2008-04-14Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION; struct pike_string *save_file = c->lex.current_file; int save_line = c->lex.current_line; c->lex.current_file = $2->current_file; c->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;
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_line = save_line; c->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;
1e9a882007-10-05Henrik Grubbström (Grubba)  int ref_no;
c20a522000-07-08Henrik Grubbström (Grubba) 
1e9a882007-10-05Henrik Grubbström (Grubba)  if (Pike_compiler->num_create_args < 0) {
e6c0892001-03-30Henrik Grubbström (Grubba)  yyerror("Can't define more variables after ..."); }
c20a522000-07-08Henrik Grubbström (Grubba)  push_finished_type(Pike_compiler->compiler_frame->current_type);
beb25e2005-10-14Henrik Grubbström (Grubba)  if ($3 && (Pike_compiler->compiler_pass == 2) && !TEST_COMPAT (0, 6)) {
c20a522000-07-08Henrik Grubbström (Grubba)  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); }
c20a522000-07-08Henrik Grubbström (Grubba)  type=compiler_pop_type();
bc3efc2007-10-06Henrik Grubbström (Grubba)  /* Add the identifier globally. * Note: Since these are the first identifiers (and references) * to be added to the program, they will be numbered in * sequence starting at 0 (zero). This means that the * counter num_create_args is sufficient extra information * to be able to keep track of them. */
1e9a882007-10-05Henrik Grubbström (Grubba)  ref_no = define_variable($5->u.sval.u.string, type, Pike_compiler->current_modifiers);
bc3efc2007-10-06Henrik Grubbström (Grubba)  free_type(type);
c20a522000-07-08Henrik Grubbström (Grubba) 
1e9a882007-10-05Henrik Grubbström (Grubba)  if (Pike_compiler->num_create_args != ref_no) { my_yyerror("Multiple definitions of create variable %S (%d != %d).", $5->u.sval.u.string, Pike_compiler->num_create_args, ref_no); } if ($4) { /* Encode varargs marker as negative number of args. */ Pike_compiler->num_create_args = -(ref_no + 1); } else { Pike_compiler->num_create_args = ref_no + 1; }
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 ;
1104c62007-10-08Henrik Grubbström (Grubba) optional_create_arguments: /* empty */ { $$ = 0; }
1e9a882007-10-05Henrik Grubbström (Grubba)  | '(' create_arguments close_paren_or_missing
c20a522000-07-08Henrik Grubbström (Grubba)  {
1104c62007-10-08Henrik Grubbström (Grubba)  /* NOTE: One more than the number of arguments, so that we < * can detect the case of no parenthesis below. */ $$ = $2 + 1;
1e9a882007-10-05Henrik Grubbström (Grubba)  free_node($3);
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)  ;
2a343f2008-04-04Henrik Grubbström (Grubba) /* Modifiers at $0. */ class: TOK_CLASS line_number_info optional_identifier
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
2a343f2008-04-04Henrik Grubbström (Grubba)  if(!$3)
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++,
2a343f2008-04-04Henrik Grubbström (Grubba)  (int) $2->line_number);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  s=make_shared_string(buffer);
2a343f2008-04-04Henrik Grubbström (Grubba)  $3=mkstrnode(s);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_string(s);
2a343f2008-04-04Henrik Grubbström (Grubba)  $<number>0|=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)  {
2a343f2008-04-04Henrik Grubbström (Grubba)  if ($<number>0 & ID_EXTERN) {
8fd9311999-12-30Henrik Grubbström (Grubba)  yywarning("Extern declared class definition."); }
2a343f2008-04-04Henrik Grubbström (Grubba)  low_start_new_program(0, 1, $3->u.sval.u.string, $<number>0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  &$<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) 
2a343f2008-04-04Henrik Grubbström (Grubba)  store_linenumber($2->line_number, $2->current_file);
9b39022003-03-27Martin Stjernholm  debug_malloc_name(Pike_compiler->new_program,
2a343f2008-04-04Henrik Grubbström (Grubba)  $2->current_file->str, $2->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;
2a343f2008-04-04Henrik Grubbström (Grubba)  i=isidentifier($3->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,
2a343f2008-04-04Henrik Grubbström (Grubba)  $<number>0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  &$<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,
2a343f2008-04-04Henrik Grubbström (Grubba)  $3->u.sval.u.string, $<number>0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  &$<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,
2a343f2008-04-04Henrik Grubbström (Grubba)  $<number>0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  &$<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,
2a343f2008-04-04Henrik Grubbström (Grubba)  $<number>0,
993ba72000-02-15Fredrik Hübinette (Hubbe)  &$<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. */
e021fe2008-04-14Henrik Grubbström (Grubba)  $<number>$ = THIS_COMPILATION->lex.pragmas; THIS_COMPILATION->lex.pragmas &= ~ID_MODIFIER_MASK;
afbd442004-10-22Andreas (Kaos) Stenius  }
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;
1e9a882007-10-05Henrik Grubbström (Grubba)  /* Check if we have create arguments but no locally defined create(). */
2a343f2008-04-04Henrik Grubbström (Grubba)  if ($6) {
1e9a882007-10-05Henrik Grubbström (Grubba)  struct pike_string *create_string = NULL; struct reference *ref = NULL; struct identifier *id = NULL; int ref_id; MAKE_CONST_STRING(create_string, "create"); if (((ref_id = isidentifier(create_string)) < 0) || (ref = PTR_FROM_INT(Pike_compiler->new_program, ref_id))->inherit_offset || (id = ID_FROM_PTR(Pike_compiler->new_program, ref))->func.offset == -1) { int e; node *create_code = NULL; struct pike_type *type = NULL; int nargs = Pike_compiler->num_create_args; int f; push_compiler_frame(SCOPE_LOCAL); /* Init: Prepend the create arguments. */ if (Pike_compiler->num_create_args < 0) { for (e = 0; e < -Pike_compiler->num_create_args; e++) { id = Pike_compiler->new_program->identifiers + e; add_ref(id->type); add_local_name(id->name, id->type, 0);
b1d40c2008-01-04Henrik Grubbström (Grubba)  /* Note: add_local_name() above will return e. */
01e7e52008-01-03Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[e].flags |= LOCAL_VAR_IS_USED;
1e9a882007-10-05Henrik Grubbström (Grubba)  } } else { for (e = 0; e < Pike_compiler->num_create_args; e++) { id = Pike_compiler->new_program->identifiers + e; add_ref(id->type); add_local_name(id->name, id->type, 0);
b1d40c2008-01-04Henrik Grubbström (Grubba)  /* Note: add_local_name() above will return e. */
01e7e52008-01-03Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[e].flags |= LOCAL_VAR_IS_USED;
1e9a882007-10-05Henrik Grubbström (Grubba)  } } /* First: Deduce the type for the create() function. */ push_type(T_VOID); /* Return type. */ if ((e = nargs) < 0) { /* Varargs */ e = nargs = -nargs; push_finished_type(Pike_compiler->compiler_frame->variable[--e].type); pop_type_stack(T_ARRAY); /* Pop one level of array. */ } else { /* Not varargs. */ push_type(T_VOID); } push_type(T_MANY); while(e--) { push_finished_type(Pike_compiler->compiler_frame->variable[e].type); push_type(T_FUNCTION); } type = compiler_pop_type(); /* Second: Declare the function. */ Pike_compiler->compiler_frame->current_function_number= define_function(create_string, type, ID_INLINE | ID_STATIC, IDENTIFIER_PIKE_FUNCTION | (Pike_compiler->num_create_args < 0?IDENTIFIER_VARARGS:0), 0, OPT_SIDE_EFFECT); /* Third: Generate the initialization code. * * global_arg = [type]local_arg; * [,..] */ for(e=0; e<nargs; 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(). */ free_type(local_node->type); copy_pike_type(local_node->type, mixed_type_string); 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(e))); } } /* 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. */
0b84582007-10-06Henrik Grubbström (Grubba)  f=dooptcode(create_string, create_code, type, ID_STATIC);
1e9a882007-10-05Henrik Grubbström (Grubba)  #ifdef PIKE_DEBUG if(Pike_interpreter.recoveries && Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer) Pike_fatal("Stack error (underflow)\n"); if(Pike_compiler->compiler_pass == 1 && f!=Pike_compiler->compiler_frame->current_function_number) Pike_fatal("define_function screwed up! %d != %d\n", f, Pike_compiler->compiler_frame->current_function_number); #endif /* Done. */ free_type(type); pop_compiler_frame(); } }
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  }
2a343f2008-04-04Henrik Grubbström (Grubba)  $$=mkidentifiernode($<number>4);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
2a343f2008-04-04Henrik Grubbström (Grubba)  free_node($2);
afbd442004-10-22Andreas (Kaos) Stenius  free_node($3);
3c0c281998-01-26Fredrik Hübinette (Hubbe)  check_tree($$,0);
e021fe2008-04-14Henrik Grubbström (Grubba)  THIS_COMPILATION->lex.pragmas = $<number>5;
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)  ;
2a343f2008-04-04Henrik Grubbström (Grubba) /* Modifiers at $0. */ enum: TOK_ENUM
a418ce2001-03-31Henrik Grubbström (Grubba)  { 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();
2a343f2008-04-04Henrik Grubbström (Grubba)  if ($3) {
a418ce2001-03-31Henrik Grubbström (Grubba)  ref_push_type_value(t);
2a343f2008-04-04Henrik Grubbström (Grubba)  add_constant($3->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();
2a343f2008-04-04Henrik Grubbström (Grubba)  free_node($3);
a418ce2001-03-31Henrik Grubbström (Grubba)  } $$ = 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
a23d572008-01-07Henrik Grubbström (Grubba)  {
e021fe2008-04-14Henrik Grubbström (Grubba)  if (!(THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES) && $1) {
a23d572008-01-07Henrik Grubbström (Grubba)  if ($1->token == F_ARRAY_LVALUE) { mark_lvalues_as_used(CAR($1)); } else if (($1->token == F_LOCAL) && !($1->u.integer.b)) { Pike_compiler->compiler_frame->variable[$1->u.integer.a].flags |= LOCAL_VAR_IS_USED; } } }
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 {
e021fe2008-04-14Henrik Grubbström (Grubba)  if (!(THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES)) {
147cb72008-01-05Henrik Grubbström (Grubba)  mark_lvalues_as_used($2); }
10fe602003-10-01Martin Stjernholm  $$=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
147cb72008-01-05Henrik Grubbström (Grubba)  { $$=$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 */
55bd772005-02-18Henrik Grubbström (Grubba) optional_block: /* EMPTY */ { $$=0; }
ff02322008-05-07Henrik Grubbström (Grubba)  | '{' line_number_info /* FIXME: Use implicit_identifier to make __func__ point to the lambda? */ 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)  }
55bd772005-02-18Henrik Grubbström (Grubba)  statements end_block
a30f092000-07-12Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
c68a292001-06-10Henrik Grubbström (Grubba)  int f/*, e */;
a30f092000-07-12Fredrik Hübinette (Hubbe)  struct pike_string *name;
e021fe2008-04-14Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION; struct pike_string *save_file = c->lex.current_file; int save_line = c->lex.current_line; c->lex.current_file = $2->current_file; c->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));
e3866b2007-09-03Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) {
cbdf332003-03-27Martin Stjernholm  /* Doing this in pass 1 might induce too strict checks on types * in cases where we got placeholders. */ type=find_return_type($5);
e3866b2007-09-03Henrik Grubbström (Grubba)  if (type) { push_finished_type(type); free_type(type); } else { yywarning("Failed to determine return type for implicit lambda."); push_type(T_ZERO); } } else { /* Tentative return type. */
a30f092000-07-12Fredrik Hübinette (Hubbe)  push_type(T_MIXED);
e3866b2007-09-03Henrik Grubbström (Grubba)  }
a30f092000-07-12Fredrik Hübinette (Hubbe)  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();
b2e7262007-09-15Henrik Grubbström (Grubba)  name = get_new_name();
a30f092000-07-12Fredrik Hübinette (Hubbe)  #ifdef LAMBDA_DEBUG fprintf(stderr, "%d: IMPLICIT LAMBDA: %s 0x%08lx 0x%08lx\n",
b2e7262007-09-15Henrik Grubbström (Grubba)  Pike_compiler->compiler_pass, name->str, (long)Pike_compiler->new_program->id, Pike_compiler->local_class_counter-1);
a30f092000-07-12Fredrik Hübinette (Hubbe) #endif /* LAMBDA_DEBUG */ f=dooptcode(name,
9b39022003-03-27Martin Stjernholm  $5,
a30f092000-07-12Fredrik Hübinette (Hubbe)  type,
f14d5f2007-10-11Henrik Grubbström (Grubba)  ID_STATIC | ID_PRIVATE | ID_INLINE | ID_USED);
a30f092000-07-12Fredrik 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);
a30f092000-07-12Fredrik Hübinette (Hubbe)  } else { $$ = mkidentifiernode(f); }
d4f23b2001-08-10Martin Stjernholm 
e021fe2008-04-14Henrik Grubbström (Grubba)  c->lex.current_line = save_line; c->lex.current_file = save_file;
9b39022003-03-27Martin Stjernholm  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(); } ;
55bd772005-02-18Henrik Grubbström (Grubba) apply: expr4 open_paren_with_line_info expr_list ')' optional_block
db271d1998-04-27Henrik Grubbström (Grubba)  {
55bd772005-02-18Henrik Grubbström (Grubba)  $$ = mkapplynode($1, mknode(F_ARG_LIST, $3, $5)); COPY_LINE_NUMBER_INFO($$, $2); free_node ($2); } | expr4 open_paren_with_line_info error ')' optional_block { $$=mkapplynode($1, $5);
10fe602003-10-01Martin Stjernholm  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); }
55bd772005-02-18Henrik Grubbström (Grubba)  ;
2a343f2008-04-04Henrik Grubbström (Grubba) implicit_modifiers: {
2479872008-05-07Henrik Grubbström (Grubba)  if (TEST_COMPAT(7, 6)) { $$ = Pike_compiler->current_modifiers = (THIS_COMPILATION->lex.pragmas & ID_MODIFIER_MASK); } else { $$ = Pike_compiler->current_modifiers = ID_STATIC|ID_INLINE|ID_PRIVATE | (THIS_COMPILATION->lex.pragmas & ID_MODIFIER_MASK); }
2a343f2008-04-04Henrik Grubbström (Grubba)  } ;
55bd772005-02-18Henrik Grubbström (Grubba) expr4: string | TOK_NUMBER | TOK_FLOAT { $$=mkfloatnode((FLOAT_TYPE)$1); } | catch | gauge | typeof | sscanf | lambda
2a343f2008-04-04Henrik Grubbström (Grubba)  | implicit_modifiers class { $$ = $2; } | implicit_modifiers enum { $$ = $2; }
55bd772005-02-18Henrik Grubbström (Grubba)  | idents2 | apply
10fe602003-10-01Martin Stjernholm  | 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
408a1e2004-10-30Martin Stjernholm  range_bound expected_dot_dot range_bound ']'
d2c6081996-11-07Fredrik Hübinette (Hubbe)  {
408a1e2004-10-30Martin Stjernholm  $$=mknode(F_RANGE,$1,mknode(':',$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 ')'
63e5842005-01-27Henrik Grubbström (Grubba)  { $$=$2; if ($$) { COPY_LINE_NUMBER_INFO($$, $1); } free_node ($1); }
10fe602003-10-01Martin Stjernholm  | open_paren_with_line_info '{' expr_list close_brace_or_missing ')' {
eebdfd2005-02-28Henrik Grubbström (Grubba)  /* FIXME: May eat lots of stack; cf Standards.FIPS10_4.divisions */
10fe602003-10-01Martin Stjernholm  $$=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 ')' {
eebdfd2005-02-28Henrik Grubbström (Grubba)  /* FIXME: May eat lots of stack; cf Standards.FIPS10_4.divisions */
10fe602003-10-01Martin Stjernholm  $$=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 {
eebdfd2005-02-28Henrik Grubbström (Grubba)  /* FIXME: May eat lots of stack; cf Standards.FIPS10_4.divisions */
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); } | 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;
0df6e32007-10-13Henrik Grubbström (Grubba)  if((refp->inherit_offset == funp.inherit_offset) && (refp->identifier_offset == funp.identifier_offset) && ((refp->id_flags | ID_USED) == (funp.id_flags | ID_USED))) {
acbe8a2002-09-21Martin Stjernholm  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 {
8853882008-04-26Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION;
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  }
8853882008-04-26Henrik Grubbström (Grubba)  if (inherit_depth == c->compilation_depth) break;
91b0d92002-05-05Martin Stjernholm  if (!TEST_COMPAT (7, 2) && ID_FROM_INT (inherit_state->previous->new_program,
ddd9962008-04-06Henrik Grubbström (Grubba)  inherit_state->parent_identifier)->name ==
91b0d92002-05-05Martin Stjernholm  $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))
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("No such inherit %S.", $1->u.sval.u.string);
e5674c2002-06-07Martin Stjernholm  else { if ($1->u.sval.u.string == this_program_string) { inherit_state = Pike_compiler; inherit_depth = 0; e = 0; } else
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("No inherit or surrounding class %S.", $1->u.sval.u.string);
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 {
8853882008-04-26Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION;
3604362002-05-05Martin Stjernholm  inherit_state = Pike_compiler;
8853882008-04-26Henrik Grubbström (Grubba)  for (inherit_depth = 0; inherit_depth < c->compilation_depth;
3604362002-05-05Martin Stjernholm  inherit_depth++, inherit_state = inherit_state->previous) {}
f971aa2008-05-30Henrik Grubbström (Grubba)  $$ = -1;
3604362002-05-05Martin Stjernholm  }
82e1b72000-06-22Henrik Grubbström (Grubba)  | inherit_specifier TOK_IDENTIFIER TOK_COLON_COLON {
a2f4232008-05-30Henrik Grubbström (Grubba)  int e = 0;
7e64282008-05-30Henrik Grubbström (Grubba)  if ($1 < 0) { $1 = 0; }
0b3d0f2000-06-26Henrik Grubbström (Grubba) #if 0
a2f4232008-05-30Henrik Grubbström (Grubba)  /* FIXME: The inherit modifiers aren't kept. */ if (!(inherit_state->new_program->inherits[$1].flags & ID_PRIVATE)) {
0b3d0f2000-06-26Henrik Grubbström (Grubba) #endif /* 0 */
a2f4232008-05-30Henrik Grubbström (Grubba)  e = find_inherit(inherit_state->new_program->inherits[$1].prog, $2->u.sval.u.string);
0b3d0f2000-06-26Henrik Grubbström (Grubba) #if 0
a2f4232008-05-30Henrik Grubbström (Grubba)  }
0b3d0f2000-06-26Henrik Grubbström (Grubba) #endif /* 0 */
a2f4232008-05-30Henrik Grubbström (Grubba)  if (!e) { if (inherit_state->new_program->inherits[$1].name) { my_yyerror("No such inherit %S::%S.", inherit_state->new_program->inherits[$1].name, $2->u.sval.u.string);
82e1b72000-06-22Henrik Grubbström (Grubba)  } else {
a2f4232008-05-30Henrik Grubbström (Grubba)  my_yyerror("No such inherit %S.", $2->u.sval.u.string); } $$ = -1; } else { /* We know stuff about the inherit structure... */
7e64282008-05-30Henrik Grubbström (Grubba)  $$ = 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)) &&
388e5d2008-05-30Henrik Grubbström (Grubba)  !($$ = program_magic_identifier (Pike_compiler, 0, -1,
0ee38f2002-05-11Martin Stjernholm  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)  {
4d889f2008-04-25Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION;
45e8a81997-01-26Fredrik Hübinette (Hubbe)  node *tmp2;
ac87152000-09-25Fredrik Hübinette (Hubbe) 
4d889f2008-04-25Henrik Grubbström (Grubba)  if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier);
de1d7d2000-07-10Henrik Grubbström (Grubba)  copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
ac87152000-09-25Fredrik Hübinette (Hubbe) 
4d889f2008-04-25Henrik Grubbström (Grubba)  tmp2 = mkconstantsvaluenode(&c->default_module); $$ = 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)  }
a0af022006-01-21Henrik Grubbström (Grubba)  | TOK_VERSION TOK_COLON_COLON TOK_IDENTIFIER {
4d889f2008-04-25Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION;
a0af022006-01-21Henrik Grubbström (Grubba)  int old_major = Pike_compiler->compat_major; int old_minor = Pike_compiler->compat_minor;
cd48582006-01-26Henrik Grubbström (Grubba)  struct svalue *efun = NULL;
a0af022006-01-21Henrik Grubbström (Grubba)  change_compiler_compatibility($1->u.integer.a, $1->u.integer.b); if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $3->u.sval.u.string);
cd48582006-01-26Henrik Grubbström (Grubba)  /* Check predef:: first, and then the modules. */
4d889f2008-04-25Henrik Grubbström (Grubba)  if ((c->default_module.type == T_MAPPING) && (efun = low_mapping_lookup(c->default_module.u.mapping, &($3->u.sval)))) {
cd48582006-01-26Henrik Grubbström (Grubba)  $$ = mkconstantsvaluenode(efun); } else if (!($$ = resolve_identifier(Pike_compiler->last_identifier))) {
a0af022006-01-21Henrik Grubbström (Grubba)  if((Pike_compiler->flags & COMPILATION_FORCE_RESOLVE) || (Pike_compiler->compiler_pass==2)) { my_yyerror("Undefined identifier %d.%d::%S.", $1->u.integer.a, $1->u.integer.b, Pike_compiler->last_identifier); $$=0; }else{ $$=mknode(F_UNDEFINED,0,0); } } change_compiler_compatibility(old_major, old_minor); free_node($1); free_node($3); } | TOK_VERSION TOK_COLON_COLON bad_identifier { free_node($1); $$=0; }
82e1b72000-06-22Henrik Grubbström (Grubba)  | inherit_specifier TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
388e5d2008-05-30Henrik Grubbström (Grubba)  int id;
fae37d1998-08-30Henrik Grubbström (Grubba) 
388e5d2008-05-30Henrik 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) 
388e5d2008-05-30Henrik Grubbström (Grubba)  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) 
388e5d2008-05-30Henrik Grubbström (Grubba)  if (id != -1) { if (inherit_depth > 0) { $$ = mkexternalnode(inherit_state->new_program, id); } else { $$ = mkidentifiernode(id);
0ee38f2002-05-11Martin Stjernholm  }
388e5d2008-05-30Henrik Grubbström (Grubba)  } else if (($$ = program_magic_identifier (inherit_state, inherit_depth, $1, Pike_compiler->last_identifier, 1))) { /* All done. */ } else { if ((Pike_compiler->flags & COMPILATION_FORCE_RESOLVE) || (Pike_compiler->compiler_pass == 2)) { if (($1 >= 0) && inherit_state->new_program->inherits[$1].name) { my_yyerror("Undefined identifier %S::%S.", inherit_state->new_program->inherits[$1].name, Pike_compiler->last_identifier); } else { my_yyerror("Undefined identifier %S.", Pike_compiler->last_identifier);
8c64232000-06-26Henrik Grubbström (Grubba)  }
388e5d2008-05-30Henrik Grubbström (Grubba)  $$=0;
8c64232000-06-26Henrik Grubbström (Grubba)  }
388e5d2008-05-30Henrik Grubbström (Grubba)  else $$=mknode(F_UNDEFINED,0,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)) {
2c448d2004-11-05Henrik Grubbström (Grubba)  yywarning("Undefined identifier ::%S.", $2->u.sval.u.string);
1e5c292002-12-02Henrik Grubbström (Grubba)  } else {
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Undefined identifier ::%S.", $2->u.sval.u.string);
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) 
408a1e2004-10-30Martin Stjernholm range_bound: /* empty */ {$$ = mknode (F_RANGE_OPEN, NULL, NULL);}
55356e1999-05-26Fredrik Hübinette (Hubbe)  | comma_expr
408a1e2004-10-30Martin Stjernholm  {$$ = mknode (F_RANGE_FROM_BEG, $1, NULL);} | '<' comma_expr {$$ = mknode (F_RANGE_FROM_END, $2, NULL);} | TOK_LEX_EOF { yyerror("Unexpected end of file."); $$ = mknode (F_RANGE_OPEN, NULL, NULL); } | '<' TOK_LEX_EOF { yyerror("Unexpected end of file."); $$ = mknode (F_RANGE_OPEN, NULL, NULL); }
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)  {
e021fe2008-04-14Henrik Grubbström (Grubba)  if ($6 && !(THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES)) {
a23d572008-01-07Henrik Grubbström (Grubba)  mark_lvalues_as_used($6); }
37e4132008-05-17Marcus Comstedt  $$=mknode(F_SSCANF,mknode(':', mkintnode(TEST_COMPAT(7, 6)? SSCANF_FLAG_76_COMPAT : 0), mknode(F_ARG_LIST,$3,$5)),$6);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
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);
147cb72008-01-05Henrik Grubbström (Grubba)  /* Note: Variable intentionally not marked as used. */
abdfb62002-09-28Martin Stjernholm  if (id >= 0)
c981662006-03-02Henrik Grubbström (Grubba)  $$=mklocalnode(id,-1);
abdfb62002-09-28Martin Stjernholm  else $$ = 0;
3c0c281998-01-26Fredrik Hübinette (Hubbe)  free_node($2);
3ddb531996-11-02Fredrik Hübinette (Hubbe)  }
147cb72008-01-05Henrik Grubbström (Grubba)  /* FIXME: Add production for type6 ==> constant type svalue here? */
1d73ef1999-11-23Henrik Grubbström (Grubba)  | bad_expr_ident
498ec11999-11-12Henrik Grubbström (Grubba)  { $$=mknewintnode(0); }
39245b1998-04-17Henrik Grubbström (Grubba)  ;
147cb72008-01-05Henrik 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; }
147cb72008-01-05Henrik Grubbström (Grubba)  | ',' lvalue lvalue_list { $$ = mknode(F_LVALUE_LIST,$2,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
9aee972008-05-06Henrik Grubbström (Grubba) string_segment: TOK_STRING | TOK_FUNCTION_NAME { struct compiler_frame *f = Pike_compiler->compiler_frame;
ff02322008-05-07Henrik Grubbström (Grubba)  if (!f || (f->current_function_number < 0)) { $$ = mkstrnode(lfun_strings[LFUN___INIT]);
9aee972008-05-06Henrik Grubbström (Grubba)  } else { struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, f->current_function_number); $$ = mkstrnode(id->name); } } ; string: string_segment | string string_segment
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
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("array"); }
d315082008-03-27Henrik Grubbström (Grubba)  | TOK_ATTRIBUTE_ID { yyerror_reserved("__attribute__"); }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | TOK_CLASS
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("class"); }
316e7d2008-04-04Henrik Grubbström (Grubba)  | TOK_DEPRECATED_ID { yyerror_reserved("__deprecated__"); }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | TOK_ENUM
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("enum"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FLOAT_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("float");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FUNCTION_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("function");}
d315082008-03-27Henrik Grubbström (Grubba)  | TOK_FUNCTION_NAME { yyerror_reserved("__FUNCTION__");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INT_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("int"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MAPPING_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("mapping"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MIXED_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("mixed"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_MULTISET_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("multiset"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_OBJECT_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("object"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PROGRAM_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("program"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_STRING_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("string"); }
5e3aa52001-04-01Henrik Grubbström (Grubba)  | TOK_TYPEDEF
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("typedef"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_VOID_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("void"); }
a663191998-04-17Henrik Grubbström (Grubba)  ; bad_expr_ident:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_INLINE
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("inline"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LOCAL_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("local"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_NO_MASK
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("nomask"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PREDEF
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("predef"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PRIVATE
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("private"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PROTECTED
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("protected"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_PUBLIC
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("public"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_OPTIONAL
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("optional"); }
8f733e2000-07-12Henrik Grubbström (Grubba)  | TOK_VARIANT
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("variant"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_STATIC
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("static"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_EXTERN
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("extern"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FINAL_ID
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("final");}
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DO
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("do"); }
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
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("return"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IMPORT
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("import"); }
528fe12004-10-23Martin Nilsson  | TOK_FACET
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("facet"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_INHERIT
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("inherit"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CATCH
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("catch"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_GAUGE
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("gauge"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_LAMBDA
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("lambda"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SSCANF
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("sscanf"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_SWITCH
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("switch"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_TYPEOF
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("typeof"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_BREAK
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("break"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CASE
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("case"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_CONTINUE
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("continue"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_DEFAULT
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("default"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FOR
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("for"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_FOREACH
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("foreach"); }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_IF
1fb2de2004-10-23Martin Nilsson  { yyerror_reserved("if"); }
8c77b61998-04-13Henrik Grubbström (Grubba)  ;
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) %%
2be52d2007-11-10Martin Nilsson static void yyerror_reserved(const char *keyword)
1fb2de2004-10-23Martin Nilsson {
94d66b2008-05-24Henrik Grubbström (Grubba)  my_yyerror("%s is a reserved word.", keyword);
1fb2de2004-10-23Martin Nilsson }
b2e7262007-09-15Henrik Grubbström (Grubba) static struct pike_string *get_new_name() { char buf[40]; /* Generate a name for a global symbol... */ sprintf(buf,"__lambda_%ld_%ld_line_%d", (long)Pike_compiler->new_program->id, (long)(Pike_compiler->local_class_counter++ & 0xffffffff), /* OSF/1 cc bug. */
e021fe2008-04-14Henrik Grubbström (Grubba)  (int) THIS_COMPILATION->lex.current_line);
b2e7262007-09-15Henrik Grubbström (Grubba)  return make_shared_string(buf); }
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--)
2c8a262008-01-03Henrik Grubbström (Grubba)  if(f->variable[e].name==str) { f->variable[e].flags |= LOCAL_VAR_IS_USED;
120d842000-11-08Fredrik Hübinette (Hubbe)  return e;
2c8a262008-01-03Henrik Grubbström (Grubba)  }
120d842000-11-08Fredrik Hübinette (Hubbe)  return -1; }
401f2a2006-04-02Henrik Grubbström (Grubba) /* Add a local variable to the current function in frame. * NOTE: Steals the references to type and def, but not to str. */
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);
ef9a242006-07-06Henrik Grubbström (Grubba)  debug_malloc_touch(str);
05ae7d2006-03-01Henrik Grubbström (Grubba)  /* NOTE: The number of locals can be 0..255 (not 256), due to * the use of READ_INCR_BYTE() in apply_low.h. */ if (frame->current_number_of_locals == MAX_LOCAL-1)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
401f2a2006-04-02Henrik Grubbström (Grubba)  my_yyerror("Too many local variables: no space for local variable %S.", str); free_type(type); if (def) free_node(def);
abdfb62002-09-28Martin Stjernholm  return -1;
401f2a2006-04-02Henrik Grubbström (Grubba)  } else {
2c8a262008-01-03Henrik Grubbström (Grubba)  int var = frame->current_number_of_locals;
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) {
2c8a262008-01-03Henrik Grubbström (Grubba)  yywarning("Declaring local variable %S with type void " "(converted to type zero).", str);
1191241999-12-18Henrik Grubbström (Grubba)  }
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)  }
1e5c8b2008-01-03Henrik Grubbström (Grubba)  frame->variable[var].type = type;
2c8a262008-01-03Henrik Grubbström (Grubba)  frame->variable[var].name = str; reference_shared_string(str); frame->variable[var].def = def;
e021fe2008-04-14Henrik Grubbström (Grubba)  frame->variable[var].line = THIS_COMPILATION->lex.current_line; copy_shared_string(frame->variable[var].file, THIS_COMPILATION->lex.current_file);
02a79a2000-09-04Fredrik Hübinette (Hubbe) 
4d889f2008-04-25Henrik Grubbström (Grubba)  if (pike_types_le(void_type_string, type)) { /* Don't warn about unused voidable variables. */ frame->variable[var].flags = LOCAL_VAR_IS_USED; } else { frame->variable[var].flags = 0; }
02a79a2000-09-04Fredrik Hübinette (Hubbe) 
97f6282000-03-07Fredrik Hübinette (Hubbe)  frame->current_number_of_locals++;
2c8a262008-01-03Henrik Grubbström (Grubba)  if(frame->current_number_of_locals > frame->max_number_of_locals)
215bed1996-09-28Fredrik Hübinette (Hubbe)  {
2c8a262008-01-03Henrik Grubbström (Grubba)  frame->max_number_of_locals = frame->current_number_of_locals;
215bed1996-09-28Fredrik Hübinette (Hubbe)  }
97f6282000-03-07Fredrik Hübinette (Hubbe) 
2c8a262008-01-03Henrik Grubbström (Grubba)  return var;
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); }
a23d572008-01-07Henrik Grubbström (Grubba) /* Mark local variables declared in a multi-assign or sscanf expression * as used. */
6572be2008-01-05Henrik Grubbström (Grubba) static void mark_lvalues_as_used(node *n)
147cb72008-01-05Henrik Grubbström (Grubba) { while (n && n->token == F_LVALUE_LIST) {
3424a62008-06-12Henrik Grubbström (Grubba)  if (!CAR(n)) { /* Can happen if a variable hasn't been declared. */ } else if (CAR(n)->token == F_ARRAY_LVALUE) {
147cb72008-01-05Henrik Grubbström (Grubba)  mark_lvalues_as_used(CAAR(n)); } else if ((CAR(n)->token == F_LOCAL) && !(CAR(n)->u.integer.b)) {
c4e78f2008-01-05Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[CAR(n)->u.integer.a].flags |=
147cb72008-01-05Henrik Grubbström (Grubba)  LOCAL_VAR_IS_USED; } n = CDR(n); } }
0080352007-09-16Henrik Grubbström (Grubba) #if 0 /* Note that this function eats a reference to each of * 'type' and 'initializer', but not to 'name'. * Note also that 'initializer' may be NULL. */ static node *add_static_variable(struct pike_string *name, struct pike_type *type, int depth, node *initializer) { struct compiler_frame *f = Pike_compiler->compiler_frame; int i; int id; node *n = NULL; if (initializer) { /* FIXME: We need to pop levels off local and external variables here. */ } for(i = depth; f && i; i--) { f->lexical_scope |= SCOPE_SCOPED; f = f->previous; } if (!f) { int parent_depth = i; struct program_state *p = Pike_compiler; struct pike_string *tmp_name; while (i--) { if (!p->previous) { my_yyerror("Too many levels of static (%d, max:%d).", depth, depth - (i+1)); parent_depth -= i+1; break; } p->new_program->flags |= PROGRAM_USES_PARENT; p = p->previous; } tmp_name = get_new_name(); id = define_parent_variable(p, tmp_name, type, ID_STATIC|ID_PRIVATE|ID_INLINE); free_string(tmp_name); if (id >= 0) { if (def) { p->init_node = mknode(F_COMMA_EXPR, Pike_compiler->init_node, mkcastnode(void_type_string, mknode(F_ASSIGN, initializer, mkidentifiernode(id)))); initializer = NULL; } n = mkexternalnode(id, parent_depth); } } else if (depth) { f->lexical_scope|=SCOPE_SCOPE_USED; tmp_name = get_new_name(); id = low_add_local_name(f, tmp_name, type, NULL); free_string(tmp_name); if(f->min_number_of_locals < id+1) f->min_number_of_locals = id+1; if (initializer) { /* FIXME! */ yyerror("Initializers not yet supported for static variables with function scope."); } n = mklocalnode(id, depth); } id = add_local_name(name, type, n); if (id >= 0) { if (initializer) { return mknode(F_ASSIGN, initializer, mklocalnode(id,0)); } return mklocalnode(id, 0); } if (initializer) { free_node(initializer); } return NULL; } #endif /* 0 */
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) 
2d5f592008-01-03Henrik Grubbström (Grubba)  f->variable[e].flags |= LOCAL_VAR_IS_USED;
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) 
1faa902006-02-25Henrik Grubbström (Grubba)  if(depth) {
8322b62000-05-08Fredrik Hübinette (Hubbe)  q->lexical_scope|=SCOPE_SCOPE_USED;
1faa902006-02-25Henrik Grubbström (Grubba)  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) {
e021fe2008-04-14Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION;
9036e82001-08-16Martin Stjernholm  int args; ref_push_string(s);
e021fe2008-04-14Henrik Grubbström (Grubba)  ref_push_string(c->lex.current_file); if (c->handler && c->handler->prog) { ref_push_object(c->handler);
9036e82001-08-16Martin Stjernholm  args = 3; } else args = 2;
e021fe2008-04-14Henrik Grubbström (Grubba)  if (safe_apply_handler("handle_import", c->handler, c->compat_handler,
9036e82001-08-16Martin Stjernholm  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) { }