Example #1
0
void goto_checkt::invalidate(const exprt &lhs)
{
  if(lhs.id()==ID_index)
    invalidate(to_index_expr(lhs).array());
  else if(lhs.id()==ID_member)
    invalidate(to_member_expr(lhs).struct_op());
  else if(lhs.id()==ID_symbol)
  {
    // clear all assertions about 'symbol'
    find_symbols_sett find_symbols_set;
    find_symbols_set.insert(to_symbol_expr(lhs).get_identifier());

    for(assertionst::iterator
        it=assertions.begin();
        it!=assertions.end();
        ) // no it++
    {
      assertionst::iterator next=it;
      next++;

      if(has_symbol(*it, find_symbols_set) ||
         has_dereference(*it))
        assertions.erase(it);

      it=next;
    }
  }
  else
  {
    // give up, clear all
    assertions.clear();
  }
}
/**
 * May or may not add a symbol, if line contains one.
 * Potentially catches a multiply defined symbol, returns the
 * integer of how much the location counter needs to increment.
 **/
int maybe_add_symbol(char *line, unsigned int lc, unsigned int ds, unsigned int ts, short second_pass) {
  char *label, *val;
  char *dupline = strdup(line);

  label = strtok(dupline, " \t");

  if (label[strlen(label)-1] != ':')
    return 1;

  label[strlen(label)-1] = '\0'; // remove colon

  if (has_symbol(label) && second_pass == 0) {
    add_error(ln, 'M', label);
    // multiply defined symbol
  } else if (label != NULL && !has_symbol(label)) {
    if (num_symbols >= MIN_SYMTABLE_LENGTH) {
      symbol_table = realloc(symbol_table, (num_symbols * REALLOC_MULTIPLIER) * sizeof(symbol *));
    }

    symbol_table[num_symbols] = malloc(sizeof(symbol));
    symbol_table[num_symbols]->name = strdup(label);
    symbol_table[num_symbols]->lc = lc;

    num_symbols++;
  }

  if (ds) {
    // data segment needs additional parsing
    val = strtok(NULL, " \t\n");
    if (strcmp(val, WORD_DIRECTIVE) == 0) {
      val = strtok(NULL, " \t\n");

      val = strtok(val, ":");
      val = strtok(NULL, ":");

      return atoi(val);
    } else if (strcmp(val, RESW_DIRECTIVE) == 0) {
      val = strtok(NULL, " \t\n");

      return atoi(val);
    }
  }

  return 1;
}
Example #3
0
 static RCP<const Basic> diff(const FunctionSymbol &self,
         const RCP<const Symbol> &x) {
     RCP<const Basic> diff = zero, t;
     RCP<const Basic> self_ = self.rcp_from_this();
     RCP<const Symbol> s;
     std::string name;
     unsigned count  = 0;
     bool found_x = false;
     for (const auto &a : self.get_args()) {
         if (eq(*a, *x)) {
             found_x = true;
             count++;
         } else if (count < 2 and neq(*a->diff(x), *zero)) {
             count++;
         }
     }
     if (count == 1 and found_x) {
         return Derivative::create(self_, {x});
     }
     for (unsigned i = 0; i < self.get_args().size(); i++) {
         t = self.get_args()[i]->diff(x);
         if (neq(*t, *zero)) {
             name = "x";
             do {
                 name = "_" + name;
                 s = symbol(name);
             } while (has_symbol(*self_, s));
             vec_basic v = self.get_args();
             v[i] = s;
             map_basic_basic m;
             insert(m, v[i], self.get_args()[i]);
             diff = add(diff, mul(t,
                 make_rcp<const Subs>(Derivative::create(self.create(v),
                         {v[i]}), m)));
         }
     }
     return diff;
 }