Example #1
0
  Status GRCsim::visit(BinaryOp &e)
  {
    assert(e.source1);
    assert(e.source2);
    if(debug) cerr<<"Warning: 3-valued-simulator does NOT support BinaryOp yet!\n";
    int val1 = intVal(e.source1);
    int val2 = intVal(e.source2);

    int result =
      (e.op == "and") ? (val1 && val2) :
      (e.op == "or") ? (val1 || val2) :
      (e.op == "+") ? (val1 + val2) :
      (e.op == "-") ? (val1 - val2) :
      (e.op == "*") ? (val1 * val2) :
      (e.op == "/") ? (val1 / val2) :
      (e.op == "mod") ? (val1 % val2) :
      (e.op == "=") ? (val1 == val2) :
      (e.op == "<>") ? (val1 != val2) :
      (e.op == "<") ? (val1 < val2) :
      (e.op == "<=") ? (val1 <= val2) :
      (e.op == ">") ? (val1 > val2) :
      (e.op == ">=") ? (val1 >= val2) :
      0;

    return Status(result);
  }
Example #2
0
void cShortcut::attribChanged (const QString &name)
{
  if (name == "command") {
    d->command = strVal ("command");
    updateVisibleName ();
    return;
  }
  if (name == "key") {
    d->key = intVal ("key");
    updateVisibleName ();
    return;
  }
  if (name == "modifiers") {
    d->modifiers = intVal ("modifiers");
    updateVisibleName ();
    return;
  }
  if (name == "send") {
    d->send = boolVal ("send");
    return;
  }
  if (name == "overwrite") {
    d->overwrite = boolVal ("overwrite");
    return;
  }
  if (name == "script") updateVisibleName ();
}
Example #3
0
void cgStElem(IRLS& env, const IRInstruction* inst) {
  auto const rbase = srcLoc(env, inst, 0).reg();
  auto const ridx = srcLoc(env, inst, 1).reg();
  auto const idx = inst->src(1);
  auto& v = vmain(env);

  if (idx->hasConstVal() && deltaFits(idx->intVal(), sz::dword)) {
    storeTV(v, rbase[idx->intVal()], srcLoc(env, inst, 2), inst->src(2));
  } else {
    storeTV(v, rbase[ridx], srcLoc(env, inst, 2), inst->src(2));
  }
}
Example #4
0
void cgLdElem(IRLS& env, const IRInstruction* inst) {
  auto const rbase = srcLoc(env, inst, 0).reg();
  auto const ridx = srcLoc(env, inst, 1).reg();
  auto const idx = inst->src(1);
  auto& v = vmain(env);

  if (idx->hasConstVal() && deltaFits(idx->intVal(), sz::dword)) {
    loadTV(v, inst->dst(), dstLoc(env, inst, 0), rbase[idx->intVal()]);
  } else {
    loadTV(v, inst->dst(), dstLoc(env, inst, 0), rbase[ridx]);
  }
}
Example #5
0
/*
 * Extract an int64 value from a DefElem.
 */
int64
defGetInt64(DefElem *def)
{
	if (def->arg == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 errmsg("%s requires a numeric value",
						def->defname)));
	switch (nodeTag(def->arg))
	{
		case T_Integer:
			return (int64) intVal(def->arg);
		case T_Float:

			/*
			 * Values too large for int4 will be represented as Float
			 * constants by the lexer.	Accept these if they are valid int8
			 * strings.
			 */
			return DatumGetInt64(DirectFunctionCall1(int8in,
										 CStringGetDatum(strVal(def->arg))));
		default:
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("%s requires a numeric value",
							def->defname)));
	}
	return 0;					/* keep compiler quiet */
}
Example #6
0
/*
 * BeginStreamScan
 */
void
BeginStreamScan(ForeignScanState *node, int eflags)
{
    ForeignScan *plan = (ForeignScan *) node->ss.ps.plan;
    StreamScanState *state;
    ListCell *lc;
    List *colnames = (List *) linitial(plan->fdw_private);
    List *physical_tlist = (List *) lsecond(plan->fdw_private);
    Value *sample_cutoff = (Value *) lthird(plan->fdw_private);
    int i = 0;

    state = palloc0(sizeof(StreamScanState));

    state->pi = palloc(sizeof(StreamProjectionInfo));
    state->pi->mcxt = AllocSetContextCreate(CurrentMemoryContext,
                                            "ExecProjectContext",
                                            ALLOCSET_DEFAULT_MINSIZE,
                                            ALLOCSET_DEFAULT_INITSIZE,
                                            ALLOCSET_DEFAULT_MAXSIZE);

    state->pi->ecxt = CreateStandaloneExprContext();
    state->pi->outdesc = ExecTypeFromTL(physical_tlist, false);
    state->pi->indesc = NULL;
    state->sample_cutoff = sample_cutoff ? intVal(sample_cutoff) : -1;

    Assert(state->pi->outdesc->natts == list_length(colnames));

    foreach(lc, colnames)
    {
        Value *v = (Value *) lfirst(lc);
        namestrcpy(&(state->pi->outdesc->attrs[i++]->attname), strVal(v));
    }
Example #7
0
Variant SSATmp::variantVal() const {
  switch (type().toDataType()) {
    case KindOfUninit:
    case KindOfNull:
      // Upon return both will converted to KindOfNull anyway.
      return init_null();
    case KindOfBoolean:
      return boolVal();
    case KindOfInt64:
      return intVal();
    case KindOfDouble:
      return dblVal();
    case KindOfStaticString:
    case KindOfString:
      return Variant(const_cast<StringData*>(strVal()));
    case KindOfArray:
      return const_cast<ArrayData*>(arrVal());
    case KindOfObject:
    case KindOfResource:
    case KindOfRef:
    case KindOfClass:
      break;
  }
  not_reached();
}
Example #8
0
/*
 * Extract a string value (otherwise uninterpreted) from a DefElem.
 */
char *
defGetString(DefElem *def)
{
	if (def->arg == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 errmsg("%s requires a parameter",
						def->defname)));
	switch (nodeTag(def->arg))
	{
		case T_Integer:
			{
				char	   *str = palloc(32);

				snprintf(str, 32, "%ld", (long) intVal(def->arg));
				return str;
			}
		case T_Float:

			/*
			 * T_Float values are kept in string form, so this type cheat
			 * works (and doesn't risk losing precision)
			 */
			return strVal(def->arg);
		case T_String:
			return strVal(def->arg);
		case T_TypeName:
			return TypeNameToString((TypeName *) def->arg);
		case T_List:
			return NameListToString((List *) def->arg);
		default:
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
	}
	return NULL;				/* keep compiler quiet */
}
Example #9
0
 Status GRCsim::visit(StartCounter &stcnt)
 {
   if (debug) cerr << ":start counter\n";
   if(debug) cerr<<"Warning: 3-valued-simulator does NOT support StartCounter yet!\n";
   assert(stcnt.counter);
   assert(stcnt.count);
   counters[stcnt.counter] = intVal(stcnt.count);
   return Status();
 }
Example #10
0
  Status GRCsim::visit(CheckCounter &chkcnt)
  {
    assert(chkcnt.counter);
    assert(chkcnt.predicate);
    if (intVal(chkcnt.predicate))
      counters[chkcnt.counter]--;

    return Status( counters[chkcnt.counter] == 0);
  }
Example #11
0
// Read next sector of stream
void ole2_bufread(OLE2Stream* olest) 
{
	BYTE *ptr;

	assert(olest);
	assert(olest->ole);

    if ((DWORD)olest->fatpos!=ENDOFCHAIN)
    {
		if(olest->sfat) {
			assert(olest->ole->SSAT);
			assert(olest->buf);
			assert(olest->ole->SSecID);

			ptr = olest->ole->SSAT + olest->fatpos*olest->ole->lssector;
			memcpy(olest->buf, ptr, olest->bufsize); 

			olest->fatpos=intVal(olest->ole->SSecID[olest->fatpos]);
			olest->pos=0;
			olest->cfat++;
		} else {

			assert(olest->fatpos >= 0);

			//printf("fatpos: %d max=%u\n",olest->fatpos, (olest->ole->cfat*olest->ole->lsector)/4);
			if(olest->fatpos > (olest->ole->cfat*olest->ole->lsector)/4) exit(-1);

#if 0 // TODO: remove
			fseek(olest->ole->file,olest->fatpos*olest->ole->lsector+512,0);
			ret = fread(olest->buf,1,olest->bufsize,olest->ole->file);
			assert(ret == olest->bufsize);
#endif
			assert((int)olest->fatpos >= 0);
			sector_read(olest->ole, olest->buf, olest->fatpos);
			//printf("Fat val: %d[0x%X]\n",olest->fatpos,olest->ole->SecID[olest->fatpos], olest->ole->SecID[olest->fatpos]);
			olest->fatpos=intVal(olest->ole->SecID[olest->fatpos]);
			olest->pos=0;
			olest->cfat++;
		}
    }
	// else printf("ENDOFCHAIN!!!\n");
}
TInt COpenMAXALTestModule::validateAudioCodecDescriptorAtIndex(
        XAuint32 aAudioCodecId,
        XAAudioCodecDescriptor& aDesc,
        CStifItemParser& aItem )
    {
    TInt status(KErrNone);
    TInt intVal(0);
    TInt loopIndex(0);
    
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.maxChannels);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.minBitsPerSample);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.maxBitsPerSample);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.minSampleRate);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.maxSampleRate);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.isFreqRangeContinuous);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.numSampleRatesSupported);
    for(loopIndex = 0; loopIndex < aDesc.numSampleRatesSupported; loopIndex++)
        {
        RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.pSampleRatesSupported[loopIndex]);
        }
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.minBitRate);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.maxBitRate);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.isBitrateRangeContinuous);
    RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.numBitratesSupported);
    for(loopIndex = 0; loopIndex < aDesc.numBitratesSupported; loopIndex++)
        {
        RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.pBitratesSupported[loopIndex]);
        }
    switch (aAudioCodecId)
        {
        case XA_AUDIOCODEC_PCM:
            RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.profileSetting);
            if (!status)
                {
                RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.modeSetting);
                }
            break;
        case XA_AUDIOCODEC_AMR:
            RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.profileSetting);
            if (!status)
                {
                RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.modeSetting);
                }
            break;
        case XA_AUDIOCODEC_AAC:
            RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.profileSetting);
            if (!status)
                {
                RETURN_ERR_IF_NOT_EQUAL(aItem, intVal, aDesc.modeSetting);
                }
            break;
        }
    return status;
    }
Example #13
0
  Status GRCsim::visit(UnaryOp &e)
  {
    if(debug) cerr<<"Warning: 3-valued-simulator does NOT support UnaryOp yet!\n";

    int val = intVal(e.source);

    int result =
      (e.op == "not") ? ( !val ) :
      (e.op == "-") ? ( -val ) :
      0;
     
    return Status(result);
  }
Example #14
0
/*
 * Extract a boolean value from a DefElem.
 */
bool
defGetBoolean(DefElem *def)
{
	/*
	 * If no parameter given, assume "true" is meant.
	 */
	if (def->arg == NULL)
		return true;

	/*
	 * Allow 0, 1, "true", "false", "on", "off"
	 */
	switch (nodeTag(def->arg))
	{
		case T_Integer:
			switch (intVal(def->arg))
			{
				case 0:
					return false;
				case 1:
					return true;
				default:
					/* otherwise, error out below */
					break;
			}
			break;
		default:
			{
				char	   *sval = defGetString(def);

				/*
				 * The set of strings accepted here should match up with the
				 * grammar's opt_boolean production.
				 */
				if (pg_strcasecmp(sval, "true") == 0)
					return true;
				if (pg_strcasecmp(sval, "false") == 0)
					return false;
				if (pg_strcasecmp(sval, "on") == 0)
					return true;
				if (pg_strcasecmp(sval, "off") == 0)
					return false;
			}
			break;
	}
	ereport(ERROR,
			(errcode(ERRCODE_SYNTAX_ERROR),
			 errmsg("%s requires a Boolean value",
					def->defname)));
	return false;				/* keep compiler quiet */
}
Example #15
0
  Status GRCsim::visit(Emit &e)
  {
    assert(e.signal);
    SignalSymbol *ss = e.signal;
    if(ss->type && ss->type->name=="integer"){
  	signals_v[ss]=intVal(e.value);
  	if(debug) cerr<<" value : "<<signals_v[ss]<<" ";
    }
    if (debug) cerr << ":emit " << ss->name <<" = "<<globalcc<< endl;
    if(signals[ss] != 1)
      signals[ss] = globalcc;

    return Status();
  }
Example #16
0
// Move in stream
void ole2_seek(OLE2Stream* olest,DWORD ofs)
{
	if(olest->sfat) {
		ldiv_t div_rez=ldiv(ofs,olest->ole->lssector);
		int i;
		olest->fatpos=olest->start;

		if (div_rez.quot!=0)
		{
			for (i=0;i<div_rez.quot;i++)
				olest->fatpos=intVal(olest->ole->SSecID[olest->fatpos]);
		}

		ole2_bufread(olest);
		olest->pos=div_rez.rem;
		olest->eof=0;
		olest->cfat=div_rez.quot;
		//printf("%i=%i %i\n",ofs,div_rez.quot,div_rez.rem);
	} else {
		ldiv_t div_rez=ldiv(ofs,olest->ole->lsector);
		int i;
		olest->fatpos=olest->start;

		if (div_rez.quot!=0)
		{
			for (i=0;i<div_rez.quot;i++)
				olest->fatpos=intVal(olest->ole->SecID[olest->fatpos]);
		}

		ole2_bufread(olest);
		olest->pos=div_rez.rem;
		olest->eof=0;
		olest->cfat=div_rez.quot;
		//printf("%i=%i %i\n",ofs,div_rez.quot,div_rez.rem);
	}
}
Example #17
0
  Status GRCsim::visit(Assign &a)
  {
    assert(a.variable);
    assert(a.value);
    assert(a.variable->type);

    if(debug) cerr<<"Warning: 3-valued-simulator does NOT support Assign yet!\n";

    if (a.variable->type->name != "integer" &&
        a.variable->type->name != "boolean") {
      throw IR::Error("Only integer and boolean variables supported");
    }

    var[a.variable] = intVal(a.value);

    return Status();
  }
Example #18
0
std::string Instruction::getJumpName() {
  std::string result = "";
  bitset<26> jmp = jmp_offset();
  bitset<32> intVal(0);

  for( int i = 0; i < 26; i++ ) {
    intVal[i] = jmp[i];
  }

  for( int i = 26; i < 32; i++ ) {
    intVal[i] = jmp[25];
  }

  std::cout << intVal.to_string() << std::endl;

  result = std::to_string( static_cast<int>( intVal.to_ulong() ) );
  return result;
}
Example #19
0
TEST(Type, Const) {
  auto five = Type::cns(5);
  EXPECT_LT(five, Type::Int);
  EXPECT_NE(five, Type::Int);
  EXPECT_TRUE(five.isConst());
  EXPECT_EQ(5, five.intVal());
  EXPECT_TRUE(five.isConst(Type::Int));
  EXPECT_TRUE(five.isConst(5));
  EXPECT_FALSE(five.isConst(5.0));
  EXPECT_TRUE(Type::Gen.maybe(five));
  EXPECT_EQ(Type::Int, five | Type::Int);
  EXPECT_EQ(Type::Int, five | Type::cns(10));
  EXPECT_EQ(five, five | Type::cns(5));
  EXPECT_EQ(five, Type::cns(5) & five);
  EXPECT_EQ(five, five & Type::Int);
  EXPECT_EQ(five, Type::Gen & five);
  EXPECT_EQ("Int<5>", five.toString());
  EXPECT_EQ(five, five - Type::Arr);
  EXPECT_EQ(five, five - Type::cns(1));
  EXPECT_EQ(Type::Bottom, five - Type::Int);
  EXPECT_EQ(Type::Bottom, five - five);
  EXPECT_EQ(Type::Int, five.dropConstVal());
  EXPECT_TRUE(five.not(Type::cns(2)));

  auto True = Type::cns(true);
  EXPECT_EQ("Bool<true>", True.toString());
  EXPECT_LT(True, Type::Bool);
  EXPECT_NE(True, Type::Bool);
  EXPECT_TRUE(True.isConst());
  EXPECT_EQ(true, True.boolVal());
  EXPECT_TRUE(Type::Uncounted.maybe(True));
  EXPECT_FALSE(five <= True);
  EXPECT_FALSE(five > True);

  EXPECT_TRUE(five.not(True));
  EXPECT_EQ(Type::Int | Type::Bool, five | True);
  EXPECT_EQ(Type::Bottom, five & True);

  EXPECT_TRUE(Type::Uninit.isConst());
  EXPECT_TRUE(Type::InitNull.isConst());
  EXPECT_FALSE(Type::Null.isConst());
  EXPECT_FALSE((Type::Uninit | Type::Bool).isConst());
  EXPECT_FALSE(Type::Int.isConst());
}
Example #20
0
  void GRCsim::init()
  {
    entergrc = dynamic_cast<EnterGRC*>(top->control_flow_graph);
    if (entergrc)
    	grcroot = dynamic_cast<GRCNode*>(entergrc->successors.back());
    else
  	grcroot = dynamic_cast<GRCNode*>(top->control_flow_graph);
    assert (grcroot);
    stroot = dynamic_cast<STexcl *>(top->selection_tree);
    assert(stroot);
    boot = dynamic_cast<STleaf* >(stroot->children.back());
    assert(boot);

    globalcc = 1;  
    setState(boot,true);
    ternary = false;
    
    if ( debug & debugDFS ) cerr << "will dfs\n";
    jump = false;
    dfs(grcroot);
    if (debug & debugDFS ) cerr << "init ok\n";
    
    if (debug & debugDFS ){
      cerr << "--------topo-------:\n";
      for (vector<GRCNode*>::iterator i = topo.end()-1; i >= topo.begin(); i--)
        cerr << cfgmap[*i] << ' ';
      cerr << "\n";
    }

    // Initialize constants

    assert(module->constants);
    for ( SymbolTable::const_iterator i = module->constants->begin();
  	i != module->constants->end() ; i++ ) {
      ConstantSymbol *cs = dynamic_cast<ConstantSymbol*>(*i);
      if (cs && cs->initializer) {
        assert(cs->type);
        if (cs->type->name != "integer" &&
  	  cs->type->name != "boolean")
  	throw IR::Error("only integer and boolean constants are supported");
        var[cs] = intVal(cs->initializer);
      }
    }
  }
Example #21
0
  Status GRCsim::visit(Test &s)
  {
    GRCNode *successor;

    assert(s.predicate);
    //assert(s.successors.size()==2);
    int predvalue = intVal(s.predicate);

    if (predvalue==-1){//unknown

      if (debug) {
        cerr << cfgmap[&s] << ":test -- " << predvalue << " --> ";
        for(vector<GRCNode *>::iterator i = s.successors.begin();
         i != s.successors.end(); i++){
          if (*i) cerr << cfgmap[*i];
          else cerr<<" (none)";
        }
        cerr<<"\n";
      }

      ternary = true;

      for(vector<GRCNode *>::iterator i = s.successors.begin();
         i != s.successors.end(); i++){
        schedule(*i,-1);
      }
    }
    else{
      assert ( predvalue >= 0 && predvalue < (int)s.successors.size() );
      successor = s.successors[predvalue];

      if (debug) {
        cerr << cfgmap[&s] << ":test --" << predvalue << "--> ";
        if (successor) cerr << cfgmap[successor];
        else cerr << "(none)";
        cerr << '\n';
      }

      if (successor) schedule(successor,globalcc);
    }
    
    return Status(); 
  }
Example #22
0
/*
 *		oidparse				- get OID from IConst/FConst node
 */
Oid
oidparse(Node *node)
{
	switch (nodeTag(node))
	{
		case T_Integer:
			return intVal(node);
		case T_Float:

			/*
			 * Values too large for int4 will be represented as Float
			 * constants by the lexer.	Accept these if they are valid OID
			 * strings.
			 */
			return oidin_subr(strVal(node), NULL);
		default:
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
	}
	return InvalidOid;			/* keep compiler quiet */
}
Example #23
0
/*
 * Extract an int32 value from a DefElem.
 */
int32
defGetInt32(DefElem *def)
{
	if (def->arg == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 errmsg("%s requires an integer value",
						def->defname)));
	switch (nodeTag(def->arg))
	{
		case T_Integer:
			return (int32) intVal(def->arg);
		default:
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("%s requires an integer value",
							def->defname)));
	}
	return 0;					/* keep compiler quiet */
}
Example #24
0
Variant SSATmp::variantVal() const {
  switch (type().toDataType()) {
  case KindOfUninit:
  case KindOfNull:
    // Upon return both will converted to KindOfNull anyway.
    return init_null();
  case KindOfBoolean:
    return boolVal();
  case KindOfInt64:
    return intVal();
  case KindOfDouble:
    return dblVal();
  case KindOfString:
  case KindOfStaticString:
    return Variant(const_cast<StringData*>(strVal()));
  case KindOfArray:
    return const_cast<ArrayData*>(arrVal());
  default:
    always_assert(false);
  }
}
Example #25
0
/*
 * Extract a type length indicator (either absolute bytes, or
 * -1 for "variable") from a DefElem.
 */
int
defGetTypeLength(DefElem *def)
{
	if (def->arg == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 errmsg("%s requires a parameter",
						def->defname)));
	switch (nodeTag(def->arg))
	{
		case T_Integer:
			return intVal(def->arg);
		case T_Float:
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("%s requires an integer value",
							def->defname)));
			break;
		case T_String:
			if (pg_strcasecmp(strVal(def->arg), "variable") == 0)
				return -1;		/* variable length */
			break;
		case T_TypeName:
			/* cope if grammar chooses to believe "variable" is a typename */
			if (pg_strcasecmp(TypeNameToString((TypeName *) def->arg),
							  "variable") == 0)
				return -1;		/* variable length */
			break;
		case T_List:
			/* must be an operator name */
			break;
		default:
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(def->arg));
	}
	ereport(ERROR,
			(errcode(ERRCODE_SYNTAX_ERROR),
			 errmsg("invalid argument for %s: \"%s\"",
					def->defname, defGetString(def))));
	return 0;					/* keep compiler quiet */
}
Example #26
0
/**
 * Get weight associated with queue. See queue.c.
 *
 * Attention is paid in order to avoid catalog lookups when not allowed.  The
 * superuser() function performs catalog lookups in certain cases. Also the
 * GetResqueueCapabilityEntry will always  do a catalog lookup. In such cases
 * use the default weight.
 */
static int
ResourceQueueGetPriorityWeight(Oid queueId)
{
	List	   *capabilitiesList = NULL;
	List	   *entry = NULL;
	ListCell   *le = NULL;
	int			weight = BackoffDefaultWeight();

	if (!IsTransactionState())
		return weight;

	if (superuser())
		return BackoffSuperuserStatementWeight();

	if (queueId == InvalidOid)
		return weight;

	capabilitiesList = GetResqueueCapabilityEntry(queueId);		/* This is a list of
																 * lists */

	if (!capabilitiesList)
		return weight;

	foreach(le, capabilitiesList)
	{
		Value	   *key = NULL;

		entry = (List *) lfirst(le);
		Assert(entry);
		key = (Value *) linitial(entry);
		Assert(key->type == T_Integer); /* This is resource type id */
		if (intVal(key) == PG_RESRCTYPE_PRIORITY)
		{
			Value	   *val = lsecond(entry);

			Assert(val->type == T_String);
			weight = BackoffPriorityValueToInt(strVal(val));
		}
	}
Example #27
0
/*
 * Extract a numeric value (actually double) from a DefElem.
 */
double
defGetNumeric(DefElem *def)
{
	if (def->arg == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 errmsg("%s requires a numeric value",
						def->defname)));
	switch (nodeTag(def->arg))
	{
		case T_Integer:
			return (double) intVal(def->arg);
		case T_Float:
			return floatVal(def->arg);
		default:
			ereport(ERROR,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("%s requires a numeric value",
							def->defname)));
	}
	return 0;					/* keep compiler quiet */
}
Example #28
0
File: type.cpp Project: skynet/hhvm
TEST(Type, Const) {
  auto five = Type::cns(5);
  EXPECT_LT(five, Type::Int);
  EXPECT_NE(five, Type::Int);
  EXPECT_TRUE(five.isConst());
  EXPECT_EQ(5, five.intVal());
  EXPECT_TRUE(five.isConst(Type::Int));
  EXPECT_TRUE(five.isConst(5));
  EXPECT_FALSE(five.isConst(5.0));
  EXPECT_TRUE(Type::Gen.maybe(five));
  EXPECT_EQ(Type::Int, five | Type::Int);
  EXPECT_EQ(Type::Int, five | Type::cns(10));
  EXPECT_EQ(five, five | Type::cns(5));
  EXPECT_EQ(five, Type::cns(5) & five);
  EXPECT_EQ(five, five & Type::Int);
  EXPECT_EQ(five, Type::Gen & five);
  EXPECT_EQ("Int<5>", five.toString());
  EXPECT_EQ(five, five - Type::Arr);
  EXPECT_EQ(five, five - Type::cns(1));
  EXPECT_EQ(Type::Int, Type::Int - five); // conservative
  EXPECT_EQ(Type::Bottom, five - Type::Int);
  EXPECT_EQ(Type::Bottom, five - five);
  EXPECT_EQ(Type::PtrToGen,
            (Type::PtrToGen|Type::Nullptr) - Type::Nullptr);
  EXPECT_EQ(Type::Int, five.dropConstVal());
  EXPECT_TRUE(five.not(Type::cns(2)));

  auto True = Type::cns(true);
  EXPECT_EQ("Bool<true>", True.toString());
  EXPECT_LT(True, Type::Bool);
  EXPECT_NE(True, Type::Bool);
  EXPECT_TRUE(True.isConst());
  EXPECT_EQ(true, True.boolVal());
  EXPECT_TRUE(Type::Uncounted.maybe(True));
  EXPECT_FALSE(five <= True);
  EXPECT_FALSE(five > True);

  EXPECT_TRUE(five.not(True));
  EXPECT_EQ(Type::Int | Type::Bool, five | True);
  EXPECT_EQ(Type::Bottom, five & True);

  EXPECT_TRUE(Type::Uninit.isConst());
  EXPECT_TRUE(Type::InitNull.isConst());
  EXPECT_FALSE(Type::Null.isConst());
  EXPECT_FALSE((Type::Uninit | Type::Bool).isConst());
  EXPECT_FALSE(Type::Int.isConst());

  auto array = make_packed_array(1, 2, 3, 4);
  auto arrData = ArrayData::GetScalarArray(array.get());
  auto constArray = Type::cns(arrData);
  auto packedArray = Type::Arr.specialize(ArrayData::kPackedKind);
  auto mixedArray = Type::Arr.specialize(ArrayData::kMixedKind);

  EXPECT_TRUE(constArray <= packedArray);
  EXPECT_TRUE(constArray < packedArray);
  EXPECT_FALSE(packedArray <= constArray);
  EXPECT_TRUE(constArray <= constArray);
  EXPECT_FALSE(packedArray <= mixedArray);
  EXPECT_FALSE(mixedArray <= packedArray);
  EXPECT_FALSE(constArray <= mixedArray);
  EXPECT_EQ(constArray, constArray & packedArray);

  ArrayTypeTable::Builder ratBuilder;
  auto rat1 = ratBuilder.packedn(RepoAuthType::Array::Empty::No,
                                 RepoAuthType(RepoAuthType::Tag::Str));
  auto ratArray1 = Type::Arr.specialize(rat1);
  auto rat2 = ratBuilder.packedn(RepoAuthType::Array::Empty::No,
                                 RepoAuthType(RepoAuthType::Tag::Int));
  auto ratArray2 = Type::Arr.specialize(rat2);
  EXPECT_EQ(Type::Arr, ratArray1 & ratArray2);
  EXPECT_TRUE(ratArray1 < Type::Arr);
  EXPECT_TRUE(ratArray1 <= ratArray1);
  EXPECT_TRUE(ratArray1 < (Type::Arr|Type::Obj));
  EXPECT_FALSE(ratArray1 < ratArray2);
  EXPECT_NE(ratArray1, ratArray2);

  auto packedRat = packedArray & ratArray1;
  EXPECT_EQ("Arr=PackedKind:N([Str])", packedRat.toString());
  EXPECT_TRUE(packedRat <= packedArray);
  EXPECT_TRUE(packedRat < packedArray);
  EXPECT_TRUE(packedRat <= ratArray1);
  EXPECT_TRUE(packedRat < ratArray1);
  EXPECT_EQ(packedRat, packedRat & packedArray);
  EXPECT_EQ(packedRat, packedRat & ratArray1);
}
Example #29
0
// Open physical file
OLE2* ole2_open(const BYTE *file)
{
    //BYTE buf[1024];
    OLE2Header* oleh;
    OLE2* ole;
    OLE2Stream* olest;
    PSS*	pss;
    BYTE* name = NULL;

#ifdef OLE_DEBUG
    printf("----------------------------------------------\n");
    printf("ole2_open %s\n", file);
#endif

	if(xls_debug) printf("ole2_open: %s\n", file);
    ole=(OLE2*)calloc(1, sizeof(OLE2));
    if (!(ole->file=fopen((char *)file,"rb")))
    {
        if(xls_debug) printf("File not found\n");
        free(ole);
        return(NULL);
    }
    // read header and check magic numbers
    oleh=(OLE2Header*)malloc(512);
    fread(oleh,1,512,ole->file);
    convertHeader(oleh);

	// make sure the file looks good. Note: this code only works on Little Endian machines
	if(oleh->id[0] != 0xE011CFD0 || oleh->id[1] != 0xE11AB1A1 || oleh->byteorder != 0xFFFE) {
		fclose(ole->file);
        printf("Not an excel file\n");
		free(ole);
		return NULL;
	}

    //ole->lsector=(WORD)pow(2,oleh->lsector);
    //ole->lssector=(WORD)pow(2,oleh->lssector);
	ole->lsector=512;
    ole->lssector=64;
	assert(oleh->lsectorB==9);	// 2**9 == 512
	assert(oleh->lssectorB==6);	// 2**6 == 64
	
    ole->cfat=oleh->cfat;
    ole->dirstart=oleh->dirstart;
    ole->sectorcutoff=oleh->sectorcutoff;
    ole->sfatstart=oleh->sfatstart;
    ole->csfat=oleh->csfat;
    ole->difstart=oleh->difstart;
    ole->cdif=oleh->cdif;
    ole->files.count=0;

#ifdef OLE_DEBUG
		printf("==== OLE HEADER ====\n");
		//printf ("Header Size:   %i \n", sizeof(OLE2Header));
		//printf ("id[0]-id[1]:   %X-%X \n", oleh->id[0], oleh->id[1]);
		printf ("verminor:      %X \n",oleh->verminor);
		printf ("verdll:        %X \n",oleh->verdll);
		//printf ("Byte order:    %X \n",oleh->byteorder);
		printf ("sect len:      %X (%i)\n",ole->lsector,ole->lsector);		// ole
		printf ("mini len:      %X (%i)\n",ole->lssector,ole->lssector);	// ole
		printf ("Fat sect.:     %i \n",oleh->cfat);
		printf ("Dir Start:     %i \n",oleh->dirstart);
		
		printf ("Mini Cutoff:   %i \n",oleh->sectorcutoff);
		printf ("MiniFat Start: %X \n",oleh->sfatstart);
		printf ("Count MFat:    %i \n",oleh->csfat);
		printf ("Dif start:     %X \n",oleh->difstart);
		printf ("Count Dif:     %i \n",oleh->cdif);
		printf ("Fat Size:      %u (0x%X) \n",oleh->cfat*ole->lsector,oleh->cfat*ole->lsector);
#endif
    // read directory entries
    read_MSAT(ole, oleh);

	// reuse this buffer
    pss = (PSS*)oleh;
	// oleh = (void *)NULL; // Not needed as oleh not used from here on
	
    olest=ole2_sopen(ole,ole->dirstart, -1);
    do
    {
        ole2_read(pss,1,sizeof(PSS),olest);
        convertPss(pss);
        name=unicode_decode(pss->name, pss->bsize, 0, "UTF-8");
#ifdef OLE_DEBUG	
		printf("OLE NAME: %s count=%d\n", name, ole->files.count);
#endif
        if (pss->type == PS_USER_ROOT || pss->type == PS_USER_STREAM) // (name!=NULL) // 
        {

#ifdef OLE_DEBUG		
			printf("OLE TYPE: %s file=%d \n", pss->type == PS_USER_ROOT ? "root" : "user", ole->files.count);
#endif		
            if (ole->files.count==0)
            {
                ole->files.file=malloc(sizeof(struct st_olefiles_data));
            } else {
                ole->files.file=realloc(ole->files.file,(ole->files.count+1)*sizeof(struct st_olefiles_data));
            }
            ole->files.file[ole->files.count].name=name;
            ole->files.file[ole->files.count].start=pss->sstart;
            ole->files.file[ole->files.count].size=pss->size;
            ole->files.count++;
			
			if(pss->sstart == ENDOFCHAIN) {
				if (xls_debug) verbose("END OF CHAIN\n");
			} else
			if(pss->type == PS_USER_STREAM) {
#ifdef OLE_DEBUG
					printf("----------------------------------------------\n");
					printf("name: %s (size=%d [c=%c])\n", name, pss->bsize, name ? name[0]:' ');
					printf("bsize %i\n",pss->bsize);
					printf("type %i\n",pss->type);
					printf("flag %i\n",pss->flag);
					printf("left %X\n",pss->left);
					printf("right %X\n",pss->right);
					printf("child %X\n",pss->child);
					printf("guid %.4X-%.4X-%.4X-%.4X %.4X-%.4X-%.4X-%.4X\n",pss->guid[0],pss->guid[1],pss->guid[2],pss->guid[3],
						pss->guid[4],pss->guid[5],pss->guid[6],pss->guid[7]);
					printf("user flag %.4X\n",pss->userflags);
					printf("sstart %.4d\n",pss->sstart);
					printf("size %.4d\n",pss->size);
#endif
			} else
			if(pss->type == PS_USER_ROOT) {
				DWORD sector, k, blocks;
				BYTE *wptr;
				
				blocks = (pss->size + (ole->lsector - 1)) / ole->lsector;	// count partial
				ole->SSAT = (BYTE *)malloc(blocks*ole->lsector);
				// printf("blocks %d\n", blocks);

				assert(ole->SSecID);
				
				sector = pss->sstart;
				wptr=(BYTE*)ole->SSAT;
				for(k=0; k<blocks; ++k) {
					// printf("block %d sector %d\n", k, sector);
					assert(sector != ENDOFCHAIN);
					fseek(ole->file,sector*ole->lsector+512,0);
					fread(wptr,1,ole->lsector,ole->file);
					wptr += ole->lsector;
					sector = intVal(ole->SecID[sector]);
				}
			}	
		} else {
			free(name);
		}
    }
    while (!olest->eof);

	ole2_fclose(olest);
    free(pss);

    return ole;
}
Example #30
0
/*
 *	DefineAggregate
 *
 * "oldstyle" signals the old (pre-8.2) style where the aggregate input type
 * is specified by a BASETYPE element in the parameters.  Otherwise,
 * "args" is a pair, whose first element is a list of FunctionParameter structs
 * defining the agg's arguments (both direct and aggregated), and whose second
 * element is an Integer node with the number of direct args, or -1 if this
 * isn't an ordered-set aggregate.
 * "parameters" is a list of DefElem representing the agg's definition clauses.
 */
ObjectAddress
DefineAggregate(List *name, List *args, bool oldstyle, List *parameters,
				const char *queryString)
{
	char	   *aggName;
	Oid			aggNamespace;
	AclResult	aclresult;
	char		aggKind = AGGKIND_NORMAL;
	List	   *transfuncName = NIL;
	List	   *finalfuncName = NIL;
	List	   *combinefuncName = NIL;
	List	   *serialfuncName = NIL;
	List	   *deserialfuncName = NIL;
	List	   *mtransfuncName = NIL;
	List	   *minvtransfuncName = NIL;
	List	   *mfinalfuncName = NIL;
	bool		finalfuncExtraArgs = false;
	bool		mfinalfuncExtraArgs = false;
	List	   *sortoperatorName = NIL;
	TypeName   *baseType = NULL;
	TypeName   *transType = NULL;
	TypeName   *serialType = NULL;
	TypeName   *mtransType = NULL;
	int32		transSpace = 0;
	int32		mtransSpace = 0;
	char	   *initval = NULL;
	char	   *minitval = NULL;
	char	   *parallel = NULL;
	int			numArgs;
	int			numDirectArgs = 0;
	oidvector  *parameterTypes;
	ArrayType  *allParameterTypes;
	ArrayType  *parameterModes;
	ArrayType  *parameterNames;
	List	   *parameterDefaults;
	Oid			variadicArgType;
	Oid			transTypeId;
	Oid			serialTypeId = InvalidOid;
	Oid			mtransTypeId = InvalidOid;
	char		transTypeType;
	char		mtransTypeType = 0;
	char		proparallel = PROPARALLEL_UNSAFE;
	ListCell   *pl;

	/* Convert list of names to a name and namespace */
	aggNamespace = QualifiedNameGetCreationNamespace(name, &aggName);

	/* Check we have creation rights in target namespace */
	aclresult = pg_namespace_aclcheck(aggNamespace, GetUserId(), ACL_CREATE);
	if (aclresult != ACLCHECK_OK)
		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
					   get_namespace_name(aggNamespace));

	/* Deconstruct the output of the aggr_args grammar production */
	if (!oldstyle)
	{
		Assert(list_length(args) == 2);
		numDirectArgs = intVal(lsecond(args));
		if (numDirectArgs >= 0)
			aggKind = AGGKIND_ORDERED_SET;
		else
			numDirectArgs = 0;
		args = (List *) linitial(args);
	}

	/* Examine aggregate's definition clauses */
	foreach(pl, parameters)
	{
		DefElem    *defel = (DefElem *) lfirst(pl);

		/*
		 * sfunc1, stype1, and initcond1 are accepted as obsolete spellings
		 * for sfunc, stype, initcond.
		 */
		if (pg_strcasecmp(defel->defname, "sfunc") == 0)
			transfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "sfunc1") == 0)
			transfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "finalfunc") == 0)
			finalfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "combinefunc") == 0)
			combinefuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "serialfunc") == 0)
			serialfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "deserialfunc") == 0)
			deserialfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "msfunc") == 0)
			mtransfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "minvfunc") == 0)
			minvtransfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "mfinalfunc") == 0)
			mfinalfuncName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "finalfunc_extra") == 0)
			finalfuncExtraArgs = defGetBoolean(defel);
		else if (pg_strcasecmp(defel->defname, "mfinalfunc_extra") == 0)
			mfinalfuncExtraArgs = defGetBoolean(defel);
		else if (pg_strcasecmp(defel->defname, "sortop") == 0)
			sortoperatorName = defGetQualifiedName(defel);
		else if (pg_strcasecmp(defel->defname, "basetype") == 0)
			baseType = defGetTypeName(defel);
		else if (pg_strcasecmp(defel->defname, "hypothetical") == 0)
		{
			if (defGetBoolean(defel))
			{
				if (aggKind == AGGKIND_NORMAL)
					ereport(ERROR,
							(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
							 errmsg("only ordered-set aggregates can be hypothetical")));
				aggKind = AGGKIND_HYPOTHETICAL;
			}
		}
		else if (pg_strcasecmp(defel->defname, "stype") == 0)
			transType = defGetTypeName(defel);
		else if (pg_strcasecmp(defel->defname, "serialtype") == 0)
			serialType = defGetTypeName(defel);
		else if (pg_strcasecmp(defel->defname, "stype1") == 0)
			transType = defGetTypeName(defel);
		else if (pg_strcasecmp(defel->defname, "sspace") == 0)
			transSpace = defGetInt32(defel);
		else if (pg_strcasecmp(defel->defname, "mstype") == 0)
			mtransType = defGetTypeName(defel);
		else if (pg_strcasecmp(defel->defname, "msspace") == 0)
			mtransSpace = defGetInt32(defel);
		else if (pg_strcasecmp(defel->defname, "initcond") == 0)
			initval = defGetString(defel);
		else if (pg_strcasecmp(defel->defname, "initcond1") == 0)
			initval = defGetString(defel);
		else if (pg_strcasecmp(defel->defname, "minitcond") == 0)
			minitval = defGetString(defel);
		else if (pg_strcasecmp(defel->defname, "parallel") == 0)
			parallel = defGetString(defel);
		else
			ereport(WARNING,
					(errcode(ERRCODE_SYNTAX_ERROR),
					 errmsg("aggregate attribute \"%s\" not recognized",
							defel->defname)));
	}