EnumeratedInputSymbolRef::EnumeratedInputSymbolRef(const Enumeration* enumeration,
    InputSource& input,
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state) :
  symbol(0), parameters(0)
{
  char buf[100];
  input.readString(buf, 99);

  XABSL_DEBUG_INIT(errorHandler.message("creating reference to enumerated input symbol \"%s\"", buf));

  if(!symbols.enumeratedInputSymbols.exists(buf))
  {
    errorHandler.error("XabslEnumeratedInputSymbolRef::XabslEnumeratedInputSymbolRef(): enumerated input symbol \"%s\" was not registered at the engine", buf);
    return;
  }

  symbol = symbols.enumeratedInputSymbols[buf];
  this->enumeration = symbol->enumeration;

  if(enumeration != NULL && enumeration != this->enumeration)
  {
    errorHandler.error("XabslEnumeratedInputSymbolRef::XabslEnumeratedInputSymbolRef(): enumeration input symbol \"%s\" does not match enumeration type \"%s\"", buf, enumeration->n);
  }

  parameters = new ParameterAssignment(&symbol->parameters, errorHandler);

  parameters->create(input, symbols, option, state);
}
bool DecimalExpression::createOperand(DecimalExpression*& operand,
                                            InputSource& input, 
                                            Array<Action*>& actions,
                                            ErrorHandler& errorHandler,
                                            OptionParameters& parameters,
                                            Symbols& symbols,
                                            unsigned long& timeOfOptionExecution,
                                            unsigned long& timeOfStateExecution)
{
  operand = DecimalExpression::create(input,actions,errorHandler,parameters, symbols,
    timeOfOptionExecution,timeOfStateExecution);
  
  if (operand == 0) 
  {
    errorHandler.error("XabslDecimalExpression::createOperand(): created operand is 0");
    return false;
  }
  
  if (errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslDecimalExpression::createOperand(): could not create operand");
    if (operand != 0) delete operand;
    return false;
  }
  
  return true;
}
bool EnumeratedExpression::createOperand(const EnumeratedExpression*& operand,
    const Enumeration* enumeration,
    InputSource& input,
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state)
{
  operand = EnumeratedExpression::create(enumeration, input, errorHandler, symbols, option, state);

  if(operand == 0)
  {
    errorHandler.error("XabslEnumeratedExpression::createOperand(): created operand is 0");
    return false;
  }

  if(errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslEnumeratedExpression::createOperand(): could not create operand");
    if(operand != 0) delete operand;
    return false;
  }

  return true;
}
Exemplo n.º 4
0
IfElseBlock::IfElseBlock(InputSource& input,
                         ErrorHandler& errorHandler,
                         Symbols& symbols,
                         Option& option,
                         State& state) :
  ifCondition(0), ifStatement(0), elseStatement(0)
{

  // if case
  XABSL_DEBUG_INIT(errorHandler.message("creating if statement"));

  ifCondition = BooleanExpression::create(input, errorHandler, symbols, option, state);
  if(errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create if condition");
    return;
  }

  ifStatement = Statement::createStatement(input, errorHandler, symbols, option, state);
  if(errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create if statement");
    return;
  }

  // else case
  XABSL_DEBUG_INIT(errorHandler.message("creating else statement"));

  elseStatement = Statement::createStatement(input, errorHandler, symbols, option, state);
  if(errorHandler.errorsOccurred)
    errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create else statement");

}
DecimalInputSymbolRef::DecimalInputSymbolRef(InputSource& input, 
                                                               Array<Action*>& actions,
                                                               ErrorHandler& errorHandler,
                                                               OptionParameters& optionParameters,
                                                               Symbols& symbols,
                                                               unsigned long& timeOfOptionExecution,
                                                               unsigned long& timeOfStateExecution) :
  symbol(0), parameters(0)
{
  char buf[100];
  input.readString(buf,99);
  
  XABSL_DEBUG_INIT(errorHandler.message("creating a reference to decimal input symbol \"%s\"",buf));
  
  if (!symbols.decimalInputSymbols.exists(buf))
  {
    errorHandler.error("XabslDecimalInputSymbolRef::DecimalInputSymbolRef(): decimal input symbol \"%s\" was not registered",buf);
    return;
  }
  
  symbol = symbols.decimalInputSymbols[buf];

  parameters = new ParameterAssignment(&symbol->parameters, errorHandler);

  parameters->create(input, optionParameters, symbols, timeOfOptionExecution, timeOfStateExecution, actions);
}
EnumeratedInputSymbolComparison::EnumeratedInputSymbolComparison(InputSource& input,
  ErrorHandler& errorHandler,
  Symbols& symbols,
  Option& option,
  State& state)
{
  if (!EnumeratedExpression::createOperand(operand1,NULL,input,errorHandler,symbols,option,state))
  {
    errorHandler.error("XabslEnumeratedInputSymbolComparison::EnumeratedInputSymbolComparison(): could not create enumerated expression");
    operand1 = operand2 = 0;
    return;
  }
  if (!EnumeratedExpression::createOperand(operand2,operand1->enumeration,input,errorHandler,symbols,option,state))
  {
    errorHandler.error("XabslEnumeratedInputSymbolComparison::EnumeratedInputSymbolComparison(): could not create enumerated expression");
    operand2 = 0;
    return;
  }
}
EnumeratedInputSymbolComparison::EnumeratedInputSymbolComparison(InputSource& input,
  Array<Action*>& actions,
  ErrorHandler& errorHandler,
  OptionParameters& parameters,
  Symbols& symbols,
  unsigned long& timeOfOptionExecution,
  unsigned long& timeOfStateExecution)
{
  if (!EnumeratedExpression::createOperand(operand1,NULL,input,actions,errorHandler,parameters,symbols,timeOfOptionExecution,timeOfStateExecution))
  {
    errorHandler.error("XabslEnumeratedInputSymbolComparison::EnumeratedInputSymbolComparison(): could not create enumerated expression");
    operand1 = operand2 = 0;
    return;
  }
  if (!EnumeratedExpression::createOperand(operand2,operand1->enumeration,input,actions,errorHandler,parameters,symbols,timeOfOptionExecution,timeOfStateExecution))
  {
    errorHandler.error("XabslEnumeratedInputSymbolComparison::EnumeratedInputSymbolComparison(): could not create enumerated expression");
    operand2 = 0;
    return;
  }
}
ConditionalEnumeratedExpression::ConditionalEnumeratedExpression(const Enumeration* enumeration,
    InputSource& input, 
    Array<Action*>& actions,
    ErrorHandler& errorHandler,
    OptionParameters& parameters,
    Symbols& symbols,
    unsigned long& timeOfOptionExecution,
    unsigned long& timeOfStateExecution)
{
  XABSL_DEBUG_INIT(errorHandler.message("creating a question mark operator"));

  condition = BooleanExpression::create(input,actions,errorHandler,parameters, symbols,
    timeOfOptionExecution,timeOfStateExecution);

  if (condition == 0) 
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): created condition is 0");
    return;
  }
  else if (errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): could not create condition");
    delete condition;
    return;
  }

  if (!EnumeratedExpression::createOperand(expression1,enumeration,input,actions,errorHandler,parameters,symbols,timeOfOptionExecution,timeOfStateExecution))
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): could not create decimal expression1");
    return;
  }
  
  if (!EnumeratedExpression::createOperand(expression2,enumeration,input,actions,errorHandler,parameters,symbols,timeOfOptionExecution,timeOfStateExecution))
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): could not create decimal expression2");
    return;
  }
  this->enumeration = enumeration;
}
EnumeratedValue::EnumeratedValue(const Enumeration* enumeration,
                                 InputSource& input,
                                 ErrorHandler& errorHandler)
{
  char buf[100];
  input.readString(buf, 99);

  if(enumeration == NULL)
  {
    errorHandler.error("XabslEnumeratedValue::EnumeratedValue(): enumerated value can not be created without specifying enumeration");
    return;
  }

  if(!enumeration->enumElements.exists(buf))
  {
    errorHandler.error("XabslEnumeratedValue::EnumeratedValue(): enum element \"%s\" of enumeration \"%s\" was not registered", buf, enumeration->n);
    return;
  }

  value = enumeration->enumElements[buf]->v;
  this->enumeration = enumeration;
}
Exemplo n.º 10
0
IfElseBlock::IfElseBlock(InputSource& input,    
                                     Array<Action*>& actions,
                                     ErrorHandler& errorHandler,
                                     Array<State*>& states,
                                     OptionParameters& parameters,
                                     Symbols& symbols,    
                                     unsigned long& timeOfOptionExecution,
                                     unsigned long& timeOfStateExecution) :
ifCondition(0), ifStatement(0), elseStatement(0)
{
  
  // if case
  XABSL_DEBUG_INIT(errorHandler.message("creating if statement"));
  
  ifCondition = BooleanExpression::create(input, actions, errorHandler, 
    parameters, symbols, timeOfOptionExecution, timeOfStateExecution);
  if (errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create if condition");
    return;
  }
  
  ifStatement = Statement::createStatement(input,actions, errorHandler,
    states,parameters, symbols, timeOfOptionExecution, timeOfStateExecution);
  if (errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create if statement");
    return;
  }
    
  // else case
  XABSL_DEBUG_INIT(errorHandler.message("creating else statement"));
  
  elseStatement = Statement::createStatement(input, actions,
    errorHandler, states, parameters, symbols, timeOfOptionExecution, timeOfStateExecution);
  if (errorHandler.errorsOccurred)
    errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create else statement");
  
}
EnumeratedOptionParameterRef::EnumeratedOptionParameterRef(const Enumeration* enumeration,
    InputSource& input,
    ErrorHandler& errorHandler,
    Option& option)
{
  char buf[100];
  input.readString(buf, 99);

  XABSL_DEBUG_INIT(errorHandler.message("creating a reference to enumerated option parameter \"%s\"", buf));

  if(!option.parameters->enumerated.exists(buf))
  {
    errorHandler.error("XabslEnumeratedOptionParameterRef::EnumeratedOptionParameterRef(): enumerated option parameter \"%s\" does not exist", buf);
    return;
  }

  parameter = option.parameters->enumerated.getPElement(buf)->e;
  this->enumeration = option.parameters->enumerations[buf];
  if(enumeration != NULL && enumeration != this->enumeration)
  {
    errorHandler.error("XabslEnumeratedOptionParameterRef::EnumeratedOptionParameterRef(): enumeration input symbol \"%s\" does not match enumeration type \"%s\"", buf, enumeration->n);
  }
}
bool BooleanExpression::createOperand(BooleanExpression*& operand,
                                            InputSource& input, 
                                            ErrorHandler& errorHandler,
                                            Symbols& symbols,
                                            Option& option,
                                            State& state)
{
  operand = BooleanExpression::create(input,errorHandler,symbols,option,state);
  
  if (operand == 0) 
  {
    errorHandler.error("XabslBooleanExpression::createOperand(): created operand is 0");
    return false;
  }
  
  if (errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslBooleanExpression::createOperand(): could not create operand");
    delete operand;
    return false;
  }
  
  return true;
}
EnumeratedOutputSymbolRef::EnumeratedOutputSymbolRef(const Enumeration* enumeration,
    InputSource& input,
    ErrorHandler& errorHandler,
    Symbols& symbols)
{
  char buf[100];
  input.readString(buf, 99);

  XABSL_DEBUG_INIT(errorHandler.message("creating a reference to an enumerated output symbol \"%s\"", buf));

  if(!symbols.enumeratedOutputSymbols.exists(buf))
  {
    errorHandler.error("XabslEnumeratedOutputSymbolRef::EnumeratedOutputSymbolRef(): enumerated output symbol \"%s\" was not registered", buf);
    return;
  }

  symbol = symbols.enumeratedOutputSymbols[buf];
  this->enumeration = symbol->enumeration;

  if(enumeration != NULL && enumeration != this->enumeration)
  {
    errorHandler.error("XabslEnumeratedInputSymbolRef::XabslEnumeratedInputSymbolRef(): enumeration input symbol \"%s\" does not match enumeration type \"%s\"", buf, enumeration->n);
  }
}
ConditionalEnumeratedExpression::ConditionalEnumeratedExpression(const Enumeration* enumeration,
    InputSource& input,
    ErrorHandler& errorHandler,
    Symbols& symbols,
    Option& option,
    State& state)
{
  XABSL_DEBUG_INIT(errorHandler.message("creating a question mark operator"));

  condition = BooleanExpression::create(input, errorHandler, symbols, option, state);

  if(condition == 0)
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): created condition is 0");
    return;
  }
  else if(errorHandler.errorsOccurred)
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): could not create condition");
    delete condition;
    return;
  }

  if(!EnumeratedExpression::createOperand(expression1, enumeration, input, errorHandler, symbols, option, state))
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): could not create decimal expression1");
    return;
  }

  if(!EnumeratedExpression::createOperand(expression2, enumeration, input, errorHandler, symbols, option, state))
  {
    errorHandler.error("XabslQuestionMarkOperator::QuestionMarkOperator(): could not create decimal expression2");
    return;
  }
  this->enumeration = enumeration;
}
BooleanOutputSymbolRef::BooleanOutputSymbolRef(InputSource& input, 
                                                               ErrorHandler& errorHandler,
                                                               Symbols& symbols)
{
  char buf[100];
  input.readString(buf,99);
  
  XABSL_DEBUG_INIT(errorHandler.message("creating a reference to a boolean output symbol \"%s\"",buf));
  
  if (!symbols.booleanOutputSymbols.exists(buf))
  {
    errorHandler.error("XabslBooleanOutputSymbolRef::BooleanOutputSymbolRef(): boolean output symbol \"%s\" was not registered",buf);
    return;
  }
  
  symbol = symbols.booleanOutputSymbols[buf];
}
BooleanOptionParameterRef::BooleanOptionParameterRef(InputSource& input, 
                                                   ErrorHandler& errorHandler,
                                                   Option& option)
{
  char buf[100];
  input.readString(buf,99);
  
  XABSL_DEBUG_INIT(errorHandler.message("creating a reference to boolean option parameter \"%s\"",buf));
  
  if (!option.parameters->boolean.exists(buf))
  {
    errorHandler.error("XabslBooleanOptionParameterRef::BooleanOptionParameterRef(): boolean option parameter \"%s\" does not exist",buf);
    return;
  }
  
  parameter = option.parameters->boolean.getPElement(buf)->e;
}
Exemplo n.º 17
0
DecimalOptionParameterRef::DecimalOptionParameterRef(InputSource& input, 
                                                   ErrorHandler& errorHandler,
                                                   OptionParameters& parameters)
{
  char buf[100];
  input.readString(buf,99);
  
  XABSL_DEBUG_INIT(errorHandler.message("creating a reference to decimal option parameter \"%s\"",buf));
  
  if (!parameters.decimal.exists(buf))
  {
    errorHandler.error("XabslDecimalOptionParameterRef::DecimalOptionParameterRef(): decimal option parameter \"%s\" does not exist",buf);
    return;
  }
  
  parameter = parameters.decimal.getPElement(buf)->e;
}
BooleanInputSymbolRef::BooleanInputSymbolRef(InputSource& input, 
                                                               ErrorHandler& errorHandler,
                                                               Symbols& symbols,
                                                               Option& option,
                                                               State& state) :
  symbol(0), parameters(0)
{
  char buf[100];
  input.readString(buf,99);
  
  XABSL_DEBUG_INIT(errorHandler.message("creating reference to boolean input symbol \"%s\"",buf));
  
  if (!symbols.booleanInputSymbols.exists(buf))
  {
    errorHandler.error("XabslBooleanInputSymbolRef::XabslBooleanInputSymbolRef(): boolean input symbol \"%s\" was not registered at the engine",buf);
    return;
  }
  
  symbol = symbols.booleanInputSymbols[buf];

  parameters = new ParameterAssignment(&symbol->parameters, errorHandler);

  parameters->create(input, symbols, option, state);
}
Exemplo n.º 19
0
int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);

    /*QSettings test("test.ini", QSettings::IniFormat);
    test.beginGroup("compiler");
    test.setValue("test-value", "asd");
    test.setValue("other-value", "val");
    test.endGroup();
    test.beginGroup("opt");
    test.setValue("test-value2", "asd2");
    test.setValue("other-value2", "val2");
    test.endGroup();
    test.sync();
    return 0;*/

    QTime bigTimer;
    bigTimer.start();

    QStringList params = a.arguments();
    if (params.size() != 2) {
        qCritical() << "Expecting file to compile";
        return 0;
    }


    ErrorHandler errHandler;

    Settings settings;
    bool success = false;
    success = settings.loadDefaults();
    if (!success) {
        errHandler.error(ErrorCodes::ecSettingsLoadingFailed, errHandler.tr("Loading the default settings \"%1\" failed").arg(settings.loadPath()), CodePoint());
        return ErrorCodes::ecSettingsLoadingFailed;
    }


    Lexer lexer;
    QObject::connect(&lexer, &Lexer::error, &errHandler, &ErrorHandler::error);
    QObject::connect(&lexer, &Lexer::warning, &errHandler, &ErrorHandler::warning);
    QTime timer;
    timer.start();
    if (lexer.tokenizeFile(params[1], settings) == Lexer::Success) {
        qDebug() << "Lexical analysing took " << timer.elapsed() << "ms";
#ifdef DEBUG_OUTPUT
        lexer.writeTokensToFile("tokens.txt");
#endif
    }
    else {
        errHandler.error(ErrorCodes::ecLexicalAnalysingFailed, errHandler.tr("Lexical analysing failed"), CodePoint(lexer.files().first().first));
        return ErrorCodes::ecLexicalAnalysingFailed;
    }

    Parser parser;
    QObject::connect(&parser, &Parser::error, &errHandler, &ErrorHandler::error);
    QObject::connect(&parser, &Parser::warning, &errHandler, &ErrorHandler::warning);

    timer.start();
    ast::Program *program = parser.parse(lexer.tokens(), settings);
    qDebug() << "Parsing took " << timer.elapsed() << "ms";
    if (!parser.success()) {
        errHandler.error(ErrorCodes::ecParsingFailed, errHandler.tr("Parsing failed \"%1\"").arg(params[1]), CodePoint());
        return ErrorCodes::ecParsingFailed;
    }

#ifdef DEBUG_OUTPUT
    if (program) {
        QFile file("ast.txt");
        if (file.open(QFile::WriteOnly)) {
            QTextStream stream(&file);
            program->write(stream);
            file.close();
        }
    }
#endif



    CodeGenerator codeGenerator;
    //QObject::connect(&codeGenerator, &CodeGenerator::error, &errHandler, &ErrorHandler::error);
    //QObject::connect(&codeGenerator, &CodeGenerator::warning, &errHandler, &ErrorHandler::warning);
    QObject::connect(&codeGenerator, &CodeGenerator::error, &errHandler, &ErrorHandler::error);
    QObject::connect(&codeGenerator, &CodeGenerator::warning, &errHandler, &ErrorHandler::warning);

    timer.start();
    if (!codeGenerator.initialize(settings)) {
        return ErrorCodes::ecCodeGeneratorInitializationFailed;
    }


    qDebug() << "Code generator initialization took " << timer.elapsed() << "ms";
    timer.start();
    if (!codeGenerator.generate(program)) {
        errHandler.error(ErrorCodes::ecCodeGenerationFailed, errHandler.tr("Code generation failed"), CodePoint());
        return ErrorCodes::ecCodeGenerationFailed;
    }

    qDebug() << "Code generation took" << timer.elapsed() << "ms";
    qDebug() << "LLVM-IR generated";

    timer.start();
    codeGenerator.createExecutable(settings.defaultOutputFile());
    qDebug() << "Executable generation took " << timer.elapsed() << "ms";
    qDebug() << "The whole compilation took " << bigTimer.elapsed() << "ms";
    return 0;
}
inline void XMLInternalErrorHandler::error(const SAXParseException& toCatch)
{
    fSawError = true;
    if (fUserErrorHandler)
        fUserErrorHandler->error(toCatch);
}