コード例 #1
0
ファイル: Environment.cpp プロジェクト: wrightaprilm/revbayes
/** Add alias to variable to frame. */
void Environment::addAlias( const std::string& name, const RevPtr<RevVariable>& theVar )
{
    
    /* Throw an error if the name string is empty. */
    if ( name == "" )
    {
        throw RbException("Invalid attempt to add unnamed reference variable to frame.");
    }
    
    /* Throw an error if the variable exists. Note that we cannot use the function
     existsVariable because that function looks recursively in parent frames, which
     would make it impossible to hide global variables. */
    if ( variableTable.find( name ) != variableTable.end() )
    {
        throw RbException( "Variable " + name + " already exists in frame" );
    }
    
    /* Insert new alias to variable in variable table (we do not and should not name it) */
    variableTable.insert( std::pair<std::string, RevPtr<RevVariable> >( name, theVar ) );
    
#ifdef DEBUG_WORKSPACE
    printf("Inserted \"%s\" (alias of \"%s\") in frame\n", name.c_str(), theVar->getName() );
#endif
    
}
コード例 #2
0
/** Get semantic value: insert symbol and return the rhs value of the assignment */
RevPtr<Variable> SyntaxDeterministicAssignment::evaluateContent( Environment& env )
{
#ifdef DEBUG_PARSER
    printf( "Evaluating deterministic assignment\n" );
#endif
    
    // Get the rhs expression wrapped and executed into a variable.
    // We need to call evaluateDynamicContent to get some elements
    // to evaluate their semantic content properly
    RevPtr<Variable> theVariable = rhsExpression->evaluateDynamicContent(env);
    
    // Get variable slot from lhs using the evaluateLHSContent to get the
    // appropriate behavior in the variable syntax element class.
    RevPtr<Variable> theSlot = lhsExpression->evaluateLHSContent( env, theVariable->getRevObject().getType() );

    // Check if the variable returned from the rhs expression is a named
    // variable in the environment. If so, we want to create an indirect
    // reference to it; otherwise, we want to fill the slot with a clone
    // of the variable returned by the rhs expression.
    if ( theVariable->getName() != "" )
        theSlot->setRevObject( theVariable->getRevObject().makeIndirectReference() );
    else
        theSlot->setRevObject( theVariable->getRevObject().clone() );
    
#ifdef DEBUG_PARSER
    env.printValue(std::cerr);
#endif    
    
    // We return the rhs variable itself as the semantic value of the
    // assignment statement. It can be used in further assignments.
    return theVariable;
}
コード例 #3
0
ファイル: Environment.cpp プロジェクト: wrightaprilm/revbayes
/**
 * Erase a variable by its address. We just delegate the call to erase by name.
 */
void Environment::eraseVariable(const RevPtr<RevVariable>& var)
{
    
    // Delegate call
    eraseVariable( var->getName() );
}