当前位置: 首页>>代码示例>>C++>>正文


C++ ASTType::ToNameString方法代码示例

本文整理汇总了C++中ASTType::ToNameString方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTType::ToNameString方法的具体用法?C++ ASTType::ToNameString怎么用?C++ ASTType::ToNameString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ASTType的用法示例。


在下文中一共展示了ASTType::ToNameString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CollectCustomTypes_TemplateArguments

	void CollectCustomTypes_TemplateArguments(bool verbose = false)
	{
		auto templateArguments = tools::LINQSelect(allChildren, [](ASTNode* it) { return it->GetType() == ASTNode::Type::TemplateArg; });
		for (auto it : templateArguments)
		{
			ASTType* itType = (ASTType*)it;
			if (itType->ToIdentifierString().empty() == false)
				continue; // template argument does not define a type
			if (itType->HasModifier(CxxToken::Type::Class) == false && itType->HasModifier(CxxToken::Type::Typename))
				continue; // template argument does not have "class" or "typename"

			auto parents = it->GatherParents();
			auto scopes = tools::LINQSelect(parents, [](ASTNode* it) { return it->GetType() == ASTNode::Type::Namespace || it->GetType() == ASTNode::Type::Template || (it->GetType() >= ASTNode::Type::Class && it->GetType() <= ASTNode::Type::Union); });
			std::reverse(scopes.begin(), scopes.end());

			std::string v;
			for (auto itScope : scopes)
			{
				v.append(itScope->ToString());
				v.append("::");
			}

			v.append(itType->ToNameString());
			if (verbose)
			{
				fprintf(stderr, "CollectCustomType_TemplateArgument: %s\n", v.c_str());
			}


			CollectCustomTypes_Add(v, it);
		}
	}
开发者ID:Lssikkes,项目名称:CppReflector,代码行数:32,代码来源:moduleCppTransfiguration.cpp

示例2: ResolveTypes

	void ResolveTypes(ASTNode* node, ScopeResolveTypes& tscope, bool verbose=false)
	{
#		define LOCATIONINFO " (line %d, source \"%s\").\n"
#		define LOCATIONINFODATA  nodeType->tokenSource->Tokens[nodeType->typeName[0].Index].TokenLine, nodeType->tokenSource->SourceIdentifier()
		bool isScope = false;
		ASTType* nodeType = dynamic_cast<ASTType*>(node);
		if (nodeType && nodeType->HasType() && nodeType->IsBuiltinType() == false)
		{

			bool typeNameFromRoot = false;
			std::string typeName = nodeType->ToNameString(false);
			if (typeName.size() >= 2 && typeName.at(0) == ':' && typeName.at(1) == ':')
			{
				typeNameFromRoot = true;
				typeName.erase(typeName.begin(), typeName.begin() + 2);
			}

			if (verbose)
			{
				fprintf(stderr, "RESOLVE ");
				for (auto it : tscope.usingNamespaces)
					fprintf(stderr, "{%s} ", it.c_str());
				for (auto it : tscope.inScopes)
					fprintf(stderr, "[%s] ", it->ToString().c_str());
				fprintf(stderr, "%s", nodeType->ToNameString().c_str());

			}

			// check if name points directly to node
			std::string resolvedAs;
			//if (typeNameFromRoot)
			{

				// try to find directly
				if (resolvedAs.empty())
				{
					auto found = allCustomTypes.find(typeName);
					if (found != allCustomTypes.end())
					{
						nodeType->resolvedType = found->second;
						resolvedAs = found->first;
					}
				}
				
				// go backwards over scopes and try to find that way
				if (resolvedAs.empty())
				{
					for (int i = tscope.inScopes.size() - 1; i >= 0; i--)
					{
						std::string prefix;
						for (int j = 0; j <= i; j++)
							prefix += tscope.inScopes[j]->ToString() + "::";

						auto found = allCustomTypes.find(prefix + typeName);
						if (found != allCustomTypes.end())
						{
							nodeType->resolvedType = found->second;
							resolvedAs = found->first;
							break;
						}
					}
				}

				// try finding with "using namespace"
				if (resolvedAs.empty())
				{
					for (int i = 0; i < tscope.usingNamespaces.size(); i++)
					{

						auto found = allCustomTypes.find(tscope.usingNamespaces[i] + "::" + typeName);
						if (found != allCustomTypes.end())
						{
							if (resolvedAs.empty() == false)
								fprintf(stderr, "Warning: Ambiguous \"using namespace\" detected during type resolve: \"%s\" could also be \"%s\". Using latter." LOCATIONINFO, resolvedAs.c_str(), found->first.c_str(), LOCATIONINFODATA);
							nodeType->resolvedType = found->second;
							resolvedAs = found->first;
						}
					}
				}
			}

			if (verbose)
				fprintf(stderr, " AS \"%s\"\n", resolvedAs.c_str());

			if (resolvedAs.empty() && nodeType->GetType() != ASTNode::Type::TemplateArg)
				fprintf(stderr, "Warning: Type \"%s\" could not be resolved " LOCATIONINFO, typeName.c_str(), LOCATIONINFODATA);
#		undef LOCATIONINFO
#		undef LOCATIONINFODATA
		}

		// nesting
		switch (node->GetType())
		{
		case ASTNode::Type::Class:
		case ASTNode::Type::Struct:
		case ASTNode::Type::Union:
		case ASTNode::Type::Namespace:
		case ASTNode::Type::Template:
			isScope = true;
			break;
//.........这里部分代码省略.........
开发者ID:Lssikkes,项目名称:CppReflector,代码行数:101,代码来源:moduleCppTransfiguration.cpp


注:本文中的ASTType::ToNameString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。