int
subloc_here(int where, int sk)
{
	int i;
	int ret = 0;

	loop_here(where, i)
	{
		if (kind(i) == T_loc && subkind(i) == sk)
		{
			ret = i;
			break;
		}
	}
	next_here;

	return ret;
}
Example #2
0
ValueRecovery ValueRep::recoveryForJSValue() const
{
    switch (kind()) {
    case LateRegister:
    case Register:
        return ValueRecovery::inGPR(gpr(), DataFormatJS);
    case Stack:
        RELEASE_ASSERT(!(offsetFromFP() % sizeof(EncodedJSValue)));
        return ValueRecovery::displacedInJSStack(
            VirtualRegister(offsetFromFP() / sizeof(EncodedJSValue)),
            DataFormatJS);
    case Constant:
        return ValueRecovery::constant(JSValue::decode(value()));
    default:
        RELEASE_ASSERT_NOT_REACHED();
        return { };
    }
}
Example #3
0
bool typeFitsConstraint(Type t, GuardConstraint gc) {
  switch (gc.category) {
    case DataTypeGeneric:
      return true;

    case DataTypeCountness:
    case DataTypeBoxAndCountness:
      // Consumers using this constraint expect the type to be relaxed to
      // Uncounted or left alone, so something like Arr|Obj isn't specific
      // enough.
      return !t.maybe(TCounted) ||
             t.subtypeOfAny(TStr, TArr, TVec, TDict, TKeyset, TObj,
                            TRes, TBoxedCell);

    case DataTypeBoxAndCountnessInit:
      return typeFitsConstraint(t, DataTypeBoxAndCountness) &&
             (t <= TUninit || !t.maybe(TUninit));

    case DataTypeSpecific:
      return t.isKnownDataType();

    case DataTypeSpecialized:
      // Type::isSpecialized() returns true for types like {Arr<Packed>|Int}
      // and Arr has non-specialized subtypes, so we require that t is
      // specialized, a strict subtype of Obj or Arr, and that it fits the
      // specific requirements of gc.

      assertx(gc.wantClass() ^ gc.wantArrayKind());

      if (t < TObj && t.clsSpec()) {
        return gc.wantClass() &&
               t.clsSpec().cls()->classof(gc.desiredClass());
      }
      if (t < TArr && t.arrSpec()) {
        auto arrSpec = t.arrSpec();
        if (gc.wantArrayKind() && !arrSpec.kind()) return false;
        return true;
      }

      return false;
  }

  not_reached();
}
Example #4
0
static int
get_command(int who, char *s)
{
  int fact;                     /* who controls us now? */
  char *order;

  if (!valid_box(who) || kind(who) == T_deadchar)
    return FALSE;

  fact = player(who);

  if (fact == 0)
    return FALSE;

  order = top_order(fact, who);

/*
 *  If we don't have any orders, then fail.
 */

  if (order == NULL)
    return FALSE;

/*
 *  Update the player's last turn field so we know if he's been
 *  playing or not.
 */

  {
    struct entity_player *p;

    p = p_player(fact);
    p->last_order_turn = sysclock.turn;
  }

  assert(strlen(order) < LEN);  /* maybe not a valid assert */

  strncpy(s, order, LEN - 1);
  s[LEN - 1] = '\0';

  pop_order(fact, who);

  return TRUE;
}
void
all_char_here(int who, ilist *l)
{
	int i;
	struct loc_info *p;

	assert(valid_box(who));

	ilist_clear(l);

	p = rp_loc_info(who);

	if (p == NULL)
		return;

	for (i = 0; i < ilist_len(p->here_list); i++)
		if (kind(p->here_list[i]) == T_char)
			add_char_here(p->here_list[i], l);
}
Example #6
0
static int
exec_precedence(int who)
{
  int n;
  int stack_depth = 0;
  int pos;

  if (kind(who) != T_char)
    return 0;

  for (n = who; n; n = stack_parent(n), stack_depth++);

  pos = here_pos(who);

  assert(stack_depth < 100);
  assert(pos < 10000);

  return stack_depth * 10000 + pos;
}
Example #7
0
int
v_relore(struct command *c)
{
  int i;
  int skill = c->a;

  if (!valid_box(skill) || kind(skill) != T_skill) {
    wout(c->who, "%s is not a skill.", c->parse[1]);
    return FALSE;
  }

  loop_char(i) {
    if (has_skill(i, skill))
      queue_lore(i, skill, TRUE);
  }
  next_char;

  return TRUE;
}
Example #8
0
bool KeyLauncher::onKeyPress(int keycode)
{
    QString key;
    QStringList args;
    ConfigEx& cfg = ConfigEx::getInstance("keyhelper");

    key = KeyNames::getName(keycode);
    if(key == QString::null) {
        return(false);
    }

    QString group = kind();
    group[0] = group[0].upper();

    /* read application launcher */
    QString app = KHUtil::currentApp();
    if(!app.isEmpty()) {
        cfg.setGroup(group + "_" + app);
        /* read config */
        args = cfg.readListEntry(key, '\t');
    }

    /* read default launcher */
    if(args.isEmpty()) {
        cfg.setGroup(group);

        /* read config */
        args = cfg.readListEntry(key, '\t');
    }

    if(args.isEmpty()) {
        return(false);
    }

    /* launch application */
    LnkWrapper lnk(args);
    if(lnk.isValid()) {
        //args.remove(args.begin());
        lnk.instance().execute();
    }

    return(true);
}
Example #9
0
		String FunctionParser::parseFunctionNameElement() {
			auto validTokens = {
				Token::NAME,
				Token::MOVE,
				Token::NULLVAL
			};
			
			const auto token = reader_.expectOneOf(validTokens);                    
			switch (token.kind()) {
				case Token::NAME:
					return token.name();
				case Token::MOVE:
					return reader_.makeCString("move");
				case Token::NULLVAL:
					return reader_.makeCString("null");
				default:
					return reader_.makeCString("<invalid>");
			}
		}
Example #10
0
char *
nation_s(int n)
{
  static char nation_title[80];
  static char neutral_title[80];

  nation_title[0] = 0;
  neutral_title[0] = 0;
  /*
   *  Wed Apr 16 11:29:27 1997 -- Scott Turner
   *
   *  Check for a concealment.
   *
   */
  if (get_effect(n, ef_conceal_nation, 0, 0)) {
    int new_nation = get_effect(n, ef_conceal_nation, 0, 0);
    assert(new_nation >= 1 && kind(new_nation) == T_nation);
    if (rp_nation(new_nation)->neutral)
      strcpy(neutral_title, ", neutral");
    sprintf(nation_title, ", %s%s", rp_nation(new_nation)->name,
            neutral_title);
  }
  else if (nation(n)) {
    if (rp_nation(nation(n))->neutral)
      strcpy(neutral_title, ", neutral");
    sprintf(nation_title, ", %s%s", rp_nation(nation(n))->name,
            neutral_title);
  }
  else if (subkind(n) == sub_garrison) {
    /*
     *  Special case for an uncommanded garrison?
     *
     */
    strcpy(nation_title, ", uncontrolled");
  }
  else if (refugee(n)) {
    strcpy(nation_title, ", refugee");
  };

  return nation_title;

};
Example #11
0
char *
liner_desc(int n)
{

  switch (kind(n)) {
  case T_ship:
    return liner_desc_ship(n);
  case T_loc:
    return liner_desc_loc(n);
  case T_char:
    return liner_desc_char(n);
  case T_road:
    return liner_desc_road(n);
  case T_storm:
    return liner_desc_storm(n);

  default:
    assert(FALSE);
  }
}
inline jlong
EventLogger::Entry::dump( Stream* s, jlong time ) const {
  time += delta();
  jlong usec = time * 1000 * 1000 / _freq;
  const jlong msec = usec / 1000;
  s->print( "%6d", jint(msec) );
  if( _use_usec ) {
    usec %= 1000;
    s->print(".");
    if( usec < 100 ) {
      s->print("0");
    }
    if( usec < 10 ) {
      s->print("0");
    }
    s->print("%d", usec);
  }
  s->print_cr(" %8d %s %s", jint(time), kind(), name() );
  return time;
}
Example #13
0
void EnumMember::toJsonBuffer(OutBuffer *buf)
{
    //printf("EnumMember::toJsonBuffer()\n");
    buf->writestring("{\n");

    JsonProperty(buf, Pname, toChars());
    JsonProperty(buf, Pkind, kind());

    if (prot())
        JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

    if (comment)
        JsonProperty(buf, Pcomment, (const char *)comment);

    if (loc.linnum)
        JsonProperty(buf, Pline, loc.linnum);

    JsonRemoveComma(buf);
    buf->writestring("}\n");
}
Example #14
0
void
isetwidth(void)
{
  nialptr     z;
  nialint     ts;

  z = apop();
  if (kind(z) == inttype) {
    ts = intval(z);
    if (ts >= 0) {           
      apush(createint(ssizew));
      ssizew = ts;
    }
    else
      buildfault("width out of range");
  }
  else
    buildfault("width not an integer");
  freeup(z);
}
Object HHVM_STATIC_METHOD(AwaitAllWaitHandle, fromArray,
                          const Array& dependencies) {
  auto ad = dependencies.get();
  assertx(ad);
  assertx(ad->isPHPArray());
  if (!ad->size()) return Object{returnEmpty()};

retry:
  switch (ad->kind()) {
    case ArrayData::kPackedKind:
      return c_AwaitAllWaitHandle::FromPackedArray(ad);

    case ArrayData::kMixedKind:
      return c_AwaitAllWaitHandle::FromMixedArray(MixedArray::asMixed(ad));

    case ArrayData::kProxyKind:
      ad = ProxyArray::innerArr(ad);
      goto retry;

    case ArrayData::kApcKind:
    case ArrayData::kGlobalsKind:
      // APC can't store WaitHandles, GlobalsArray is used only for
      // $GLOBALS, which contain non-WaitHandles.
      failArray();

    case ArrayData::kEmptyKind:
      // Handled by dependencies->size() check.
      not_reached();

    case ArrayData::kVecKind:
    case ArrayData::kDictKind:
    case ArrayData::kKeysetKind:
      // Shouldn't get Hack arrays
      not_reached();

    case ArrayData::kNumKinds:
      not_reached();
  }

  not_reached();
}
Example #16
0
/*
 * Helper for empty array -> packed transitions.  Creates an array
 * with one element.  The element is transferred into the array (should
 * already be incref'd).
 */
ALWAYS_INLINE
ArrayLval EmptyArray::MakePackedInl(TypedValue tv) {
  auto const cap = kPackedSmallSize;
  auto const ad = static_cast<ArrayData*>(
    MM().objMalloc(sizeof(ArrayData) + cap * sizeof(TypedValue))
  );
  assert(cap == CapCode::ceil(cap).code);
  ad->m_sizeAndPos = 1; // size=1, pos=0
  ad->initHeader(CapCode::exact(cap), HeaderKind::Packed, 1);

  auto const lval = reinterpret_cast<TypedValue*>(ad + 1);
  lval->m_data = tv.m_data;
  lval->m_type = tv.m_type;

  assert(ad->kind() == ArrayData::kPackedKind);
  assert(ad->m_size == 1);
  assert(ad->m_pos == 0);
  assert(ad->hasExactlyOneRef());
  assert(PackedArray::checkInvariants(ad));
  return { ad, &tvAsVariant(lval) };
}
Example #17
0
/*
 * Helper for empty array -> packed transitions.  Creates an array
 * with one element.  The element is transferred into the array (should
 * already be incref'd).
 */
ALWAYS_INLINE
std::pair<ArrayData*,TypedValue*> EmptyArray::MakePackedInl(TypedValue tv) {
  auto const cap = kPackedSmallSize;
  auto const ad = static_cast<ArrayData*>(
    MM().objMalloc(sizeof(ArrayData) + cap * sizeof(TypedValue))
  );
  assert(cap == CapCode::ceil(cap).code);
  ad->m_sizeAndPos = 1; // size=1, pos=0
  ad->m_hdr.init(CapCode::exact(cap), HeaderKind::Packed, 0);

  auto& lval = *reinterpret_cast<TypedValue*>(ad + 1);
  lval.m_data = tv.m_data;
  lval.m_type = tv.m_type;

  assert(ad->kind() == ArrayData::kPackedKind);
  assert(ad->m_size == 1);
  assert(ad->m_pos == 0);
  assert(ad->getCount() == 0);
  assert(PackedArray::checkInvariants(ad));
  return { ad, &lval };
}
Example #18
0
static      nialptr
to_int(nialptr x)
{
  nialptr     z,
              xi;
  nialint     i,
              t = tally(x);
  int         v = valence(x);

  /* create the result container */
  z = new_create_array(inttype, v, 0, shpptr(x, v));
  for (i = 0; i < t; i++) {
    xi = fetch_array(x, i);
    if (kind(xi) == inttype) {
      copy1(z, i, xi, 0);
    }
    else   /* type must be boolean */
      store_int(z, i, boolval(xi));
  }
  return (z);
}
Example #19
0
		std::string Predicate::toString() const {
			switch (kind()) {
				case TRUE:
				{
					return "true";
				}
				case FALSE:
				{
					return "false";
				}
				case SELFCONST:
				{
					return "selfconst";
				}
				case AND:
				{
					return makeString("%s and %s",
						andLeft().toString().c_str(),
						andRight().toString().c_str());
				}
				case OR:
				{
					return makeString("%s or %s",
						orLeft().toString().c_str(),
						orRight().toString().c_str());
				}
				case SATISFIES:
				{
					return makeString("%s : %s",
						satisfiesType()->toDiagString().c_str(),
						satisfiesRequirement()->toDiagString().c_str());
				}
				case VARIABLE:
				{
					return variableTemplateVar()->fullName().last().asStdString();
				}
			}
			
			locic_unreachable("Unknown predicate kind.");
		}
Example #20
0
void ExitValue::dumpInContext(PrintStream& out, DumpContext* context) const
{
    switch (kind()) {
    case InvalidExitValue:
        out.print("Invalid");
        return;
    case ExitValueDead:
        out.print("Dead");
        return;
    case ExitValueArgument:
        out.print("Argument(", exitArgument(), ")");
        return;
    case ExitValueConstant:
        out.print("Constant(", inContext(constant(), context), ")");
        return;
    case ExitValueInJSStack:
        out.print("InJSStack:r", virtualRegister());
        return;
    case ExitValueInJSStackAsInt32:
        out.print("InJSStackAsInt32:r", virtualRegister());
        return;
    case ExitValueInJSStackAsInt52:
        out.print("InJSStackAsInt52:r", virtualRegister());
        return;
    case ExitValueInJSStackAsDouble:
        out.print("InJSStackAsDouble:r", virtualRegister());
        return;
    case ExitValueArgumentsObjectThatWasNotCreated:
        out.print("ArgumentsObjectThatWasNotCreated");
        return;
    case ExitValueRecovery:
        out.print("Recovery(", recoveryOpcode(), ", arg", leftRecoveryArgument(), ", arg", rightRecoveryArgument(), ", ", recoveryFormat(), ")");
        return;
    case ExitValueMaterializeNewObject:
        out.print("Materialize(", pointerDump(objectMaterialization()), ")");
        return;
    }
    
    RELEASE_ASSERT_NOT_REACHED();
}
Example #21
0
void SCCP::analyzeBranch(BlockEndInstr* end) {
    switch (kind(end)) {
    case HR_goto:
        addBlock(cast<GotoInstr>(end)->target);
        break;
    case HR_if:
    case HR_switch: {
        CondInstr* cond = (CondInstr*)end;
        ArmInstr* arm = getConstArm(cond);
        if (arm)
            addBlock(arm);
        else
            for (ArrayRange<ArmInstr*> a = armRange(cond); !a.empty();)
                addBlock(a.popFront());
        break;
    }
    }
    if (end->catch_blocks != NULL) {
        for (CatchBlockRange r(end); !r.empty();)
            addBlock(r.popFront());
    }
}
Example #22
0
void PutByIdVariant::dumpInContext(PrintStream& out, DumpContext* context) const
{
    switch (kind()) {
    case NotSet:
        out.print("<empty>");
        return;
        
    case Replace:
        out.print(
            "<Replace: ", inContext(structure(), context), ", ", offset(), ">");
        return;
        
    case Transition:
        out.print(
            "<Transition: ", inContext(oldStructure(), context), " -> ",
            pointerDumpInContext(newStructure(), context), ", [",
            listDumpInContext(constantChecks(), context), "], ", offset(), ">");
        return;
    }
    
    RELEASE_ASSERT_NOT_REACHED();
}
Example #23
0
static int
keep_undead_check(struct command *c, int check_bond)
{
  int target = c->a;

  if (kind(target) != T_char || subkind(target) != sub_demon_lord) {
    wout(c->who, "%s is not a demon lord.", box_code(target));
    return FALSE;
  }

  if (subloc(target) != subloc(c->who)) {
    wout(c->who, "%s is not here.", box_code(target));
    return FALSE;
  }

  if (check_bond && loyal_kind(target) != LOY_summon) {
    wout(c->who, "%s is no longer bonded.", box_code(target));
    return FALSE;
  }

  return TRUE;
}
Example #24
0
void TextTrack::addCue(PassRefPtr<TextTrackCue> prpCue, ExceptionCode& ec)
{
    if (!prpCue)
        return;

    RefPtr<TextTrackCue> cue = prpCue;

    // 4.7.10.12.6 Text tracks exposing in-band metadata
    // The UA will use DataCue to expose only text track cue objects that belong to a text track that has a text
    // track kind of metadata.
    // If a DataCue is added to a TextTrack via the addCue() method but the text track does not have its text
    // track kind set to metadata, throw a InvalidNodeTypeError exception and don't add the cue to the TextTrackList
    // of the TextTrack.
    if (cue->cueType() == TextTrackCue::Data && kind() != metadataKeyword()) {
        ec = INVALID_NODE_TYPE_ERR;
        return;
    }

    // TODO(93143): Add spec-compliant behavior for negative time values.
    if (!cue->startMediaTime().isValid() || !cue->endMediaTime().isValid() || cue->startMediaTime() < MediaTime::zeroTime() || cue->endMediaTime() < MediaTime::zeroTime())
        return;

    // 4.8.10.12.5 Text track API

    // The addCue(cue) method of TextTrack objects, when invoked, must run the following steps:

    // 1. If the given cue is in a text track list of cues, then remove cue from that text track
    // list of cues.
    TextTrack* cueTrack = cue->track();
    if (cueTrack && cueTrack != this)
        cueTrack->removeCue(cue.get(), ASSERT_NO_EXCEPTION);

    // 2. Add cue to the method's TextTrack object's text track's text track list of cues.
    cue->setTrack(this);
    ensureTextTrackCueList()->add(cue);
    
    if (m_client)
        m_client->textTrackAddCue(this, cue.get());
}
Example #25
0
File: json.c Project: 1100110/dmd
void Dsymbol::jsonProperties(JsonOut *json)
{
    if (!isTemplateDeclaration()) // TemplateDeclaration::kind() acts weird sometimes
    {
        json->property("name", toChars());
        json->property("kind", kind());
    }

    if (prot() != PROTpublic)
        json->property("protection", Pprotectionnames[prot()]);

    json->property("comment", (const char *)comment);

    json->property("line", &loc);

#if 0
    if (!isModule())
    {
        Module *module = getModule();
        if (module)
        {
            json->propertyStart("module");
            json->objectStart();
            module->jsonProperties(json);
            json->objectEnd();
        }

        Module *accessModule = getAccessModule();
        if (accessModule && accessModule != module)
        {
            json->propertyStart("accessModule");
            json->objectStart();
            accessModule->jsonProperties(json);
            json->objectEnd();
        }
    }
#endif
}
Example #26
0
int32_t ExecuteRequest::encode_batch(int version, BufferVec* bufs, Handler* handler) const {
  int32_t length = 0;
  const std::string& id(prepared_->id());

  // <kind><id><n><value_1>...<value_n> ([byte][short bytes][short][bytes]...[bytes])
  int buf_size = sizeof(uint8_t) + sizeof(uint16_t) + id.size() + sizeof(uint16_t);

  bufs->push_back(Buffer(buf_size));
  length += buf_size;

  Buffer& buf = bufs->back();
  size_t pos = buf.encode_byte(0, kind());
  pos = buf.encode_string(pos, id.data(), id.size());

  buf.encode_uint16(pos, elements_count());
  if (elements_count() > 0) {
    int32_t result = copy_buffers(version, bufs, handler);
    if (result < 0) return result;
    length += result;
  }

  return length;
}
PassRefPtrWillBeRawPtr<Blob> DataObjectItem::getAsFile() const
{
    if (kind() != FileKind)
        return nullptr;

    if (m_source == InternalSource) {
        if (m_file)
            return m_file.get();
        ASSERT(m_sharedBuffer);
        // FIXME: This code is currently impossible--we never populate m_sharedBuffer when dragging
        // in. At some point though, we may need to support correctly converting a shared buffer
        // into a file.
        return nullptr;
    }

    ASSERT(m_source == PasteboardSource);
    if (type() == mimeTypeImagePng) {
        // FIXME: This is pretty inefficient. We copy the data from the browser
        // to the renderer. We then place it in a blob in WebKit, which
        // registers it and copies it *back* to the browser. When a consumer
        // wants to read the data, we then copy the data back into the renderer.
        // https://bugs.webkit.org/show_bug.cgi?id=58107 has been filed to track
        // improvements to this code (in particular, add a registerClipboardBlob
        // method to the blob registry; that way the data is only copied over
        // into the renderer when it's actually read, not when the blob is
        // initially constructed).
        RefPtr<SharedBuffer> data = static_cast<PassRefPtr<SharedBuffer> >(blink::Platform::current()->clipboard()->readImage(blink::WebClipboard::BufferStandard));
        RefPtr<RawData> rawData = RawData::create();
        rawData->mutableData()->append(data->data(), data->size());
        OwnPtr<BlobData> blobData = BlobData::create();
        blobData->appendData(rawData, 0, -1);
        blobData->setContentType(mimeTypeImagePng);
        return Blob::create(BlobDataHandle::create(blobData.release(), data->size()));
    }

    return nullptr;
}
Example #28
0
void VariableEvent::dump(PrintStream& out) const
{
    switch (kind()) {
    case Reset:
        out.printf("Reset");
        break;
    case BirthToFill:
        dumpFillInfo("BirthToFill", out);
        break;
    case BirthToSpill:
        dumpSpillInfo("BirthToSpill", out);
        break;
    case Birth:
        out.print("Birth(", id(), ")");
        break;
    case Fill:
        dumpFillInfo("Fill", out);
        break;
    case Spill:
        dumpSpillInfo("Spill", out);
        break;
    case Death:
        out.print("Death(", id(), ")");
        break;
    case MovHintEvent:
        out.print("MovHint(", id(), ", ", bytecodeRegister(), ")");
        break;
    case SetLocalEvent:
        out.print(
            "SetLocal(machine:", machineRegister(), " -> bytecode:", bytecodeRegister(),
            ", ", dataFormatToString(dataFormat()), ")");
        break;
    default:
        RELEASE_ASSERT_NOT_REACHED();
        break;
    }
}
Example #29
0
File: struct.c Project: duralog/ldc
void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
    buf->printf("%s ", kind());
    if (!isAnonymous())
        buf->writestring(toChars());
    if (!members)
    {
        buf->writeByte(';');
        buf->writenl();
        return;
    }
    buf->writenl();
    buf->writeByte('{');
    buf->writenl();
    buf->level++;
    for (size_t i = 0; i < members->dim; i++)
    {
        Dsymbol *s = (*members)[i];
        s->toCBuffer(buf, hgs);
    }
    buf->level--;
    buf->writeByte('}');
    buf->writenl();
}
Example #30
0
void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
    if (!isAnonymous())
    {
        buf->printf("%s ", kind());
        buf->writestring(toChars());
        if (baseclasses->dim)
            buf->writestring(" : ");
    }
    for (size_t i = 0; i < baseclasses->dim; i++)
    {
        BaseClass *b = (*baseclasses)[i];

        if (i)
            buf->writestring(", ");
        //buf->writestring(b->base->ident->toChars());
        b->type->toCBuffer(buf, NULL, hgs);
    }
    if (members)
    {
        buf->writenl();
        buf->writeByte('{');
        buf->writenl();
        buf->level++;
        for (size_t i = 0; i < members->dim; i++)
        {
            Dsymbol *s = (*members)[i];
            s->toCBuffer(buf, hgs);
        }
        buf->level--;
        buf->writestring("}");
    }
    else
        buf->writeByte(';');
    buf->writenl();
}