Esempio n. 1
0
File: ast.cpp Progetto: o-/rift
 void visit(ast::TypeCall * node) override {
     s << "type";
     visit(static_cast<ast::SpecialCall*>(node));
 }
Esempio n. 2
0
void
Visitor::visit(Type* t) {
  switch (t->kind) {
  case typename_type: return visit(as<Typename_type>(t));
  case unit_type: return visit(as<Unit_type>(t));
  case bool_type: return visit(as<Bool_type>(t));
  case nat_type: return visit(as<Nat_type>(t));
  case int_type: return visit(as<Int_type>(t));
  case char_type: return visit(as<Char_type>(t));
  case fn_type: return visit(as<Fn_type>(t));
  case range_type: return visit(as<Range_type>(t));
  case bitfield_type: return visit(as<Bitfield_type>(t));
  case record_type: return visit(as<Record_type>(t));
  case variant_type: return visit(as<Variant_type>(t));
  case dep_variant_type: return visit(as<Dep_variant_type>(t));
  case enum_type: return visit(as<Enum_type>(t));
  case array_type: return visit(as<Array_type>(t));
  case dep_type: return visit(as<Dep_type>(t));
  case module_type: return visit(as<Module>(t));
  case net_str_type: return visit(as<Net_str_type>(t));
  case net_seq_type: return visit(as<Net_seq_type>(t));
  default: return no_such_visitor(t);
  }
}
Esempio n. 3
0
void
Visitor::visit(Stmt* s) {
  if (Decl* d = as<Decl>(s))
    return visit(d);
  return no_such_visitor(s);
}
Esempio n. 4
0
void Label::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    if (! _visible || (_utf8Text.empty() && _children.empty()) )
    {
        return;
    }
    
    if (_systemFontDirty || _contentDirty)
    {
        updateContent();
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    if (!_utf8Text.empty() && _shadowEnabled && (_shadowDirty || (flags & FLAGS_DIRTY_MASK)))
    {
        _position.x += _shadowOffset.width;
        _position.y += _shadowOffset.height;
        _transformDirty = _inverseDirty = true;

        _shadowTransform = transform(parentTransform);

        _position.x -= _shadowOffset.width;
        _position.y -= _shadowOffset.height;
        _transformDirty = _inverseDirty = true;

        _shadowDirty = false;
    }

    bool visibleByCamera = isVisitableByVisitingCamera();
    if (_children.empty() && !_textSprite && !visibleByCamera)
    {
        return;
    }

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    _director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    _director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    if (!_children.empty())
    {
        sortAllChildren();

        int i = 0;
        // draw children zOrder < 0
        for (; i < _children.size(); i++)
        {
            auto node = _children.at(i);

            if (node && node->getLocalZOrder() < 0)
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        
        this->drawSelf(visibleByCamera, renderer, flags);

        for (auto it = _children.cbegin() + i; it != _children.cend(); ++it)
        {
            (*it)->visit(renderer, _modelViewTransform, flags);
        }
            
    }
    else
    {
        this->drawSelf(visibleByCamera, renderer, flags);
    }

    _director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
Esempio n. 5
0
void
List_extractor::operator()(Expr* e) { visit(e); }
Esempio n. 6
0
void LatexDocVisitor::visitPre(DocParamList *pl)
{
  if (m_hide) return;
  DocParamSect::Type parentType = DocParamSect::Unknown;
  DocParamSect *sect = 0;
  if (pl->parent() && pl->parent()->kind()==DocNode::Kind_ParamSect)
  {
    parentType = ((DocParamSect*)pl->parent())->type();
    sect=(DocParamSect*)pl->parent();
  }
  bool useTable = parentType==DocParamSect::Param ||
                  parentType==DocParamSect::RetVal ||
                  parentType==DocParamSect::Exception ||
                  parentType==DocParamSect::TemplateParam;
  if (!useTable)
  {
    m_t << "\\item[";
  }
  if (sect && sect->hasInOutSpecifier())
  {
    if (pl->direction()!=DocParamSect::Unspecified)
    {
      m_t << "\\mbox{\\tt ";
      if (pl->direction()==DocParamSect::In)
      {
        m_t << "in";
      }
      else if (pl->direction()==DocParamSect::Out)
      {
        m_t << "out";
      }
      else if (pl->direction()==DocParamSect::InOut)
      {
        m_t << "in,out";
      }
      m_t << "} ";
    }
    if (useTable) m_t << " & ";
  }
  if (sect && sect->hasTypeSpecifier())
  {
    QListIterator<DocNode> li(pl->paramTypes());
    DocNode *type;
    bool first=TRUE;
    for (li.toFirst();(type=li.current());++li)
    {
      if (!first) m_t << " | "; else first=FALSE;
      if (type->kind()==DocNode::Kind_Word)
      {
        visit((DocWord*)type); 
      }
      else if (type->kind()==DocNode::Kind_LinkedWord)
      {
        visit((DocLinkedWord*)type); 
      }
    }
    if (useTable) m_t << " & ";
  }
  m_t << "{\\em ";
  //QStrListIterator li(pl->parameters());
  //const char *s;
  QListIterator<DocNode> li(pl->parameters());
  DocNode *param;
  bool first=TRUE;
  for (li.toFirst();(param=li.current());++li)
  {
    if (!first) m_t << ","; else first=FALSE;
    m_insideItem=TRUE;
    if (param->kind()==DocNode::Kind_Word)
    {
      visit((DocWord*)param); 
    }
    else if (param->kind()==DocNode::Kind_LinkedWord)
    {
      visit((DocLinkedWord*)param); 
    }
    m_insideItem=FALSE;
  }
  m_t << "}";
  if (useTable)
  {
    m_t << " & ";
  }
  else
  {
    m_t << "]";
  }
}
Esempio n. 7
0
 void visit(TypeAArray *t)
 {
     t->index->accept(this);
     visit((TypeNext *)t);
 }
Esempio n. 8
0
expr replace_visitor::visit_app(expr const & e) {
    lean_assert(is_app(e));
    return update_app(e, visit(app_fn(e)), visit(app_arg(e)));
}
Esempio n. 9
0
expr replace_visitor::visit_binding(expr const & e) {
    lean_assert(is_binding(e));
    expr new_d = visit(binding_domain(e));
    expr new_b = visit(binding_body(e));
    return update_binding(e, new_d, new_b);
}
Esempio n. 10
0
void link_traverse(void (*visit)(link_t))
{
    link_t p;
    for(p = head->next; p!= tail; p = p->next)
        visit(p);
}
Esempio n. 11
0
expr replace_visitor::visit_mlocal(expr const & e) {
    lean_assert(is_mlocal(e));
    return update_mlocal(e, visit(mlocal_type(e)));
}
Esempio n. 12
0
File: ast.cpp Progetto: o-/rift
 void visit(ast::SpecialCall * node) override {
     visit(static_cast<ast::Call*>(node));
 }
Esempio n. 13
0
File: ast.cpp Progetto: o-/rift
 void visit(ast::UserCall * node) override {
     node->name->accept(this);
     visit(static_cast<ast::Call*>(node));
 }
Esempio n. 14
0
File: ast.cpp Progetto: o-/rift
 void visit(ast::LengthCall * node) override {
     s << "length";
     visit(static_cast<ast::SpecialCall*>(node));
 }
Esempio n. 15
0
static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit,
                        void *closure) {
  const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r;
  visit(r, m->group, closure);
}
void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    if (!_visible || !hasContent())
        return;
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);

    //Add group command
        
    _groupCommand.init(_globalZOrder);
    renderer->addCommand(&_groupCommand);

    renderer->pushGroup(_groupCommand.getRenderQueueID());

    _beforeVisitCmd.init(_globalZOrder);
    _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
    renderer->addCommand(&_beforeVisitCmd);
    if (_alphaThreshold < 1)
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#else
        // since glAlphaTest do not exists in OES, use a shader that writes
        // pixel only if greater than an alpha threshold
        GLProgram *program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
        GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
        // set our alphaThreshold
        program->use();
        program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
        // we need to recursively apply this shader to all the nodes in the stencil node
        // FIXME: we should have a way to apply shader to all nodes without having to do this
        setProgram(_stencil, program);
        
#endif

    }
    _stencil->visit(renderer, _modelViewTransform, flags);

    _afterDrawStencilCmd.init(_globalZOrder);
    _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
    renderer->addCommand(&_afterDrawStencilCmd);

    int i = 0;
    bool visibleByCamera = isVisitableByVisitingCamera();
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for(auto size = _children.size(); i < size; i++)
        {
            auto node = _children.at(i);
            
            if ( node && node->getLocalZOrder() < 0 )
                node->visit(renderer, _modelViewTransform, flags);
            else
                break;
        }
        // self draw
        if (visibleByCamera)
            this->draw(renderer, _modelViewTransform, flags);
        
        for(auto it=_children.cbegin()+i, itCend = _children.cend(); it != itCend; ++it)
            (*it)->visit(renderer, _modelViewTransform, flags);
    }
    else if (visibleByCamera)
    {
        this->draw(renderer, _modelViewTransform, flags);
    }

    _afterVisitCmd.init(_globalZOrder);
    _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
    renderer->addCommand(&_afterVisitCmd);

    renderer->popGroup();
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
Esempio n. 17
0
std::string Value::getDescription()
{
    std::string ret("\n");
    ret += visit(*this, 0);
    return ret;
}
Esempio n. 18
0
void Scale9Sprite::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    
    uint32_t flags = processParentFlags(parentTransform, parentFlags);
    
    // IMPORTANT:
    // To ease the migration to v3.0, we still support the Mat4 stack,
    // but it is deprecated and your code should not rely on it
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
    
    int i = 0;      // used by _children
    int j = 0;      // used by _protectedChildren
    
    sortAllChildren();
    sortAllProtectedChildren();
    
    //
    // draw children and protectedChildren zOrder < 0
    //
    for( ; i < _children.size(); i++ )
    {
        auto node = _children.at(i);
        
        if ( node && node->getLocalZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, flags);
        else
            break;
    }
    
//    if (_scale9Enabled)
//    {
//        for( ; j < _protectedChildren.size(); j++ )
//        {
//            auto node = _protectedChildren.at(j);
//            
//            if ( node && node->getLocalZOrder() < 0 )
//                node->visit(renderer, _modelViewTransform, flags);
//            else
//                break;
//        }
//    }
//    else
//    {
//        if (_scale9Image && _scale9Image->getLocalZOrder() < 0 )
//        {
//            _scale9Image->visit(renderer, _modelViewTransform, flags);
//        }
//    }
    
    //
    // draw self
    //
//    if (isVisitableByVisitingCamera())
//        this->draw(renderer, _modelViewTransform, flags);
    
    //
    // draw children and protectedChildren zOrder >= 0
    //
//    if (_scale9Enabled)
//    {
//        for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
//            (*it)->visit(renderer, _modelViewTransform, flags);
//    }
//    else
//    {
//        if (_scale9Image && _scale9Image->getLocalZOrder() >= 0 )
//        {
//            _scale9Image->visit(renderer, _modelViewTransform, flags);
//        }
//    }
    
    
    for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, flags);
    
    // FIX ME: Why need to set _orderOfArrival to 0??
    // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920
    // setOrderOfArrival(0);
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    
}
int main(int argc, char *argv[]){

  element_type test_array[20];
  int i;
  BTREE T = init_tree();
  TREE_NODE p;
  int height;
 
  
  for(i=0; i<20; i++){
    test_array[i]= random(200);
    printf("%d, ", test_array[i]);
  }
  printf("\n");
  T =  creat_tree(test_array, sizeof(test_array)/sizeof(test_array[0]), T);
  height = height_recursive(T);
  printf("height is %d\n", height);

  printf("preorder:\n");
  preorder_recursive(T); 
  printf("\n");

  printf("inoder:\n");
  inorder_recursive(T);
  printf("\n");

  printf("postorder:\n");
  postorder_recursive(T);
  printf("\n");

  printf("preorder nonrec:\n");
  preorder_norecursive(T);
  printf("\n");

  printf("inorder nonrec:\n");
  inorder_norecursive(T);
  printf("\n");

  printf("postorder nonrec:\n");
  postorder_norcursive(T);
  printf("\n");
 
  printf("levelorder:\n");
  levelorder(T);
  printf("\n");

  printf("print leaf recursive:\n");
  output_leaf_recursive(T);
  printf("\n"); 

  printf("print leaf norecursive\n");
  output_leaf_norecursive(T);
  printf("\n");

  printf("find an element\n");
  if(find_tree(177, T) == NULL)
    printf("no such element\n");
  else
    preorder_recursive(find_tree(177, T));
  printf("\n");

  printf("min node\n");
  visit(find_min(T)->element);
  printf("\n");
  
  printf("max node\n");
  visit(find_max(T)->element);
  printf("\n");

  printf("delet:\n");
  tree_delete(115, T);
  preorder_recursive(T);
  printf("\n");
  
  printf("exchange tree:\n");
  exchange_recursive(T);
  preorder_recursive(T);
  printf("\n");

  printf("exchange tree norecursive:\n");
  exchange_norecursive(T);
  preorder_recursive(T);
  printf("\n");


  free_tree(T);
 
  return 0;
}
Esempio n. 20
0
void RTFDocVisitor::visitPre(DocParamList *pl)
{
  static int columnPos[4][5] = 
  { { 2, 25, 100, 100, 100 }, // no inout, no type
    { 3, 14,  35, 100, 100 }, // inout, no type
    { 3, 25,  50, 100, 100 }, // no inout, type
    { 4, 14,  35, 55,  100 }, // inout, type
  };
  int config=0;
  if (m_hide) return;
  DBG_RTF("{\\comment RTFDocVisitor::visitPre(DocParamList)}\n");

  DocParamSect::Type parentType = DocParamSect::Unknown;
  DocParamSect *sect = 0;
  if (pl->parent() && pl->parent()->kind()==DocNode::Kind_ParamSect)
  {
    parentType = ((DocParamSect*)pl->parent())->type();
    sect=(DocParamSect*)pl->parent();
  }
  bool useTable = parentType==DocParamSect::Param ||
                  parentType==DocParamSect::RetVal ||
                  parentType==DocParamSect::Exception ||
                  parentType==DocParamSect::TemplateParam;
  if (sect && sect->hasInOutSpecifier()) config+=1;
  if (sect && sect->hasTypeSpecifier())  config+=2;
  if (useTable)
  {
    int i;
    m_t << "\\trowd \\trgaph108\\trleft426\\tblind426"
         "\\trbrdrt\\brdrs\\brdrw10\\brdrcf15 "
         "\\trbrdrl\\brdrs\\brdrw10\\brdrcf15 "
         "\\trbrdrb\\brdrs\\brdrw10\\brdrcf15 "
         "\\trbrdrr\\brdrs\\brdrw10\\brdrcf15 "
         "\\trbrdrh\\brdrs\\brdrw10\\brdrcf15 "
         "\\trbrdrv\\brdrs\\brdrw10\\brdrcf15 "<< endl;
    for (i=0;i<columnPos[config][0];i++)
    {
      m_t << "\\clvertalt\\clbrdrt\\brdrs\\brdrw10\\brdrcf15 "
           "\\clbrdrl\\brdrs\\brdrw10\\brdrcf15 "
           "\\clbrdrb\\brdrs\\brdrw10\\brdrcf15 "
           "\\clbrdrr \\brdrs\\brdrw10\\brdrcf15 "
           "\\cltxlrtb "
           "\\cellx" << (rtf_pageWidth*columnPos[config][i+1]/100) << endl;
    }
    m_t << "\\pard \\widctlpar\\intbl\\adjustright" << endl;
  }

  if (sect && sect->hasInOutSpecifier())
  {
    if (useTable)
    {
      m_t << "{";
    }

    // Put in the direction: in/out/in,out if specified.
    if (pl->direction()!=DocParamSect::Unspecified)
    {
      if (pl->direction()==DocParamSect::In)
      {
        m_t << "in";
      }
      else if (pl->direction()==DocParamSect::Out)
      {
        m_t << "out";
      }
      else if (pl->direction()==DocParamSect::InOut)
      {
        m_t << "in,out";
      }
    }

    if (useTable)
    {
      m_t << "\\cell }";
    }
  }

  if (sect && sect->hasTypeSpecifier())
  {
    if (useTable)
    {
      m_t << "{";
    }
    QListIterator<DocNode> li(pl->paramTypes());
    DocNode *type;
    bool first=TRUE;
    for (li.toFirst();(type=li.current());++li)
    {
      if (!first) m_t << " | "; else first=FALSE;
      if (type->kind()==DocNode::Kind_Word)
      {
        visit((DocWord*)type); 
      }
      else if (type->kind()==DocNode::Kind_LinkedWord)
      {
        visit((DocLinkedWord*)type); 
      }
    }
    if (useTable)
    {
      m_t << "\\cell }";
    }
  }
  

  if (useTable)
  {
    m_t << "{";
  }

  m_t << "{\\i ";
  //QStrListIterator li(pl->parameters());
  //const char *s;
  QListIterator<DocNode> li(pl->parameters());
  DocNode *param;
  bool first=TRUE;
  for (li.toFirst();(param=li.current());++li)
  {
    if (!first) m_t << ","; else first=FALSE;
    if (param->kind()==DocNode::Kind_Word)
    {
      visit((DocWord*)param); 
    }
    else if (param->kind()==DocNode::Kind_LinkedWord)
    {
      visit((DocLinkedWord*)param); 
    }
  }
  m_t << "} ";

  if (useTable)
  {
    m_t << "\\cell }{";
  }
  m_lastIsPara=TRUE;
}
Esempio n. 21
0
 void visit(TypeFunction *t)
 {
     visit((TypeNext *)t);
     // Currently TypeInfo_Function doesn't store parameter types.
 }
Esempio n. 22
0
 expr operator()(expr const & e) { return visit(e); }
Esempio n. 23
0
/*
 * Note that this routine must be called with the lock on the process
 * already held.  Insert a btl instance into the proc array and assign 
 * it an address.
 */
int mca_btl_tcp2_proc_insert( mca_btl_tcp2_proc_t* btl_proc, 
                             mca_btl_base_endpoint_t* btl_endpoint )
{
    struct sockaddr_storage endpoint_addr_ss;
    unsigned int perm_size;
    int rc, *a = NULL;
    size_t i, j;

#ifndef WORDS_BIGENDIAN
    /* if we are little endian and our peer is not so lucky, then we
       need to put all information sent to him in big endian (aka
       Network Byte Order) and expect all information received to
       be in NBO.  Since big endian machines always send and receive
       in NBO, we don't care so much about that case. */
    if (btl_proc->proc_ompi->proc_arch & OPAL_ARCH_ISBIGENDIAN) {
        btl_endpoint->endpoint_nbo = true;
    }
#endif

    /* insert into endpoint array */
    btl_endpoint->endpoint_proc = btl_proc;
    btl_proc->proc_endpoints[btl_proc->proc_endpoint_count++] = btl_endpoint;

    /* sanity checks */
    if( NULL == local_interfaces ) {
        if( NULL == mca_btl_tcp2_retrieve_local_interfaces() )
            return OMPI_ERR_OUT_OF_RESOURCE;
    }
    if( 0 == num_local_interfaces ) {
        return OMPI_ERR_UNREACH;
    }

    if( NULL == peer_interfaces ) {
        max_peer_interfaces = max_local_interfaces;
        peer_interfaces = (mca_btl_tcp2_interface_t**)malloc( max_peer_interfaces * sizeof(mca_btl_tcp2_interface_t*) );
    }
    num_peer_interfaces = 0;
    memset(peer_kindex_to_index, -1, sizeof(int)*MAX_KERNEL_INTERFACE_INDEX);
    memset(peer_interfaces, 0, max_peer_interfaces * sizeof(mca_btl_tcp2_interface_t*));

    /*
     * identify all kernel interfaces and the associated addresses of
     * the peer
     */

    for( i = 0; i < btl_proc->proc_addr_count; i++ ) {

        int index;

        mca_btl_tcp2_addr_t* endpoint_addr = btl_proc->proc_addrs + i;

        mca_btl_tcp2_proc_tosocks (endpoint_addr, &endpoint_addr_ss);

        index = peer_kindex_to_index[endpoint_addr->addr_ifkindex];

        if(-1 == index) {
            index = num_peer_interfaces++;
            peer_kindex_to_index[endpoint_addr->addr_ifkindex] = index;
            if( num_peer_interfaces == max_peer_interfaces ) {
                max_peer_interfaces <<= 1;
                peer_interfaces = (mca_btl_tcp2_interface_t**)realloc( peer_interfaces,
                                                                      max_peer_interfaces * sizeof(mca_btl_tcp2_interface_t*) );
                if( NULL == peer_interfaces )
                    return OMPI_ERR_OUT_OF_RESOURCE;
            }
            peer_interfaces[index] = (mca_btl_tcp2_interface_t *) malloc(sizeof(mca_btl_tcp2_interface_t));
            mca_btl_tcp2_initialise_interface(peer_interfaces[index], 
                                             endpoint_addr->addr_ifkindex, index);
        }       
        
        /*
         * in case one of the peer addresses is already in use,
         * mark the complete peer interface as 'not available'
         */
        if(endpoint_addr->addr_inuse) {
            peer_interfaces[index]->inuse = 1;
        }

        switch(endpoint_addr_ss.ss_family) {
        case AF_INET:
            peer_interfaces[index]->ipv4_address = (struct sockaddr_storage*) malloc(sizeof(endpoint_addr_ss));
            peer_interfaces[index]->ipv4_endpoint_addr = endpoint_addr;
            memcpy(peer_interfaces[index]->ipv4_address, 
                   &endpoint_addr_ss, sizeof(endpoint_addr_ss));
            break;
        case AF_INET6:
            peer_interfaces[index]->ipv6_address = (struct sockaddr_storage*) malloc(sizeof(endpoint_addr_ss));
            peer_interfaces[index]->ipv6_endpoint_addr = endpoint_addr;
            memcpy(peer_interfaces[index]->ipv6_address, 
                   &endpoint_addr_ss, sizeof(endpoint_addr_ss));
            break;
        default:
            opal_output(0, "unknown address family for tcp: %d\n",
                        endpoint_addr_ss.ss_family);
            /*
             * return OMPI_UNREACH or some error, as this is not
             * good
             */
        }
    }

    /*
     * assign weights to each possible pair of interfaces    
     */

    perm_size = num_local_interfaces;
    if(num_peer_interfaces > perm_size) {
        perm_size = num_peer_interfaces;
    }

    weights = (enum mca_btl_tcp2_connection_quality**) malloc(perm_size
                                                             * sizeof(enum mca_btl_tcp2_connection_quality*));
    
    best_addr = (mca_btl_tcp2_addr_t ***) malloc(perm_size
                                                * sizeof(mca_btl_tcp2_addr_t **));
    for(i = 0; i < perm_size; ++i) {
        weights[i] = (enum mca_btl_tcp2_connection_quality*) malloc(perm_size *
                                                                   sizeof(enum mca_btl_tcp2_connection_quality));
        memset(weights[i], 0, perm_size * sizeof(enum mca_btl_tcp2_connection_quality));

        best_addr[i] = (mca_btl_tcp2_addr_t **) malloc(perm_size *
                                                      sizeof(mca_btl_tcp2_addr_t *));
        memset(best_addr[i], 0, perm_size * sizeof(mca_btl_tcp2_addr_t *));
    }
    

    for(i=0; i<num_local_interfaces; ++i) {
        for(j=0; j<num_peer_interfaces; ++j) {

            /*  initially, assume no connection is possible */
            weights[i][j] = CQ_NO_CONNECTION;

            /* check state of ipv4 address pair */
            if(NULL != local_interfaces[i]->ipv4_address &&
               NULL != peer_interfaces[j]->ipv4_address) {

                /*  check for loopback */
                if ((opal_net_islocalhost((struct sockaddr *)local_interfaces[i]->ipv4_address)
                     && !opal_net_islocalhost((struct sockaddr *)peer_interfaces[j]->ipv4_address))
                    || (opal_net_islocalhost((struct sockaddr *)peer_interfaces[j]->ipv4_address)
                        && !opal_net_islocalhost((struct sockaddr *)local_interfaces[i]->ipv4_address))
                    || (opal_net_islocalhost((struct sockaddr *)local_interfaces[i]->ipv4_address)
                        && !opal_ifislocal(btl_proc->proc_ompi->proc_hostname))) {

                    /* No connection is possible on these interfaces */
                
                    /*  check for RFC1918 */
                } else if(opal_net_addr_isipv4public((struct sockaddr*) local_interfaces[i]->ipv4_address)
                          && opal_net_addr_isipv4public((struct sockaddr*) 
                                                        peer_interfaces[j]->ipv4_address)) {
                    if(opal_net_samenetwork((struct sockaddr*) local_interfaces[i]->ipv4_address,
                                            (struct sockaddr*) peer_interfaces[j]->ipv4_address,
                                            local_interfaces[i]->ipv4_netmask)) {
                        weights[i][j] = CQ_PUBLIC_SAME_NETWORK;
                    } else {
                        weights[i][j] = CQ_PUBLIC_DIFFERENT_NETWORK;
                    }
                    best_addr[i][j] = peer_interfaces[j]->ipv4_endpoint_addr;
                    continue;
                } else {
                    if(opal_net_samenetwork((struct sockaddr*) local_interfaces[i]->ipv4_address,
                                            (struct sockaddr*) peer_interfaces[j]->ipv4_address,
                                            local_interfaces[i]->ipv4_netmask)) {
                        weights[i][j] = CQ_PRIVATE_SAME_NETWORK;
                    } else {
                        weights[i][j] = CQ_PRIVATE_DIFFERENT_NETWORK;
                    }
                    best_addr[i][j] = peer_interfaces[j]->ipv4_endpoint_addr;
                }
            }

            /* check state of ipv6 address pair - ipv6 is always public,
             * since link-local addresses are skipped in opal_ifinit()
             */
            if(NULL != local_interfaces[i]->ipv6_address &&
               NULL != peer_interfaces[j]->ipv6_address) {

                /*  check for loopback */
                if ((opal_net_islocalhost((struct sockaddr *)local_interfaces[i]->ipv6_address)
                     && !opal_net_islocalhost((struct sockaddr *)peer_interfaces[j]->ipv6_address))
                    || (opal_net_islocalhost((struct sockaddr *)peer_interfaces[j]->ipv6_address)
                        && !opal_net_islocalhost((struct sockaddr *)local_interfaces[i]->ipv6_address))
                    || (opal_net_islocalhost((struct sockaddr *)local_interfaces[i]->ipv6_address)
                        && !opal_ifislocal(btl_proc->proc_ompi->proc_hostname))) {

                    /* No connection is possible on these interfaces */

                } else if(opal_net_samenetwork((struct sockaddr*) local_interfaces[i]->ipv6_address,
                                               (struct sockaddr*) peer_interfaces[j]->ipv6_address,
                                               local_interfaces[i]->ipv6_netmask)) {
                    weights[i][j] = CQ_PUBLIC_SAME_NETWORK;
                } else {
                    weights[i][j] = CQ_PUBLIC_DIFFERENT_NETWORK;
                }
                best_addr[i][j] = peer_interfaces[j]->ipv6_endpoint_addr;
            } 

        } /* for each peer interface */
    } /* for each local interface */

    /*
     * determine the size of the set to permute (max number of
     * interfaces
     */

    best_assignment = (unsigned int *) malloc (perm_size * sizeof(int));

    a = (int *) malloc(perm_size * sizeof(int));
    if (NULL == a) {
        return OMPI_ERR_OUT_OF_RESOURCE;
    }

    /* Can only find the best set of connections when the number of
     * interfaces is not too big.  When it gets larger, we fall back
     * to a simpler and faster (and not as optimal) algorithm. 
     * See ticket https://svn.open-mpi.org/trac/ompi/ticket/2031 
     * for more details about this issue.  */
    if (perm_size <= MAX_PERMUTATION_INTERFACES) {
        memset(a, 0, perm_size * sizeof(int));
        max_assignment_cardinality = -1;
        max_assignment_weight = -1;
        visit(0, -1, perm_size, a);

        rc = OMPI_ERR_UNREACH;
        for(i = 0; i < perm_size; ++i) {
            if(best_assignment[i] > num_peer_interfaces
               || weights[i][best_assignment[i]] == CQ_NO_CONNECTION
               || peer_interfaces[best_assignment[i]]->inuse 
               || NULL == peer_interfaces[best_assignment[i]]) {
                continue;
            } 
            peer_interfaces[best_assignment[i]]->inuse++;
            btl_endpoint->endpoint_addr = best_addr[i][best_assignment[i]];
            btl_endpoint->endpoint_addr->addr_inuse++;
            rc = OMPI_SUCCESS;
            break;
        }
    } else {
        enum mca_btl_tcp2_connection_quality max;
        int i_max = 0, j_max = 0;
        /* Find the best connection that is not in use.  Save away
         * the indices of the best location. */
        max = CQ_NO_CONNECTION;
        for(i=0; i<num_local_interfaces; ++i) {
            for(j=0; j<num_peer_interfaces; ++j) {
                if (!peer_interfaces[j]->inuse) {
                    if (weights[i][j] > max) {
                        max = weights[i][j];
                        i_max = i;
                        j_max = j;
                    }
                }
            }
        }
        /* Now see if there is a some type of connection available. */
        rc = OMPI_ERR_UNREACH;
        if (CQ_NO_CONNECTION != max) {
            peer_interfaces[j_max]->inuse++;
            btl_endpoint->endpoint_addr = best_addr[i_max][j_max];
            btl_endpoint->endpoint_addr->addr_inuse++;
            rc = OMPI_SUCCESS;
        }
    }

    for(i = 0; i < perm_size; ++i) {
        free(weights[i]);
        free(best_addr[i]);
    }

    for(i = 0; i < num_peer_interfaces; ++i) {
        if(NULL != peer_interfaces[i]->ipv4_address) {
            free(peer_interfaces[i]->ipv4_address);
        }
        if(NULL != peer_interfaces[i]->ipv6_address) {
            free(peer_interfaces[i]->ipv6_address);
        }
        free(peer_interfaces[i]);
    }
    free(peer_interfaces);
    peer_interfaces = NULL;
    max_peer_interfaces = 0;

    for(i = 0; i < num_local_interfaces; ++i) {
        if(NULL != local_interfaces[i]->ipv4_address) {
            free(local_interfaces[i]->ipv4_address);
        }
        if(NULL != local_interfaces[i]->ipv6_address) {
            free(local_interfaces[i]->ipv6_address);
        }
        free(local_interfaces[i]);
    }
    free(local_interfaces);
    local_interfaces = NULL;
    max_local_interfaces = 0;

    free(weights);
    free(best_addr);
    free(best_assignment);
    free(a);

    return rc;
}
Esempio n. 24
0
 expr visit_app(expr const & e) {
     expr new_f = visit(app_fn(e));
     expr new_v = visit(app_arg(e));
     return update_app(e, new_f, new_v);
 }
Esempio n. 25
0
void
List_extractor::visit(Module* m) {
  for (Decl* d : *m->decls())
    visit(d);
}
Esempio n. 26
0
void CtrGenerator::visit(const P_ConstraintList& list) {
	for (vector<P_NumConstraint*>::const_iterator it=list.ctrs.begin(); it!=list.ctrs.end(); it++) {
		visit(**it);
	}
}
Esempio n. 27
0
void
Visitor::visit(Term* t) {
  if (Decl* d = as<Decl>(t))
    return visit(d);
  if (Stmt* s = as<Stmt>(t))
    return visit(s);
  switch (t->kind) {
  case unit_term: return visit(as<Unit>(t));
  case bool_term: return visit(as<Bool>(t));
  case int_term: return visit(as<Int>(t));
  case default_term: return visit(as<Default>(t));
  case fn_term: return visit(as<Fn>(t));
  case call_term: return visit(as<Call>(t));
  case promo_term: return visit(as<Promo>(t));
  case pred_term: return visit(as<Pred>(t));
  case range_term: return visit(as<Range>(t));
  case variant_term: return visit(as<Variant>(t));
  case unary_term: return visit(as<Unary>(t));
  case binary_term: return visit(as<Binary>(t));
  case builtin_term: return visit(as<Builtin>(t));
  default: return no_such_visitor(t);
  }
}
Esempio n. 28
0
void XmlDocVisitor::visitPre(DocParamList *pl)
{
  if (m_hide) return;
  m_t << "<parameteritem>" << endl;
  m_t << "<parameternamelist>" << endl;
  //QStrListIterator li(pl->parameters());
  //const char *s;
  QListIterator<DocNode> li(pl->parameters());
  DocNode *param;
  for (li.toFirst();(param=li.current());++li)
  {
    if (pl->paramTypes().count()>0)
    {
      QListIterator<DocNode> li(pl->paramTypes());
      DocNode *type;
      for (li.toFirst();(type=li.current());++li)
      {
        m_t << "<parametertype>";
        if (type->kind()==DocNode::Kind_Word)
        {
          visit((DocWord*)type); 
        }
        else if (type->kind()==DocNode::Kind_LinkedWord)
        {
          visit((DocLinkedWord*)type); 
        }
        m_t << "</parametertype>" << endl;
      }
    }
    m_t << "<parametername";
    if (pl->direction()!=DocParamSect::Unspecified)
    {
      m_t << " direction=\"";
      if (pl->direction()==DocParamSect::In)
      {
        m_t << "in";
      }
      else if (pl->direction()==DocParamSect::Out)
      {
        m_t << "out";
      }
      else if (pl->direction()==DocParamSect::InOut)
      {
        m_t << "inout";
      }
      m_t << "\"";
    }
    m_t << ">";
    if (param->kind()==DocNode::Kind_Word)
    {
      visit((DocWord*)param); 
    }
    else if (param->kind()==DocNode::Kind_LinkedWord)
    {
      visit((DocLinkedWord*)param); 
    }
    m_t << "</parametername>" << endl;
  }
  m_t << "</parameternamelist>" << endl;
  m_t << "<parameterdescription>" << endl;
}
Esempio n. 29
0
void insertAsserts(IRUnit& unit) {
    // Note: it doesn't matter what order we visit the blocks for this pass.
    for (auto& block : poSortCfg(unit)) visit(unit, block);
}
Esempio n. 30
0
File: ast.cpp Progetto: o-/rift
 void visit(ast::EvalCall * node) override {
     s << "eval";
     visit(static_cast<ast::SpecialCall*>(node));
 }