void PUScriptCompiler::convertToAST(const PUConcreteNodeList &nodes,PUAbstractNodeList &aNodes)
{
    
    _current = NULL;
    _nodes = &aNodes;
    visitList(nodes);
}
Exemplo n.º 2
0
 void SignatureConvertor::visit(const qi::Signature& sig) {
   switch(sig.type()) {
     case '[':
       visitList(sig);
       break;
     case '{':
       visitMap(sig);
       break;
     case '(':
       visitTuple(sig);
       break;
     case '#':
       visitVarArgs(sig);
       break;
     default:
       visitSimple(sig);
       break;
   }
 }
void PUScriptCompiler::visit(PUConcreteNode *node)
{
    PUAbstractNode* asn = NULL;
    
    // Handle properties and objects here
    if(!node->children.empty())
    {
        // Grab the last two nodes
        PUConcreteNode* temp1 = NULL;
        PUConcreteNode* temp2 = NULL;
        PUConcreteNodeList::reverse_iterator iter = node->children.rbegin();
        if(iter != node->children.rend())
        {
            temp1 = *iter;
            iter++;
        }
        if(iter != node->children.rend())
            temp2 = *iter;
        
        
        //brance inner//
        if(temp1->type == CNT_RBRACE && temp2->type == CNT_LBRACE)
        {
           
            if(node->children.size() < 2)
            {
                return;
            }
            
            PUObjectAbstractNode *impl = new  (std::nothrow) PUObjectAbstractNode(_current);
            impl->line = node->line;
            impl->file = node->file;
            impl->abstract = false;

            list<PUConcreteNode*> temp;
//          printf("token:%s\n",node->token.c_str());
            temp.push_back(node);
            for(PUConcreteNodeList::const_iterator i = node->children.begin(); i != node->children.end(); i++)
            {
                temp.push_back(*i);
            }
            
            //add brance type//
            PUConcreteNodeList::const_iterator iter1 = temp.begin();
            impl->cls = (*iter1)->token;
          
            iter1++;

            //add brance name//
            if(iter1 != temp.end() && ((*iter1)->type == CNT_WORD))
            {
                
                impl->name = (*iter1)->token;
               
                iter1++;
            }
            
            while(iter1 != temp.end() && (*iter1)->type != CNT_LBRACE)
            {
                
                PUAtomAbstractNode *atom = new (std::nothrow) PUAtomAbstractNode(impl);
                atom->file = (*iter1)->file;
                atom->line = (*iter1)->line;
                atom->type = ANT_ATOM;
                atom->value = (*iter1)->token;
                impl->values.push_back(atom);
                iter1++;
               
            }
            
            asn = impl;
            _current = impl;
            visitList(temp2->children);
            _current = impl->parent;
        }
        //no brance//
        else
        {
            PUPropertyAbstractNode *impl = new (std::nothrow) PUPropertyAbstractNode(_current);
            impl->line = node->line;
            impl->file = node->file;
            impl->name = node->token;
            
           
            
            asn = impl;
            _current = impl;
            
            // Visit the children of the {
            visitList(node->children);
            
            // Go back up the stack
            _current = impl->parent;
            
        }
    }
    else
    {
        PUAtomAbstractNode *impl = new (std::nothrow) PUAtomAbstractNode(_current);
        impl->line = node->line;
        impl->file = node->file;
        impl->value = node->token;
        asn = impl;
       //  printf("PropertyAbstractNode:%s\n", impl->value.c_str());

    }
    
    if(asn)
    {
        if(_current)
        {
            if(_current->type == ANT_PROPERTY)
            {
                PUPropertyAbstractNode *impl = reinterpret_cast<PUPropertyAbstractNode*>(_current);
                //PUAtomAbstractNode* assd = dynamic_cast<PUAtomAbstractNode*>(asn);
                impl->values.push_back(asn);
            }
            else
            {
                PUObjectAbstractNode *impl = reinterpret_cast<PUObjectAbstractNode*>(_current);
                impl->children.push_back(asn);


            }
        }
        else
        {
            _nodes->push_back(asn);
     //        printf("mNodes:%s\n", atom->value.c_str());
        }
    }
}
Exemplo n.º 4
0
 void visitVarArgs(AnyIterator begin, AnyIterator end)
 {
   visitList(begin, end);
 }