Esempio n. 1
0
// --------------------------------------------------- MacroEnsamZ::compNMAtr()
void MacroEnsamZ::compNMAtr()
{
	if ( estado == ENOBJETO )
	{
		std::string acceso;
		std::string nombre;
		std::string ref = Zero::OBJ_NOTHING;
		std::string lit;
		Zero::AnalizadorLexico::TipoToken tk = Zero::AnalizadorLexico::NADA;

		// Accesibilidad
		lex->pasaEsp();
		acceso = lex->getLiteral(' ');
		if (acceso != Zero::NMAtr::PRIVADO
		 && acceso != Zero::NMAtr::PUBLICO)
		{
			throw Zero::ESintxIdNoValido("Se esperaba marca de acceso");
		}

		// Es un atributo: asegurar que no hay método actual
		metodoActual = "";

		// Nombre del atributo
		lex->pasaEsp();
		nombre = lex->getToken();
		if (!Zero::NombreIdentificador::compruebaId(nombre))
			throw Zero::ESintxIdNoValido(nombre.c_str());
		if (!(idsProg.buscaObjeto(objetoActual)
			->insertaAtributo(nombre, ( acceso == Zero::NMAtr::PUBLICO ))))
		{
			throw Zero::ESintxIdNoValido("Nombre de atributo duplicado");
		}

		// Pasar el '='
		lex->pasaEsp();
		if (lex->getCaracterActual() != '=') {
			throw Zero::ESintxIdNoValido("Se esperaba '='");
		}
		lex->avanza();
		lex->pasaEsp();


		// Identificador del objeto/LitNumerico/LitCadena
		tk = lex->getTipoSiguienteToken();
		if (tk == Zero::AnalizadorLexico::IDENTIFICADOR)
		{
			lex->pasaEsp();
			ref = lex->getToken();
                        lex->getToken(); // Vaciarlo

			if (!Zero::NombreReferencia::compruebaRef(ref)) {
				throw Zero::ESintxIdNoValido(ref.c_str());
            }
		}
		else
		if (tk == Zero::AnalizadorLexico::LITNUMERICO)
		{
			lex->pasaEsp();
			lit = lex->getNumero();
			if ( !Zero::AnalizadorLexico::compruebaFlotante( lit ) ) {
				throw Zero::ESintxFltNoValido( lit.c_str() );
			}

            lit = '+' + lit;
		}
		else
		if (tk == Zero::AnalizadorLexico::LITCADENA)
		{
			// Llegar hasta las comillas
			lex->pasaEsp();
			if (lex->getCaracterActual() != '"')
				throw Zero::ESintxComillasEsperadas( "\"" );

			// Pasar las comillas y obtener literal
			lex->avanza();
			lit = '"' + lex->getLiteral('"');
		}
		else {
			// No hay nada
			throw Zero::ESintxIdNoValido("Se esperaba referencia, "
						"literal de cadena o numérico"
									);
		}

		if (tk != Zero::AnalizadorLexico::NADA
 		 && tk != Zero::AnalizadorLexico::IDENTIFICADOR)
		{
             // Es un literal (cadena, numérico ...)
      		Zero::Literal l( nombre, lit );
			literalesPorObjeto.push_back(l);
			Zero::NMAtr atr( acceso, nombre, Zero::OBJ_NOTHING, lit );
// 			atr.escribe( sal );
			(*log)( '\t' + Zero::NMAtr::mnemoStr + ' ' + acceso + ' '
						 + nombre + ' ' + l.getLiteralConTipo()
			);
        }
		else {
			Zero::NMAtr atr( acceso, nombre, ref );
// 			atr.escribe( sal );
			(*log)( '\t' + atr.listar() );
		}
	}
	else throw Zero::ESintxAtrNoPermitido("");

	return;
}
Esempio n. 2
0
void bcp_implementation::scan_license(const fs::path& p, const fileview& v)
{
   std::pair<const license_info*, int> licenses = get_licenses();
   //
   // scan file for all the licenses in the list:
   //
   int license_count = 0;
   int author_count = 0;
   int nonbsl_author_count = 0;
   bool has_non_bsl_license = false;
   fileview::const_iterator start_of_license = v.begin(), 
                            end_of_license = v.end();
   bool start_in_middle_of_line = false;

   for(int i = 0; i < licenses.second; ++i)
   {
      boost::match_results<fileview::const_iterator> m;
      if(boost::regex_search(v.begin(), v.end(), m, licenses.first[i].license_signature))
      {
           start_of_license = m[0].first;
         end_of_license = m[0].second;

         if (is_non_bsl_license(i) && i < licenses.second - 1) 
           has_non_bsl_license = true;

         // add this license to the list:
         m_license_data[i].files.insert(p);
         ++license_count;
         //
         // scan for the associated copyright declarations:
         //
         boost::regex_iterator<const char*> cpy(v.begin(), v.end(), licenses.first[i].copyright_signature);
         boost::regex_iterator<const char*> ecpy;
         while(cpy != ecpy)
         {
#if 0
             // Not dealing with copyrights because we don't have the years
            if ((*cpy)[0].first < start_of_license) 
              start_of_license = (*cpy)[0].first;
            if ((*cpy)[0].second > end_of_license) 
              end_of_license = (*cpy)[0].second;
#endif

            // extract the copy holders as a list:
            std::string author_list = cpy->format(licenses.first[i].copyright_formatter, boost::format_all);
            // now enumerate that list for all the names:
            static const boost::regex author_separator("(?:\\s*,(?!\\s*(?:inc|ltd)\\b)\\s*|\\s+(,\\s*)?(and|&)\\s+)|by\\s+", boost::regex::perl | boost::regex::icase);
            boost::regex_token_iterator<std::string::const_iterator> atr(author_list.begin(), author_list.end(), author_separator, -1);
            boost::regex_token_iterator<std::string::const_iterator> eatr;
            while(atr != eatr)
            {
               // get the reformatted authors name:
               std::string name = format_authors_name(*atr);
               // add to list of authors for this file:
               if(name.size() && name[0] != '-')
               {
                  m_license_data[i].authors.insert(name);
                  // add file to author index:
                  m_author_data[name].insert(p);
                  ++author_count;

                  // If this is not the Boost Software License (license 0), and the author hasn't given 
                  // blanket permission, note this for the report.
                  if (has_non_bsl_license
                      && m_bsl_authors.find(name) == m_bsl_authors.end()) {
                    ++nonbsl_author_count;
                    m_authors_for_bsl_migration.insert(name);
                  }
               }
               ++atr;
            }
            ++cpy;
         }

         while (start_of_license != v.begin()
                && *start_of_license != '\r'
                && *start_of_license != '\n'
                && *start_of_license != '.')
           --start_of_license;

         if (start_of_license != v.begin()) {
           if (*start_of_license == '.')
             start_in_middle_of_line = true;
           ++start_of_license;
         }

         while (end_of_license != v.end()
                && *end_of_license != '\r'
                && *end_of_license != '\n')
           ++end_of_license;
      }
   }
   if(license_count == 0)
      m_unknown_licenses.insert(p);
   if(license_count && !author_count)
      m_unknown_authors.insert(p);

   if (has_non_bsl_license) {
     bool converted = false;
     if (nonbsl_author_count == 0 
         && license_count == 1) {
       // Grab a few lines of context
       fileview::const_iterator context_start = 
         context_before_license(v, start_of_license);
       fileview::const_iterator context_end = 
         context_after_license(v, end_of_license);

       // TBD: For files that aren't C++ code, this will have to
       // change.
       std::string prefix = find_prefix(v, start_of_license);

       // Create enough information to permit manual verification of
       // the correctness of the transformation
       std::string before_conversion = 
         html_escape(context_start, start_of_license);
       before_conversion += "<b>";
       before_conversion += html_escape(start_of_license, end_of_license);
       before_conversion += "</b>";
       before_conversion += html_escape(end_of_license, context_end);

       std::string after_conversion = 
         html_escape(context_start, start_of_license);
       if (start_in_middle_of_line)
         after_conversion += '\n';

       after_conversion += "<b>";
       for (int i = 0; i < boost_license_lines; ++i) {
         if (i > 0) after_conversion += '\n';
         after_conversion += prefix + boost_license_text[i];
       }
       after_conversion += "</b>";
       after_conversion += html_escape(end_of_license, context_end);

       m_converted_to_bsl[p] = 
         std::make_pair(before_conversion, after_conversion);

       // Perform the actual conversion
       if (m_bsl_convert_mode) {
          try{
             std::ofstream out((m_boost_path / p).string().c_str());
            if (!out) {
               std::string msg("Cannot open file for license conversion: ");
               msg += p.string();
               std::runtime_error e(msg);
               boost::throw_exception(e);
            }

            out << std::string(v.begin(), start_of_license);
            if (start_in_middle_of_line)
               out << std::endl;

            for (int j = 0; j < boost_license_lines; ++j) {
               if (j > 0) out << std::endl;
               out << prefix << boost_license_text[j];
            }
            out << std::string(end_of_license, v.end());

            converted = true;
       }
       catch(const std::exception& e)
       {
          std::cerr << e.what() << std::endl;
       }
      }
     }

     if (!converted) {
       if (nonbsl_author_count > 0) m_cannot_migrate_to_bsl.insert(p);
       else m_can_migrate_to_bsl.insert(p);
     }
   }
}
Esempio n. 3
0
//this sets the parameters of the class DavidsonHarel, adds the energy functions and
//starts the optimization process
void DavidsonHarelLayout::call(GraphAttributes &AG)
{
	// all edges straight-line
	AG.clearAllBends();

	DavidsonHarel dh;
	Repulsion rep(AG);
	Attraction atr(AG);
	Overlap over(AG);
	Planarity plan(AG);
	//PlanarityGrid plan(AG);
	//PlanarityGrid2 plan(AG);
	//NodeIntersection ni(AG);

	// Either use a fixed value...
	if (DIsGreater(m_prefEdgeLength, 0.0))
	{
		atr.setPreferredEdgelength(m_prefEdgeLength);
	}
	// ...or set it depending on vertex sizes
	else atr.reinitializeEdgeLength(m_multiplier);
	 

	dh.addEnergyFunction(&rep,m_repulsionWeight);
	dh.addEnergyFunction(&atr,m_attractionWeight);
	dh.addEnergyFunction(&over,m_nodeOverlapWeight);
	if (m_crossings) dh.addEnergyFunction(&plan,m_planarityWeight);
	//dh.addEnergyFunction(&ni,2000.0);

	//dh.setNumberOfIterations(m_numberOfIterations);
	//dh.setStartTemperature(m_startTemperature);
	const Graph& G = AG.constGraph();
	//TODO: Immer Anzahl Iterationen abhängig von Größe
	if (m_numberOfIterations == 0)
	{
		switch (m_speed)  //todo: function setSpeedParameters
		{
		  case sppFast: {
				          m_numberOfIterations = max(75, 3*G.numberOfNodes()); 
						  m_startTemperature = 400;
						} break;
		  case sppMedium: {
				            m_numberOfIterations = 10*G.numberOfNodes(); 
							m_startTemperature = 1500;
						  } 
				          break;
		  case sppHQ: {
				        m_numberOfIterations = 2500*G.numberOfNodes(); //should be: isolate
						m_startTemperature = 2000;
					  } 
					  break;
		  default: OGDF_THROW_PARAM(AlgorithmFailureException, afcIllegalParameter); break;
		}//switch
	}//if
	else
	{
		if (m_itAsFactor)
			dh.setNumberOfIterations(200+m_numberOfIterations*G.numberOfNodes());
		else
			dh.setNumberOfIterations(m_numberOfIterations);
	}
	dh.setStartTemperature(m_startTemperature);
	dh.call(AG);
}