Exemplo n.º 1
0
std::string CppClass::getTextOfTemplateParamList(const ItemTextOptionFlags & options) const
{
	if(! this->isTemplate()) {
		return "";
	}

	string text;
	const TemplateDecl * templateDecl = dyn_cast<TemplateDecl>(this->getDecl());
	const TemplateParameterList * templateParamList = templateDecl->getTemplateParameters();
	for(TemplateParameterList::const_iterator it = templateParamList->begin(); it != templateParamList->end(); ++it) {
		if(! text.empty()) {
			text.append(", ");
		}

		const NamedDecl * namedDecl = *it;
		Decl::Kind kind = namedDecl->getKind();

		string defaultValue;
		if(kind == Decl::TemplateTypeParm) {
			const TemplateTypeParmDecl * paramDecl = dyn_cast<TemplateTypeParmDecl>(namedDecl);
			if(options.has(itoWithArgType)) {
				text.append(paramDecl->wasDeclaredWithTypename() ? "typename " : "class ");
			}
			text.append(paramDecl->getNameAsString());
			if(paramDecl->hasDefaultArgument()) {
				defaultValue = CppType(paramDecl->getDefaultArgument()).getQualifiedName();
			}
		}
		else if(kind == Decl::NonTypeTemplateParm) {
			const NonTypeTemplateParmDecl * paramDecl = dyn_cast<NonTypeTemplateParmDecl>(namedDecl);
			if(options.has(itoWithArgType)) {
				text.append(CppType(paramDecl->getType()).getQualifiedName(paramDecl->getNameAsString()));
			}
			else {
				text.append(paramDecl->getNameAsString());
			}
			if(paramDecl->hasDefaultArgument()) {
				defaultValue = exprToText(this->getASTContext(), paramDecl->getDefaultArgument());
			}
		}
		else if(kind == Decl::TemplateTemplateParm) {
			const TemplateTemplateParmDecl * paramDecl = dyn_cast<TemplateTemplateParmDecl>(namedDecl);
			if(options.has(itoWithArgType)) {
				text.append(declToText(this->getASTContext(), paramDecl));
			}
			else {
				text.append(paramDecl->getNameAsString());
			}
			if(paramDecl->hasDefaultArgument()) {
				defaultValue = getTemplateArgumentName(this->getASTContext(), paramDecl->getDefaultArgument().getArgument());
			}
		}
		if(! defaultValue.empty() && options.has(itoWithDefaultValue)) {
			text.append(" = " + defaultValue);
		}
	}

	return text;
}
Exemplo n.º 2
0
			Node nodeFromString(QString const &value, CppType type = CppType())
			{
				unsigned id = type.metaTypeId();

				if(!value.size())
				{
					if(id == QVariant::String)
						return Node(LiteralValue(value));
					return Node();
				}

				// XXX: maybe fuller support of user types, now assume all user types are
				// resources
				if(id >= QVariant::UserType)
					return Node(QUrl::fromEncoded(value.toAscii()));

				switch(id)
				{
				case CppType::None: break;
				case QVariant::Bool: return Node(LiteralValue(value == "true"));
				case QVariant::Int: return Node(LiteralValue(value.toInt()));
				case QVariant::UInt: return Node(LiteralValue(value.toUInt()));
				case QVariant::LongLong: return Node(LiteralValue(value.toLongLong()));
				case QVariant::ULongLong: return Node(LiteralValue(value.toULongLong()));
				case QVariant::Double: return Node(LiteralValue(value.toDouble()));
				case QVariant::Char: break; // return Node(LiteralValue(QChar));
				case QVariant::Map: break; // return Node(LiteralValue(QVariantMap));
				case QVariant::List: break; // return Node(LiteralValue(QVariantList));
				case QVariant::String: break; // return Node(LiteralValue(QString));
				case QVariant::StringList: break; // return Node(LiteralValue(QStringList));

				case QVariant::ByteArray:
					return Node(LiteralValue(value.toAscii())); // TODO: really?

				case QVariant::BitArray: break; // return Node(LiteralValue(QBitArray));

				case QVariant::Date:
					return Node(LiteralValue(QDate::fromString(value, Qt::ISODate)));

				case QVariant::Time:
					return Node(LiteralValue(QTime::fromString(value, Qt::ISODate)));

				case QVariant::DateTime:
					return Node(LiteralValue(QDateTime::fromString(value, Qt::ISODate)));
				// As of 3.9.2009, tracker is permissive regarding IRI's, so are we.
				case QVariant::Url: return Node(QUrl::fromEncoded(value.toAscii()));
				//	case QVariant::Url:
				//		return Node(QUrl::fromEncoded(value.toAscii(), QUrl::StrictMode));
				default: break;
				}
				return Node(LiteralValue(value));
			}
Exemplo n.º 3
0
string getTemplateArgumentName(const TemplateArgument & argument)
{
	string qualifiedName;

	switch(argument.getKind()) {
		case TemplateArgument::Null:
			qualifiedName = "NULL";
			break;

		case TemplateArgument::Type:
			qualifiedName = CppType(argument.getAsType()).getQualifiedName();
			break;

		case TemplateArgument::Declaration:
			qualifiedName = dyn_cast<NamedDecl>(argument.getAsDecl())->getQualifiedNameAsString();
			break;

		case TemplateArgument::Integral:
		case TemplateArgument::Expression:
			qualifiedName = exprToText(argument.getAsExpr());
			break;

		case TemplateArgument::Template:
			qualifiedName = argument.getAsTemplate().getAsTemplateDecl()->getQualifiedNameAsString();
			break;

		case TemplateArgument::TemplateExpansion:
			break;

		case TemplateArgument::Pack:
			break;

	}

	return qualifiedName;
}
Exemplo n.º 4
0
const CppClass * BaseClass::getCppClass() const
{
	const CppItem * cppItem = this->cppContext->findClassByType(CppType(this->baseSpecifier->getType()));
	GASSERT(cppItem != NULL && cppItem->isClass());
	return static_cast<const CppClass *>(cppItem);
}