Beispiel #1
0
void
SymbolTreeBuilder::visit(ConditionNode& node)
{
    node.setScope(currentScope());

    if (node.hasConditionComponent())
    {
        _curStatment = node.condition();
        node.condition()->accept(*this);
        // check condition expression
        if (!_expResult.type->isPromotableToBoolean())
        {
            throw SemanticException("Condition expression can not be promoted to boolean\n",
                                    node);
        }
    }

    if (node.hasOnTrueComponent())
    {
        // begin new scope
        beginScope();
        node.onTrue()->accept(*this);
        endScope();
    }

    if (node.hasOnFalseComponent())
    {
        // begin new scope
        beginScope();
        node.onFalse()->accept(*this);
        endScope();
    }
}
Beispiel #2
0
void
SymbolTreeBuilder::visit(FunctionDeclNode& node)
{
    visit(static_cast<FunctionDeclBaseNode&>(node));

    const char* func_name = node.functionNameWithType();

    // declare func
    FunctionType* type = _typeRegistry.registerFunction(&node);
    if (!type)
    {
        std::stringstream stream;
        stream << "Failed to register '" << func_name
        << "'"
        << std::endl;
        throw SemanticException(stream.str(), node);
    }

    _curFunctionDecl = _curScope->declareSymbol(func_name, type, 0);
    YAL_ASSERT(_curFunctionDecl);

    // begin new scope
    beginScope();


    // check for object type
    if (node.isObjectFunction())
    {
        Type* object_type = node.objectType();
        Symbol* self_sym = _curScope->declareSymbol("self", object_type,
                                                    (!object_type->isObjectType() ? Symbol::kFlagReference  : 0)| Symbol::kFlagAssignable | Symbol::kFlagVariable);
        (void) self_sym;
        YAL_ASSERT(self_sym);
    }


    node.functionArguments()->accept(*this);


    node.functionCode()->accept(*this);

    // register function in module
    YAL_ASSERT(_parserState->module.function(func_name) == nullptr);
    _parserState->module.addFunction(new ModuleFunction(_curFunctionDecl,
                                                        &node));

    // end scope
    endScope();
    _curFunctionDecl = nullptr;
}
Beispiel #3
0
void
SymbolTreeBuilder::visit(WhileLoopNode& node)
{
    node.setScope(currentScope());

    _curStatment = &node;
    node.condition()->accept(*this);
    // check condition expression
    if (!_expResult.type->isPromotableToBoolean())
    {
        throw SemanticException("Condition expression can not be promoted to boolean\n",
                                node);
    }

    // begin new scope
    beginScope();
    node.code()->accept(*this);
    endScope();
}
Beispiel #4
0
void
SymbolTreeBuilder::visit(FunctionDeclNativeNode& node)
{
    visit(static_cast<FunctionDeclBaseNode&>(node));

    const char* func_name = node.functionNameWithType();

    // declare func
    FunctionType* type = _typeRegistry.registerFunction(&node);
    if (!type)
    {
        std::stringstream stream;
        stream << "Failed to register '" << func_name
               << "'"
               << std::endl;
        throw SemanticException(stream.str(), node);
    }

    _curFunctionDecl = _curScope->declareSymbol(func_name, type, 0);
    YAL_ASSERT(_curFunctionDecl);

    beginScope();

    if (node.hasFunctionArguments())
    {
        node.functionArguments()->accept(*this);
    }

    // register function in module
    YAL_ASSERT(_parserState->module.function(func_name) == nullptr);
    _parserState->module.addFunction(new ModuleFunction(_curFunctionDecl,
                                                              &node));

    // end scope
    endScope();
    _curFunctionDecl = nullptr;
}
Beispiel #5
0
void JSONWriter::beginObject()
  {
  beginScope(Scope::Object);
  }
Beispiel #6
0
void JSONWriter::beginArray()
  {
  beginScope(Scope::Array);
  }