pike.git / src / operators.c

version» Context lines:

pike.git/src/operators.c:5468:    struct compilation *c = THIS_COMPILATION;    if(count_args(CDR(n)) != 1) return 0;    if(do_docode(CDR(n),DO_NOT_COPY) != 1)    Pike_fatal("Count args was wrong in sizeof().\n");    emit0(F_SIZEOF);    return 1;   }      extern int generate_call_function(node *n);    + /*! @decl void _Static_assert(int constant_expression, string constant_message) +  *! +  *! Perform a compile-time assertion check. +  *! +  *! If @[constant_expression] is false, a compiler error message +  *! containing @[constant_message] will be generated. +  *! +  *! @note +  *! Note that the function call compiles to the null statement, +  *! and thus does not affect the run-time. +  *! +  *! @seealso +  *! @[cpp::static_assert] +  */ + static int generate__Static_assert(node *n) + { +  struct compilation *c = THIS_COMPILATION; +  ptrdiff_t tmp; +  node **expr = my_get_arg(&_CDR(n), 0); +  node **msg = my_get_arg(&_CDR(n), 1); +  if(!expr || !msg || count_args(CDR(n)) != 2) { +  yyerror("Bad number of arguments to _Static_assert()."); +  return 1; +  } +  tmp = eval_low(*msg, 0); +  if (tmp < 1) { +  yyerror("Argument 2 to _Static_assert() is not constant."); +  return 1; +  } +  if (tmp > 1) pop_n_elems(tmp-1); +  if (TYPEOF(Pike_sp[-1]) != T_STRING) { +  yyerror("Bad argument 2 to _Static_assert(), expected string."); +  return 1; +  } +  tmp = eval_low(*expr, 0); +  if (tmp < 1) { +  pop_stack(); +  yyerror("Argument 1 to _Static_assert is not constant."); +  return 1; +  } +  if (tmp > 1) pop_n_elems(tmp-1); +  if (SAFE_IS_ZERO(Pike_sp-1)) { +  my_yyerror("Assertion failed: %S", Pike_sp[-2].u.string); +  } +  pop_n_elems(2); +  return 1; + } +    /*! @class string_assignment    */      struct program *string_assignment_program;      #undef THIS   #define THIS ((struct string_assignment_storage *)(CURRENT_STORAGE))   /*! @decl int `[](int i)    *!    *! String index operator.
pike.git/src/operators.c:5821:    tFunc(tOr5(tStr,tMultiset,tArray,tMapping,tObj),tInt),    OPT_TRY_OPTIMIZE, optimize_sizeof, generate_sizeof);       /* function(mixed,mixed ...:mixed) */    ADD_EFUN2("`()",f_call_function,tFuncV(tMix,tMix,tMix),OPT_SIDE_EFFECT | OPT_EXTERNAL_DEPEND,0,generate_call_function);       /* This one should be removed */    /* function(mixed,mixed ...:mixed) */    ADD_EFUN2("call_function",f_call_function,tFuncV(tMix,tMix,tMix),OPT_SIDE_EFFECT | OPT_EXTERNAL_DEPEND,0,generate_call_function);    +  /* From the 201x C standard */ +  ADD_EFUN2("_Static_assert", NULL, +  tFunc(tInt tStr, tVoid), OPT_TRY_OPTIMIZE, +  NULL, generate__Static_assert);       start_new_program();    ADD_STORAGE(struct string_assignment_storage);    /* function(int:int) */    ADD_FUNCTION2("`[]", f_string_assignment_index, tFunc(tInt,tInt), 0,    OPT_EXTERNAL_DEPEND);    /* function(int,int:int) */    ADD_FUNCTION2("`[]=", f_string_assignment_assign_index,    tFunc(tInt tInt,tInt), 0, OPT_SIDE_EFFECT);    set_init_callback(init_string_assignment_storage);