Example #1
0
void AssignmentStatement::evaluate(SymTab &symTab,
								   std::unique_ptr<FuncTab> &funcTab) {
	if(_lhsExpression == nullptr) {
        symTab.setValueFor(lhsVariable(),
						   rhsExpression()->evaluate(symTab, funcTab));
    } else {
		auto lhsindex = dynamic_cast<NumberDescriptor*>
			(_lhsExpression->evaluate(symTab, funcTab).get());
		if(lhsindex->type() != TypeDescriptor::INTEGER) {
			std::cout << "AssignmentStatement::evaluate error index must be";
			std::cout << " an integer\n";
			exit(1);
		}
		int index = lhsindex->value.intValue;
		auto lhs = symTab.getValueFor(lhsVariable());
		auto rhs = _rhsExpression->evaluate(symTab, funcTab);
		if(lhs->type() == TypeDescriptor::STRINGARRAY) {
            if(rhs->type() != TypeDescriptor::STRING){
                std::cout<<"array value not of compatible types"<<std::endl;
                exit(1);
            }
			auto desc = dynamic_cast<StringDescriptor*>(rhs.get());
            std::string val = desc->value;
            dynamic_cast<StringArray*>(lhs.get())->setSubStr(index, val);
        } else if(lhs->type() == TypeDescriptor::NUMBERARRAY) {
            if(rhs->type() != TypeDescriptor::INTEGER){
                std::cout<<"array value not of compatible types"<<std::endl;
                exit(1);
            }
			auto desc = dynamic_cast<NumberDescriptor*>(rhs.get());
			int val = desc->value.intValue;
            dynamic_cast<NumberArray*>(lhs.get())->setSubNum(index, val);
        } 
	}
}
Example #2
0
StmtIndex::StmtIndex(AstVariable* lhs,
                     AstIdxdata* rhs)
    : _rhsIdxdata(rhs)
{
    // set LHS variable
    lhsVariable(lhs);

    buoyancySink();
}
Example #3
0
StmtCreateData::StmtCreateData(AstVariable* lhs,
                               const bool lexScope)
    : _outerLexicalScope(lexScope),
      _initializeData(false),
      _uintValue(0),
      _intValue(0),
      _floatValue(0),
      _doubleValue(0)
{
    // set LHS variable
    lhsVariable(lhs);

    // array memory creation rises to the top
    buoyancyRise();
}
Example #4
0
StmtReduce::StmtReduce(AstVariable* lhs,
                       AstDotprod* rhs)
    : _rhsAccum(NULL),
      _rhsDotprod(rhs),
      _rhsW(rhs->insideW()),
      _rhsH(rhs->insideH()),
      _nestStmt()
{
    // set LHS variable
    lhsVariable(lhs);

    // code sinks
    buoyancySink();
    descendAst(*lhs);
}
Example #5
0
bool StmtReduce::randomness(void) const
{
    return lhsVariable()->randomness();
}