Exemplo n.º 1
0
/**! Constructor
  Constructs a mediator object with a CCompositeFilter
  as the default filter. We also set up the proper 
  skip and processing counts that user supplied.

  \throw can throw a CFatalException

*/
CFilterMain::CFilterMain(int argc, char** argv)
  : m_mediator(0),
  m_argsInfo(new gengetopt_args_info)
{
  cmdline_parser(argc,argv,m_argsInfo);  

  try {

    if (m_argsInfo->oneshot_given) {
      m_mediator = new COneShotMediator(0,new CCompositeFilter,0,
          m_argsInfo->number_of_sources_arg); 
    } else {
      m_mediator = new CInfiniteMediator(0,new CCompositeFilter,0);
    } 
    // Set up the data source 
    CDataSource* source = constructDataSource(); 
    m_mediator->setDataSource(source);

    // Set up the sink source 
    CDataSink* sink = constructDataSink(); 
    m_mediator->setDataSink(sink);

    // set up the skip and count args
    if (m_argsInfo->skip_given) {
      m_mediator->setSkipCount(m_argsInfo->skip_arg);
    }  

    if (m_argsInfo->count_given) {
      m_mediator->setProcessCount(m_argsInfo->count_arg);
    }  



  } catch (CException& exc) {
    std::cout << exc.ReasonText() << std::endl;
    std::cout << exc.WasDoing() << std::endl;
    throw CFatalException();
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
    throw CFatalException();
  }
  catch (...) {
    std::cout << "Unanticipated exception type\n";
    throw CFatalException();
  }
}
Exemplo n.º 2
0
/**! The main loop
    This is just a wrapper around the mediator's mainLoop. It is here
    that the processing occurs in the application. */
void CFilterMain::operator()()
{
  try {
    m_mediator->initialize();
    m_mediator->mainLoop();
    m_mediator->finalize();
  } catch (CException& exc) {
    std::cerr << exc.WasDoing() << " : " << exc.ReasonText() << std::endl;
    throw CFatalException(); 
  }

}
Exemplo n.º 3
0
/**! 
  Makes a call to the stringListToIntegers that maps the
  the names of ring item types to their associated identifying
  numbers. 

  \return a list of ring item numbers
*/
std::vector<uint16_t> 
CFilterMain::constructExcludesList()
{
  std::vector<uint16_t> exclude;
  std::vector<int> e;
  if (m_argsInfo->exclude_given) {
    try {
      e = stringListToIntegers(std::string(m_argsInfo->exclude_arg));
    }
    catch (...) {
      std::cerr << "Invalid value for --exclude, must be a list of item types was: "
        << std::string(m_argsInfo->sample_arg) << std::endl;
      throw CFatalException();
      
    }
    for (int i = 0; i < e.size(); i++) {
      exclude.push_back(e[i]);
    }
  }
  return exclude;
}
Exemplo n.º 4
0
/**! The main loop
    This is just a wrapper around the mediator's mainLoop. It is here
    that the processing occurs in the application. */
void CFilterMain::operator()()
{
  try {
    m_mediator->initialize();

    // allow the finalize operations to be called if an exception is 
    // thrown from the main loop. Consider the arrival of an 
    // ABNORMAL_ENDRUN
    try {
      m_mediator->mainLoop();
    } catch (CException& exc) {
      std::cerr << exc.WasDoing() << " : " << exc.ReasonText() << std::endl;
    } catch (...) {
      std::cerr << "Caught unknown exception thrown from main loop. ";
      std::cerr << "Shutting down filter." << std::endl;
    }

    m_mediator->finalize();
  } catch (CException& exc) {
    std::cerr << exc.WasDoing() << " : " << exc.ReasonText() << std::endl;
    throw CFatalException(); 
  }

}
Exemplo n.º 5
0
Arquivo: cli.cpp Projeto: selius/ncc
CCompilerParameters CCommandLineInterface::ParseArguments()
{
	if (Args.size() < 2) {
		PrintVersion();
		PrintHelp();
		throw CFatalException(EXIT_CODE_TOO_FEW_ARGUMENTS);
	}

	string CurArg;
	string CurOpt;
	bool OptionsEnd = false;

	for (ArgumentsIterator it = ++Args.begin(); it != Args.end(); ++it) {
		CurArg = *it;
		if (!OptionsEnd && CurArg[0] == '-' && CurArg.length() > 1) {
			if (CurArg == "-v" || CurArg == "--version") {
				PrintVersion();
				throw CFatalException(EXIT_CODE_SUCCESS);
			} else if (CurArg == "-h" || CurArg == "--help") {
				PrintHelp(true);
				throw CFatalException(EXIT_CODE_SUCCESS);
			} else if (CurArg == "-o") {
				RequireArgument(it);

				if (!Parameters.OutputFilename.empty()) {
					throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "only one output file could be specified");
				}

				Parameters.OutputFilename = *(++it);
			} else if (CurArg == "-S" || CurArg == "--scan" || CurArg == "-P" || CurArg == "--parse" || CurArg == "-G" || CurArg == "--generate") {
				if (Parameters.CompilerMode != COMPILER_MODE_UNDEFINED) {
					throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "only one mode could be specified");
				}

				if (CurArg == "-S" || CurArg == "--scan") {
					Parameters.CompilerMode = COMPILER_MODE_SCAN;
				} else if (CurArg == "-P" || CurArg == "--parse") {
					Parameters.CompilerMode = COMPILER_MODE_PARSE;
				} else if (CurArg == "-G" || CurArg == "--generate") {
					Parameters.CompilerMode = COMPILER_MODE_GENERATE;
				}
			} else if (CurArg == "-T" || CurArg == "--symbol-tables") {
				Parameters.SymbolTables = true;
			} else if (CurArg == "-O" || CurArg == "--optimize") {
				Parameters.Optimize = true;
			} else if (CurArg == "--parser-output-mode") {
				RequireArgument(it);

				string OptValue = *(++it);
				if (OptValue == "linear") {
					Parameters.ParserOutputMode = PARSER_OUTPUT_MODE_LINEAR;
				} else if (OptValue == "tree") {
					Parameters.ParserOutputMode = PARSER_OUTPUT_MODE_TREE;
				} else {
					throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "invalid value for " + CurArg + " option");
				}
			} else if (CurArg == "--parser-mode") {
				RequireArgument(it);

				string OptValue = *(++it);
				if (OptValue == "normal") {
					Parameters.ParserMode = PARSER_MODE_NORMAL;
				} else if (OptValue == "expression") {
					Parameters.ParserMode = PARSER_MODE_EXPRESSION;
				} else {
					throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "invalid value for " + CurArg + " option");
				}
			} else if (CurArg == "--tree") {
				RequireArgument(it);

				if (!Parameters.TreeFilename.empty()) {
					throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "only one tree output file could be specified");
				}

				Parameters.TreeFilename = *(++it);
			} else if (CurArg == "--") {
				OptionsEnd = true;
			} else {
				throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "invalid option: " + CurArg);
			}
		} else {
			if (!Parameters.InputFilename.empty()) {
				throw CFatalException(EXIT_CODE_TOO_MANY_INPUT_FILES, "only one input file per run is supported");
			}

			Parameters.InputFilename = CurArg;
		}
	}
	if (Parameters.InputFilename.empty()) {
		throw CFatalException(EXIT_CODE_NO_INPUT_FILE, "no input file");
	}

	if (Parameters.CompilerMode == COMPILER_MODE_UNDEFINED) {
		Parameters.CompilerMode = COMPILER_MODE_GENERATE;	// default mode
	}

	if (Parameters.ParserMode == PARSER_MODE_EXPRESSION && Parameters.CompilerMode != COMPILER_MODE_PARSE) {
		throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "expressions-only parser mode can only be selected when compiler mode is parsing");
	}

	if (Parameters.SymbolTables && (Parameters.CompilerMode != COMPILER_MODE_PARSE || Parameters.ParserMode != PARSER_MODE_NORMAL)) {
		throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "symbol tables printing can only be enabled when compiler mode is parsing and parser mode is normal");
	}

	if (Parameters.Optimize && Parameters.CompilerMode != COMPILER_MODE_GENERATE) {
		throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "optimization can only be enabled when compiler mode is code generation");
	}

	if (!Parameters.TreeFilename.empty() && Parameters.CompilerMode != COMPILER_MODE_GENERATE) {
		throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, "parse tree can only be written to a separate file when compiler mode is code generation");
	}

	return Parameters;
}
Exemplo n.º 6
0
Arquivo: cli.cpp Projeto: selius/ncc
void CCommandLineInterface::RequireArgument(ArgumentsIterator &AOption)
{
	if (AOption == --Args.end()) {
		throw CFatalException(EXIT_CODE_INVALID_ARGUMENTS, *AOption + " option requires an argument");
	}
}