std::string typeNameToString(const TypeName& type) { std::ostringstream stream; for (size_t i = 0; i < type.size(); ++i) { stream << type[i]; if (i < type.size() - 1) stream << '.'; } return stream.str(); }
TypeName typeNameFromString(const std::string& typeStr) { TypeName result; for (size_t index = 0; index < typeStr.size() && index != std::string::npos; ) { size_t nextSep = typeStr.find_first_of('.', index); if (nextSep == std::string::npos) nextSep = typeStr.size(); result.push_back(typeStr.substr(index, nextSep - index)); index = nextSep + 1; } return result; }
void BindingProperty::setDynamicTypeNameAndExpression(const TypeName &typeName, const QString &expression) { Internal::WriteLocker locker(model()); if (!isValid()) throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); if (name() == "id") { // the ID for a node is independent of the state, so it has to be set with ModelNode::setId throw InvalidPropertyException(__LINE__, __FUNCTION__, __FILE__, name()); } if (expression.isEmpty()) throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, name()); if (typeName.isEmpty()) throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, name()); if (internalNode()->hasProperty(name())) { //check if oldValue != value Internal::InternalProperty::Pointer internalProperty = internalNode()->property(name()); if (internalProperty->isBindingProperty() && internalProperty->toBindingProperty()->expression() == expression && internalProperty->toBindingProperty()->dynamicTypeName() == typeName) return; } if (internalNode()->hasProperty(name()) && !internalNode()->property(name())->isBindingProperty()) model()->d->removeProperty(internalNode()->property(name())); model()->d->setDynamicBindingProperty(internalNode(), name(), typeName, expression); }
//@@ In what situations would I produce different name by // these two functions? // string Context:: type_name (SemanticGraph::Type& t, string const& nss) { // There cannot be a named type inside an anonymous one. // if (t.named ()) { string r; TypeName tn (*this, r, nss); tn.dispatch (t); return r; } else return anon_prefix_ + id (t.name ()) + anon_suffix_; }
void SymbolResolvingVisitor::resolveTypeReference(TypeReference *typeRef) const { if(typeRef->isResolved()) return; TypeName typeName = typeRef->getTypeName(); SymbolBase *symbol = globalScope_->findSymbol(typeName); if(!symbol) errorSink_->error(typeRef->getLocation(), (boost::format("Referenced type '%s' was not found") % typeName.getFullName()).str()); TypeBase *foundType = dynamic_cast<TypeBase*>(symbol); assert(foundType != nullptr); //TODO: a human readable message in the case of unknown types typeRef->setType(foundType); }
void VariantProperty::setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value) { Internal::WriteLocker locker(model()); if (!isValid()) throw InvalidModelNodeException(__LINE__, __FUNCTION__, __FILE__); if (type.isEmpty()) throw InvalidArgumentException(__LINE__, __FUNCTION__, __FILE__, name()); if (internalNode()->hasProperty(name())) { //check if oldValue != value Internal::InternalProperty::Pointer internalProperty = internalNode()->property(name()); if (internalProperty->isVariantProperty() && internalProperty->toVariantProperty()->value() == value && internalProperty->toVariantProperty()->dynamicTypeName() == type) return; } if (internalNode()->hasProperty(name()) && !internalNode()->property(name())->isVariantProperty()) model()->d->removeProperty(internalNode()->property(name())); model()->d->setDynamicVariantProperty(internalNode(), name(), type, value); }