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. */
1b10db2002-10-08Martin Nilsson 
3c7fe72015-12-28Per Hedbor %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
32bc322008-06-18Henrik Grubbström (Grubba) %token TOK_RESERVED
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_IF %token TOK_IMPORT %token TOK_INHERIT %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_OBJECT_ID %token TOK_OR_EQ
fbff332016-05-17Per Hedbor %token TOK_POW %token TOK_POW_EQ
f76b4c2000-05-11Henrik Grubbström (Grubba) %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
fa47dd2016-09-27Henrik Grubbström (Grubba) %token TOK_WEAK
f76b4c2000-05-11Henrik Grubbström (Grubba) %token TOK_WHILE %token TOK_XOR_EQ %token TOK_OPTIONAL
0ad6502012-10-02Per Hedbor %token TOK_SAFE_INDEX %token TOK_SAFE_START_INDEX
e04ce12013-12-11Per Hedbor %token TOK_BITS
6e0fce2013-05-28Per Hedbor %token TOK_AUTO_ID
f76b4c2000-05-11Henrik Grubbström (Grubba) 
215bed1996-09-28Fredrik Hübinette (Hubbe)  %right '=' %right '?'
0ad6502012-10-02Per Hedbor 
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 '~'
a495492016-11-08Henrik Grubbström (Grubba) %right TOK_POW
f76b4c2000-05-11Henrik Grubbström (Grubba) %nonassoc TOK_INC TOK_DEC
215bed1996-09-28Fredrik Hübinette (Hubbe)  %{ /* This is the grammar definition of Pike. */ #include "global.h" #ifdef HAVE_MEMORY_H #include <memory.h> #endif #include "interpret.h" #include "array.h" #include "object.h"
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);
28b7362008-07-08Henrik Grubbström (Grubba) static struct pike_string *get_new_name(struct pike_string *prefix);
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 *);
e33ab92008-07-18Henrik Grubbström (Grubba) static node *safe_inc_enum(node *n);
7f012e2014-11-09Henrik Grubbström (Grubba) static node *find_versioned_identifier(struct pike_string *identifier, int major, int minor);
9036e82001-08-16Martin Stjernholm static int call_handle_import(struct pike_string *s);
b754192016-01-19Henrik Grubbström (Grubba) static void update_current_type();
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 %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_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
6e0fce2013-05-28Per Hedbor %type <number> TOK_AUTO_ID
f76b4c2000-05-11Henrik Grubbström (Grubba) %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
8457542016-05-13Henrik Grubbström (Grubba) %type <number> save_block_level %type <number> save_locals
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
a83d122013-11-08Henrik Grubbström (Grubba) %type <n> real_string_constant %type <n> real_string_or_identifier
3c0c281998-01-26Fredrik Hübinette (Hubbe) %type <n> string_constant
a83d122013-11-08Henrik Grubbström (Grubba) %type <n> string_or_identifier
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
e04ce12013-12-11Per Hedbor %type <n> TOK_BITS
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
32bc322008-06-18Henrik Grubbström (Grubba) %type <n> TOK_RESERVED
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
6dddaa2016-11-09Henrik Grubbström (Grubba) %type <n> anon_class %type <n> named_class
a418ce2001-03-31Henrik Grubbström (Grubba) %type <n> enum
e33ab92008-07-18Henrik Grubbström (Grubba) %type <n> enum_value
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
615cf52016-02-02Henrik Grubbström (Grubba) %type <n> splice_expr
7e50571996-11-02Fredrik Hübinette (Hubbe) %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
aea6a42016-05-09Henrik Grubbström (Grubba) %type <n> expr5
7e50571996-11-02Fredrik Hübinette (Hubbe) %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
f99cdd2016-05-08Henrik Grubbström (Grubba) %type <n> literal_expr
7e50571996-11-02Fredrik Hübinette (Hubbe) %type <n> local_name_list
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
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
e33ab92008-07-18Henrik Grubbström (Grubba) %type <n> propagated_enum_value
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
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
bc62892009-06-22Henrik Grubbström (Grubba) 
f2dbd22016-01-25Henrik Grubbström (Grubba) %type <ptr> start_function %type <ptr> start_lambda
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) 
a83d122013-11-08Henrik Grubbström (Grubba) real_string_or_identifier: TOK_IDENTIFIER | real_string_constant
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
a83d122013-11-08Henrik Grubbström (Grubba) optional_rename_inherit: ':' real_string_or_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)) {
cf2ad92008-06-24Henrik Grubbström (Grubba)  STACK_LEVEL_CHECK(2);
9036e82001-08-16Martin Stjernholm  $$=mksvaluenode(Pike_sp-1); pop_stack();
10e16f1999-11-04Henrik Grubbström (Grubba)  }
9036e82001-08-16Martin Stjernholm  else $$=mknewintnode(0);
cf2ad92008-06-24Henrik Grubbström (Grubba)  STACK_LEVEL_CHECK(1);
43fc171999-09-19Fredrik Hübinette (Hubbe)  if($$->name) free_string($$->name);
cf2ad92008-06-24Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-1]) != T_STRING) {
cf2ad92008-06-24Henrik Grubbström (Grubba)  Pike_fatal("Compiler lost track of program name.\n"); } #endif /* PIKE_DEBUG */ /* FIXME: Why not use $1->u.sval.u.string here? */
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)  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)  }
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) 
3a30d72014-10-05Martin Nilsson  if (Pike_compiler->current_modifiers & ID_EXTERN) {
bcf72b2008-07-13Henrik Grubbström (Grubba)  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;
09afd22008-06-19Henrik Grubbström (Grubba)  }
bcf72b2008-07-13Henrik Grubbström (Grubba)  } 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 if (Pike_compiler->compiler_pass == 1) { yyerror("Invalid extern declared constant."); add_constant($1->u.sval.u.string, &svalue_undefined,
019b3d2000-07-09Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers & ~ID_EXTERN);
bcf72b2008-07-13Henrik Grubbström (Grubba)  }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  } else {
bcf72b2008-07-13Henrik Grubbström (Grubba)  if(!is_const($3)) {
8b07b32008-07-13Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) { yyerror("Constant definition is not constant."); } add_constant($1->u.sval.u.string, 0,
bcf72b2008-07-13Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers & ~ID_EXTERN); } else { if(!Pike_compiler->num_parse_error)
57cddc1998-04-19Per Hedbor  {
bcf72b2008-07-13Henrik Grubbström (Grubba)  ptrdiff_t tmp=eval_low($3,1); if(tmp < 1) { yyerror("Error in constant definition."); push_undefined(); }else{
bd67392015-10-14Martin Nilsson  pop_n_elems((INT32)(tmp - 1));
bcf72b2008-07-13Henrik Grubbström (Grubba)  } } else {
f23f062004-03-12Henrik Grubbström (Grubba)  push_undefined();
57cddc1998-04-19Per Hedbor  }
bcf72b2008-07-13Henrik Grubbström (Grubba)  add_constant($1->u.sval.u.string, Pike_sp-1, Pike_compiler->current_modifiers & ~ID_EXTERN); pop_stack();
c6ae0c1996-11-26Fredrik Hübinette (Hubbe)  }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  }
bcf72b2008-07-13Henrik Grubbström (Grubba)  const_def_ok:
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) 
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) 
ab6b782016-05-07Henrik Grubbström (Grubba) /* This variant is used to start a new compiler frame for functions * with a declared return type. * * On entry the return type to be is taken from
acabf12016-01-09Henrik Grubbström (Grubba)  * * compiler_frame->current_type *
ab6b782016-05-07Henrik Grubbström (Grubba)  * in the current frame (stored there eg via simple_type). This is * then copied to * * compiler_frame->current_return_type * * for the new frame.
acabf12016-01-09Henrik Grubbström (Grubba)  */
f2dbd22016-01-25Henrik Grubbström (Grubba) start_function: /* 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)  {
f2dbd22016-01-25Henrik Grubbström (Grubba)  yyerror("Internal compiler error (start_function).");
ab6b782016-05-07Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_return_type,
f2dbd22016-01-25Henrik Grubbström (Grubba)  mixed_type_string);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }else{
ab6b782016-05-07Henrik Grubbström (Grubba)  copy_pike_type(Pike_compiler->compiler_frame->current_return_type, Pike_compiler->compiler_frame->previous->current_type);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
bc62892009-06-22Henrik Grubbström (Grubba)  $$ = Pike_compiler->compiler_frame;
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; } ;
e17b7b2016-01-16Henrik Grubbström (Grubba) def: modifiers optional_attributes simple_type optional_constant
f2dbd22016-01-25Henrik Grubbström (Grubba)  TOK_IDENTIFIER start_function
0ad6502012-10-02Per Hedbor  '('
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");
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ($5->u.sval.u.string == create_string) {
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);
1686e22008-06-25Henrik Grubbström (Grubba)  /* Note: add_local_name() above will return e. */ 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++) { 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);
1686e22008-06-25Henrik Grubbström (Grubba)  /* Note: add_local_name() above will return e. */ Pike_compiler->compiler_frame->variable[e].flags |= LOCAL_VAR_IS_USED;
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_return_type);
0ad6502012-10-02Per Hedbor 
eb6ba72016-01-11Henrik Grubbström (Grubba)  e = $<number>8 + $9 - 1;
1e9a882007-10-05Henrik Grubbström (Grubba)  if(Pike_compiler->varargs &&
eb6ba72016-01-11Henrik Grubbström (Grubba)  (!$<number>8 || (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) 
a2af982014-03-01Henrik Grubbström (Grubba)  if (Pike_compiler->current_attributes) { node *n = Pike_compiler->current_attributes;
316e7d2008-04-04Henrik Grubbström (Grubba)  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();
eb6ba72016-01-11Henrik Grubbström (Grubba)  int i = isidentifier($5->u.sval.u.string);
be57ea2000-07-14Henrik Grubbström (Grubba) 
28c83a2013-05-26Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass != 1) { if (i < 0) {
2c448d2004-11-05Henrik Grubbström (Grubba)  my_yyerror("Identifier %S lost after first pass.",
eb6ba72016-01-11Henrik Grubbström (Grubba)  $5->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=
eb6ba72016-01-11Henrik Grubbström (Grubba)  define_function($5->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;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  } block_or_semi { int e;
eb6ba72016-01-11Henrik Grubbström (Grubba)  if($12)
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;
eb6ba72016-01-11Henrik Grubbström (Grubba)  c->lex.current_file = $5->current_file; c->lex.current_line = $5->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."); }
eb6ba72016-01-11Henrik Grubbström (Grubba)  for(e=0; e<$<number>8+$9; e++)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
eb6ba72016-01-11Henrik Grubbström (Grubba)  if((e >= $<number>8) &&
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)  {
eb6ba72016-01-11Henrik Grubbström (Grubba)  my_yyerror("Missing name for argument %d.", e - $<number>8);
b9188f1999-12-13Henrik Grubbström (Grubba)  } else {
9039702000-08-15Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) { /* 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);*/
faa3232013-02-19Henrik Grubbström (Grubba)  local_node = mkcastnode(mixed_type_string, mklocalnode(e, 0));
9039702000-08-15Henrik Grubbström (Grubba) 
faa3232013-02-19Henrik Grubbström (Grubba)  /* NOTE: The cast to mixed above is needed to avoid generating * compilation errors, as well as avoiding optimizations * in mksoftcastnode().
9039702000-08-15Henrik Grubbström (Grubba)  */ check_args = mknode(F_COMMA_EXPR, check_args, mksoftcastnode(Pike_compiler->compiler_frame->variable[e].type, local_node)); }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
b9188f1999-12-13Henrik Grubbström (Grubba)  } }
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ($<number>8) {
1e9a882007-10-05Henrik Grubbström (Grubba)  /* Hook in the initializers for the create arguments. */
eb6ba72016-01-11Henrik Grubbström (Grubba)  for (e = $<number>8; e--;) { $12 = mknode(F_COMMA_EXPR,
1e9a882007-10-05Henrik Grubbström (Grubba)  mknode(F_POP_VALUE, mknode(F_ASSIGN, mklocalnode(e, 0), mkidentifiernode(e)), NULL),
eb6ba72016-01-11Henrik Grubbström (Grubba)  $12);
1e9a882007-10-05Henrik Grubbström (Grubba)  } }
587c6a2001-06-30Martin Stjernholm  {
eb6ba72016-01-11Henrik Grubbström (Grubba)  int l = $12->line_number; struct pike_string *f = $12->current_file;
587c6a2001-06-30Martin Stjernholm  if (check_args) { /* Prepend the arg checking code. */
eb6ba72016-01-11Henrik Grubbström (Grubba)  $12 = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, check_args, NULL), $12);
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) 
eb6ba72016-01-11Henrik Grubbström (Grubba)  f=dooptcode($5->u.sval.u.string, $12, $<n>11->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;
3c7fe72015-12-28Per Hedbor  if (Pike_compiler->compiler_pass == 2 && Pike_compiler->compiler_frame->current_return_type->type == PIKE_T_AUTO)
6e0fce2013-05-28Per Hedbor  {
3c7fe72015-12-28Per Hedbor  /* Change "auto" return type to actual return type. */ push_finished_type(Pike_compiler->compiler_frame->current_return_type->car);
eb6ba72016-01-11Henrik Grubbström (Grubba)  e = $<number>8 + $9 - 1;
3c7fe72015-12-28Per Hedbor  if(Pike_compiler->varargs &&
eb6ba72016-01-11Henrik Grubbström (Grubba)  (!$<number>8 || (Pike_compiler->num_create_args >= 0)))
3c7fe72015-12-28Per Hedbor  { push_finished_type(Pike_compiler->compiler_frame->variable[e].type); e--; pop_type_stack(T_ARRAY); }else{ push_type(T_VOID); } push_type(T_MANY); for(; e>=0; e--) { push_finished_type(Pike_compiler->compiler_frame->variable[e].type); push_type(T_FUNCTION); } if (Pike_compiler->current_attributes) { node *n = Pike_compiler->current_attributes; while (n) { push_type_attribute(CDR(n)->u.sval.u.string); n = CAR(n);
6e0fce2013-05-28Per Hedbor  }
3c7fe72015-12-28Per Hedbor  } free_type( i->type ); i->type = compiler_pop_type();
6e0fce2013-05-28Per Hedbor  }
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",
eb6ba72016-01-11Henrik Grubbström (Grubba)  $5->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; }
6e0fce2013-05-28Per Hedbor  if( Pike_compiler->compiler_frame->current_return_type->type == PIKE_T_AUTO ) yyerror("'auto' return type not allowed for prototypes\n");
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
eb6ba72016-01-11Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_frame != $6) {
bc62892009-06-22Henrik Grubbström (Grubba)  Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n",
eb6ba72016-01-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame, $6,
bc62892009-06-22Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->previous); } #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($5); free_node($10); free_node($<n>11);
b5aa651999-12-16Henrik Grubbström (Grubba)  }
e17b7b2016-01-16Henrik Grubbström (Grubba)  | modifiers optional_attributes simple_type
f2dbd22016-01-25Henrik Grubbström (Grubba)  optional_constant TOK_IDENTIFIER start_function
b5aa651999-12-16Henrik Grubbström (Grubba)  error {
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG
eb6ba72016-01-11Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_frame != $6) {
bc62892009-06-22Henrik Grubbström (Grubba)  Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n",
eb6ba72016-01-11Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame, $6,
bc62892009-06-22Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->previous); } #endif
b5aa651999-12-16Henrik Grubbström (Grubba)  pop_compiler_frame();
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($5);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
e17b7b2016-01-16Henrik Grubbström (Grubba)  | modifiers optional_attributes simple_type optional_constant bad_identifier
8c77b61998-04-13Henrik Grubbström (Grubba)  {
884b6f2008-06-17Martin Stjernholm  compiler_discard_type();
8c77b61998-04-13Henrik Grubbström (Grubba)  }
33b82c1999-12-19Henrik Grubbström (Grubba)  '(' arguments ')' block_or_semi {
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ($10) free_node($10);
316e7d2008-04-04Henrik Grubbström (Grubba)  }
e17b7b2016-01-16Henrik Grubbström (Grubba)  | modifiers optional_attributes simple_type optional_constant name_list ';'
7e50571996-11-02Fredrik Hübinette (Hubbe)  | inheritance {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  | import {}
d2c6081996-11-07Fredrik Hübinette (Hubbe)  | constant {}
6dddaa2016-11-09Henrik Grubbström (Grubba)  | modifiers named_class { free_node($2); }
2a343f2008-04-04Henrik Grubbström (Grubba)  | 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
0ad6502012-10-02Per Hedbor  '{'
21b2c91999-12-17Fredrik Hübinette (Hubbe)  {
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) 
dd46aa2014-08-11Per Hedbor new_arg_name: full_type 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);
0ad6502012-10-02Per Hedbor 
01e7e52008-01-03Henrik Grubbström (Grubba)  i = add_local_name($3->u.sval.u.string, compiler_pop_type(),0);
ceb95a2008-06-26Henrik Grubbström (Grubba)  if (i >= 0) { /* Don't warn about unused arguments. */
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:
0085e42014-10-05Martin Nilsson  TOK_FINAL_ID { $$ = ID_FINAL | ID_INLINE; }
2181762014-08-15Martin Nilsson  | TOK_STATIC { $$ = ID_PROTECTED; if( !(THIS_COMPILATION->lex.pragmas & ID_NO_DEPRECATION_WARNINGS) && !TEST_COMPAT(7, 8) && Pike_compiler->compiler_pass==1 )
edd1962014-11-12Stephen R. van den Berg  yywarning("Keyword static is deprecated in favour of 'protected'.");
2181762014-08-15Martin Nilsson  }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | TOK_EXTERN { $$ = ID_EXTERN; } | TOK_OPTIONAL { $$ = ID_OPTIONAL; }
d411722008-07-14Henrik Grubbström (Grubba)  | TOK_PRIVATE { $$ = ID_PRIVATE | ID_PROTECTED; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | 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; }
91f4112016-11-05Henrik Grubbström (Grubba)  | TOK_WEAK { $$ = ID_WEAK; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
315aa81999-12-17Fredrik Hübinette (Hubbe) magic_identifiers1:
0085e42014-10-05Martin Nilsson  TOK_FINAL_ID { $$ = "final"; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | 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"; }
fa47dd2016-09-27Henrik Grubbström (Grubba)  | TOK_WEAK { $$ = "__weak__"; }
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"; }
28b7362008-07-08Henrik Grubbström (Grubba)  | TOK_FUNCTION_NAME { $$ = "__func__"; }
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"; }
6e0fce2013-05-28Per Hedbor  /* | TOK_AUTO_ID { $$ = "auto"; } */
315aa81999-12-17Fredrik Hübinette (Hubbe)  ; magic_identifiers3:
f76b4c2000-05-11Henrik Grubbström (Grubba)  TOK_IF { $$ = "if"; } | TOK_DO { $$ = "do"; } | TOK_FOR { $$ = "for"; } | TOK_WHILE { $$ = "while"; } | TOK_ELSE { $$ = "else"; } | TOK_FOREACH { $$ = "foreach"; } | TOK_CATCH { $$ = "catch"; } | TOK_GAUGE { $$ = "gauge"; } | TOK_CLASS { $$ = "class"; } | TOK_BREAK { $$ = "break"; } | TOK_CASE { $$ = "case"; } | TOK_CONSTANT { $$ = "constant"; } | TOK_CONTINUE { $$ = "continue"; } | TOK_DEFAULT { $$ = "default"; } | TOK_IMPORT { $$ = "import"; } | TOK_INHERIT { $$ = "inherit"; } | TOK_LAMBDA { $$ = "lambda"; } | TOK_PREDEF { $$ = "predef"; } | TOK_RETURN { $$ = "return"; } | TOK_SSCANF { $$ = "sscanf"; } | TOK_SWITCH { $$ = "switch"; } | TOK_TYPEOF { $$ = "typeof"; }
1977e22002-08-18Martin Stjernholm  | TOK_GLOBAL { $$ = "global"; }
315aa81999-12-17Fredrik Hübinette (Hubbe)  ;
21b2c91999-12-17Fredrik Hübinette (Hubbe) magic_identifiers: magic_identifiers1 | magic_identifiers2 | magic_identifiers3 ;
32bc322008-06-18Henrik Grubbström (Grubba) magic_identifier: TOK_IDENTIFIER | TOK_RESERVED
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); } ;
a2af982014-03-01Henrik Grubbström (Grubba) optional_attributes: /* empty */ { if (Pike_compiler->current_attributes) { free_node(Pike_compiler->current_attributes); } if ((Pike_compiler->current_attributes = THIS_COMPILATION->lex.attributes)) { add_ref(Pike_compiler->current_attributes); } } | optional_attributes attribute { if ($2) { Pike_compiler->current_attributes = mknode(F_ARG_LIST, Pike_compiler->current_attributes, $2); } }
316e7d2008-04-04Henrik Grubbström (Grubba)  ;
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)  } ;
b59ab22016-01-10Henrik Grubbström (Grubba) /* Either a basic_type-prefixed expression, or an identifier type. * Value on type stack. */
dd46aa2014-08-11Per Hedbor type2: type | identifier_type ;
6bc9281998-04-10Fredrik Hübinette (Hubbe) 
e17b7b2016-01-16Henrik Grubbström (Grubba) /* Full type expression. * Value moved to compiler_frame->current_type. */
dd46aa2014-08-11Per Hedbor simple_type: full_type
6bc9281998-04-10Fredrik Hübinette (Hubbe)  {
b754192016-01-19Henrik Grubbström (Grubba)  update_current_type();
6bc9281998-04-10Fredrik Hübinette (Hubbe)  } ;
58949e2016-01-15Henrik Grubbström (Grubba) /* Basic_type-prefixed expression or an identifier type.
35a4052016-01-24Henrik Grubbström (Grubba)  * Value moved to compiler_frame->current_type.
58949e2016-01-15Henrik Grubbström (Grubba)  */ simple_type2: type2
3c0c281998-01-26Fredrik Hübinette (Hubbe)  {
35a4052016-01-24Henrik Grubbström (Grubba)  update_current_type();
3c0c281998-01-26Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
b59ab22016-01-10Henrik Grubbström (Grubba) /* Full type expression. Value on type stack. * Typically used in contexts where there must be a type, * and expressions are invalid. */
dd46aa2014-08-11Per Hedbor full_type: full_type '|' type3 { push_type(T_OR); } | type3
1220212001-05-08Henrik Grubbström (Grubba)  ;
b59ab22016-01-10Henrik Grubbström (Grubba) /* Basic_type-prefixed expression. Value on type stack. * Typically used in contexts where expressions are valid. */
dd46aa2014-08-11Per Hedbor type: type '|' type3 { push_type(T_OR); }
0ad6502012-10-02Per Hedbor  | basic_type
1220212001-05-08Henrik Grubbström (Grubba)  ;
b59ab22016-01-10Henrik Grubbström (Grubba) /* Either a basic_type or an identifier type. Value on type stack. */
dd46aa2014-08-11Per Hedbor type3: basic_type | identifier_type ;
1220212001-05-08Henrik Grubbström (Grubba) 
b59ab22016-01-10Henrik Grubbström (Grubba) /* Literal type. Value on type stack. */
1220212001-05-08Henrik Grubbström (Grubba) basic_type: TOK_FLOAT_ID { push_type(T_FLOAT); } | TOK_VOID_ID { push_type(T_VOID); } | TOK_MIXED_ID { push_type(T_MIXED); }
ec9bc12016-05-01Henrik Grubbström (Grubba)  | TOK_AUTO_ID { push_type(T_ZERO); push_type(PIKE_T_AUTO); }
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 {}
6513262014-02-16Henrik Grubbström (Grubba)  | TOK_PROGRAM_ID opt_program_type { push_type(T_PROGRAM); }
1220212001-05-08Henrik Grubbström (Grubba)  | TOK_ARRAY_ID opt_array_type { push_type(T_ARRAY); } | TOK_MULTISET_ID opt_array_type { push_type(T_MULTISET); }
dd46aa2014-08-11Per Hedbor  | TOK_ATTRIBUTE_ID '(' string_constant ',' full_type ')'
d315082008-03-27Henrik Grubbström (Grubba)  { 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); }
dd46aa2014-08-11Per Hedbor  | TOK_DEPRECATED_ID '(' full_type ')'
316e7d2008-04-04Henrik Grubbström (Grubba)  { 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)  ;
b59ab22016-01-10Henrik Grubbström (Grubba) /* Identifier type. Value on type stack. */
6bc9281998-04-10Fredrik Hübinette (Hubbe) identifier_type: idents
0ad6502012-10-02Per Hedbor  {
17f4dc2014-05-04Henrik Grubbström (Grubba)  if ($1) { fix_type_field($1); if (!pike_types_le($1->type, typeable_type_string) && (THIS_COMPILATION->lex.pragmas & ID_STRICT_TYPES)) { yytype_report(REPORT_WARNING, $1->current_file, $1->line_number, typeable_type_string, $1->current_file, $1->line_number, $1->type, 0, "Invalid type."); }
38f9312014-05-03Henrik Grubbström (Grubba)  }
7a08f32000-01-25Henrik Grubbström (Grubba)  resolv_constant($1);
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-1]) == 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;
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-1]) == 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{
017b572011-10-28Henrik Grubbström (Grubba)  int f = FIND_LFUN(p->inherits[SUBTYPEOF(Pike_sp[-1])].prog, LFUN_CALL);
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  if(f!=-1) {
017b572011-10-28Henrik Grubbström (Grubba)  SET_SVAL_SUBTYPE(Pike_sp[-1], f + p->inherits[SUBTYPEOF(Pike_sp[-1])]. identifier_level); SET_SVAL_TYPE(Pike_sp[-1], T_FUNCTION);
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  }else{
3a77fb2003-02-26Henrik Grubbström (Grubba)  extern void f_object_program(INT32);
abe9fe2014-09-18Martin Nilsson  if (Pike_compiler->compiler_pass == 2)
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)  } }
017b572011-10-28Henrik Grubbström (Grubba)  switch(TYPEOF(Pike_sp[-1])) {
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  case T_FUNCTION:
bc62892009-06-22Henrik Grubbström (Grubba)  if((p = program_from_function(Pike_sp-1))) {
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  push_object_type(0, p?(p->id):0);
bc62892009-06-22Henrik Grubbström (Grubba)  break; } else { /* Attempt to get the return type for the function. */ struct pike_type *a, *b; a = get_type_of_svalue(Pike_sp-1); /* Note: check_splice_call() below eats a reference from a. * Note: CALL_INHIBIT_WARNINGS is needed since we don't * provide a function name (and we don't want * warnings here anyway). */ a = check_splice_call(NULL, a, 0, mixed_type_string, NULL, CALL_INHIBIT_WARNINGS); if (a) { b = new_get_return_type(a, 0); free_type(a); if (b) { push_finished_type(b); free_type(b); break; } }
ef08eb2001-05-13Fredrik Hübinette (Hubbe)  }
1139252010-05-29Henrik Grubbström (Grubba)  /* FALL_THROUGH */
0ad6502012-10-02Per Hedbor 
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;
0ad6502012-10-02Per Hedbor 
7a08f32000-01-25Henrik Grubbström (Grubba)  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); }
960a872016-05-14Henrik Grubbström (Grubba)  | typeof { if ($1) { push_finished_type($1->u.sval.u.type); free_node($1); } else { push_finished_type(mixed_type_string); } }
7a08f32000-01-25Henrik Grubbström (Grubba)  ;
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
017b572011-10-28Henrik Grubbström (Grubba)  if (($2->token != F_CONSTANT) || (TYPEOF($2->u.sval) != 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
017b572011-10-28Henrik Grubbström (Grubba)  if (($2->token != F_CONSTANT) || (TYPEOF($2->u.sval) != 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)  }
e04ce12013-12-11Per Hedbor  | '(' TOK_BITS ')' { push_int_type( 0, (1<<$2->u.sval.u.integer)-1 ); free_node( $2 ); }
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) {
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF($4->u.sval) == T_INT) {
96c3932002-08-27Henrik Grubbström (Grubba)  max = $4->u.sval.u.integer; } 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(); }
011ad31999-10-22Fredrik Hübinette (Hubbe)  }
96c3932002-08-27Henrik Grubbström (Grubba)  if($2->token == F_CONSTANT) {
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF($2->u.sval) == T_INT) {
96c3932002-08-27Henrik Grubbström (Grubba)  min = $2->u.sval.u.integer;
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(); }
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. */
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-2]) == T_STRING) {
f62c412001-03-05Henrik Grubbström (Grubba)  push_type_name(Pike_sp[-2].u.string); }
d2c6081996-11-07Fredrik Hübinette (Hubbe)  pop_n_elems(2); } ;
6513262014-02-16Henrik Grubbström (Grubba) opt_program_type: /* Empty */ { push_object_type(0, 0); }
dd46aa2014-08-11Per Hedbor  | '(' full_type ')'
6513262014-02-16Henrik Grubbström (Grubba)  | '(' error ')' { push_object_type(0, 0); yyerror("Invalid program subtype."); } ;
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); } }
dd46aa2014-08-11Per Hedbor  full_type ')'
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) 
dd46aa2014-08-11Per Hedbor function_type_list2: full_type { $$=1; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | function_type_list2 ',' { }
dd46aa2014-08-11Per Hedbor  full_type
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
dd46aa2014-08-11Per Hedbor opt_array_type: '(' full_type ')'
7e50571996-11-02Fredrik Hübinette (Hubbe)  | { push_type(T_MIXED); } ;
215bed1996-09-28Fredrik Hübinette (Hubbe)  opt_mapping_type: '('
0ad6502012-10-02Per Hedbor  {
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
dd46aa2014-08-11Per Hedbor  full_type ':'
0ad6502012-10-02Per Hedbor  {
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
dd46aa2014-08-11Per Hedbor  full_type
0ad6502012-10-02Per Hedbor  {
92aeb12001-02-26Henrik Grubbström (Grubba)  push_reverse_type(T_MAPPING);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ')'
0ad6502012-10-02Per Hedbor  | /* empty */
7e50571996-11-02Fredrik Hübinette (Hubbe)  { 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) 
eb6ba72016-01-11Henrik Grubbström (Grubba) new_name: TOK_IDENTIFIER
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
a2af982014-03-01Henrik Grubbström (Grubba)  node *n;
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type);
a2af982014-03-01Henrik Grubbström (Grubba)  n = Pike_compiler->current_attributes; while(n) { push_type_attribute(CDR(n)->u.sval.u.string); n = CAR(n); }
4142a61998-05-19Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
eb6ba72016-01-11Henrik Grubbström (Grubba)  define_variable($1->u.sval.u.string, type,
019b3d2000-07-09Henrik Grubbström (Grubba)  Pike_compiler->current_modifiers);
d68a072001-02-20Henrik Grubbström (Grubba)  free_type(type);
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  | bad_identifier {} | TOK_IDENTIFIER '='
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
3699402001-02-20Henrik Grubbström (Grubba)  struct pike_type *type;
a2af982014-03-01Henrik Grubbström (Grubba)  node *n;
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->current_type);
a2af982014-03-01Henrik Grubbström (Grubba)  n = Pike_compiler->current_attributes; while(n) { push_type_attribute(CDR(n)->u.sval.u.string); n = CAR(n); }
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."); }
eb6ba72016-01-11Henrik Grubbström (Grubba)  $<number>$=define_variable($1->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 {
9dce2a2013-07-16Henrik Grubbström (Grubba)  if ((Pike_compiler->compiler_pass == 2) &&
eb6ba72016-01-11Henrik Grubbström (Grubba)  !TEST_COMPAT(7, 8) && ($4) && ($4->token == F_CONSTANT) &&
85c69f2013-07-13Henrik Grubbström (Grubba)  !Pike_compiler->num_parse_error) {
9dce2a2013-07-16Henrik Grubbström (Grubba)  /* Check if it is zero, in which case we can throw it away.
548c512013-07-01Henrik Grubbström (Grubba)  * * NB: The compat test is due to that this changes the semantics * of calling __INIT() by hand. */
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ((TYPEOF($4->u.sval) == PIKE_T_INT) && !SUBTYPEOF($4->u.sval) && !$4->u.sval.u.integer &&
9dce2a2013-07-16Henrik Grubbström (Grubba)  !IDENTIFIER_IS_ALIAS(ID_FROM_INT(Pike_compiler->new_program,
eb6ba72016-01-11Henrik Grubbström (Grubba)  $<number>3)->identifier_flags)) {
9dce2a2013-07-16Henrik Grubbström (Grubba)  /* NB: Inherited variables get converted into aliases by * define_variable, and we need to support clearing * of inherited variables. */
85aa842015-02-06Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (l_flag > 5) { fprintf(stderr, "Ignoring initialization to zero for variable %s.\n",
eb6ba72016-01-11Henrik Grubbström (Grubba)  $1->u.sval.u.string->str);
85aa842015-02-06Henrik Grubbström (Grubba)  } #endif /* PIKE_DEBUG */
bb88422015-12-29Per Hedbor  if(Pike_compiler->compiler_frame->current_type->type == PIKE_T_AUTO)
6e0fce2013-05-28Per Hedbor  { // auto variable type needs to be updated.
eb6ba72016-01-11Henrik Grubbström (Grubba)  fix_type_field( $4 ); fix_auto_variable_type( $<number>3, $4->type );
6e0fce2013-05-28Per Hedbor  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($4); $4 = NULL;
548c512013-07-01Henrik Grubbström (Grubba)  } }
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ($4) {
bb88422015-12-29Per Hedbor  // this is done in both passes to get somewhat better handling // of auto types. // // an example is: auto a = typeof(b); auto b = (["foo":"bar"]); // if this is only done in the second pass the type of a will be // type(auto), not type(mapping(..)) if( Pike_compiler->compiler_frame->current_type->type == PIKE_T_AUTO )
6e0fce2013-05-28Per Hedbor  {
eb6ba72016-01-11Henrik Grubbström (Grubba)  fix_type_field( $4 ); fix_auto_variable_type( $<number>3, $4->type );
6e0fce2013-05-28Per Hedbor  }
548c512013-07-01Henrik Grubbström (Grubba)  Pike_compiler->init_node=mknode(F_COMMA_EXPR,Pike_compiler->init_node, mkcastnode(void_type_string,
eb6ba72016-01-11Henrik Grubbström (Grubba)  mknode(F_ASSIGN,$4, mkidentifiernode($<number>3))));
548c512013-07-01Henrik Grubbström (Grubba)  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '=' error
2968361998-04-14Henrik Grubbström (Grubba)  {
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
2968361998-04-14Henrik Grubbström (Grubba)  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '=' TOK_LEX_EOF
e67c861998-08-01Henrik Grubbström (Grubba)  { yyerror("Unexpected end of file in variable definition.");
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
e67c861998-08-01Henrik Grubbström (Grubba)  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  | bad_identifier '=' expr0
8c77b61998-04-13Henrik Grubbström (Grubba)  {
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($3);
8c77b61998-04-13Henrik Grubbström (Grubba)  }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
35a4052016-01-24Henrik Grubbström (Grubba) /* Type at compiler_frame->current_type. */
eb6ba72016-01-11Henrik Grubbström (Grubba) new_local_name: TOK_IDENTIFIER
abdfb62002-09-28Martin Stjernholm  { int id;
3c7fe72015-12-28Per Hedbor  struct pike_type *type;
35a4052016-01-24Henrik Grubbström (Grubba)  copy_pike_type(type, Pike_compiler->compiler_frame->current_type);
eb6ba72016-01-11Henrik Grubbström (Grubba)  id = add_local_name($1->u.sval.u.string, type, 0);
3c7fe72015-12-28Per Hedbor  if( type->type == PIKE_T_AUTO ) { /* FIXME: Update type on assign instead! */ yyerror("auto only valid when the variable is assigned in definition."); }
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;
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  | bad_identifier { $$=0; }
35a4052016-01-24Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '=' { push_finished_type(Pike_compiler->compiler_frame->current_type); type_stack_mark(); } expr0
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
abdfb62002-09-28Martin Stjernholm  int id;
6e0fce2013-05-28Per Hedbor  struct pike_type *type;
35a4052016-01-24Henrik Grubbström (Grubba)  pop_stack_mark(); update_current_type(); copy_pike_type(type, Pike_compiler->compiler_frame->current_type);
6e0fce2013-05-28Per Hedbor  if( type->type == PIKE_T_AUTO && Pike_compiler->compiler_pass == 2) { free_type( type );
35a4052016-01-24Henrik Grubbström (Grubba)  fix_type_field( $4 ); copy_pike_type( type, $4->type );
6e0fce2013-05-28Per Hedbor  }
eb6ba72016-01-11Henrik Grubbström (Grubba)  id = add_local_name($1->u.sval.u.string, 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; }
35a4052016-01-24Henrik Grubbström (Grubba)  $$=mknode(F_ASSIGN,$4,mklocalnode(id,0));
b1d40c2008-01-04Henrik Grubbström (Grubba)  } else
abdfb62002-09-28Martin Stjernholm  $$ = 0;
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
35a4052016-01-24Henrik Grubbström (Grubba)  | bad_identifier '='
8c77b61998-04-13Henrik Grubbström (Grubba)  {
35a4052016-01-24Henrik Grubbström (Grubba)  push_finished_type(Pike_compiler->compiler_frame->current_type); type_stack_mark(); } expr0 { pop_stack_mark(); update_current_type(); free_node($4);
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
35a4052016-01-24Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '=' { push_finished_type(Pike_compiler->compiler_frame->current_type); type_stack_mark(); } error
8c77b61998-04-13Henrik Grubbström (Grubba)  {
35a4052016-01-24Henrik Grubbström (Grubba)  pop_stack_mark(); update_current_type();
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
8c77b61998-04-13Henrik Grubbström (Grubba)  /* No yyerok here since we aren't done yet. */
5b6acd1998-04-30Fredrik Hübinette (Hubbe)  $$=0;
8c77b61998-04-13Henrik Grubbström (Grubba)  }
35a4052016-01-24Henrik Grubbström (Grubba)  | TOK_IDENTIFIER '='
e67c861998-08-01Henrik Grubbström (Grubba)  {
35a4052016-01-24Henrik Grubbström (Grubba)  push_finished_type(Pike_compiler->compiler_frame->current_type); type_stack_mark(); } TOK_LEX_EOF { pop_stack_mark(); update_current_type();
e67c861998-08-01Henrik Grubbström (Grubba)  yyerror("Unexpected end of file in local variable definition.");
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($1);
e67c861998-08-01Henrik Grubbström (Grubba)  /* No yyerok here since we aren't done yet. */ $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik 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;
0ad6502012-10-02Per Hedbor  }
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);
40a5d92015-02-07Henrik Grubbström (Grubba)  $5 = pop_local_variables($<number>2, $5);
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) 
eb9ef92010-11-19Henrik Grubbström (Grubba) /* Node with line number info at $0. */
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 '}'.");
eb9ef92010-11-19Henrik Grubbström (Grubba)  if ($<n>0) { low_yyreport(REPORT_ERROR, $<n>0->current_file, $<n>0->line_number, parser_system_string, 0, "Opening '{' was here."); }
73a2a11998-04-27Henrik Grubbström (Grubba)  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) 
35a4052016-01-24Henrik Grubbström (Grubba) /* Type at compiler_frame->current_type. */
215bed1996-09-28Fredrik Hübinette (Hubbe) local_name_list: new_local_name
35a4052016-01-24Henrik Grubbström (Grubba)  | local_name_list ',' new_local_name { $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
215bed1996-09-28Fredrik 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{
bd67392015-10-14Martin Nilsson  pop_n_elems((INT32)(tmp - 1));
f5df592000-10-25Fredrik Hübinette (Hubbe)  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)  }
0ad6502012-10-02Per Hedbor  | ';' { $$=0; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
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
9637492016-10-06Henrik Grubbström (Grubba)  | simple_type2 local_function { $$=mkcastnode(void_type_string, $2); }
6dddaa2016-11-09Henrik Grubbström (Grubba)  | implicit_modifiers named_class { $$=mkcastnode(void_type_string, $2); }
5a0fd52001-01-10Martin Stjernholm  ; 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) 
acabf12016-01-09Henrik Grubbström (Grubba) /* This variant is used to push the compiler context for * functions without a declared return type (ie lambdas). */
f2dbd22016-01-25Henrik Grubbström (Grubba) start_lambda: /* empty */
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
8322b62000-05-08Fredrik Hübinette (Hubbe)  push_compiler_frame(SCOPE_LOCAL);
bc62892009-06-22Henrik Grubbström (Grubba) 
ab6b782016-05-07Henrik Grubbström (Grubba)  debug_malloc_touch(Pike_compiler->compiler_frame->current_return_type); if(Pike_compiler->compiler_frame->current_return_type) free_type(Pike_compiler->compiler_frame->current_return_type); copy_pike_type(Pike_compiler->compiler_frame->current_return_type, any_type_string);
bc62892009-06-22Henrik Grubbström (Grubba)  $$ = Pike_compiler->compiler_frame;
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;
28b7362008-07-08Henrik Grubbström (Grubba)  $$=mkstrnode(name = get_new_name(NULL));
2479872008-05-07Henrik Grubbström (Grubba)  free_string(name);
ff02322008-05-07Henrik Grubbström (Grubba)  } ;
f2dbd22016-01-25Henrik Grubbström (Grubba) lambda: TOK_LAMBDA line_number_info implicit_identifier start_lambda
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);
ab6b782016-05-07Henrik Grubbström (Grubba)  e=$5-1;
9072562008-05-07Henrik Grubbström (Grubba)  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);
0ad6502012-10-02Per Hedbor  }
9072562008-05-07Henrik Grubbström (Grubba)  type=compiler_pop_type(); Pike_compiler->compiler_frame->current_function_number = define_function(name, type,
95489a2008-06-29Martin Nilsson  ID_PROTECTED | ID_PRIVATE | ID_INLINE | ID_USED,
9072562008-05-07Henrik Grubbström (Grubba)  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 
ab6b782016-05-07Henrik Grubbström (Grubba)  debug_malloc_touch($7); $7=mknode(F_COMMA_EXPR,$7,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. */
ab6b782016-05-07Henrik Grubbström (Grubba)  type=find_return_type($7);
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)  }
ab6b782016-05-07Henrik Grubbström (Grubba)  e=$5-1; if($<number>6)
7e50571996-11-02Fredrik Hübinette (Hubbe)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
7e50571996-11-02Fredrik Hübinette (Hubbe)  e--;
5b368e2001-03-31Henrik Grubbström (Grubba)  pop_type_stack(T_ARRAY);
7e50571996-11-02Fredrik Hübinette (Hubbe)  }else{ push_type(T_VOID); }
9039702000-08-15Henrik Grubbström (Grubba)  Pike_compiler->varargs=0;
7e50571996-11-02Fredrik Hübinette (Hubbe)  push_type(T_MANY);
dfed932001-03-03Henrik Grubbström (Grubba)  for(; e>=0; e--) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  push_finished_type(Pike_compiler->compiler_frame->variable[e].type);
dfed932001-03-03Henrik Grubbström (Grubba)  push_type(T_FUNCTION); }
0ad6502012-10-02Per Hedbor 
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,
ab6b782016-05-07Henrik Grubbström (Grubba)  $7,
8267f41998-01-28Fredrik Hübinette (Hubbe)  type,
95489a2008-06-29Martin Nilsson  ID_PROTECTED | 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);
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (Pike_compiler->compiler_frame != $4) { Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n", Pike_compiler->compiler_frame, $4, Pike_compiler->compiler_frame->previous); } #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  pop_compiler_frame();
7e50571996-11-02Fredrik Hübinette (Hubbe)  }
f2dbd22016-01-25Henrik Grubbström (Grubba)  | TOK_LAMBDA line_number_info implicit_identifier start_lambda error
b5aa651999-12-16Henrik Grubbström (Grubba)  {
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (Pike_compiler->compiler_frame != $4) { Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n", Pike_compiler->compiler_frame, $4, Pike_compiler->compiler_frame->previous); } #endif
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) 
f2dbd22016-01-25Henrik Grubbström (Grubba) local_function: TOK_IDENTIFIER start_function 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)  push_finished_type(Pike_compiler->compiler_frame->current_return_type);
0ad6502012-10-02Per Hedbor 
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); }
0ad6502012-10-02Per Hedbor 
a566ca1999-12-14Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
97f6282000-03-07Fredrik Hübinette (Hubbe)  /***/
a566ca1999-12-14Fredrik Hübinette (Hubbe) 
28b7362008-07-08Henrik Grubbström (Grubba)  name = get_new_name($1->u.sval.u.string);
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,
e33ab92008-07-18Henrik Grubbström (Grubba)  ID_PROTECTED | ID_PRIVATE | 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,
95489a2008-06-29Martin Nilsson  ID_PROTECTED | 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;
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (Pike_compiler->compiler_frame != $2) { Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n", Pike_compiler->compiler_frame, $2, Pike_compiler->compiler_frame->previous); } #endif
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{
0ad6502012-10-02Per Hedbor  if(Pike_compiler->compiler_frame->lexical_scope &
b6cdf32000-06-28Fredrik Hübinette (Hubbe)  (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)  }
f2dbd22016-01-25Henrik Grubbström (Grubba)  | TOK_IDENTIFIER start_function error
b5aa651999-12-16Henrik Grubbström (Grubba)  {
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (Pike_compiler->compiler_frame != $2) { Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n", Pike_compiler->compiler_frame, $2, Pike_compiler->compiler_frame->previous); } #endif
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)  ;
e17b7b2016-01-16Henrik Grubbström (Grubba) create_arg: modifiers simple_type 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 ..."); }
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ($3) {
6489182016-01-22Henrik Grubbström (Grubba)  push_finished_type(Pike_compiler->compiler_frame->current_type);
e6c0892001-03-30Henrik Grubbström (Grubba)  push_type(T_ARRAY);
6489182016-01-22Henrik Grubbström (Grubba)  type = compiler_pop_type(); } else { copy_pike_type(type, Pike_compiler->compiler_frame->current_type);
e6c0892001-03-30Henrik Grubbström (Grubba)  }
c20a522000-07-08Henrik Grubbström (Grubba) 
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. */
eb6ba72016-01-11Henrik Grubbström (Grubba)  ref_no = define_variable($4->u.sval.u.string, type,
1e9a882007-10-05Henrik Grubbström (Grubba)  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).",
eb6ba72016-01-11Henrik Grubbström (Grubba)  $4->u.sval.u.string,
1e9a882007-10-05Henrik Grubbström (Grubba)  Pike_compiler->num_create_args, ref_no); }
eb6ba72016-01-11Henrik Grubbström (Grubba)  if ($3) {
1e9a882007-10-05Henrik Grubbström (Grubba)  /* 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); */
eb6ba72016-01-11Henrik Grubbström (Grubba)  free_node($4);
c20a522000-07-08Henrik Grubbström (Grubba)  $$=0; }
e17b7b2016-01-16Henrik Grubbström (Grubba)  | modifiers simple_type bad_identifier { $$=0; }
c20a522000-07-08Henrik Grubbström (Grubba)  ; 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) 
eb9ef92010-11-19Henrik Grubbström (Grubba) failsafe_program: '{' program { $<n>$ = NULL; } 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. */
6dddaa2016-11-09Henrik Grubbström (Grubba) anon_class: TOK_CLASS line_number_info { struct pike_string *s; char buffer[42]; sprintf(buffer,"__class_%ld_%ld_line_%d", (long)Pike_compiler->new_program->id, (long)Pike_compiler->local_class_counter++, (int) $2->line_number); s = make_shared_string(buffer); $<n>$ = mkstrnode(s); free_string(s); $<number>0 |= ID_PROTECTED | ID_PRIVATE | ID_INLINE; } { /* fprintf(stderr, "LANGUAGE.YACC: CLASS start\n"); */ if(Pike_compiler->compiler_pass==1) { if ($<number>0 & ID_EXTERN) { yywarning("Extern declared class definition."); } low_start_new_program(0, 1, $<n>3->u.sval.u.string, $<number>0, &$<number>$); /* fprintf(stderr, "Pass 1: Program %s has id %d\n", $4->u.sval.u.string->str, Pike_compiler->new_program->id); */ store_linenumber($2->line_number, $2->current_file); debug_malloc_name(Pike_compiler->new_program, $2->current_file->str, $2->line_number); }else{ int i; struct identifier *id; int tmp=Pike_compiler->compiler_pass; i=isidentifier($<n>3->u.sval.u.string); if(i<0) { /* Seriously broken... */ yyerror("Pass 2: program not defined!"); low_start_new_program(0, 2, 0, $<number>0, &$<number>$); }else{ id=ID_FROM_INT(Pike_compiler->new_program, i); if(IDENTIFIER_IS_CONSTANT(id->identifier_flags)) { struct svalue *s; if ((id->func.const_info.offset >= 0) && (TYPEOF(*(s = &PROG_FROM_INT(Pike_compiler->new_program,i)-> constants[id->func.const_info.offset].sval)) == T_PROGRAM)) { low_start_new_program(s->u.program, 2, $<n>3->u.sval.u.string, $<number>0, &$<number>$); /* fprintf(stderr, "Pass 2: Program %s has id %d\n", $4->u.sval.u.string->str, Pike_compiler->new_program->id); */ }else{ yyerror("Pass 2: constant redefined!"); low_start_new_program(0, 2, 0, $<number>0, &$<number>$); } }else{ yyerror("Pass 2: class constant no longer constant!"); low_start_new_program(0, 2, 0, $<number>0, &$<number>$); } } Pike_compiler->compiler_pass=tmp; } } { /* Clear scoped modifiers. */ $<number>$ = THIS_COMPILATION->lex.pragmas; THIS_COMPILATION->lex.pragmas &= ~ID_MODIFIER_MASK; } optional_create_arguments failsafe_program { struct program *p; /* Check if we have create arguments but no locally defined create(). */ if ($6) { 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; struct pike_type *type = NULL; int nargs = Pike_compiler->num_create_args; 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); /* Note: add_local_name() above will return e. */ Pike_compiler->compiler_frame->variable[e].flags |= LOCAL_VAR_IS_USED; } } 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); /* Note: add_local_name() above will return e. */ Pike_compiler->compiler_frame->variable[e].flags |= LOCAL_VAR_IS_USED; } } /* 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_PROTECTED, IDENTIFIER_PIKE_FUNCTION | (Pike_compiler->num_create_args < 0?IDENTIFIER_VARARGS:0), 0, OPT_SIDE_EFFECT); if (Pike_compiler->compiler_pass == 2) { node *create_code = NULL; int f; /* 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);*/ local_node = mkcastnode(mixed_type_string, local_node); /* NOTE: The cast to mixed above is needed to avoid generating * compilation errors, as well as avoiding optimizations * in mksoftcastnode(). */ 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. */ f=dooptcode(create_string, create_code, type, ID_PROTECTED); #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(); } } if(Pike_compiler->compiler_pass == 1) p=end_first_pass(0); else p=end_first_pass(1); /* fprintf(stderr, "LANGUAGE.YACC: CLASS end\n"); */ if(p) { /* Update the type for the program constant, * since we might have a lfun::create(). */ struct identifier *i; struct svalue sv; SET_SVAL(sv, T_PROGRAM, 0, program, p); i = ID_FROM_INT(Pike_compiler->new_program, $<number>4); free_type(i->type); i->type = get_type_of_svalue(&sv); free_program(p); } else if (!Pike_compiler->num_parse_error) { /* Make sure code in this class is aware that something went wrong. */ Pike_compiler->num_parse_error = 1; } $$=mkidentifiernode($<number>4); free_node($2); free_node($<n>3); check_tree($$,0); THIS_COMPILATION->lex.pragmas = $<number>5; } ; /* Modifiers at $0. */ named_class: TOK_CLASS line_number_info simple_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);
95489a2008-06-29Martin Nilsson  $<number>0|=ID_PROTECTED | 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;
89378b2010-11-23Henrik Grubbström (Grubba)  if ((id->func.const_info.offset >= 0) &&
017b572011-10-28Henrik Grubbström (Grubba)  (TYPEOF(*(s = &PROG_FROM_INT(Pike_compiler->new_program,i)-> constants[id->func.const_info.offset].sval)) == 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 ||
5a1b592009-11-17Henrik Grubbström (Grubba)  ((id = ID_FROM_PTR(Pike_compiler->new_program, ref))->func.offset == -1)) {
1e9a882007-10-05Henrik Grubbström (Grubba)  int e; struct pike_type *type = NULL; int nargs = Pike_compiler->num_create_args; push_compiler_frame(SCOPE_LOCAL);
0ad6502012-10-02Per Hedbor 
1e9a882007-10-05Henrik Grubbström (Grubba)  /* 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,
95489a2008-06-29Martin Nilsson  ID_INLINE | ID_PROTECTED,
1e9a882007-10-05Henrik Grubbström (Grubba)  IDENTIFIER_PIKE_FUNCTION | (Pike_compiler->num_create_args < 0?IDENTIFIER_VARARGS:0), 0, OPT_SIDE_EFFECT);
0ad6502012-10-02Per Hedbor 
5a1b592009-11-17Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) { node *create_code = NULL; int f;
1e9a882007-10-05Henrik Grubbström (Grubba) 
5a1b592009-11-17Henrik Grubbström (Grubba)  /* Third: Generate the initialization code. * * global_arg = [type]local_arg; * [,..] */ for(e=0; e<nargs; e++)
1e9a882007-10-05Henrik Grubbström (Grubba)  {
5a1b592009-11-17Henrik Grubbström (Grubba)  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);*/
faa3232013-02-19Henrik Grubbström (Grubba)  local_node = mkcastnode(mixed_type_string, local_node);
0ad6502012-10-02Per Hedbor 
faa3232013-02-19Henrik Grubbström (Grubba)  /* NOTE: The cast to mixed above is needed to avoid generating * compilation errors, as well as avoiding optimizations * in mksoftcastnode(). */
5a1b592009-11-17Henrik Grubbström (Grubba)  local_node = mksoftcastnode(Pike_compiler->compiler_frame-> variable[e].type, local_node); } create_code = mknode(F_COMMA_EXPR, create_code, mknode(F_ASSIGN, local_node, mkidentifiernode(e)));
1e9a882007-10-05Henrik Grubbström (Grubba)  } }
5a1b592009-11-17Henrik Grubbström (Grubba)  /* Fourth: Add a return 0; at the end. */
1e9a882007-10-05Henrik Grubbström (Grubba) 
5a1b592009-11-17Henrik Grubbström (Grubba)  create_code = mknode(F_COMMA_EXPR, mknode(F_POP_VALUE, create_code, NULL), mknode(F_RETURN, mkintnode(0), NULL));
1e9a882007-10-05Henrik Grubbström (Grubba) 
5a1b592009-11-17Henrik Grubbström (Grubba)  /* Fifth: Define the function. */
1e9a882007-10-05Henrik Grubbström (Grubba) 
5a1b592009-11-17Henrik Grubbström (Grubba)  f=dooptcode(create_string, create_code, type, ID_PROTECTED);
1e9a882007-10-05Henrik Grubbström (Grubba)  #ifdef PIKE_DEBUG
5a1b592009-11-17Henrik Grubbström (Grubba)  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);
1e9a882007-10-05Henrik Grubbström (Grubba) #endif
5a1b592009-11-17Henrik Grubbström (Grubba)  }
1e9a882007-10-05Henrik Grubbström (Grubba)  /* 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) {
5a1b592009-11-17Henrik Grubbström (Grubba)  /* Update the type for the program constant, * since we might have a lfun::create(). */ struct identifier *i; struct svalue sv;
017b572011-10-28Henrik Grubbström (Grubba)  SET_SVAL(sv, T_PROGRAM, 0, program, p);
5a1b592009-11-17Henrik Grubbström (Grubba)  i = ID_FROM_INT(Pike_compiler->new_program, $<number>4); free_type(i->type); i->type = get_type_of_svalue(&sv);
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; } ;
e33ab92008-07-18Henrik Grubbström (Grubba) enum_value: /* EMPTY */ { $$ = 0; } | '=' safe_expr0 { $$ = $2; } ; /* Previous enum value at $0. */ enum_def: /* EMPTY */ | simple_identifier enum_value
a418ce2001-03-31Henrik Grubbström (Grubba)  {
e33ab92008-07-18Henrik Grubbström (Grubba)  if ($1) { if ($2) { /* Explicit enum value. */
a418ce2001-03-31Henrik Grubbström (Grubba) 
e33ab92008-07-18Henrik Grubbström (Grubba)  /* This can be made more lenient in the future */
a418ce2001-03-31Henrik Grubbström (Grubba) 
e33ab92008-07-18Henrik Grubbström (Grubba)  /* 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; }
a418ce2001-03-31Henrik Grubbström (Grubba) 
e33ab92008-07-18Henrik Grubbström (Grubba)  if(!is_const($2))
a418ce2001-03-31Henrik Grubbström (Grubba)  {
e33ab92008-07-18Henrik Grubbström (Grubba)  if(Pike_compiler->compiler_pass==2) yyerror("Enum definition is not constant.");
a418ce2001-03-31Henrik Grubbström (Grubba)  push_int(0);
e33ab92008-07-18Henrik Grubbström (Grubba)  } else { if(!Pike_compiler->num_parse_error) { ptrdiff_t tmp=eval_low($2,1); if(tmp < 1) { yyerror("Error in enum definition."); push_int(0); }else{
bd67392015-10-14Martin Nilsson  pop_n_elems((INT32)(tmp - 1));
e33ab92008-07-18Henrik Grubbström (Grubba)  } } else { push_int(0); }
a418ce2001-03-31Henrik Grubbström (Grubba)  }
e33ab92008-07-18Henrik Grubbström (Grubba)  free_node($2); free_node($<n>0); $<n>0 = mkconstantsvaluenode(Pike_sp-1);
a418ce2001-03-31Henrik Grubbström (Grubba)  } else {
e33ab92008-07-18Henrik Grubbström (Grubba)  /* Implicit enum value. */ $<n>0 = safe_inc_enum($<n>0); push_svalue(&$<n>0->u.sval);
a418ce2001-03-31Henrik Grubbström (Grubba)  }
e33ab92008-07-18Henrik Grubbström (Grubba)  add_constant($1->u.sval.u.string, Pike_sp-1, (Pike_compiler->current_modifiers & ~ID_EXTERN) | ID_INLINE); /* Update the type. */ { struct pike_type *current = pop_unfinished_type(); struct pike_type *new = get_type_of_svalue(Pike_sp-1);
2a61e82011-03-24Henrik Grubbström (Grubba)  struct pike_type *res = or_pike_types(new, current, 3);
e33ab92008-07-18Henrik Grubbström (Grubba)  free_type(current); free_type(new); type_stack_mark(); push_finished_type(res); free_type(res); } pop_stack(); free_node($1);
43eaff2008-07-18Henrik Grubbström (Grubba)  } else if ($2) { free_node($2);
a418ce2001-03-31Henrik Grubbström (Grubba)  } } ;
e33ab92008-07-18Henrik Grubbström (Grubba) /* Previous enum value at $-2 */ propagated_enum_value:
a418ce2001-03-31Henrik Grubbström (Grubba)  {
e33ab92008-07-18Henrik Grubbström (Grubba)  $$ = $<n>-2;
a418ce2001-03-31Henrik Grubbström (Grubba)  } ;
e33ab92008-07-18Henrik Grubbström (Grubba) /* Previous enum value at $0. */
a418ce2001-03-31Henrik Grubbström (Grubba) enum_list: enum_def
e33ab92008-07-18Henrik Grubbström (Grubba)  | enum_list ',' propagated_enum_value enum_def { $<n>0 = $3; }
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."); } type_stack_mark(); push_type(T_ZERO); /* Joined type so far. */ }
0ad6502012-10-02Per Hedbor  optional_identifier '{'
a418ce2001-03-31Henrik Grubbström (Grubba)  {
e33ab92008-07-18Henrik Grubbström (Grubba)  push_int(-1); /* Previous value. */ $<n>$ = mkconstantsvaluenode(Pike_sp-1);
a418ce2001-03-31Henrik Grubbström (Grubba)  pop_stack();
e33ab92008-07-18Henrik Grubbström (Grubba)  }
eb9ef92010-11-19Henrik Grubbström (Grubba)  enum_list { $<n>$ = NULL; } end_block
e33ab92008-07-18Henrik Grubbström (Grubba)  { struct pike_type *t = pop_unfinished_type(); free_node($<n>5);
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); } ;
8457542016-05-13Henrik Grubbström (Grubba) save_locals: /* empty */
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
8457542016-05-13Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->last_block_level = $$ = Pike_compiler->compiler_frame->current_number_of_locals;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  }
8457542016-05-13Henrik Grubbström (Grubba)  ; save_block_level: /* empty */
02a79a2000-09-04Fredrik Hübinette (Hubbe)  { /* Trick to store more than one number on compiler stack - Hubbe */
8457542016-05-13Henrik Grubbström (Grubba)  $$ = Pike_compiler->compiler_frame->last_block_level;
02a79a2000-09-04Fredrik Hübinette (Hubbe)  }
8457542016-05-13Henrik Grubbström (Grubba)  ; cond: TOK_IF save_block_level save_locals line_number_info
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)));
8457542016-05-13Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $4);
0ef4e02002-05-09Henrik Grubbström (Grubba)  $$ = mkcastnode(void_type_string, $$);
8457542016-05-13Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $4); free_node($4); $$ = pop_local_variables($3, $$); Pike_compiler->compiler_frame->last_block_level = $2;
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; }
0ad6502012-10-02Per Hedbor  ;
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); } ;
8457542016-05-13Henrik Grubbström (Grubba) foreach: TOK_FOREACH save_block_level save_locals line_number_info
3c7fe72015-12-28Per Hedbor  '(' expr0 foreach_lvalues end_cond { /* Fix AUTO type. */ struct pike_type *ind=NULL, *val=NULL; if(Pike_compiler->compiler_pass == 2) { fix_type_field( $6 ); fix_type_field( $7 ); check_foreach_type( $6, $7, &ind, &val ); if( $7->token == ':' ) { if( CAR($7) && CAR($7)->type->type == PIKE_T_AUTO ) { if( CAR($7)->token == F_LOCAL && !CAR($7)->u.integer.b) { copy_pike_type(Pike_compiler->compiler_frame->variable[CAR($7)->u.integer.a].type, ind); } else { yywarning("Unexpected auto type usage\n"); } } if( CDR($7) && CDR($7)->type->type == PIKE_T_AUTO ) { if( CDR($7)->token == F_LOCAL && !CDR($7)->u.integer.b) { copy_pike_type(Pike_compiler->compiler_frame->variable[CDR($7)->u.integer.a].type, val); } else { yywarning("Unexpected auto type usage\n"); } } } else { fix_type_field( $7 ); if( $7->type->type == PIKE_T_AUTO ) { if( $7->token == F_LOCAL && !$7->u.integer.b) { copy_pike_type(Pike_compiler->compiler_frame->variable[$7->u.integer.a].type, val); } else { yywarning("Unexpected auto type usage\n"); } } /* old style foreach. */ } if(ind)free_type(ind); if(val)free_type(val); $<number>$=0; } } 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),
3c7fe72015-12-28Per Hedbor  $10);
998e1f1998-04-15Henrik Grubbström (Grubba)  } else { /* Error in lvalue */
3c7fe72015-12-28Per Hedbor  $$=mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $6), $10);
998e1f1998-04-15Henrik Grubbström (Grubba)  }
8457542016-05-13Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $4); free_node($4); $$ = pop_local_variables($3, $$); Pike_compiler->compiler_frame->last_block_level = $2;
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."); } ;
8457542016-05-13Henrik Grubbström (Grubba) for: TOK_FOR save_block_level save_locals line_number_info
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)));
8457542016-05-13Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $4); free_node($4); $$ = pop_local_variables($3, $$); Pike_compiler->compiler_frame->last_block_level = $2;
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) 
8457542016-05-13Henrik Grubbström (Grubba) while: TOK_WHILE save_block_level save_locals line_number_info
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));
8457542016-05-13Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $4); free_node($4); $$ = pop_local_variables($3, $$); Pike_compiler->compiler_frame->last_block_level = $2;
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) 
8457542016-05-13Henrik Grubbström (Grubba) switch: TOK_SWITCH save_block_level save_locals line_number_info
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);
8457542016-05-13Henrik Grubbström (Grubba)  COPY_LINE_NUMBER_INFO($$, $4); free_node($4); $$ = pop_local_variables($3, $$); Pike_compiler->compiler_frame->last_block_level = $2;
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)  {
c2c9322014-08-10Martin Nilsson  if(!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); } ;
0ad6502012-10-02Per Hedbor 
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
35a4052016-01-24Henrik Grubbström (Grubba)  | simple_type2 local_name_list { $$=$2; }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
0ad6502012-10-02Per Hedbor 
7e50571996-11-02Fredrik Hübinette (Hubbe)  comma_expr2: expr0 | comma_expr2 ',' expr0 {
0ad6502012-10-02Per Hedbor  $$ = mknode(F_COMMA_EXPR, mkcastnode(void_type_string, $1), $3);
7e50571996-11-02Fredrik Hübinette (Hubbe)  } ;
215bed1996-09-28Fredrik Hübinette (Hubbe) 
615cf52016-02-02Henrik Grubbström (Grubba) splice_expr: 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; }
fbff332016-05-17Per Hedbor  | TOK_POW_EQ { $$=F_POW_EQ; }
f76b4c2000-05-11Henrik Grubbström (Grubba)  | 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)  ;
0ad6502012-10-02Per Hedbor 
215bed1996-09-28Fredrik Hübinette (Hubbe) 
615cf52016-02-02Henrik Grubbström (Grubba) expr_list2: splice_expr | expr_list2 ',' splice_expr { $$=mknode(F_ARG_LIST,$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
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) 
0ad6502012-10-02Per Hedbor assoc_pair: expr0 expected_colon expr0
3271182004-03-18Henrik Grubbström (Grubba)  { $$=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); }
fbff332016-05-17Per Hedbor  | expr1 TOK_POW expr1 { $$=mkopernode("`**",$1,$3); }
7e50571996-11-02Fredrik Hübinette (Hubbe)  | expr1 '%' expr1 { $$=mkopernode("`%",$1,$3); } | expr1 '/' expr1 { $$=mkopernode("`/",$1,$3); }
0ad6502012-10-02Per Hedbor  | expr1 TOK_LOR error
f76b4c2000-05-11Henrik Grubbström (Grubba)  | expr1 TOK_LAND error
0ad6502012-10-02Per Hedbor  | expr1 '|' error | expr1 '^' error | expr1 '&' error | expr1 TOK_EQ error | expr1 TOK_NE error | expr1 '>' error | expr1 TOK_GE error | expr1 '<' error | expr1 TOK_LE error | expr1 TOK_LSH error | expr1 TOK_RSH error | expr1 '+' error | expr1 '-' error | expr1 '*' error | expr1 '%' error
97358e1998-04-23Fredrik Hübinette (Hubbe)  | 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); }
5192732015-05-15Henrik Grubbström (Grubba)  | '~' expr2 { if ($2 && ($2->token == F_CONSTANT) && (TYPEOF($2->u.sval) == T_INT)) { $$ = mkintnode(~($2->u.sval.u.integer)); free_node($2); } else { $$ = mkopernode("`~", $2, 0); } } | '-' expr2 { if ($2 && ($2->token == F_CONSTANT) && (TYPEOF($2->u.sval) == T_INT) && !INT_TYPE_NEG_OVERFLOW($2->u.sval.u.integer)) { $$ = mkintnode(-($2->u.sval.u.integer)); free_node($2); } else { $$=mkopernode("`-", $2, 0); } }
7e50571996-11-02Fredrik Hübinette (Hubbe)  ;
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? */
f2dbd22016-01-25Henrik Grubbström (Grubba)  start_lambda
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);
40a5d92015-02-07Henrik Grubbström (Grubba)  $5 = pop_local_variables($<number>4, $5);
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)  }
0ad6502012-10-02Per Hedbor 
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); */
0ad6502012-10-02Per Hedbor 
a30f092000-07-12Fredrik Hübinette (Hubbe)  type=compiler_pop_type();
28b7362008-07-08Henrik Grubbström (Grubba)  name = get_new_name(NULL);
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 */
0ad6502012-10-02Per Hedbor 
a30f092000-07-12Fredrik Hübinette (Hubbe)  f=dooptcode(name,
9b39022003-03-27Martin Stjernholm  $5,
a30f092000-07-12Fredrik Hübinette (Hubbe)  type,
95489a2008-06-29Martin Nilsson  ID_PROTECTED | 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);
bc62892009-06-22Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG if (Pike_compiler->compiler_frame != $3) { Pike_fatal("Lost track of compiler_frame!\n" " Got: %p (Expected: %p) Previous: %p\n", Pike_compiler->compiler_frame, $3, Pike_compiler->compiler_frame->previous); } #endif
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: {
3a30d72014-10-05Martin Nilsson  $$ = Pike_compiler->current_modifiers = ID_PROTECTED|ID_INLINE|ID_PRIVATE | (THIS_COMPILATION->lex.pragmas & ID_MODIFIER_MASK);
2a343f2008-04-04Henrik Grubbström (Grubba)  } ;
aea6a42016-05-09Henrik Grubbström (Grubba) expr4: idents2 | expr5 | expr5 '.' line_number_info TOK_IDENTIFIER { $$=index_node($1,".",$4->u.sval.u.string); COPY_LINE_NUMBER_INFO($$, $3); free_node ($1); free_node ($3); free_node ($4); } ; expr5: literal_expr
55bd772005-02-18Henrik Grubbström (Grubba)  | catch | gauge | typeof | sscanf | lambda
6dddaa2016-11-09Henrik Grubbström (Grubba)  | implicit_modifiers anon_class { $$ = $2; }
2a343f2008-04-04Henrik Grubbström (Grubba)  | implicit_modifiers enum { $$ = $2; }
55bd772005-02-18Henrik Grubbström (Grubba)  | 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)  }
0ad6502012-10-02Per Hedbor  | expr4 TOK_SAFE_START_INDEX line_number_info expr0 ']' {
2525892013-11-02Per Hedbor  /* A[?X] to ((tmp=A) && tmp[X]) */
aa50312014-12-09Henrik Grubbström (Grubba)  if( $1 && ($1->token == F_LOCAL) )
0ad6502012-10-02Per Hedbor  {
efd3b62013-10-28Arne Goedeke  $$=mknode(F_LAND, copy_node($1), mknode(F_INDEX, $1, $4));
0ad6502012-10-02Per Hedbor  } else { fix_type_field( $1 );
aa50312014-12-09Henrik Grubbström (Grubba)  if( $1 && $1->type )
0ad6502012-10-02Per Hedbor  { int temporary; $1->type->refs++; temporary = add_local_name(empty_pike_string, $1->type, 0); Pike_compiler->compiler_frame->variable[temporary].flags |= LOCAL_VAR_IS_USED; $$=mknode(F_LAND, mknode(F_ASSIGN, $1, mklocalnode(temporary,0)), mknode(F_INDEX, mklocalnode(temporary,0), $4));
b7dce32016-05-12Henrik Grubbström (Grubba)  $$ = pop_local_variables(temporary, $$);
0ad6502012-10-02Per Hedbor  } else { $$=mknode(F_INDEX, $1,$4); yyerror("Indexing unexpected value."); } } COPY_LINE_NUMBER_INFO($$, $3); free_node ($3); } | expr4 TOK_SAFE_START_INDEX line_number_info range_bound expected_dot_dot range_bound ']' {
2525892013-11-02Per Hedbor  /* A[?X..Y] to ((tmp=A) && tmp[X..Y]) */
0ad6502012-10-02Per Hedbor  node *range = mknode(':',$4,$6);
aa50312014-12-09Henrik Grubbström (Grubba)  if( $1 && ($1->token == F_LOCAL ) )
0ad6502012-10-02Per Hedbor  {
efd3b62013-10-28Arne Goedeke  $$ = mknode( F_LAND, copy_node($1), mknode(F_RANGE, $1, range) );
0ad6502012-10-02Per Hedbor  } else { fix_type_field( $1 );
aa50312014-12-09Henrik Grubbström (Grubba)  if( $1 && $1->type )
0ad6502012-10-02Per Hedbor  { int temporary; $1->type->refs++; temporary = add_local_name(empty_pike_string, $1->type, 0); Pike_compiler->compiler_frame->variable[temporary].flags |= LOCAL_VAR_IS_USED; $$=mknode(F_LAND, mknode(F_ASSIGN, $1, mklocalnode(temporary,0) ), mknode(F_RANGE, mklocalnode(temporary,0), range) );
b7dce32016-05-12Henrik Grubbström (Grubba)  $$ = pop_local_variables(temporary, $$);
0ad6502012-10-02Per Hedbor  } else { $$ = mknode( F_LAND, $1, mknode(F_RANGE,$1,range) ); yyerror("Indexing unexpected value."); } } COPY_LINE_NUMBER_INFO($$, $3); free_node ($3); }
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 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 ')'."); } | 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)  }
0ad6502012-10-02Per Hedbor  | expr4 TOK_SAFE_INDEX line_number_info TOK_IDENTIFIER { /* A?->B to ((tmp=A) && tmp->B) */ int temporary;
aa50312014-12-09Henrik Grubbström (Grubba)  if( $1 && ($1->token == F_LOCAL) )
0ad6502012-10-02Per Hedbor  {
efd3b62013-10-28Arne Goedeke  $$=mknode(F_LAND, copy_node($1), mknode(F_ARROW, $1, $4));
0ad6502012-10-02Per Hedbor  } else { fix_type_field( $1 );
2a01c22015-07-21Arne Goedeke  if( $1 && $1->type )
0ad6502012-10-02Per Hedbor  {
b7dce32016-05-12Henrik Grubbström (Grubba)  add_ref($1->type);
0ad6502012-10-02Per Hedbor  temporary = add_local_name(empty_pike_string, $1->type, 0);
b7dce32016-05-12Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->variable[temporary].flags |= LOCAL_VAR_IS_USED;
0ad6502012-10-02Per Hedbor  $$=mknode(F_LAND, mknode(F_ASSIGN, $1, mklocalnode(temporary,0)), mknode(F_ARROW, mklocalnode(temporary,0), $4));
b7dce32016-05-12Henrik Grubbström (Grubba)  $$ = pop_local_variables(temporary, $$);
0ad6502012-10-02Per Hedbor  } else { $$=mknode(F_ARROW, $1,$4); yyerror("Indexing unexpected value."); } } COPY_LINE_NUMBER_INFO($$, $3); free_node ($3); }
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,
6530932008-06-29Martin Nilsson  SEE_PROTECTED|
71d9702000-06-21Henrik Grubbström (Grubba)  SEE_PRIVATE)) >= 0)) {
acbe8a2002-09-21Martin Stjernholm  struct reference *ref = Pike_compiler->new_program->identifier_references + i;
ec80082014-08-24Martin Nilsson  if (IDENTIFIER_IS_VARIABLE (
acbe8a2002-09-21Martin Stjernholm  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 {
919d482013-06-08Henrik Grubbström (Grubba)  if (!(ref->id_flags & ID_LOCAL)) {
acbe8a2002-09-21Martin Stjernholm  /* 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;
919d482013-06-08Henrik Grubbström (Grubba)  if (!(refp->id_flags & ID_LOCAL)) continue;
0df6e32007-10-13Henrik Grubbström (Grubba)  if((refp->inherit_offset == funp.inherit_offset) &&
919d482013-06-08Henrik Grubbström (Grubba)  (refp->identifier_offset == funp.identifier_offset)) {
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; } ;
f99cdd2016-05-08Henrik Grubbström (Grubba) literal_expr: string | TOK_NUMBER | TOK_FLOAT { $$=mkfloatnode((FLOAT_TYPE)$1); } | open_paren_with_line_info '{' expr_list close_brace_or_missing ')' { /* FIXME: May eat lots of stack; cf Standards.FIPS10_4.divisions */ $$=mkefuncallnode("aggregate",$3); COPY_LINE_NUMBER_INFO($$, $1); 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 ')' { /* FIXME: May eat lots of stack; cf Standards.FIPS10_4.divisions */ $$=mkefuncallnode("aggregate_mapping",$3); COPY_LINE_NUMBER_INFO($$, $1); free_node ($1); free_node ($2); } | TOK_MULTISET_START line_number_info expr_list TOK_MULTISET_END { /* FIXME: May eat lots of stack; cf Standards.FIPS10_4.divisions */ $$=mkefuncallnode("aggregate_multiset",$3); COPY_LINE_NUMBER_INFO($$, $2); free_node ($2); } | TOK_MULTISET_START line_number_info expr_list ')' { yyerror("Missing '>'."); $$=mkefuncallnode("aggregate_multiset",$3); COPY_LINE_NUMBER_INFO($$, $2); free_node ($2); } | TOK_MULTISET_START line_number_info error TOK_MULTISET_END { $$=$2; yyerrok; } | TOK_MULTISET_START line_number_info error ')' { yyerror("Missing '>'."); $$=$2; yyerrok; } | TOK_MULTISET_START line_number_info error TOK_LEX_EOF { $$=$2; yyerror("Missing '>)'."); yyerror("Unexpected end of file."); } | TOK_MULTISET_START line_number_info error ';' { $$=$2; yyerror("Missing '>)'."); } | TOK_MULTISET_START line_number_info error '}' { $$=$2; yyerror("Missing '>)'."); } ;
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)  }
8c77b61998-04-13Henrik Grubbström (Grubba)  | idents '.' bad_identifier {}
4d21331998-04-14Henrik Grubbström (Grubba)  | idents '.' error {}
591c0c1997-01-19Fredrik Hübinette (Hubbe)  ;
a83d122013-11-08Henrik Grubbström (Grubba) string_or_identifier: TOK_IDENTIFIER | string ;
062e842013-11-09Henrik Grubbström (Grubba) /* Note that the result of this rule is passed both with * the node value (inherit number) and with two global * variables (inherit_state and inherit_depth). * * Note also that inherit number -1 indicates any inherit. */
a83d122013-11-08Henrik Grubbström (Grubba) inherit_specifier: string_or_identifier TOK_COLON_COLON
82e1b72000-06-22Henrik Grubbström (Grubba)  {
8853882008-04-26Henrik Grubbström (Grubba)  struct compilation *c = THIS_COMPILATION;
062e842013-11-09Henrik Grubbström (Grubba)  struct program_state *state = Pike_compiler; int depth;
baa7712016-05-06Henrik Grubbström (Grubba)  int e = INHERIT_ALL;
82e1b72000-06-22Henrik Grubbström (Grubba) 
062e842013-11-09Henrik Grubbström (Grubba)  inherit_state = NULL; inherit_depth = 0; /* NB: The heuristics here are a bit strange * (all to make it as backward compatible as possible). * * The priority order is as follows: * * 1: Direct inherits in the current class. * * 2: The name of the current class. * * 3: 1 & 2 recursively for surrounding parent classes. * * 4: Indirect inherits in the current class. * * 5: 4 recursively for surrounding parent classes. * * 6: this_program. * * Note that a deep inherit in the current class trumphs * a not so deep inherit in a parent class (but not a * direct inherit in a parent class). To select the deep * inherit in the parent class in this case, prefix it * with the name of the parent class. */ for (depth = 0;; depth++, state = state->previous) { int inh = find_inherit(state->new_program, $1->u.sval.u.string); if (inh && (!inherit_state || (state->new_program->inherits[inh].inherit_level == 1))) { /* Found, and we've either not found anything earlier, * or this is a direct inherit (and the previous * wasn't since we didn't break out of the loop). */
91b0d92002-05-05Martin Stjernholm  e = inh;
062e842013-11-09Henrik Grubbström (Grubba)  inherit_state = state; inherit_depth = depth; if (state->new_program->inherits[inh].inherit_level == 1) { /* Name of direct inherit ==> Done. */ break; }
91b0d92002-05-05Martin Stjernholm  }
062e842013-11-09Henrik Grubbström (Grubba)  /* The top-level class does not have a name, so break here. */ if (depth == c->compilation_depth) break;
ec80082014-08-24Martin Nilsson  if (ID_FROM_INT (state->previous->new_program,
062e842013-11-09Henrik Grubbström (Grubba)  state->parent_identifier)->name ==
91b0d92002-05-05Martin Stjernholm  $1->u.sval.u.string) {
062e842013-11-09Henrik Grubbström (Grubba)  /* Name of surrounding class ==> Done. */
baa7712016-05-06Henrik Grubbström (Grubba)  e = INHERIT_SELF;
062e842013-11-09Henrik Grubbström (Grubba)  inherit_state = state; inherit_depth = depth;
91b0d92002-05-05Martin Stjernholm  break; }
8c64232000-06-26Henrik Grubbström (Grubba)  }
baa7712016-05-06Henrik Grubbström (Grubba)  if (e < 0) {
062e842013-11-09Henrik Grubbström (Grubba)  inherit_state = state; inherit_depth = depth;
baa7712016-05-06Henrik Grubbström (Grubba)  if ($1->u.sval.u.string == this_program_string || $1->u.sval.u.string == this_string) {
ec80082014-08-24Martin Nilsson  inherit_state = Pike_compiler; inherit_depth = 0;
baa7712016-05-06Henrik Grubbström (Grubba)  e = INHERIT_SELF;
e5674c2002-06-07Martin Stjernholm  }
ec80082014-08-24Martin Nilsson  else my_yyerror("No inherit or surrounding class %S.", $1->u.sval.u.string);
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) {}
baa7712016-05-06Henrik Grubbström (Grubba)  $$ = INHERIT_GLOBAL;
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) {
baa7712016-05-06Henrik Grubbström (Grubba)  $1 = INHERIT_SELF;
7e64282008-05-30Henrik Grubbström (Grubba)  }
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); }
baa7712016-05-06Henrik Grubbström (Grubba)  $$ = INHERIT_ALL;
a2f4232008-05-30Henrik Grubbström (Grubba)  } 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); }
baa7712016-05-06Henrik Grubbström (Grubba)  | inherit_specifier bad_identifier TOK_COLON_COLON { $$ = INHERIT_ALL; }
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.
13670c2015-05-25Martin Nilsson  */
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)  }
bbd8922011-07-07Henrik Grubbström (Grubba)  | '.' TOK_IDENTIFIER { struct pike_string *dot; MAKE_CONST_STRING(dot, "."); if (call_handle_import(dot)) { node *tmp=mkconstantsvaluenode(Pike_sp-1); pop_stack(); $$=index_node(tmp, ".", $2->u.sval.u.string); free_node(tmp); } else $$=mknewintnode(0); if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, $2->u.sval.u.string); free_node($2); } | 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); }
32bc322008-06-18Henrik Grubbström (Grubba)  | TOK_RESERVED { ref_push_string($1->u.sval.u.string); low_yyreport(REPORT_ERROR, NULL, 0, parser_system_string, 1, "Unknown reserved symbol %s."); free_node($1); $$ = 0; }
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 {
7f012e2014-11-09Henrik Grubbström (Grubba)  $$ = find_versioned_identifier($3->u.sval.u.string, $1->u.integer.a, $1->u.integer.b);
a0af022006-01-21Henrik Grubbström (Grubba)  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) 
c528462016-05-03Henrik Grubbström (Grubba)  $$ = find_inherited_identifier(inherit_state, inherit_depth, $1, Pike_compiler->last_identifier); if (!$$) {
388e5d2008-05-30Henrik Grubbström (Grubba)  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)  {
baa7712016-05-06Henrik 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, $2->u.sval.u.string);
fae37d1998-08-30Henrik Grubbström (Grubba) 
baa7712016-05-06Henrik Grubbström (Grubba)  $$ = find_inherited_identifier(Pike_compiler, 0, INHERIT_ALL,
c528462016-05-03Henrik Grubbström (Grubba)  Pike_compiler->last_identifier);
7e50571996-11-02Fredrik Hübinette (Hubbe)  if(!$$) {
c528462016-05-03Henrik Grubbström (Grubba)  if (Pike_compiler->compiler_pass == 2) { my_yyerror("Undefined identifier ::%S.", $2->u.sval.u.string);
2756c12002-11-27Henrik Grubbström (Grubba)  }
c528462016-05-03Henrik Grubbström (Grubba)  $$=mkintnode(0);
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);
067ddd2014-08-11Martin Nilsson  $$ = mktypenode(t);
7e50571996-11-02Fredrik Hübinette (Hubbe)  free_node(tmp);
13670c2015-05-25Martin Nilsson  }
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)  ;
13670c2015-05-25Martin Nilsson 
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."); }
13670c2015-05-25Martin Nilsson  ;
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); }
fffdad2014-10-13Martin Nilsson  $$=mknode(F_SSCANF,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); }
dd46aa2014-08-11Per Hedbor  | type2 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)  }
dd46aa2014-08-11Per Hedbor  /* FIXME: Add production for type2 ==> 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);
28b7362008-07-08Henrik Grubbström (Grubba)  if (!id->name->size_shift) { int len; if ((len = strlen(id->name->str)) == id->name->len) { /* Most common case. */ $$ = mkstrnode(id->name); } else { struct pike_string *str = make_shared_binary_string(id->name->str, len); $$ = mkstrnode(str); free_string(str); } } else { struct pike_string *str; struct array *split; MAKE_CONST_STRING(str, "\0"); split = explode(id->name, str); $$ = mkstrnode(split->item->u.string); free_array(split); }
9aee972008-05-06Henrik Grubbström (Grubba)  } } ; 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)  } ;
a83d122013-11-08Henrik Grubbström (Grubba) string_constant: string | string_constant '+' string { 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); } ; /* Same as string_constant above, but without TOK_FUNCTION_NAME. */ real_string_constant: TOK_STRING | real_string_constant TOK_STRING { 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); } | real_string_constant '+' TOK_STRING { 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); } ;
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"); }
32bc322008-06-18Henrik Grubbström (Grubba)  | TOK_RESERVED { ref_push_string($1->u.sval.u.string); low_yyreport(REPORT_ERROR, NULL, 0, parser_system_string, 1, "Unknown reserved symbol %s."); free_node($1); }
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_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"); }
fa47dd2016-09-27Henrik Grubbström (Grubba)  | TOK_WEAK { yyerror_reserved("__weak__"); }
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"); }
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 }
28b7362008-07-08Henrik Grubbström (Grubba) static struct pike_string *get_new_name(struct pike_string *prefix)
b2e7262007-09-15Henrik Grubbström (Grubba) { 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);
28b7362008-07-08Henrik Grubbström (Grubba)  if (prefix) { struct string_builder sb; init_string_builder_alloc(&sb, prefix->len + strlen(buf) + 1, prefix->size_shift); string_builder_shared_strcat(&sb, prefix); string_builder_putchar(&sb, 0); string_builder_strcat(&sb, buf); return finish_string_builder(&sb); }
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) 
067ddd2014-08-11Martin Nilsson  if (str->len) {
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;
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. */
30c0612008-06-29Martin Stjernholm static node *add_protected_variable(struct pike_string *name, struct pike_type *type, int depth, node *initializer)
0080352007-09-16Henrik Grubbström (Grubba) { 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) {
30c0612008-06-29Martin Stjernholm  my_yyerror("Too many levels of protected (%d, max:%d).",
0080352007-09-16Henrik Grubbström (Grubba)  depth, depth - (i+1)); parent_depth -= i+1; break; } p->new_program->flags |= PROGRAM_USES_PARENT; p = p->previous; }
13670c2015-05-25Martin Nilsson 
28b7362008-07-08Henrik Grubbström (Grubba)  tmp_name = get_new_name(name);
0080352007-09-16Henrik Grubbström (Grubba)  id = define_parent_variable(p, tmp_name, type,
30c0612008-06-29Martin Stjernholm  ID_PROTECTED|ID_PRIVATE|ID_INLINE);
0080352007-09-16Henrik Grubbström (Grubba)  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;
28b7362008-07-08Henrik Grubbström (Grubba)  tmp_name = get_new_name(name);
0080352007-09-16Henrik Grubbström (Grubba)  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! */
30c0612008-06-29Martin Stjernholm  yyerror("Initializers not yet supported for protected variables with function scope.");
0080352007-09-16Henrik Grubbström (Grubba)  } 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;
13670c2015-05-25Martin Nilsson 
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;
13670c2015-05-25Martin Nilsson  while(q!=f)
4218011999-01-31Fredrik Hübinette (Hubbe)  {
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;
9d52082016-10-30Martin Karlgren  q->variable[e].flags |= LOCAL_VAR_USED_IN_SCOPE;
1faa902006-02-25Henrik Grubbström (Grubba)  }
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; } }
e33ab92008-07-18Henrik Grubbström (Grubba) static node *safe_inc_enum(node *n)
a418ce2001-03-31Henrik Grubbström (Grubba) { JMP_BUF recovery;
eab66a2016-03-13Arne Goedeke  node *ret;
e33ab92008-07-18Henrik Grubbström (Grubba)  STACK_LEVEL_START(0);
a418ce2001-03-31Henrik Grubbström (Grubba) 
e33ab92008-07-18Henrik Grubbström (Grubba)  if (SETJMP(recovery)) {
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 {
e33ab92008-07-18Henrik Grubbström (Grubba)  if (n->token != F_CONSTANT) Pike_fatal("Bad node to safe_inc_enum().\n"); push_svalue(&n->u.sval);
a418ce2001-03-31Henrik Grubbström (Grubba)  push_int(1); f_add(2); } UNSETJMP(recovery);
3601d32002-11-23Martin Stjernholm  STACK_LEVEL_DONE(1);
e33ab92008-07-18Henrik Grubbström (Grubba)  free_node(n);
eab66a2016-03-13Arne Goedeke  ret = mkconstantsvaluenode(Pike_sp-1);
e33ab92008-07-18Henrik Grubbström (Grubba)  pop_stack();
eab66a2016-03-13Arne Goedeke  return ret;
a418ce2001-03-31Henrik Grubbström (Grubba) }
7f012e2014-11-09Henrik Grubbström (Grubba) static node *find_versioned_identifier(struct pike_string *identifier, int major, int minor) { struct compilation *c = THIS_COMPILATION; int old_major = Pike_compiler->compat_major; int old_minor = Pike_compiler->compat_minor; struct svalue *efun = NULL; node *res = NULL; change_compiler_compatibility(major, minor); if(Pike_compiler->last_identifier) free_string(Pike_compiler->last_identifier); copy_shared_string(Pike_compiler->last_identifier, identifier); /* Check predef:: first, and then the modules. */ if (TYPEOF(c->default_module) == T_MAPPING) { if ((efun = low_mapping_string_lookup(c->default_module.u.mapping, identifier))) res = mkconstantsvaluenode(efun); } else if (TYPEOF(c->default_module) != T_INT) { JMP_BUF tmp; if (SETJMP (tmp)) { handle_compile_exception ("Couldn't index %d.%d " "default module with \"%S\".", major, minor, identifier); } else { push_svalue(&c->default_module); ref_push_string(identifier); f_index (2); if (!IS_UNDEFINED(Pike_sp - 1)) res = mkconstantsvaluenode(Pike_sp - 1); pop_stack(); } UNSETJMP(tmp); } if (!res && !(res = resolve_identifier(identifier))) { if((Pike_compiler->flags & COMPILATION_FORCE_RESOLVE) || (Pike_compiler->compiler_pass==2)) { my_yyerror("Undefined identifier %d.%d::%S.", major, minor, identifier); }else{ res = mknode(F_UNDEFINED, 0, 0); } } change_compiler_compatibility(old_major, old_minor); return res; }
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))
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-1]) != T_INT)
9036e82001-08-16Martin Stjernholm  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; }
b754192016-01-19Henrik Grubbström (Grubba) /* Set compiler_frame->current_type from the type stack. */ static void update_current_type() { if(Pike_compiler->compiler_frame->current_type) free_type(Pike_compiler->compiler_frame->current_type); Pike_compiler->compiler_frame->current_type = compiler_pop_type(); }
61e9a01998-01-25Fredrik Hübinette (Hubbe) void cleanup_compiler(void) { }