// Lex one of '=' or '=='. inline Token Lexer::equal() { assert(peek() == '='); get(); if (peek() == '=') return symbol1(); else return symbol0(); }
inline Token Lexer::rangle() { assert(peek() == '>'); get(); if (peek() == '=') return symbol1(); else return symbol0(); }
inline Token Lexer::ampersand() { assert(peek() == '&'); get(); if (peek() == '&') return symbol1(); else return error(); }
// Lex one of '-' or '->'. inline Token Lexer::minus() { assert(peek() == '-'); get(); if (peek() == '>') return symbol1(); else return symbol0(); }
inline Token Lexer::bar() { assert(peek() == '|'); get(); if (peek() == '|') return symbol1(); else return error(); }
// Lexically analyze a single token. Token Lexer::scan() { while (!cs_.eof()) { space(); loc_ = cs_.location(); switch (cs_.peek()) { case '\0': return eof(); case '(': return symbol1(); case ')': return symbol1(); case '\\': return symbol1(); case '.': return symbol1(); case '=': return symbol1(); case ';': return symbol1(); default: // TODO: Unfold into cases. if (is_alpha(cs_.peek())) return identifier(); else error(); } } return {}; }
void StabilizeStepper::initialize_neighbor_list_managers() { const std::size_t num_beads(_space->num_beads()); PairList bond_pair(num_beads); std::list<std::pair<std::size_t, std::size_t> > bonds(_model->list_bonds()); for (auto itr(bonds.begin()); itr != bonds.end(); itr++) { bond_pair.add_pair(*itr); bond_pair.add_pair(std::make_pair((*itr).second, (*itr).first)); } PairList excludes(num_beads); for (std::size_t i(0); i < num_beads; ++i) { for (auto itr(bond_pair.begin(i)); itr != bond_pair.end(i); ++itr) { excludes.add_pair(std::make_pair(i, *itr)); for (auto jtr(bond_pair.begin(*itr)); jtr != bond_pair.end(*itr); ++jtr) { excludes.add_pair(std::make_pair(i, *jtr)); } } } Model::inter_potential_container inter_potentials(_model->list_inter_potentials()); for (auto itr(inter_potentials.begin()); itr != inter_potentials.end(); ++itr) { const double r_c((*itr)->get_cutoff_radius()); NeighborListManager manager(num_beads, r_c, r_c*3, std::numeric_limits<double>::infinity()); // TODO parameter fitting (*itr)->set_neighbor_list(manager.get_neighbor_list()); for (std::size_t i(0); i < num_beads-1; ++i) { std::string symbol0(_space->symbol(i)); for (std::size_t j(i+1); j < num_beads; j++) { std::string symbol1(_space->symbol(j)); if ((*itr)->is_valid_pair(symbol0, symbol1)) { bool is_exclude(false); for (auto itr2(excludes.begin(i)); itr2 != excludes.end(i); ++itr2) if (j == *itr2) { is_exclude = true; break; } if (!is_exclude) manager.add_candidate(std::make_pair(i,j)); } } } manager.update(*(_space.get())); _neighbor_list_managers.push_back(manager); } }
inline Token Lexer::percent() { return symbol1(); }
inline Token Lexer::star() { return symbol1(); }
inline Token Lexer::plus() { return symbol1(); }
inline Token Lexer::semicolon() { return symbol1(); }
inline Token Lexer::comma() { return symbol1(); }
inline Token Lexer::rbrack() { return symbol1(); }
inline Token Lexer::rparen() { return symbol1(); }
inline Token Lexer::lbrace() { return symbol1(); }
inline Token Lexer::dot() { return symbol1(); }
void zu::postfix_writer::do_functiondefinition_node(zu::functiondefinition_node * const node, int lvl) { //ESTA IMPLEMENTACAO SO VAI FUNCIONAR PARA INTEIROS //Quando existe, a funcao "zu" e o inicio do programa _global = false; std::string name = ""; if (node->identifier()->name() == "zu") name="_main"; else name = node->identifier()->name(); const std::string &id = node->identifier()->name(); std::shared_ptr<zu::symbol> symbol = _symtab.find(id); if(symbol != NULL){ std::cerr << node->identifier()->name() + " already defined!" << std::endl; exit(-1); }else if(symbol == NULL){ std::shared_ptr<zu::symbol> sy = std::make_shared<zu::symbol>(new basic_type(node->type()->size(), node->type()->name()), name, 0); _symtab.insert(node->identifier()->name(), sy); } if (name == "_main") { _pf.EXTERN("printi"); _pf.EXTERN("prints"); _pf.EXTERN("printd"); _pf.EXTERN("println"); _pf.EXTERN("argc"); _pf.EXTERN("argv"); _pf.EXTERN("envp"); } _pf.TEXT(); _pf.ALIGN(); if (node->isPublic()) _pf.GLOBAL(name, _pf.FUNC()); _pf.LABEL(name); // Determinar o tamanho que a funcao vai ocupar é visitar todas as suas declarations (dentro de ciclos e nos blocos) e somar. // Estas 3 linhas calculam o tamanho das variaveis declaradas LOCALMENTE stack_counter sc(_compiler, _symtab); node->accept(&sc, lvl+2); size_t localsize = sc.size(); _retsize = node->type()->size(); _symtab.push(); /************************************************************************/ int size_args = 8; //ret + oldfp cdk::sequence_node *args = node->arguments(); if (args != NULL) { //Tamanho dos argumentos + ret + oldfp for (size_t i = 0; i < args->size(); i++) { zu::declaration_node *arg = (zu::declaration_node*)args->node(i); size_args += arg->type()->size(); } int offset_args = 8; //IF DOUBLE RETURN if (node->type()->name() != basic_type::TYPE_VOID && (node->type()->name() == basic_type::TYPE_DOUBLE)){ offset_args = 16; }else if (node->type()->name() != basic_type::TYPE_VOID){ offset_args = 12; } std::shared_ptr<zu::symbol> func = _symtab.find(node->identifier()->name()); func->offset(size_args - 8); for (size_t i = 0; i < args->size(); i++) { zu::declaration_node *arg = (zu::declaration_node*)args->node(i); zu::symbol *sym = new zu::symbol(new basic_type(arg->type()->size(), arg->type()->name()), arg->identifier()->name(), offset_args); //std::cout << "pilha offsets args : " << offset_args << std::endl; offset_args += arg->type()->size(); std::shared_ptr<zu::symbol> symbol(sym); _symtab.insert(arg->identifier()->name(), symbol); } } //COLOCA RETURN NA TABELA DE SIMBOLOS if (node->type()->name() != basic_type::TYPE_VOID) { zu::symbol *sym1 = new zu::symbol(new basic_type(node->type()->size(),node->type()->name()), node->identifier()->name() , 8); std::shared_ptr<zu::symbol> symbol1(sym1); _symtab.insert(node->identifier()->name(), symbol1); sym1->function(true); }else{ _isVoid = true; } /************************************************************************/ _pf.ENTER(localsize); // Inicializacao do leftValue especial de uma funcao (accept do default - retval) if (node->literal() != nullptr) { node->literal()->accept(this, lvl+2); _pf.LOCAL(8); if(node->type()->name() == basic_type::TYPE_DOUBLE) _pf.DSTORE(); else _pf.STORE(); }/* else { } */ node->block()->accept(this, lvl+2); _pf.LOCV(8); if(node->type()->name() == basic_type::TYPE_DOUBLE) _pf.DPOP(); else _pf.POP(); _symtab.pop(); _pf.LEAVE(); _pf.RET(); _global = true; }