ExVal
ExVal::append(const ExVal v) const
{
	if (!is_list()||!v.is_list()) {
		MRSWARN("ExVal::append  only sequence types may be appended: "+getType()+", "+v.getType());
		return *this;
	}
	if (getType()==" list"||v.getType()==" list"||getType()==v.getType()) {
		mrs_natural len=natural_+v.toNatural(); ExNode** elems=new ExNode*[len];
		int l=0;
		if (natural_>0) {
			for (int i=0;i<natural_;++i,l++) {
				elems[l]=list_[i];
				elems[l]->inc_ref();
			}
		}
		if (v.toNatural()>0) {
			for (int i=0;i<v.toNatural();++i,l++) {
				elems[l]=v.list_[i];
				elems[l]->inc_ref();
			}
		}
		return ExVal(len,elems);
	}
	MRSWARN("ExVal::append  type mismatch in list concat: "+getType()+","+v.getType());
	return *this;
}
ExNode::ExNode(ExVal v) : ExRefCount()
{
	init();
	setKind(T_CONST); // what about list types
	setType(v.getType());
//    std::cout<<"ExNode<"<<getType()<<">\n";
	value=v;
}
예제 #3
0
파일: ExSymTbl.cpp 프로젝트: BitMax/marsyas
void
ExRecord::setValue(ExVal& v, std::string path, int elem_pos)
{
  if (path!="") {
    // get leading name in group: a|b|c.d|e|f.g|h|i => a|b|c d|e|f.g|h|i
    std::string name; split_on(path,'.',name,path);
    if (path!="") { // then ghd is the variable name
      // get leading name in name: a|b|c => a b|c
      std::map<std::string, ExRecord*>::iterator iter=syms_.find(name);
      ExRecord* syms=NULL;
      if (iter==syms_.end()) { syms=new ExRecord(); syms_[name]=syms; syms->inc_ref(); }
      else { syms=iter->second; }
      syms->setValue(v,path);
      return;
    }
    else {
      // get leading name in name: a|b|c => a b|c
      std::map<std::string, ExRecord*>::iterator iter=syms_.find(name);
      if (iter==syms_.end()) { // not in table, so add it
        ExRecord* r=new ExRecord(T_VAR,name,v,false); r->inc_ref();
        syms_[name]=r;
        return;
      }
      else {
        (iter->second)->setValue(v);
        return;
      }
    }
  }
  if (getKind()!=T_VAR) {
    MRSWARN("ExRecord::setValue   Attempting assignment to non-variable");
  }
  else if (elem_pos>=0) {
    if (getElemType()!=v.getType()) {
      MRSWARN("ExRecord::setValue   Type mismatch in assignment of element: "+getElemType()+" << "+v.getType());
    }
    else value_.setSeqElem(elem_pos, v);
  }
  else if (getType()!=v.getType()) {
    MRSWARN("ExRecord::setValue   Type mismatch in assignment: "+getType()+" << "+v.getType());
  } else value_=v;
}