Exemple #1
0
void If::doSemanticCheck()
{
    Node* condition = children_[0];
    Node* thenClause = children_[1];
    Node* elseClause = children_[2];
    
    // The resulting type is Void
    type_ = Void::get(context_->evalMode());

    // Semantic check the condition
    condition->semanticCheck();

    // Check that the type of the condition is 'Testable'
    if ( !isTestable(condition) )
        REP_ERROR(condition->location(), "The condition of the if is not Testable");

    // Dereference the condition as much as possible
    while ( condition->type() && condition->type()->noReferences() > 0 )
    {
        condition = mkMemLoad(condition->location(), condition);
        condition->setContext(childrenContext());
        condition->semanticCheck();
    }
    children_[0] = condition;
    // TODO (if): Remove this dereference from here

    if ( nodeEvalMode(this) == modeCt )
    {
        if ( !isCt(condition) )
            REP_ERROR(condition->location(), "The condition of the ct if should be available at compile-time (%1%)") % condition->type();

        // Get the CT value from the condition, and select an active branch
        Node* c = theCompiler().ctEval(condition);
        Node* selectedBranch = getBoolCtValue(c) ? thenClause : elseClause;

        // Expand only the selected branch
        if ( selectedBranch )
            setExplanation(selectedBranch);
        else
            setExplanation(mkNop(location_));
        return;
    }

    // Semantic check the clauses
    if ( thenClause )
        thenClause->semanticCheck();
    if ( elseClause )
        elseClause->semanticCheck();
}
    void compileExpression()
    {
        ErrorReporter anErrorReporter( *static_cast< Tmixin_* >( this ) );
        PropertyAccess aPropertyAccess( *static_cast< Tmixin_* >( this ) );
        EntityResolver anEntityResolver( *static_cast< Tmixin_* >( this ) );
        VariableReferenceResolver aVarRefResolver( *static_cast< Tmixin_*>( this ) );
        libecs::scripting::ExpressionCompiler theCompiler(
                anErrorReporter, aPropertyAccess, anEntityResolver,
                aVarRefResolver );

        delete theCompiledCode;
        // it is possible that compileExpression throws an exception and
        // "theCompiledCode" remains uninitialized
        theCompiledCode = 0;

        theCompiledCode = theCompiler.compileExpression( theExpression );
    }