Пример #1
0
    void DisassemblerContext::setup_term(const ValuePtr<>& term) {
      if (!m_visited_terms.insert(term).second)
        return;

      setup_term_name(term);
      
      switch (term->term_type()) {
      case term_apply: {
        ValuePtr<ApplyType> apply = value_cast<ApplyType>(term);
        setup_term(apply->recursive());
        for (std::vector<ValuePtr<> >::const_iterator ii = apply->parameters().begin(), ie = apply->parameters().end(); ii != ie; ++ii)
          setup_term(*ii);
        break;
      }
      
      case term_exists: {
        ValuePtr<Exists> exists = value_cast<Exists>(term);
        setup_term(exists->result());
        break;
      }
        
      case term_parameter_placeholder:
      case term_recursive_parameter: {
        setup_term(term->type());
        break;
      }
        
      case term_functional: {
        class MyVisitor : public FunctionalValueVisitor {
          DisassemblerContext *m_self;
        public:
          MyVisitor(DisassemblerContext *self) : m_self(self) {}
          virtual void next(const ValuePtr<>& v) {if (v) m_self->setup_term(v);}
        };
        
        MyVisitor my_visitor(this);
        value_cast<FunctionalValue>(term)->functional_visit(my_visitor);
        break;
      }
        
      case term_function_type: {
        ValuePtr<FunctionType> cast_term = value_cast<FunctionType>(term);
        const std::vector<ParameterType>& parameter_types = cast_term->parameter_types();
        for (std::vector<ParameterType>::const_iterator ii = parameter_types.begin(), ie = parameter_types.end(); ii != ie; ++ii)
          setup_term(ii->value);
        setup_term(cast_term->result_type().value);
        break;
      }
      
      default:
        return; // Skip adding to definition list
      }
      
      if (TermDefinitionList *dl = term_definition_list(term))
        dl->push_back(term);
    }
Пример #2
0
 void DisassemblerContext::print_apply_term(const ValuePtr<ApplyType>& apply, bool bracket) {
   if (bracket)
     *m_output << '(';
   
   *m_output << "apply ";
   print_term(apply->recursive(), true);
   for (std::vector<ValuePtr<> >::const_iterator ii = apply->parameters().begin(), ie = apply->parameters().end(); ii != ie; ++ii) {
     *m_output << ' ';
     print_term(*ii, true);
   }
     
   if (bracket)
     *m_output << ')';
 }