Beispiel #1
0
/* preprocess of printing calctree node  */
static int print_treenode_pre(T_KRCalcTree *node, void *data)
{ 
    int i = 0;
    FILE *printer = data;
    
    INDENT;
    for (i=0; i<indentno; i++)
        fprintf(printer, " ");
        
    switch(node->kind){
        case KR_CALCKIND_ARITH:
            fprintf(printer,"Arith Op: ");
            print_operator(printer, node->op);
            break;
        case KR_CALCKIND_LOGIC:    
            fprintf(printer,"Logic Op: ");
            print_operator(printer, node->op);
            break;
        case KR_CALCKIND_INT:
            fprintf(printer,"Num_Const: %d\n",node->attr.val.i);
            break;
        case KR_CALCKIND_FLOAT:
            fprintf(printer,"FNum_Const: %f\n",node->attr.val.d);
            break;
        case KR_CALCKIND_STRING:
            fprintf(printer,"Char_Const: %s\n",node->attr.val.s);
            break;
        case KR_CALCKIND_CID:
            fprintf(printer,"Cid: %d\n",node->id);
            break;
        case KR_CALCKIND_FID:
            fprintf(printer,"Fid: %d\n",node->id);
            break;
        case KR_CALCKIND_SID:
            fprintf(printer,"Sid: %d\n",node->id);
            break;
        case KR_CALCKIND_DID:
            fprintf(printer,"Did: %d\n",node->id);
            break;    
        case KR_CALCKIND_HID:
            fprintf(printer,"Hid: %d\n",node->id);
            break;    
        case KR_CALCKIND_SET:
            fprintf(printer,"Set: %d\n",node->id);
            break;
        case KR_CALCKIND_MINT:    
        case KR_CALCKIND_MFLOAT:    
        case KR_CALCKIND_MSTRING:    
            fprintf(printer,"Multi: %s\n",node->attr.set->name);
            break;
        case KR_CALCKIND_REGEX:
            fprintf(printer,"Regex: %s\n",node->attr.regex->pattern);
            break;    
        default:
            fprintf(printer,"Unknown kind: %d\n",node->kind);
            return -1;
    }
    return 0;
}
Beispiel #2
0
void traverse_prefix_lisp(node_type *p, int prev_op)
{
     if (!p) return;
     switch (p->type) {
     case coef_type:
          print_coefficient(p->u.coef);
          break;
     case ratfun_type:
          /* print_ratfun(p->u.ratfun); */
          /* printf("\n"); */
          print_ratfun(p->u.ratfun);
          break;
     case op1_type:
          printf("(");
          print_operator(p->u.op1.operator);
          printf(" ");
          traverse_prefix_lisp(p->u.op1.operand, p->u.op1.operator);
          printf(")");
          break;
     case op2_type:
          /* if last operator was the same as this one, don't print it again */
          if (p->u.op2.operator == prev_op && prev_op != '^') {
               traverse_prefix_lisp(p->u.op2.operand1,
                                    p->u.op2.operator);
               printf(" ");
               traverse_prefix_lisp(p->u.op2.operand2,
                                    p->u.op2.operator);
               break;
          }
          printf("(");
          print_operator(p->u.op2.operator);
          printf(" ");
          traverse_prefix_lisp(p->u.op2.operand1, p->u.op2.operator);
          printf(" ");
          traverse_prefix_lisp(p->u.op2.operand2, p->u.op2.operator);
          printf(")");
          break;
     }
}
Beispiel #3
0
void traverse_postfix(node_type *p)
{
     if (!p) return;
     switch (p->type) {
     case coef_type:
          print_coefficient(p->u.coef);
          break;
     case ratfun_type:
          print_ratfun(p->u.ratfun);
          break;
     case op1_type:
          traverse_postfix(p->u.op1.operand);
          printf(" ");
          print_operator(p->u.op1.operator);
          break;
     case op2_type:
          traverse_postfix(p->u.op2.operand1);
          printf(" ");
          traverse_postfix(p->u.op2.operand2);
          printf(" ");
          print_operator(p->u.op2.operator);
          break;
     }
}
Beispiel #4
0
/**Function********************************************************************

  Synopsis           [The type core violation handler.]

  Description        [The violation handler is implemented as
  a virtual method, which is invoked by the checker when an expression
  being checked violates the type system.
  See the violation handler TypeCheckingViolationHandler_ptr
  for more explanations.

  The below function is the default violation handler, and a
  user can potentially define its own violation handler, by deriving
  a new class from this class and by overriding this virtual method.

  This violation handler outputs an error and warning message to
  nusmv_stderr. A warning is output if the detected violation is
  TC_VIOLATION_TYPE_BACK_COMP and the system variable
  "type_checking_backward_compatibility" is true. Also the
  TC_VIOLATION_TYPE_WARNING violation outputs a warning. Only in this
  case the false value is returned, indicating that this is NOT an
  error. Otherwise the true value is returned, indicating that this is
  an error.

  Also, if the system variable "type_check_warning_on" is false,
  warning messages are not output.

  NB: if the expression is checked in some context (context is not null) then
  before providing the expression to this function the expression should be
  wrapped into context, i.e. with find_node(CONEXT, context, expr)]

  SideEffects       []

  SeeAlso           [TypeSystemViolation]

******************************************************************************/
static boolean
checker_psl_viol_handler(CheckerBase_ptr self,
                         TypeSystemViolation violation, node_ptr expression)
{
  /* In the output message, the information about the expression
     location are output. So, make sure that the input file name and
     line number are correctly set!
  */

  boolean isError = true; /* is this error or warning */

  /* get rid of the context the expression may be wrapped in */
  PslNode_ptr context = PSL_NULL;
  PslNode_ptr expr = PslNode_convert_from_node_ptr(expression);

  if (node_get_type(expression) == CONTEXT) {
    context = PslNode_convert_from_node_ptr(car(expression));
    expr = PslNode_convert_from_node_ptr(cdr(expression));
  }

  /* checks the given violation */
  nusmv_assert(TypeSystemViolation_is_valid(violation));

  /* only violation TC_VIOLATION_TYPE_BACK_COMP and the variable
     type_checking_backward_compatibility being true, may make a
     warning from an error.
     TC_VIOLATION_TYPE_WARNING always forces a warning
  */
  if (  TC_VIOLATION_TYPE_WARNING == violation
     || ( TC_VIOLATION_TYPE_BACK_COMP == violation
         && opt_backward_comp(OptsHandler_get_instance()))) {
    isError = false;
  }

  if (!isError && !opt_type_checking_warning_on(OptsHandler_get_instance())) {
    /* this is a warning and warning messages are not allowed.
     So, do nothing, just return false (this is not an error)
    */
    return false;
  }

  _PRINT_ERROR_MSG(expr, isError);

  switch (violation) {
  case TC_VIOLATION_AMBIGUOUS_IDENTIFIER:
    fprintf(nusmv_stderr,  "identifier '");
    print_node(nusmv_stderr, PslNode_convert_to_node_ptr(expr));
    fprintf(nusmv_stderr, "' is ambiguous\n");
    break;

  case TC_VIOLATION_UNCONSTANT_EXPRESSION:
    fprintf(nusmv_stderr, "Expected constant expression in '");
    print_node(nusmv_stderr, PslNode_convert_to_node_ptr(expr));
    fprintf(nusmv_stderr, "'\n");
    break;

  case TC_VIOLATION_TYPE_MANDATORY:
  case TC_VIOLATION_TYPE_BACK_COMP:
  case TC_VIOLATION_TYPE_WARNING:
    if (isError) fprintf(nusmv_stderr, "illegal ");
    else         fprintf(nusmv_stderr, "potentially incorrect ");

    switch (psl_node_get_op(expr)) {

    case PSL_SERE:
    case PSL_SERECOMPOUND:
      fprintf(nusmv_stderr, "sere type of {");
      print_node(stderr, PslNode_convert_to_node_ptr(psl_node_get_left(expr)));
      fprintf(nusmv_stderr, "} : ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_left(expr)),
                      PslNode_convert_to_node_ptr(context));
      break;

    case PSL_SERECONCAT:
      fprintf(nusmv_stderr, "operand types of sere concatenation: ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_left(expr)),
                      PslNode_convert_to_node_ptr(context));
      fprintf(nusmv_stderr, " ");
      print_operator(nusmv_stderr, expr);
      fprintf(nusmv_stderr, " ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_right(expr)),
                      PslNode_convert_to_node_ptr(context));
      break;

    case PSL_SEREFUSION:
      fprintf(nusmv_stderr, "operand types of sere fusion: ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_left(expr)),
                      PslNode_convert_to_node_ptr(context));
      fprintf(nusmv_stderr, " ");
      print_operator(nusmv_stderr, expr);
      fprintf(nusmv_stderr, " ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_right(expr)),
                      PslNode_convert_to_node_ptr(context));
      break;


    case PSL_SEREREPEATED:
      {
        PslNode_ptr sere = psl_node_sere_repeated_get_expr(expr);
        PslNode_ptr count = psl_node_sere_repeated_get_count(expr);

        fprintf(nusmv_stderr, "operand types of sere repeated: ");
        if (sere != PSL_NULL) {
          checker_base_print_type(self, nusmv_stderr,
                                  PslNode_convert_to_node_ptr(sere),
                                  PslNode_convert_to_node_ptr(context));
        }
        print_operator(nusmv_stderr, psl_node_get_left(expr));
        fprintf(nusmv_stderr, " ");

        if (count != PSL_NULL) {
          checker_base_print_type(self, nusmv_stderr,
                                  PslNode_convert_to_node_ptr(count),
                                  PslNode_convert_to_node_ptr(context));
        }
        fprintf(nusmv_stderr, " ]");
        break;
      }

    case PSL_REPLPROP:
      {
        PslNode_ptr prop = psl_node_repl_prop_get_property(expr);

        fprintf(nusmv_stderr, "operand type of ");
        print_operator(nusmv_stderr, expr);
        fprintf(nusmv_stderr, " property: ");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(prop),
                                PslNode_convert_to_node_ptr(context));
        break;
      }

      /* suffix implication */
    case PSL_PIPEMINUSGT:
    case PSL_PIPEEQGT:
      {
        PslNode_ptr pre = psl_node_suffix_implication_get_premise(expr);
        PslNode_ptr con = psl_node_suffix_implication_get_consequence(expr);

        fprintf(nusmv_stderr, "operand types of suffix implication: ");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(pre),
                                PslNode_convert_to_node_ptr(context));

        fprintf(nusmv_stderr, " ");
        print_operator(nusmv_stderr, expr);
        fprintf(nusmv_stderr, " ");

        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(con),
                                PslNode_convert_to_node_ptr(context));
        break;
      }

      /* unary operators: */
    case PSL_ALWAYS:
    case PSL_NEVER:
    case PSL_EVENTUALLYBANG:
        fprintf(nusmv_stderr, "operand types of \"");
        print_operator(nusmv_stderr, expr);
        fprintf(nusmv_stderr, "\" : ");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(psl_node_get_left(expr)),
                                PslNode_convert_to_node_ptr(context));
        break;

      /* within operators */
    case PSL_WITHINBANG:
    case PSL_WITHIN:
    case PSL_WITHINBANG_:
    case PSL_WITHIN_:
      {
        PslNode_ptr n1 = psl_node_get_left(psl_node_get_left(expr));
        PslNode_ptr n2 = psl_node_get_right(psl_node_get_left(expr));
        PslNode_ptr n3 = psl_node_get_right(expr);

        fprintf(nusmv_stderr, "operand types of \"");
        print_operator(nusmv_stderr, expr);
        fprintf(nusmv_stderr, "\" : (");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(n1),
                                PslNode_convert_to_node_ptr(context));
        fprintf(nusmv_stderr, ", ");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(n2),
                                PslNode_convert_to_node_ptr(context));
        fprintf(nusmv_stderr, ") ");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(n3),
                                PslNode_convert_to_node_ptr(context));
        break;
      }

      /* next operators */
    case PSL_NEXT_EVENT_ABANG:
    case PSL_NEXT_EVENT_A:
    case PSL_NEXT_EVENT_EBANG:
    case PSL_NEXT_EVENT_E:
    case PSL_NEXT_EVENTBANG:
    case PSL_NEXT_EVENT:
    case PSL_NEXT_ABANG:
    case PSL_NEXT_EBANG:
    case PSL_NEXT_A:
    case PSL_NEXT_E:
    case PSL_NEXTBANG:
    case PSL_NEXT:
    case PSL_X:
    case PSL_XBANG:
      {
        PslNode_ptr n1 = psl_node_extended_next_get_expr(expr);
        PslNode_ptr n2 = psl_node_extended_next_get_when(expr);
        PslNode_ptr n3 = psl_node_extended_next_get_condition(expr);

        fprintf(nusmv_stderr, "operand types of \"");
        print_operator(nusmv_stderr, expr);
        fprintf(nusmv_stderr, "\" : ");

        if (n3 != PSL_NULL) {
          fprintf(nusmv_stderr, " (");
          checker_base_print_type(self, nusmv_stderr,
                                  PslNode_convert_to_node_ptr(n3),
                                  PslNode_convert_to_node_ptr(context));
          fprintf(nusmv_stderr, ")");
        }

        if (n2 != PSL_NULL) {
          fprintf(nusmv_stderr, " [");
          checker_base_print_type(self, nusmv_stderr,
                                  PslNode_convert_to_node_ptr(n2),
                                  PslNode_convert_to_node_ptr(context));
          fprintf(nusmv_stderr, "]");
        }

        nusmv_assert(n1 != PSL_NULL); /* n1 must occur here */
        fprintf(nusmv_stderr, " (");
        checker_base_print_type(self, nusmv_stderr,
                                PslNode_convert_to_node_ptr(n1),
                                PslNode_convert_to_node_ptr(context));
        fprintf(nusmv_stderr, ")");
        break;
      }

      /* Binary operators */
    case PSL_BEFOREBANG:
    case PSL_BEFORE:
    case PSL_BEFOREBANG_:
    case PSL_BEFORE_:
    case PSL_UNTILBANG:
    case PSL_UNTIL:
    case PSL_UNTILBANG_:
    case PSL_UNTIL_:
    case PSL_ABORT:
    case PSL_W:
    case PSL_OR:
    case PSL_CARET:
    case PSL_TILDE:
    case PSL_EQEQ:
    case PSL_PIPEPIPE:
    case PSL_AMPERSANDAMPERSAND:
    case PSL_WHILENOTBANG:
    case PSL_WHILENOT:
    case PSL_WHILENOTBANG_:
    case PSL_WHILENOT_:
      fprintf(nusmv_stderr, "operand types of \"");
      print_operator(nusmv_stderr, expr);
      fprintf(nusmv_stderr,"\" : ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_left(expr)),
                      PslNode_convert_to_node_ptr(context));
      fprintf(nusmv_stderr," and ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_right(expr)),
                      PslNode_convert_to_node_ptr(context));
      break;

    case PSL_ITE:
      fprintf(nusmv_stderr, "operand types of \"");
      print_operator(nusmv_stderr, expr);
      fprintf(nusmv_stderr,"\" : ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_ite_cond(expr)),
                      PslNode_convert_to_node_ptr(context));
      fprintf(nusmv_stderr," ? ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_ite_then(expr)),
                      PslNode_convert_to_node_ptr(context));
      fprintf(nusmv_stderr," : ");
      checker_base_print_type(self, nusmv_stderr,
                      PslNode_convert_to_node_ptr(psl_node_get_ite_else(expr)),
                      PslNode_convert_to_node_ptr(context));
      break;


    default: /* unknown kind of an expression */
      error_unreachable_code();
    } /* switch (node_get_type(expr)) */

    fprintf(nusmv_stderr,"\n");
    break;

  default:
    error_unreachable_code(); /* unknown kind of error */

  } /* switch (errorKind) */

  return isError;
}
Beispiel #5
0
void traverse_infix(node_type *p)
{
     if (!p) return;
     switch (p->type) {
     case coef_type:
          print_coefficient(p->u.coef);
          break;
     case ratfun_type:
          print_ratfun(p->u.ratfun);
          break;
     case op1_type:
          /* deal with unary minus */
          if (p->u.op1.operator == UMINUS) {
               printf("-");
               if ((p->u.op1.operand->type == op2_type)
                   && (higher_priority(p->u.op1.operator,
                                       p->u.op1.operand->u.op2.operator)
                       ==1)) {
                    printf("(");
                    traverse_infix(p->u.op1.operand);
                    printf(")");
               }
               else {
                    traverse_infix(p->u.op1.operand);
               }
          }
          else {
               print_operator(p->u.op1.operator);
               printf("(");
               traverse_infix(p->u.op1.operand);
               printf(")");
          }
          break;
     case op2_type:
          /* if one of the operands is an operator of lower priority
           * than this operator, it must go in brackets */
          if ((p->u.op2.operand1->type == op2_type)
              && (higher_priority(p->u.op2.operator,
                                  p->u.op2.operand1->u.op2.operator)
                  == 1)) {
               printf("(");
               traverse_infix(p->u.op2.operand1);
               printf(")");
          }
          else if ((p->u.op2.operand1->type == op1_type)
                   && (higher_priority(p->u.op2.operator,
                                       p->u.op2.operand1->u.op1.operator)
                       == 1)) {
               printf("(");
               traverse_infix(p->u.op2.operand1);
               printf(")");
          }
          else {
               traverse_infix(p->u.op2.operand1);
          }

          /* printf(" "); */
          print_operator(p->u.op2.operator);
          /* printf(" "); */

          if ((p->u.op2.operand2->type == op2_type)
              && (higher_priority(p->u.op2.operator,
                                  p->u.op2.operand2->u.op2.operator)
                  == 1)) {
               printf("(");
               traverse_infix(p->u.op2.operand2);
               printf(")");
          }
          /* same priority but different operator, must have had brackets */
          else if ((p->u.op2.operand2->type == op2_type)
                   && (higher_priority(p->u.op2.operator,
                                       p->u.op2.operand2->u.op2.operator)
                       == 0)
                   && p->u.op2.operator != p->u.op2.operand2->u.op2.operator) {
               printf("(");
               traverse_infix(p->u.op2.operand2);
               printf(")");
          }
          else if ((p->u.op2.operand2->type == op1_type)
                   && (higher_priority(p->u.op2.operator,
                                       p->u.op2.operand2->u.op1.operator)
                       == 1)) {
               printf("(");
               traverse_infix(p->u.op2.operand2);
               printf(")");
          }
          else if ((p->u.op2.operand2->type == op1_type)
                   && (higher_priority(p->u.op2.operator,
                                       p->u.op2.operand2->u.op1.operator)
                       == 0)
                   && p->u.op2.operator != p->u.op2.operand2->u.op1.operator) {
               printf("(");
               traverse_infix(p->u.op2.operand2);
               printf(")");
          }
          else {
               traverse_infix(p->u.op2.operand2);
          }

          break;
     }
}
Beispiel #6
0
struct i_primary *shred_expression(void)
{
void **input_stream;
void **shredlocal;
struct i_primary *p1, *p2;
struct i_oper    *o1, *o2;
int prec1, prec2;
struct i_primary *prdest;

DEBUG("Parsing Expression\n");
input_stream=exp_pnt;
shredlocal=shred_pnt;

p1=*(++shredlocal)=*(++input_stream);	/* 1st primary */

shred_main:
o1=*(++shredlocal)=*(++input_stream);	/* 1st op      */
p2=*(++shredlocal)=*(++input_stream);	/* 2nd op      */

shredder:
DEBUG("----------\n");

#ifdef DEBUG_SHRED
print_primary(p1);
print_operator(o1);
#endif

if(o1->token==V_EOF)
	{
	DEBUG("End of expression encountered\n\n");
	return(p1);
	}

o2=*(input_stream+1);

#ifdef DEBUG_SHRED
print_primary(p2);
print_operator(o2);
#endif

prec1=o1->prec; prec2=o2->prec;
DEBUG("O1 prec: %d\n",prec1);
DEBUG("O2 prec: %d\n",prec2);

if(prec2>prec1)
	{
	DEBUG("Shift\n");

	*(++shredlocal)=o2;
	input_stream++;
	p1=p2;
	o1=o2;	
	p2=*(++shredlocal)=*(++input_stream);	/* 2nd op      */
	goto shredder;
	}
	else
	{
	DEBUG("Reduce\n");

	prdest=i_bin_expr_make(p1,o1,p2);

	shredlocal-=2;

	p1=*(shredlocal)=prdest;
	if(shredlocal==shred_pnt+1)
		{
		goto shred_main;		
		}
		else	
		{
		p2=p1;
		p1=*(shredlocal-2);
		o1=*(shredlocal-1);
		goto shredder;
		}
	}
}