コード例 #1
0
ファイル: ext_hh.cpp プロジェクト: aloiret/hhvm
TypedValue HHVM_FUNCTION(serialize_memoize_param, TypedValue param) {
  // Memoize throws in the emitter if any function parameters are references, so
  // we can just assert that the param is cell here
  assertx(param.m_type != KindOfRef);
  auto const type = param.m_type;

  if (isStringType(type)) {
    auto const str = param.m_data.pstr;
    if (str->empty()) {
      return make_tv<KindOfPersistentString>(s_emptyStrMemoKey.get());
    } else if ((unsigned char)str->data()[0] < '~') {
      // fb_compact_serialize always returns a string with the high-bit set in
      // the first character. Furthermore, we use ~ to begin all our special
      // constants, so anything less than ~ can't collide. There's no worry
      // about int-like strings because we use dicts (which don't perform key
      // coercion) to store the memoized values.
      str->incRefCount();
      return param;
    }
  } else if (isContainer(param) && getContainerSize(param) == 0) {
    return make_tv<KindOfPersistentString>(s_emptyArrMemoKey.get());
  } else if (type == KindOfUninit || type == KindOfNull) {
    return make_tv<KindOfPersistentString>(s_nullMemoKey.get());
  } else if (type == KindOfBoolean) {
    return make_tv<KindOfPersistentString>(
      param.m_data.num ? s_trueMemoKey.get() : s_falseMemoKey.get()
    );
  } else if (type == KindOfInt64) {
    return param;
  }

  return tvReturn(
    fb_compact_serialize(tvAsCVarRef(&param),
                         FBCompactSerializeBehavior::MemoizeParam));
}
コード例 #2
0
ファイル: debug.c プロジェクト: BPaden/garglk
/*----------------------------------------------------------------------*/
static void showInstanceLocation(int ins, char *prefix) {
    char buffer[1000];

    if (admin[ins].location == 0)
        return;
    else {
        output(prefix);
        if (isALocation(admin[ins].location)) {
            output("at");
            say(admin[ins].location);
            sprintf(buffer, "[%d]", admin[ins].location);
            output(buffer);
        } else if (isContainer(admin[ins].location)) {
		  
            if (isObject(admin[ins].location))
                output("in");
            else if (isActor(admin[ins].location))
                output("carried by");
            say(admin[ins].location);
            sprintf(buffer, "[%d]", admin[ins].location);
            output(buffer);

        } else
            output("Illegal location!");
    }
}
コード例 #3
0
ファイル: ext_math.cpp プロジェクト: NIT-Warangal/Judge
Variant f_max(int _argc, const Variant& value,
              const Variant& second /* = null_variant */,
              const Array& _argv /* = null_array */) {
  if (_argc == 1) {
    const auto& cell_value = *value.asCell();
    if (UNLIKELY(!isContainer(cell_value))) {
      return value;
    }

    ArrayIter iter(cell_value);
    if (!iter) {
      return uninit_null();
    }
    Variant ret = iter.secondRefPlus();
    ++iter;
    for (; iter; ++iter) {
      Variant currVal = iter.secondRefPlus();
      if (more(currVal, ret)) {
        ret = currVal;
      }
    }
    return ret;
  } else if (_argc == 2) {
    return more(second, value) ? second : value;
  }

  Variant ret = more(second, value) ? second : value;
  for (ArrayIter iter(_argv); iter; ++iter) {
    Variant currVal = iter.secondRef();
    if (more(currVal, ret)) {
      ret = currVal;
    }
  }
  return ret;
}
コード例 #4
0
ファイル: ext_hh.cpp プロジェクト: KOgames/hhvm
Variant HHVM_FUNCTION(serialize_memoize_param, const Variant& param) {
  // Memoize throws in the emitter if any function parameters are references, so
  // we can just assert that the param is cell here
  const auto& cell_param = *tvAssertCell(param.asTypedValue());
  auto type = param.getType();

  if (type == KindOfInt64) {
    return param;
  } else if (type == KindOfUninit || type == KindOfNull) {
    return s_empty;
  } else if (type == KindOfBoolean) {
    return param.asBooleanVal() ? s_true : s_false;
  } else if (type == KindOfString) {
    auto str = param.asCStrRef();
    if (str.empty()) {
      return s_emptyStr;
    } else if (str.charAt(0) > '9') {
      // If it doesn't start with a number, then we know it can never collide
      // with an int or any of our constants, so it's fine as is
      return param;
    }
  } else if (isContainer(cell_param) && getContainerSize(cell_param) == 0) {
    return s_emptyArr;
  }

  return fb_compact_serialize(param, FBCompactSerializeBehavior::MemoizeParam);
}
コード例 #5
0
ファイル: kml.cpp プロジェクト: agrismart/gdal-1.9.2
bool KML::isHandled(std::string const& elem) const
{
    if( isLeaf(elem) || isFeature(elem) || isFeatureContainer(elem)
        || isContainer(elem) || isRest(elem) )
    {
        return true;
    }
    return false;
}
コード例 #6
0
	void Widget::setEnabled( bool bEnabled )
	{
		if( m_state.isEnabled() != bEnabled || isContainer() )
		{
			State s = m_state;
			s.setEnabled(bEnabled);
			_setState(s);
		}
	}
コード例 #7
0
ファイル: ext_array.cpp プロジェクト: barkinet/hhvm
Variant f_array_combine(CVarRef keys, CVarRef values) {
  const auto& cell_keys = *keys.asCell();
  const auto& cell_values = *values.asCell();
  if (UNLIKELY(!isContainer(cell_keys) || !isContainer(cell_values))) {
    raise_warning("Invalid operand type was used: array_combine expects "
                  "arrays or collections");
    return uninit_null();
  }
  if (UNLIKELY(getContainerSize(cell_keys) != getContainerSize(cell_values))) {
    raise_warning("array_combine(): Both parameters should have an equal "
                  "number of elements");
    return false;
  }
  Array ret = ArrayData::Create();
  for (ArrayIter iter1(cell_keys), iter2(cell_values);
       iter1; ++iter1, ++iter2) {
    ret.lvalAt(iter1.secondRefPlus()).setWithRef(iter2.secondRefPlus());
  }
  return ret;
}
コード例 #8
0
ファイル: builtin-functions.cpp プロジェクト: 2bj/hhvm
Variant invoke(const String& function, const Variant& params,
               strhash_t hash /* = -1 */, bool tryInterp /* = true */,
               bool fatal /* = true */) {
  Func* func = Unit::loadFunc(function.get());
  if (func && (isContainer(params) || params.isNull())) {
    Variant ret;
    g_context->invokeFunc(ret.asTypedValue(), func, params);
    return ret;
  }
  return invoke_failed(function.c_str(), fatal);
}
コード例 #9
0
ファイル: REFERENCE.cpp プロジェクト: angeld29/morrgraphext
bool REFERENCE::GetInventory(TES3MACHINE& machine, VPREFERENCE pref, VPLISTNODE& firststack)
{
	firststack= 0;
	
	VMPTR<TES3REFERENCE> ref(machine,pref);
	VMPTR<TES3TEMPLATE> templ(machine,ref->templ);

	if(isContainer(templ))
		firststack= templ->inventory.first;
	
	return true;
}
コード例 #10
0
ファイル: ext_array.cpp プロジェクト: barkinet/hhvm
Variant f_array_values(CVarRef input) {
  const auto& cell_input = *input.asCell();
  if (!isContainer(cell_input)) {
    raise_warning("array_values() expects parameter 1 to be an array "
                  "or collection");
    return uninit_null();
  }
  PackedArrayInit ai(getContainerSize(cell_input));
  for (ArrayIter iter(cell_input); iter; ++iter) {
    ai.appendWithRef(iter.secondRefPlus());
  }
  return ai.toArray();
}
コード例 #11
0
void RObject::markDataDirty () {
	RK_TRACE (OBJECTS);

	type |= NeedDataUpdate;
	if (isContainer ()) {
	    RContainerObject* this_container = static_cast<RContainerObject*> (this);
		RObjectMap children = this_container->childmap;
		for (int i = children.size () - 1; i >= 0; --i) {
			children[i]->markDataDirty ();
		}
		if (this_container->rownames_object) this_container->rownames_object->markDataDirty ();
	}
}
コード例 #12
0
ファイル: builtin-functions.cpp プロジェクト: 2bj/hhvm
Variant vm_call_user_func(const Variant& function, const Variant& params,
                          bool forwarding /* = false */) {
  ObjectData* obj = nullptr;
  HPHP::Class* cls = nullptr;
  HPHP::JIT::CallerFrame cf;
  StringData* invName = nullptr;
  const HPHP::Func* f = vm_decode_function(function, cf(), forwarding,
                                           obj, cls, invName);
  if (f == nullptr || (!isContainer(params) && !params.isNull())) {
    return uninit_null();
  }
  Variant ret;
  g_context->invokeFunc((TypedValue*)&ret, f, params, obj, cls,
                          nullptr, invName, ExecutionContext::InvokeCuf);
  return ret;
}
コード例 #13
0
ファイル: builtin-functions.cpp プロジェクト: 2bj/hhvm
Variant invoke_static_method(const String& s, const String& method,
                             const Variant& params, bool fatal /* = true */) {
  HPHP::Class* class_ = Unit::lookupClass(s.get());
  if (class_ == nullptr) {
    o_invoke_failed(s.data(), method.data(), fatal);
    return uninit_null();
  }
  const HPHP::Func* f = class_->lookupMethod(method.get());
  if (f == nullptr || !(f->attrs() & AttrStatic) ||
    (!isContainer(params) && !params.isNull())) {
    o_invoke_failed(s.data(), method.data(), fatal);
    return uninit_null();
  }
  Variant ret;
  g_context->invokeFunc((TypedValue*)&ret, f, params, nullptr, class_);
  return ret;
}
コード例 #14
0
ファイル: string-util.cpp プロジェクト: Collabria/hhvm
String StringUtil::Implode(const Variant& items, const String& delim) {
  if (!isContainer(items)) {
    throw_param_is_not_container();
  }
  int size = getContainerSize(items);
  if (size == 0) return "";

  String* sitems = (String*)smart_malloc(size * sizeof(String));
  int len = 0;
  int lenDelim = delim.size();
  int i = 0;
  for (ArrayIter iter(items); iter; ++iter) {
    new (&sitems[i]) String(iter.second().toString());
    len += sitems[i].size() + lenDelim;
    i++;
  }
  len -= lenDelim; // always one delimiter less than count of items
  assert(i == size);

  String s = String(len, ReserveString);
  char *buffer = s.bufferSlice().ptr;
  const char *sdelim = delim.data();
  char *p = buffer;
  for (int i = 0; i < size; i++) {
    String &item = sitems[i];
    if (i && lenDelim) {
      memcpy(p, sdelim, lenDelim);
      p += lenDelim;
    }
    int lenItem = item.size();
    if (lenItem) {
      memcpy(p, item.data(), lenItem);
      p += lenItem;
    }
    sitems[i].~String();
  }
  smart_free(sitems);
  assert(p - buffer == len);
  s.setSize(len);
  return s;
}
コード例 #15
0
ファイル: string-util.cpp プロジェクト: HilayPatel/hhvm
String StringUtil::Implode(const Variant& items, const String& delim,
                           const bool checkIsContainer /* = true */) {
  if (checkIsContainer && !isContainer(items)) {
    throw_param_is_not_container();
  }
  int size = getContainerSize(items);
  if (size == 0) return empty_string();

  req::vector<String> sitems;
  sitems.reserve(size);
  size_t len = 0;
  size_t lenDelim = delim.size();
  for (ArrayIter iter(items); iter; ++iter) {
    sitems.emplace_back(iter.second().toString());
    len += sitems.back().size() + lenDelim;
  }
  len -= lenDelim; // always one delimiter less than count of items
  assert(sitems.size() == size);

  String s = String(len, ReserveString);
  char *buffer = s.mutableData();
  const char *sdelim = delim.data();
  char *p = buffer;
  String &init_str = sitems[0];
  int init_len = init_str.size();
  memcpy(p, init_str.data(), init_len);
  p += init_len;
  for (int i = 1; i < size; i++) {
    String &item = sitems[i];
    memcpy(p, sdelim, lenDelim);
    p += lenDelim;
    int lenItem = item.size();
    memcpy(p, item.data(), lenItem);
    p += lenItem;
  }
  assert(p - buffer == len);
  s.setSize(len);
  return s;
}
コード例 #16
0
    void OverlayContainer::copyFromTemplate(OverlayElement* templateOverlay)
    {
        OverlayElement::copyFromTemplate(templateOverlay);

            if (templateOverlay->isContainer() && isContainer())
            {
             OverlayContainer::ChildIterator it = static_cast<OverlayContainer*>(templateOverlay)->getChildIterator();
             while (it.hasMoreElements())
             {
                 OverlayElement* oldChildElement = it.getNext();
                 if (oldChildElement->isCloneable())
                 {
                     OverlayElement* newChildElement = 
                         OverlayManager::getSingleton().createOverlayElement(
                            oldChildElement->getTypeName(), 
                            mName+"/"+oldChildElement->getName());
                     newChildElement->copyFromTemplate(oldChildElement);
                     addChild(static_cast<OverlayContainer*>(newChildElement));
                 }
             }
        }
    }
コード例 #17
0
void BaseSet::addAllKeysOf(const Cell container) {
  assert(isContainer(container));

  decltype(cap()) oldCap = 0;
  bool ok = IterateKV(
    container,
    [&](ArrayData* adata) {
      auto sz = adata->size();
      if (!sz) return true;
      if (m_size) {
        oldCap = cap(); // assume minimal collisions
      }
      reserve(m_size + sz);
      mutateAndBump();
      return false;
    },
    [this](const TypedValue* key, const TypedValue* value) {
      addRaw(tvAsCVarRef(key));
    },
    [this](ObjectData* coll) {
      if (!m_size && coll->collectionType() == CollectionType::Set) {
        auto hc = static_cast<HashCollection*>(coll);
        replaceArray(hc->arrayData());
        setIntLikeStrKeys(BaseSet::intLikeStrKeys(hc));
        return true;
      }
      if (coll->collectionType() == CollectionType::Pair) {
        mutateAndBump();
      }
      return false;
    });

  if (UNLIKELY(!ok)) {
    throw_invalid_collection_parameter();
  }
  // ... and shrink back if that was incorrect
  if (oldCap) shrinkIfCapacityTooHigh(oldCap);
}
コード例 #18
0
ファイル: ext_array.cpp プロジェクト: barkinet/hhvm
Variant f_array_keys(CVarRef input, CVarRef search_value /* = null_variant */,
                     bool strict /* = false */) {
  const auto& cell_input = *input.asCell();
  if (UNLIKELY(!isContainer(cell_input))) {
    goto warn;
  }
  {
    // We treat Sets differently. For Sets, we pretend the values are
    // also the keys (similar to how Set::toArray() behaves).
    bool isSetType =
      cell_input.m_type == KindOfObject &&
      cell_input.m_data.pobj->getCollectionType() == Collection::SetType;
    if (UNLIKELY(isSetType)) {
      return arrayKeysSetHelper(cell_input, search_value, strict);
    }
    ArrayIter iter(cell_input);
    if (LIKELY(!search_value.isInitialized())) {
      PackedArrayInit ai(getContainerSize(cell_input));
      for (; iter; ++iter) {
        ai.append(iter.first());
      }
      return ai.toArray();
    }

    Array ai = Array::attach(HphpArray::MakeReserve(0));
    for (; iter; ++iter) {
      if ((strict && HPHP::same(iter.secondRefPlus(), search_value)) ||
          (!strict && HPHP::equal(iter.secondRefPlus(), search_value))) {
        ai.append(iter.first());
      }
    }
    return ai;
  }
warn:
  raise_warning("array_keys() expects parameter 1 to be an array "
                "or collection");
  return uninit_null();
}
コード例 #19
0
ファイル: qdesigner_widgetitem.cpp プロジェクト: mohdpatah/qt
bool QDesignerWidgetItem::check(const QLayout *layout, QWidget *w, Qt::Orientations *ptrToOrientations)
{
    // Check for form-editor non-containerextension-containers (QFrame, etc)
    // within laid-out form editor widgets. No check for managed() here as we
    // want container pages and widgets in the process of being morphed as
    // well. Avoid nested layouts (as the effective stretch cannot be easily
    // computed and may mess things up). Won't work for Q3 Group boxes.
    if (ptrToOrientations)
        *ptrToOrientations = 0;

    const QObject *layoutParent = layout->parent();
    if (!layoutParent || !layoutParent->isWidgetType() || !WidgetFactory::isFormEditorObject(layoutParent))
        return false;

    QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(w);
    if (!fw || !isContainer(fw->core(), w))
        return false;

    // If it is a box, restrict to its orientation
    if (ptrToOrientations)
        *ptrToOrientations = layoutOrientation(layout);

    return true;
}
コード例 #20
0
AST_MATCHER(NamedDecl, stlContainer) {
  return isContainer(Node.getQualifiedNameAsString());
}
コード例 #21
0
ファイル: Component.cpp プロジェクト: bramstein/ui
	void Component::paint(Graphics& g) const
	{
		g.pushMatrix();

		g.translate(getBounds().x,getBounds().y);

		if(rotation != 0.0f)
		{
			int x = getBounds().width /2;
			int y = getBounds().height/2;
		
			g.translate(x,y);
			g.rotate(rotation);
			g.translate(-x,-y);
		}

		// we only paint if its state is visible.
		if(isVisible() && rec.width > 0 && rec.height > 0)
		{
			bool storeDepth = false;

			if(isContainer())
			{
				// we need to store the current depth value,
				// so that it affects all children of this Component.
				storeDepth = g.pushDepth(depth);
			}

			// if this Component is currently not valid, validate it.
			if(!isValid())
			{
				validate();
			}

			if(SelectionManager::getInstance().getRenderMode() == SelectionManager::NORMAL)
			{
				// we're in the normal render mode, so check for transparency,
				// and paint everything
				bool storeTransparency = false;

				storeTransparency = g.pushTransparency(transparency);

				//displayList = g.
				//if(!isDisplayListCompiled)
				//{
				//	util::DisplayList compile(displayList);

					// first paint the background
					paintComponent(g);

					// then any custom painting,
					// which can be done by overloading
					// paintComponent.

					// then paint the borders
					paintBorder(g);

				//	isDisplayListCompiled = true;
				//}
				//else
				//{
				//	util::DisplayList::call(displayList);
				//}

				// then paint the children
				paintChildren(g);

				if(storeTransparency)
				{
					// restore transparency
					g.popTransparency();
				}
			}
			else
			{
				// this is the Picking render mode, we only do special painting
				// here, which helps to speed up this step.

				if(hasMouseListener())
				{
					paintSelectionComponent(g);
				}
				paintChildren(g);
			}

			if(isContainer())
			{
				if(storeDepth)
				{
					// restore depth values
					g.popDepth(depth);
				}
			}
		}
		g.popMatrix();
		//g.translate(-getBounds().x,-getBounds().y);
	}
コード例 #22
0
ファイル: Symbol.cpp プロジェクト: PhilllyJoy/rtags
String Symbol::toString(Flags<ToStringFlag> cursorInfoFlags,
                        Flags<Location::ToStringFlag> locationToStringFlags,
                        const std::shared_ptr<Project> &project) const
{
    auto properties = [this]()
    {
        List<String> ret;
        if (isDefinition())
            ret << "Definition";
        if (isContainer())
            ret << "Container";
        if ((flags & PureVirtualMethod) == PureVirtualMethod) {
            ret << "Pure Virtual";
        } else if (flags & VirtualMethod) {
            ret << "Virtual";
        }

        if (flags & ConstMethod) {
            ret << "Const";
        } else if (flags & StaticMethod) {
            ret << "Static";
        }

        if (flags & Variadic)
            ret << "Variadic";
        if (flags & Auto)
            ret << "Auto";
        if (flags & AutoRef)
            ret << "AutoRef";

        if (flags & MacroExpansion)
            ret << "MacroExpansion";
        if (flags & TemplateSpecialization)
            ret << "TemplateSpecialization";

        if (ret.isEmpty())
            return String();
        String joined = String::join(ret, ' ');
        joined += '\n';
        return joined;
    };

    List<String> bases;
    if (project) {
        extern String findSymbolNameByUsr(const std::shared_ptr<Project> &, const String &, const Location &location);
        for (const auto &base : baseClasses) {
            const String symbolName = findSymbolNameByUsr(project, base, location);
            if (!symbolName.isEmpty()) {
                bases << symbolName;
            }
        }
    } else {
        bases = baseClasses;
    }

    auto printTypeName = [this]() {
        String str;
        if (!typeName.isEmpty()) {
            str = typeName;
        } else if (type != CXType_Invalid) {
            str = RTags::eatString(clang_getTypeKindSpelling(type));
        } else {
            return String();
        }
        return String::format<128>("Type: %s\n", str.constData());
    };

    String ret = String::format<1024>("SymbolName: %s\n"
                                      "Kind: %s\n"
                                      "%s" // type
                                      "SymbolLength: %u\n"
                                      "%s" // range
                                      "%s" // enumValue
                                      "%s" // linkage
                                      "%s" // properties
                                      "%s" // usr
                                      "%s" // sizeof
                                      "%s" // fieldoffset
                                      "%s" // baseclasses
                                      "%s" // briefComment
                                      "%s", // xmlComment
                                      symbolName.constData(),
                                      kindSpelling().constData(),
                                      printTypeName().constData(),
                                      symbolLength,
                                      startLine != -1 ? String::format<32>("Range: %d:%d-%d:%d\n", startLine, startColumn, endLine, endColumn).constData() : "",
#if CINDEX_VERSION_MINOR > 1
                                      kind == CXCursor_EnumConstantDecl ? String::format<32>("Enum Value: %lld\n", enumValue).constData() :
#endif
                                      "",
                                      linkageSpelling(linkage),
                                      properties().constData(),
                                      usr.isEmpty() ? "" : String::format<64>("Usr: %s\n", usr.constData()).constData(),
                                      size > 0 ? String::format<16>("sizeof: %d\n", size).constData() : "",
                                      fieldOffset >= 0 ? String::format<32>("field offset (bits/bytes): %d/%d\n", fieldOffset, fieldOffset / 8).constData() : "",
                                      alignment >= 0 ? String::format<32>("alignment (bytes): %d\n", alignment).constData() : "",
                                      bases.isEmpty() ? "" : String::format<64>("BaseClasses: %s\n", String::join(bases, ", ").constData()).constData(),
                                      briefComment.isEmpty() ? "" : String::format<1024>("Brief comment: %s\n", briefComment.constData()).constData(),
                                      xmlComment.isEmpty() ? "" : String::format<16384>("Xml comment: %s\n", xmlComment.constData()).constData());
    if (!(cursorInfoFlags & IgnoreTargets) && project) {
        extern Set<Symbol> findTargets(const std::shared_ptr<Project> &, const Symbol &);
        auto targets = findTargets(project, *this);
        if (targets.size()) {
            ret.append("Targets:\n");
            auto best = RTags::bestTarget(targets);
            ret.append(String::format<128>("    %s\n", best.location.toString(locationToStringFlags).constData()));

            for (const auto &tit : targets) {
                if (tit.location != best.location)
                    ret.append(String::format<128>("    %s\n", tit.location.toString(locationToStringFlags).constData()));
            }
        }
    }

    if (!(cursorInfoFlags & IgnoreReferences) && project && !isReference()) {
        extern Set<Symbol> findCallers(const std::shared_ptr<Project> &, const Symbol &);
        auto references = findCallers(project, *this);
        if (references.size()) {
            ret.append("References:\n");
            for (const auto &r : references) {
                ret.append(String::format<128>("    %s\n", r.location.toString(locationToStringFlags).constData()));
            }
        }
    }

    return ret;
}
コード例 #23
0
ファイル: verilog.c プロジェクト: shunlir/ctags
static void createTag (tokenInfo *const token)
{
	tagEntryInfo tag;

	/* Do nothing it tag name is empty or tag kind is disabled */
	if (vStringLength (token->name) == 0 || ! kindEnabled (token->kind))
	{
		return;
	}

	/* Create tag */
	initTagEntryFull(
			&tag,
			vStringValue (token->name),
			token->lineNumber,
			getSourceLanguageName (),
			token->filePosition,
			getSourceFileTagPath (),
			kindFromKind (token->kind)
			);
	verbose ("Adding tag %s (kind %d)", vStringValue (token->name), token->kind);
	if (currentContext->kind != K_UNDEFINED)
	{
		verbose (" to context %s\n", vStringValue (currentContext->name));
		currentContext->lastKind = token->kind;
		tag.extensionFields.scopeKind = kindFromKind (currentContext->kind);
		tag.extensionFields.scopeName = vStringValue (currentContext->name);
	}
	verbose ("\n");
	if (vStringLength (token->inheritance) > 0)
	{
		tag.extensionFields.inheritance = vStringValue (token->inheritance);
		verbose ("Class %s extends %s\n", vStringValue (token->name), tag.extensionFields.inheritance);
	}
	makeTagEntry (&tag);
	if (Option.include.qualifiedTags && currentContext->kind != K_UNDEFINED)
	{
		vString *const scopedName = vStringNew ();

		vStringCopy (scopedName, currentContext->name);
		vStringCatS (scopedName, ".");
		vStringCatS (scopedName, vStringValue (token->name));
		tag.name = vStringValue (scopedName);

		makeTagEntry (&tag);

		vStringDelete (scopedName);
	}

	/* Push token as context if it is a container */
	if (isContainer (token))
	{
		tokenInfo *newScope = newToken ();

		vStringCopy (newScope->name, token->name);
		newScope->kind = token->kind;
		createContext (newScope);
	}

	/* Clear no longer required inheritance information */
	vStringClear (token->inheritance);
}
コード例 #24
0
ファイル: Symbol.cpp プロジェクト: Andersbakken/rtags
String Symbol::toString(const std::shared_ptr<Project> &project,
                        const Flags<ToStringFlag> cursorInfoFlags,
                        Flags<Location::ToStringFlag> locationToStringFlags,
                        const Set<String> &pieceFilters) const
{
    auto filterPiece = [&pieceFilters](const char *name) { return pieceFilters.isEmpty() || pieceFilters.contains(name); };
    auto properties = [this, &filterPiece]() -> String {
        List<String> ret;
        if (isDefinition() && filterPiece("definition"))
            ret << "Definition";
        if (isContainer() && filterPiece("container"))
            ret << "Container";
        if ((flags & PureVirtualMethod) == PureVirtualMethod && filterPiece("purevirtual"))
            ret << "Pure Virtual";
        if (flags & VirtualMethod && filterPiece("virtual"))
            ret << "Virtual";

        if (flags & ConstMethod) {
            if (filterPiece("constmethod"))
                ret << "ConstMethod";
        } else if (flags & StaticMethod && filterPiece("static")) {
            ret << "Static";
        }

        if (flags & Variadic && filterPiece("variadic"))
            ret << "Variadic";
        if (flags & Auto && filterPiece("auto"))
            ret << "Auto";

        if (flags & MacroExpansion && filterPiece("macroexpansion"))
            ret << "MacroExpansion";
        if (flags & TemplateSpecialization && filterPiece("templatespecialization"))
            ret << "TemplateSpecialization";
        if (flags & TemplateReference && filterPiece("templatereference"))
            ret << "TemplateReference";

        if (ret.isEmpty())
            return String();
        return String::join(ret, ' ') + '\n';
    };

    List<String> bases;
    List<String> args;

    if (project) {
        if (filterPiece("baseclasses")) {
            for (const auto &base : baseClasses) {
                bool found = false;
                for (const auto &sym : project->findByUsr(base, location.fileId(), Project::ArgDependsOn)) {
                    bases << sym.symbolName;
                    found = true;
                    break;
                }
                if (!found) {
                    bases << base;
                }
            }
        }
        if (filterPiece("arguments")) {
            for (const auto &arg : arguments) {
                const String symName = project->findSymbol(arg.cursor).symbolName;
                if (!symName.isEmpty()) {
                    args << symName;
                } else {
                    args << arg.cursor.toString(locationToStringFlags & ~Location::ShowContext);
                }
            }
        }
    } else if (filterPiece("baseClasses")) {
        bases = baseClasses;
    }

    String ret;
    auto writePiece = [&ret, &filterPiece](const char *key, const char *filter, const String &piece) {
        if (piece.isEmpty())
            return;
        if (!filterPiece(filter))
            return;
        if (key && strlen(key))
            ret << key << ": ";
        ret << piece << "\n";
    };
    writePiece(0, "location", location.toString(locationToStringFlags));
    writePiece("SymbolName", "symbolname", symbolName);
    writePiece("Kind", "kind", kindSpelling());
    if (filterPiece("type")) {
        if (!typeName.isEmpty()) {
            ret += "Type: " + typeName + "\n";
        } else if (type != CXType_Invalid) {
            ret += "Type: " + RTags::eatString(clang_getTypeKindSpelling(type)) + "\n";
        }
    }
    writePiece("SymbolLength", "symbollength", std::to_string(symbolLength));

    if (startLine != -1)
        writePiece("Range", "range", String::format<32>("%d:%d-%d:%d", startLine, startColumn, endLine, endColumn));

#if CINDEX_VERSION_MINOR > 1
    if (kind == CXCursor_EnumConstantDecl)
        writePiece("Enum Value", "enumvalue",
                   String::format<32>("%lld/0x%0llx", static_cast<long long>(enumValue), static_cast<long long>(enumValue)));

    if (isDefinition() && RTags::isFunction(kind))
        writePiece("Stack cost", "stackcost", std::to_string(stackCost));
#endif
    writePiece(0, "linkage", linkageSpelling(linkage));
    ret += properties();
    writePiece("Usr", "usr", usr);
    if (size)
        writePiece("sizeof", "sizeof", std::to_string(size));
    if (fieldOffset >= 0)
        writePiece("Field offset (bits/bytes)", "fieldoffset",
                   String::format<32>("%d/%d", fieldOffset, fieldOffset / 8));
    if (alignment >= 0)
        writePiece("Alignment", "alignment", std::to_string(alignment));
    if (!args.isEmpty())
        writePiece("Arguments", "arguments", String::join(args, ", "));
    if (!bases.isEmpty())
        writePiece("Base classes", "baseclasses", String::join(bases, ", "));
    writePiece("Brief comment", "briefcomment", briefComment);
    writePiece("XML comment", "xmlcomment", xmlComment);

    if ((cursorInfoFlags & IncludeParents && filterPiece("parent"))
        || (cursorInfoFlags & (IncludeContainingFunction) && filterPiece("cf"))
        || (cursorInfoFlags & (IncludeContainingFunctionLocation) && filterPiece("cfl"))) {
        auto syms = project->openSymbols(location.fileId());
        uint32_t idx = -1;
        if (syms) {
            idx = syms->lowerBound(location);
            if (idx == std::numeric_limits<uint32_t>::max()) {
                idx = syms->count() - 1;
            }
        }
        const unsigned int line = location.line();
        const unsigned int column = location.column();
        while (idx-- > 0) {
            const Symbol s = syms->valueAt(idx);
            if (s.isDefinition()
                && s.isContainer()
                && comparePosition(line, column, s.startLine, s.startColumn) >= 0
                && comparePosition(line, column, s.endLine, s.endColumn) <= 0) {
                if (cursorInfoFlags & IncludeContainingFunctionLocation)
                    writePiece("Containing function location", "cfl", s.location.toString(locationToStringFlags));
                if (cursorInfoFlags & IncludeContainingFunction)
                    writePiece("Containing function", "cf", s.symbolName);
                if (cursorInfoFlags & IncludeParents)
                    writePiece("Parent", "parent", s.location.toString(locationToStringFlags)); // redundant, this is a mess
                break;
            }
        }
    }



    if (cursorInfoFlags & IncludeTargets && project && filterPiece("targets")) {
        const auto targets = project->findTargets(*this);
        if (targets.size()) {
            ret.append("Targets:\n");
            auto best = RTags::bestTarget(targets);
            ret.append(String::format<128>("    %s\n", best.location.toString(locationToStringFlags).constData()));

            for (const auto &tit : targets) {
                if (tit.location != best.location)
                    ret.append(String::format<128>("    %s\n", tit.location.toString(locationToStringFlags).constData()));
            }
        }
    }

    if (cursorInfoFlags & IncludeReferences && project && !isReference() && filterPiece("references")) {
        const auto references = project->findCallers(*this);
        if (references.size()) {
            ret.append("References:\n");
            for (const auto &r : references) {
                ret.append(String::format<128>("    %s\n", r.location.toString(locationToStringFlags).constData()));
            }
        }
    }

    return ret;
}
コード例 #25
0
ファイル: MLProc.cpp プロジェクト: afofo/madronalib
// TODO null signals function but are not printed out quite right
// because sometimes the parent's null signal is used and sometimes not
void MLProc::dumpProc(int indent)
{
	int ins = getNumInputs();
	int outs = getNumOutputs();
	const MLSignal* pNullInput = &(getContext()->getNullInput());
	const MLSignal* pNullOutput = &(getContext()->getNullOutput());
		
	debug() << spaceStr(indent) << getName() << " (" << getClassName() << " " << (void *)&(*this) << ")";
	
	if (isContainer())
	{
		std::string enabledStr = isEnabled() ? " [ENABLED] " : " [DISABLED] ";
		debug() << enabledStr;
	}
	debug() << "\n";
	debug() << spaceStr(indent) << "inputs: ";
	if (ins)
	{
		for(int j = 1; j <= ins; ++j)
		{
			debug() << "[" << j << "] ";
			const MLSignal* pIn = &getInput(j);
			if (pIn == pNullInput)
			{
				debug() << "(null)  ";
			}
			else
			{
				debug() << "(" << (void *)(pIn) << ")  ";
			}
		}
	}
	else
	{
		debug() << "(none)";
	}
	debug() << "\n";
	debug() << spaceStr(indent) << "outputs: ";
	if (outs)
	{
		for(int j = 1; j <= outs; ++j)
		{
			debug() << "[" << j << "] ";
			const MLSignal* pOut = &getOutput(j);
			if(pOut == pNullOutput)
			{
				debug() << "(null)  ";
			}
			else
			{
				// can no longer determine isConstant here because signals are shared.
				debug() << "(" << (void *)(pOut)  << ")  ";
			}
		}
	}
	else
	{
		debug() << "(none)";
	}
	debug() << "\n";
}
コード例 #26
0
ファイル: verilog.c プロジェクト: pjkack/ctags
static void createTag (tokenInfo *const token)
{
	tagEntryInfo tag;
	verilogKind kind;

	/* Determine if kind is prototype */
	if (currentContext->prototype)
	{
		kind = K_PROTOTYPE;
	}
	else
	{
		kind = token->kind;
	}

	/* Do nothing it tag name is empty or tag kind is disabled */
	if (vStringLength (token->name) == 0 || ! kindEnabled (kind))
	{
		return;
	}

	/* Create tag */
	initTagEntry (&tag,
		      vStringValue (token->name),
		      kindFromKind (kind));
	tag.lineNumber = token->lineNumber;
	tag.filePosition = token->filePosition;

	verbose ("Adding tag %s (kind %d)", vStringValue (token->name), kind);
	if (currentContext->kind != K_UNDEFINED)
	{
		verbose (" to context %s\n", vStringValue (currentContext->name));
		currentContext->lastKind = kind;
		tag.extensionFields.scopeKind = kindFromKind (currentContext->kind);
		tag.extensionFields.scopeName = vStringValue (currentContext->name);
	}
	verbose ("\n");
	if (vStringLength (token->inheritance) > 0)
	{
		tag.extensionFields.inheritance = vStringValue (token->inheritance);
		verbose ("Class %s extends %s\n", vStringValue (token->name), tag.extensionFields.inheritance);
	}
	makeTagEntry (&tag);
	if (isXtagEnabled(XTAG_QUALIFIED_TAGS) && currentContext->kind != K_UNDEFINED)
	{
		vString *const scopedName = vStringNew ();

		vStringCopy (scopedName, currentContext->name);
		vStringPut (scopedName, '.');
		vStringCatS (scopedName, vStringValue (token->name));
		tag.name = vStringValue (scopedName);

		markTagExtraBit (&tag, XTAG_QUALIFIED_TAGS);
		makeTagEntry (&tag);

		vStringDelete (scopedName);
	}

	/* Push token as context if it is a container */
	if (isContainer (token))
	{
		tokenInfo *newScope = newToken ();

		vStringCopy (newScope->name, token->name);
		newScope->kind = kind;
		createContext (newScope);
	}

	/* Clear no longer required inheritance information */
	vStringClear (token->inheritance);
}
コード例 #27
0
String Symbol::toString(Flags<ToStringFlag> cursorInfoFlags,
                        Flags<Location::ToStringFlag> locationToStringFlags,
                        const std::shared_ptr<Project> &project) const
{
    auto properties = [this]()
        {
            List<String> ret;
            if (isDefinition())
                ret << "Definition";
            if (isContainer())
                ret << "Container";
            if ((flags & PureVirtualMethod) == PureVirtualMethod) {
                ret << "Pure Virtual";
            } else if (flags & VirtualMethod) {
                ret << "Virtual";
            }

            if (flags & ConstMethod) {
                ret << "Const";
            } else if (flags & StaticMethod) {
                ret << "Static";
            }

            if (flags & Variadic)
                ret << "Variadic";
            if (flags & Auto)
                ret << "Auto";
            if (flags & AutoRef)
                ret << "AutoRef";

            if (flags & MacroExpansion)
                ret << "MacroExpansion";
            if (flags & TemplateSpecialization)
                ret << "TemplateSpecialization";

            if (ret.isEmpty())
                return String();
            String joined = String::join(ret, ' ');
            joined += '\n';
            return joined;
        };

    List<String> bases;
    List<String> args;
    if (project) {
        for (const auto &base : baseClasses) {
            bool found = false;
            for (const auto &sym : project->findByUsr(base, location.fileId(), Project::ArgDependsOn, location)) {
                bases << sym.symbolName;
                found = true;
                break;
            }
            if (!found) {
                bases << base;
            }
        }
        for (const auto &arg : arguments) {
            const String symName = project->findSymbol(arg.cursor).symbolName;
            if (!symName.isEmpty()) {
                args << symName;
            } else {
                args << arg.cursor.toString(locationToStringFlags & ~Location::ShowContext);
            }
        }
    } else {
        bases = baseClasses;
    }

    auto printTypeName = [this]() {
        String str;
        if (!typeName.isEmpty()) {
            str = typeName;
        } else if (type != CXType_Invalid) {
            str = RTags::eatString(clang_getTypeKindSpelling(type));
        } else {
            return String();
        }
        return String::format<128>("Type: %s\n", str.constData());
    };

    String ret = String::format<1024>("%s\n"
                                      "SymbolName: %s\n"
                                      "Kind: %s\n"
                                      "%s" // type
                                      "SymbolLength: %u\n"
                                      "%s" // range
                                      "%s" // enumValue/stackCost
                                      "%s" // linkage
                                      "%s" // properties
                                      "%s" // usr
                                      "%s" // sizeof
                                      "%s" // fieldoffset
                                      "%s" // alignment
                                      "%s" // arguments
                                      "%s" // baseclasses
                                      "%s" // briefComment
                                      "%s", // xmlComment
                                      location.toString(locationToStringFlags).constData(),
                                      symbolName.constData(),
                                      kindSpelling().constData(),
                                      printTypeName().constData(),
                                      symbolLength,
                                      startLine != -1 ? String::format<32>("Range: %d:%d-%d:%d\n", startLine, startColumn, endLine, endColumn).constData() : "",
#if CINDEX_VERSION_MINOR > 1
                                      (kind == CXCursor_EnumConstantDecl
                                       ? String::format<32>("Enum Value: %lld/0x%0llx\n",
                                                            static_cast<long long>(enumValue),
                                                            static_cast<long long>(enumValue)).constData()
                                       : (isDefinition() && RTags::isFunction(kind)
                                          ? String::format<32>("Stack cost: %d\n", stackCost).constData()
                                          : "")),
#else
                                      "",
#endif
                                      linkageSpelling(linkage),
                                      properties().constData(),
                                      usr.isEmpty() ? "" : String::format<64>("Usr: %s\n", usr.constData()).constData(),
                                      size > 0 ? String::format<16>("sizeof: %d\n", size).constData() : "",
                                      fieldOffset >= 0 ? String::format<32>("field offset (bits/bytes): %d/%d\n", fieldOffset, fieldOffset / 8).constData() : "",
                                      alignment >= 0 ? String::format<32>("alignment (bytes): %d\n", alignment).constData() : "",
                                      args.isEmpty() ? "" : String::format<1024>("Arguments: %s\n", String::join(args, ", ").constData()).constData(),
                                      bases.isEmpty() ? "" : String::format<64>("BaseClasses: %s\n", String::join(bases, ", ").constData()).constData(),
                                      briefComment.isEmpty() ? "" : String::format<1024>("Brief comment: %s\n", briefComment.constData()).constData(),
                                      xmlComment.isEmpty() ? "" : String::format<16384>("XML comment: %s\n", xmlComment.constData()).constData());
    if (cursorInfoFlags & IncludeTargets && project) {
        const auto targets = project->findTargets(*this);
        if (targets.size()) {
            ret.append("Targets:\n");
            auto best = RTags::bestTarget(targets);
            ret.append(String::format<128>("    %s\n", best.location.toString(locationToStringFlags).constData()));

            for (const auto &tit : targets) {
                if (tit.location != best.location)
                    ret.append(String::format<128>("    %s\n", tit.location.toString(locationToStringFlags).constData()));
            }
        }
    }

    if (cursorInfoFlags & IncludeReferences && project && !isReference()) {
        const auto references = project->findCallers(*this);
        if (references.size()) {
            ret.append("References:\n");
            for (const auto &r : references) {
                ret.append(String::format<128>("    %s\n", r.location.toString(locationToStringFlags).constData()));
            }
        }
    }

    return ret;
}
コード例 #28
0
ファイル: kmlvector.cpp プロジェクト: OSGeo/gdal
void KMLVector::findLayers(KMLNode* poNode, int bKeepEmptyContainers)
{
    bool bEmpty = true;

    // Start with the trunk
    if( nullptr == poNode )
    {
        nNumLayers_ = 0;
        poNode = poTrunk_;
    }

    if( isFeature(poNode->getName())
        || isFeatureContainer(poNode->getName())
        || ( isRest(poNode->getName())
             && poNode->getName().compare("kml") != 0 ) )
    {
        return;
    }
    else if( isContainer(poNode->getName()) )
    {
        for( int z = 0; z < (int) poNode->countChildren(); z++ )
        {
            if( isContainer(poNode->getChild(z)->getName()) )
            {
                findLayers(poNode->getChild(z), bKeepEmptyContainers);
            }
            else if( isFeatureContainer(poNode->getChild(z)->getName()) )
            {
                bEmpty = false;
            }
        }

        if( bKeepEmptyContainers && poNode->getName() == "Folder" )
        {
            if (!bEmpty)
                poNode->eliminateEmpty(this);
        }
        else if(bEmpty)
        {
            return;
        }

        Nodetype nodeType = poNode->getType();
        if( bKeepEmptyContainers ||
            isFeature(Nodetype2String(nodeType)) ||
            nodeType == Mixed ||
            nodeType == MultiGeometry || nodeType == MultiPoint ||
            nodeType == MultiLineString || nodeType == MultiPolygon)
        {
            poNode->setLayerNumber(nNumLayers_++);
            papoLayers_ = static_cast<KMLNode**>(
                CPLRealloc(papoLayers_, nNumLayers_ * sizeof(KMLNode*)) );
            papoLayers_[nNumLayers_ - 1] = poNode;
        }
        else
        {
            CPLDebug( "KML", "We have a strange type here for node %s: %s",
                      poNode->getName().c_str(),
                      Nodetype2String(poNode->getType()).c_str() );
        }
    }
    else
    {
        CPLDebug( "KML",
                  "There is something wrong!  Define KML_DEBUG to see details");
        if( CPLGetConfigOption("KML_DEBUG", nullptr) != nullptr )
            print();
    }
}