예제 #1
0
파일: DataSchema.cpp 프로젝트: noriter/nit
	Schema() : DataSchema("nit.test.TestDataObject.1.0")
	{
		newProperty("Name")
			.type(DataValue::TYPE_STRING)
			.bind(PropGetName, PropSetName);

		newProperty("Age")
			.type(DataValue::TYPE_INT)
			.bind(PropGetAge, PropSetAge);

		newProperty("BirthYear")
			.type(DataValue::TYPE_INT)
			.bind(PropGetBirthYear, NULL);
	}
예제 #2
0
    bool addKeyword(const std::string& keywordName) {
        if (!supportsKeyword( keywordName ))
            throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container");

        if (hasKeyword(keywordName))
            return false;
        else {
            // if the property was already added auto generated, we just need to make it
            // non-auto generated
            if (m_autoGeneratedProperties_.count(keywordName)) {
                OpmLog::addMessage(Log::MessageType::Warning,
                                   "The keyword "+keywordName+" has been used to calculate the "
                                   "defaults of another keyword before the first time it was "
                                   "explicitly mentioned in the deck. Maybe you need to change "
                                   "the ordering of your keywords (move "+keywordName+" to the "
                                   "front?).");
                m_autoGeneratedProperties_.erase(m_autoGeneratedProperties_.find(keywordName));
                return true;
            }

            auto supportedKeyword = m_supportedKeywords.at( keywordName );
            int nx = m_eclipseGrid->getNX();
            int ny = m_eclipseGrid->getNY();
            int nz = m_eclipseGrid->getNZ();
            std::shared_ptr<GridProperty<T> > newProperty(new GridProperty<T>(nx , ny , nz , supportedKeyword));

            m_properties.insert( std::pair<std::string , std::shared_ptr<GridProperty<T> > > ( keywordName , newProperty ));
            m_property_list.push_back( newProperty );
            return true;
        }
    }
예제 #3
0
//! \brief Clears focus if escape key pressed. Otherwise calls base method.
void PropertyItem::keyPressEvent(QKeyEvent *e)
{
    if(e->key() == Qt::Key_Escape) {
        clearFocus();
        return;
    }
    QVariant oldProperty(component()->property(m_propertyName));
    if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
        if(m_edited &&
                component()->setProperty(m_propertyName, QVariant(toPlainText()))) {
            updateGroupGeometry();
            m_edited = false;
            QVariant newProperty(component()->property(m_propertyName));
            PropertiesGroup *parentGroup = static_cast<PropertiesGroup*>(group());
            Q_ASSERT(parentGroup);
            SchematicScene *schScene = parentGroup->schematicScene();
            schScene->undoStack()->push(new PropertyChangeCmd(m_propertyName,
                        newProperty, oldProperty, component()));
        }
        clearFocus();
        return;
    }

    m_edited = true;
    QGraphicsTextItem::keyPressEvent(e);
}
예제 #4
0
    bool addAutoGeneratedKeyword_(const std::string& keywordName) const {
        if (!supportsKeyword( keywordName ))
            throw std::invalid_argument("The keyword: " + keywordName + " is not supported in this container");

        if (m_properties.count( keywordName ) > 0)
            return false; // property already exists (if it is auto generated or not doesn't matter)
        else {
            auto supportedKeyword = m_supportedKeywords.at( keywordName );
            int nx = m_eclipseGrid->getNX();
            int ny = m_eclipseGrid->getNY();
            int nz = m_eclipseGrid->getNZ();
            std::shared_ptr<GridProperty<T> > newProperty(new GridProperty<T>(nx , ny , nz , supportedKeyword));

            m_autoGeneratedProperties_.insert(keywordName);

            m_properties.insert( std::pair<std::string , std::shared_ptr<GridProperty<T> > > ( keywordName , newProperty ));
            m_property_list.push_back( newProperty );
            return true;
        }
    }
예제 #5
0
	END_IT
	
	IT("Parses date and time strings")
		str1 = newString(strDup("3/24/1988 5:42am"));
		SHOULD_EQUAL(newDate(str1), 575185320)
		freeStr(str1);
		str2 = newString(strDup("10/11/2000   15:12:34"));
		SHOULD_EQUAL(newDate(str2), 971277154)
		freeStr(str2);
	END_IT
END_DESCRIBE

DESCRIBE(newObject, "tap_obj* newObject (datatype type, property* props)")
	IT("Creates a new object with the given type and properties")
		expression* expr = newExpressionInt(5);
		tap_obj* obj = newObject(TYPE_OBJ, newProperty("x", newTypelist(TYPE_INT), PROP_PRIVACY_PUBLIC, PROP_RANGE_LOCAL, expr));
		SHOULD_EQUAL(obj->type, TYPE_OBJ)
		SHOULD_EQUAL(strcmp(obj->props->name, "x"), 0)
		freeExpr(expr);
		freeObj(obj);
	END_IT
END_DESCRIBE

DESCRIBE(copyObject, "tap_obj* copyObject (tap_obj* obj)")
	IT("Copies the given object, copying its type and properties")
		expression* expr = newExpressionFlo(-9.8);
		tap_obj* obj1 = newObject(TYPE_OBJ, newProperty("y", newTypelist(TYPE_FLO), PROP_PRIVACY_PRIVATE, PROP_RANGE_GLOBAL, expr));
		tap_obj* obj2 = copyObject(obj1);
		SHOULD_NOT_EQUAL(obj1, obj2)
		SHOULD_EQUAL(obj1->type, obj2->type)
		SHOULD_NOT_EQUAL(obj1->props, obj2->props)
예제 #6
0
void InternalNode::addNodeListProperty(const QString &name)
{
    InternalProperty::Pointer newProperty(InternalNodeListProperty::create(name, internalPointer()));
    m_namePropertyHash.insert(name, newProperty);
}
예제 #7
0
파일: DataSchema.cpp 프로젝트: noriter/nit
DataProperty& DataSchema::newProperty(const String& name)
{
	Ref<DataKey> key = _namespace->add(name);

	return newProperty(key);
}
예제 #8
0
int
inlineMALblock(MalBlkPtr mb, int pc, MalBlkPtr mc)
{
	int i, k, l, n;
	InstrPtr *ns, p,q;
	int *nv, *np = NULL;

	p = getInstrPtr(mb, pc);
	q = getInstrPtr(mc, 0);
	ns = GDKzalloc((l = (mb->ssize + mc->ssize + p->retc - 3)) * sizeof(InstrPtr));
	if (ns == NULL)
		return -1;
	if ( mc->ptop > 0){
		np = (int*) GDKmalloc(mc->ptop * sizeof(int));
		if (np == 0){
			GDKfree(ns);
			return -1;
		}
	}
	nv = (int*) GDKmalloc(mc->vtop * sizeof(int));
	if (nv == 0){
		GDKfree(ns);
		if( np)
			GDKfree(np);
		return -1;
	}

	/* add all properties of the new block to the target environment */
	for (n = 0; n < mc->ptop; n++) {
		int propid = newProperty(mb);

		if (propid < 0) {
			assert(0);
			return -1;
		}
		np[n] = propid; 
		mb->prps[propid].idx = mc->prps[n].idx;
		mb->prps[propid].op = mc->prps[n].op;
		mb->prps[propid].var = mc->prps[n].var; /* fixed later */
	}

	/* add all variables of the new block to the target environment */
	for (n = 0; n < mc->vtop; n++) {
		VarPtr ov, v;

		if (isExceptionVariable(mc->var[n]->name)) {
			nv[n] = newVariable(mb,GDKstrdup(mc->var[n]->name),TYPE_str);
			if (isVarUDFtype(mc,n))
				setVarUDFtype(mb,nv[n]);
			if (isVarUsed(mc,n))
				setVarUsed(mb,nv[n]);
		} else if (isVarTypedef(mc,n)) {
			nv[n] = newTypeVariable(mb,getVarType(mc,n));
		} else if (isVarConstant(mc,n)) {
			nv[n] = cpyConstant(mb,getVar(mc,n));
		} else {
			nv[n] = newTmpVariable(mb, getVarType(mc, n));
			if (isVarUDFtype(mc,n))
				setVarUDFtype(mb,nv[n]);
			if (isVarUsed(mc,n))
				setVarUsed(mb,nv[n]);
		}
		/* remap the properties */
		ov = getVar(mc, n);
		v = getVar(mb, nv[n]);
		if (ov->propc > v->maxprop) {
			int size = sizeof(VarRecord);
        		VarPtr vnew = (VarPtr) GDKzalloc(size + ov->propc * sizeof(int));
			memcpy((char*) vnew, (char*) v, size);
			vnew->maxprop = ov->propc;
			mb->var[nv[n]] = vnew;
			GDKfree(v);
			v = getVar(mb, nv[n]);
		}
		for (i = 0; i < ov->propc; i++) 
			v->prps[i] = np[ov->prps[i]];
		v->propc = ov->propc;
	}

	/* change the property variables to the new context */
	for (n = 0; n < mc->ptop; n++) {
		if (mc->prps[n].var)
			mb->prps[np[n]].var = nv[mc->prps[n].var];
		assert( mb->prps[np[n]].var >= 0);
	}

	/* use an alias mapping to keep track of the actual arguments */
	for (n = p->retc; n < p->argc; n++)
		nv[getArg(q,n)] = getArg(p, n);

	k = 0;
	/* find the return statement of the inline function */
	for (i = 1; i < mc->stop - 1; i++) {
		q = mc->stmt[i];
		if( q->barrier== RETURNsymbol || q->barrier== YIELDsymbol){
			/* add the mapping of the return variables */
			for(n=0; n<p->retc; n++)
				nv[getArg(q,n)] = getArg(p,n);
		}
	}

	/* copy the stable part */
	for (i = 0; i < pc; i++)
		ns[k++] = mb->stmt[i];

	for (i = 1; i < mc->stop - 1; i++) {
		q = mc->stmt[i];
		if( q->token == ENDsymbol)
			break;

		/* copy the instruction and fix variable references */
		ns[k] = copyInstruction(q);
		for (n = 0; n < q->argc; n++)
			getArg(ns[k], n) = nv[getArg(q, n)];

		if (q->barrier == RETURNsymbol || q->barrier == YIELDsymbol) {
			for(n=0; n<q->retc; n++)
				clrVarFixed(mb,getArg(ns[k],n)); /* for typing */
			setModuleId(ns[k],getModuleId(q));
			setFunctionId(ns[k],getFunctionId(q));
			ns[k]->barrier = 0;
			ns[k]->token = ASSIGNsymbol;
		}
		k++;
	} 

	/* copy the remainder of the stable part */
	freeInstruction(p);
	for (i = pc + 1; i < mb->stop; i++){
		ns[k++] = mb->stmt[i];
	}
	/* remove any free instruction */
	for(; i<mb->ssize; i++)
	if( mb->stmt[i]){
		freeInstruction(mb->stmt[i]);
		mb->stmt[i]= 0;
	}
	GDKfree(mb->stmt);
	mb->stmt = ns;

	mb->ssize = l;
	mb->stop = k;
	GDKfree(np);
	GDKfree(nv);
	return pc;
}
예제 #9
0
static Stack readActionRecord(FILE *f)
{
  int length = 0, type = readUInt8(f);

  if((type&0x80) == 0x80)
    length = readUInt16(f);

  switch(type)
  {
    /* no-arg */
    case SWFACTION_GETTIMER:
    case SWFACTION_STOPDRAGMOVIE:
    case SWFACTION_NEXTFRAME:
    case SWFACTION_PREVFRAME:
    case SWFACTION_PLAY:
    case SWFACTION_STOP:
    case SWFACTION_TOGGLEQUALITY:
    case SWFACTION_STOPSOUNDS:
      return newTree(NULL, type, NULL);

    case SWFACTION_POP:
	  /* pop(); */
      return newTree(NULL, type, NULL);

    /* one-arg */
    case SWFACTION_STRINGLENGTH:
    case SWFACTION_INT:
    case SWFACTION_RANDOM:
    case SWFACTION_MBLENGTH:
    case SWFACTION_ORD:
    case SWFACTION_CHR:
    case SWFACTION_MBORD:
    case SWFACTION_MBCHR:
    case SWFACTION_LOGICALNOT:
    case SWFACTION_GETVARIABLE:
    case SWFACTION_REMOVECLIP:
    case SWFACTION_TRACE:
    case SWFACTION_SETTARGETEXPRESSION:
    case SWFACTION_CALLFRAME:
      return newTree(pop(), type, NULL);

    /* two-arg */
    case SWFACTION_ADD:
    case SWFACTION_MULTIPLY:
    case SWFACTION_DIVIDE:
    case SWFACTION_EQUAL:
    case SWFACTION_LESSTHAN:
    case SWFACTION_LOGICALAND:
    case SWFACTION_LOGICALOR:
    case SWFACTION_STRINGEQ:
    case SWFACTION_SETVARIABLE:
    case SWFACTION_STRINGCONCAT:
    case SWFACTION_STRINGCOMPARE:
	{
      Stack right = pop();
      Stack left = pop();
      return newTree(left, type, right);
	}

    case SWFACTION_GETPROPERTY:
    {
      Stack right = pop();
      Stack left = pop();

      if(right->type == 's')
      {
	Stack New = newProperty(atoi(right->data.string));
	destroy(right);
	right = New;
      }
      return newTree(left, type, right);
    }

    case SWFACTION_SUBTRACT:
    {
      Stack right = pop();
      Stack left = pop();

      if(left->type == 's' &&
	 strcmp(left->data.string, "0") == 0)
      {
	destroy(left);
	right->data.string = negateString(right->data.string);
	return right;
      }

      return newTree(left, type, right);
    }

    /* three-arg */
    case SWFACTION_SETPROPERTY:
	{
	  Stack value = pop();
	  Stack property = pop();
	  Stack target = pop();

      if(property->type == 's')
      {
	Stack New = newProperty(atoi(property->data.string));
	destroy(property);
	property = New;
      }

      return newTree(newTree(target, type, property),
		     SWFACTION_SETVARIABLE, value);
	}

    case SWFACTION_MBSUBSTRING:
    case SWFACTION_SUBSTRING:
	{
	  Stack s3 = pop();
	  Stack s2 = pop();
	  Stack s1 = pop();
      return newTree(s1, type, newTree(s2, type, s3));
	}

    case SWFACTION_DUPLICATECLIP:
    {
      Stack level = pop();
      Stack target = pop();
      Stack source = pop();
      Stack arg;

      if(level->type != 't' ||
	 level->data.tree->action != SWFACTION_ADD)
	error("WTHIT property not found in duplicateClip target level!");

      if(level->data.tree->left->type == 'p' &&
	 level->data.tree->left->data.prop == PROPERTY_WTHIT)
      {
        arg = level->data.tree->right;
	level->data.tree->right = NULL;
      }
      else if(level->data.tree->right->type == 'p' &&
	      level->data.tree->right->data.prop == PROPERTY_WTHIT)
      {
        arg = level->data.tree->left;
        level->data.tree->left = NULL;
      }
      else
	error("WTHIT property not found in duplicateClip target level!");

      destroy(level);

      return newTree(source, type, newTree(target, type, arg));
    }


    /* weird ops */
    case SWFACTION_STARTDRAGMOVIE:
    {
      Stack target = pop();
      Stack lockmouse = pop();
      Stack constraint = pop();

      if(constraint->type != 's')
	error("Sorry, decompiler can't deal with conditional constraint!");

      if(strcmp(constraint->data.string, "0") == 0)
	return newTree(constraint, type, newTree(lockmouse, type, target));
      else
	  {
		Stack s4 = pop();
		Stack s3 = pop();
		Stack s2 = pop();
		Stack s1 = pop();

	return newTree(newTree(newTree(s1, type, s2), type,
			       newTree(s3, type, s4)), type,
		       newTree(lockmouse, type, target));
	  }
    }

    case SWFACTION_PUSHDATA:
    {
      int local_type = readUInt8(f);
      if(local_type==0)
	return newString(readString(f));
      else
      {
	readUInt16(f); /* 0x0000 */
        return newProperty(getSetProperty(readUInt16(f)));
      }
    }

    case SWFACTION_GOTOFRAME:
      return newTree((Stack)readUInt16(f), type, NULL);

    case SWFACTION_GETURL:
    {
      char *url = readString(f);
      char *target = readString(f);
      return newTree((Stack)url, type, (Stack)target);
    }

    case SWFACTION_GETURL2:
	{
	  Stack target = pop();
	  Stack url = pop();
      return newTree((Stack)readUInt8(f), type, newTree(url, type, target));
	}

    case SWFACTION_WAITFORFRAMEEXPRESSION:
      return newTree((Stack)readUInt8(f), type, NULL);

    case SWFACTION_GOTOEXPRESSION:
      return newTree(pop(), type, (Stack)readUInt8(f));

    case SWFACTION_SETTARGET:
    case SWFACTION_GOTOLABEL:
      return newTree((Stack)readString(f), type, NULL);


    /* branches */
    case SWFACTION_BRANCHIFTRUE:
      return newTree(pop(), type, (Stack)readSInt16(f));

    case SWFACTION_BRANCHALWAYS:
      return newTree(NULL, type, (Stack)readSInt16(f));

    case SWFACTION_WAITFORFRAME:
	{
	  Stack left = (Stack)readUInt16(f);
	  Stack right = (Stack)readUInt8(f);
      return newTree(left, type, right);
	}

    case SWFACTION_END:
      return NULL;

    default:
      printf("Unknown Action: %02X\n", type);
      dumpBytes(f, length);
      return NULL;
  }
}
예제 #10
0
void InternalNode::addVariantProperty(const PropertyName &name)
{
    InternalProperty::Pointer newProperty(InternalVariantProperty::create(name, internalPointer()));
    m_namePropertyHash.insert(name, newProperty);
}
예제 #11
0
void InternalNode::addSignalHandlerProperty(const PropertyName &name)
{
    InternalProperty::Pointer newProperty(InternalSignalHandlerProperty::create(name, internalPointer()));
    m_namePropertyHash.insert(name, newProperty);
}
예제 #12
0
파일: Reader.cpp 프로젝트: joeld42/gto
//-*****************************************************************************
Reader::Request
Reader::property( const std::string &name, 
                  const std::string &pre_ininterp,
                  const PropertyInfo &info ) 
{
    // Fix interp for versions prior to 3.
    std::string ininterp = pre_ininterp;
    if ( fileHeader().version < 3 )
    {
        ininterp = GTO_INTERPRET_DEFAULT;
    }
    
    if ( m_objects == NULL )
    {
        GTC_THROW( "Reader reading without objects" );
    }
    
    std::string interp;

    // In case you need the property container, here it is.
    // PropertyContainer *pc  = 
    //    reinterpret_cast<PropertyContainer*>(
    //         info.component->object->objectData );
    
    Component *c =
        reinterpret_cast<Component*>( info.component->componentData );
    Property *p  = c->find( name );
    Property *np = NULL;

    // Only use the part of the interpretation up to the first semicolon.
    size_t sq = ininterp.find( ';' );

    if ( sq != std::string::npos )
    {
        interp = ininterp.substr( 0, sq );
    }
    else
    {
        interp = ininterp;
    }

    // If there's no interpretation, change the interpretation to
    // GTO_INTERPRET_DEFAULT
    if ( interp == "" )
    {
        interp = GTO_INTERPRET_DEFAULT;
    }   

    // If the property doesn't exist, try the virtual 'newProperty' function
    // which returns NULL by default. If it makes a property, awesome! Use
    // that. If not, continue below.
    if ( p == NULL )
    {
        if ( (np = newProperty( name, info )) )
        {
            c->add( np );
            np->resize( info.size );
            return Request( true, np );
        }
    }
    
    // From the layout, width & interpretation, build us a new
    // property, OR, verify that the old property is the right upcastable
    // type.
    Layout layout = gtoTypeToLayout( ( Gto::DataType )( info.type ) );
    const MetaProperty *metaProp = findMetaProperty( layout,
                                                     info.width,
                                                     interp );
    if ( metaProp == NULL )
    {
        std::cerr << "GtoContainer::Reader WARNING: "
                  << "Ignoring property \"" << name << "\""
                  << std::endl;
        return Request( false );
    }

    Property *newProp = NULL;
    if ( p != NULL )
    {
        if ( !metaProp->validUpcast( p ) )
        {
            throw TypeMismatchExc();
        }

        newProp = p;
    }
    else
    {
        newProp = metaProp->create( name );
        c->add( newProp );
    }

    // If we get here, we've got a new property, ready to receive data.
    // Resize it and send out the Request.
    assert( newProp != NULL );
    newProp->resize( info.size );
    return Request( true, newProp );
}
예제 #13
0
/*! Copies the given property with its name, type restrictions, privacy, and range
    @param prop     the property to copy
    @return         the new, duplicate property
*/
property* copyProperty (property* prop) {
    return newProperty(prop->name, copyTypelistDeep(prop->types), prop->privacy, prop->range, prop->value);
}