示例#1
0
TypeNode* TypeNameNode::getActualTypeNode(TemplateArguments* templateArguments)
{
	TypeNode* typeNode = getTypeNode(templateArguments);
	if (typeNode)
	{
		typeNode = typeNode->getActualTypeNode(templateArguments);
	}
	return typeNode;
}
示例#2
0
TypeNode* TypeNameNode::getTypeNode(TemplateArguments* templateArguments)
{
	//assert(0 == templateArguments || templateArguments->m_classTypeNode->isTemplateClassInstance());
	assert(0 != m_startTypeNode);
	TypeNode* result = 0;
	if (0 == m_typeNode)// under template parameter
	{
		assert(templateArguments && m_startTypeNode 
			&& (m_startTypeNode->isTemplateParameter() || m_startTypeNode->isTypedef()) );
		if (templateArguments->m_classTypeNode->isClass())
		{
			return 0;
		}
		TypeNode* actualStartTypeNode = m_startTypeNode->getActualTypeNode(templateArguments);
		assert(actualStartTypeNode);
		std::vector<ScopeNameNode*> scopeNameNodes;
		m_scopeNameList->collectIdentifyNodes(scopeNameNodes);
		if (scopeNameNodes.size() == 1)
		{
			result = actualStartTypeNode;
		}
		else
		{
			scopeNameNodes.erase(scopeNameNodes.begin());
			TypeNode* initialTypeTreeNode = 0;
			TypeNode* finalTypeTreeNode = 0;
			if (g_typeTree.findNodeByScopeNames(initialTypeTreeNode, finalTypeTreeNode,
				scopeNameNodes, actualStartTypeNode, templateArguments))
			{
				assert(finalTypeTreeNode);
				result = finalTypeTreeNode;
			}
		}
	}
	else if (m_typeNode->isTemplateParameter())
	{
		assert(templateArguments);
		result = templateArguments->findTypeNode(m_scopeNameList->m_scopeName->m_name->m_str);
	}
	else if (m_typeNode->isTemplateClass())
	{
		assert(templateArguments);
		if (m_scopeNameList->m_scopeName->isTemplateForm())
		{
			result = g_typeTree.findNodeByScopeName(m_scopeNameList->m_scopeName, m_typeNode->m_enclosing, templateArguments);
		}
		else
		{
			assert(m_scopeNameList->m_scopeName->m_name->m_str == templateArguments->m_className);
			result = templateArguments->m_classTypeNode;
		}
	}
	else if (m_typeNode->isUnderTemplateClass())
	{
		assert(templateArguments);
		if (m_startTypeNode->isUnderTemplateClass())
		{
			std::vector<TypeNode*> typeNodes;
			TypeNode* typeNode = m_typeNode;
			while (typeNode)
			{
				if (typeNode->isTemplateClass())
				{
					break;
				}
				typeNodes.push_back(typeNode);
				typeNode = typeNode->m_enclosing;
			}
			assert(typeNode->isTemplateClass() && typeNode->m_name == templateArguments->m_className);
			typeNode = templateArguments->m_classTypeNode;
			auto it = typeNodes.rbegin();
			auto end = typeNodes.rend();
			for (; it != end; ++it)
			{
				TypeNode* tempTypeNode = *it;
				typeNode = typeNode->getChildNode(tempTypeNode->m_name);
				assert(typeNode);
			}
			if (typeNode->isTypedef())
			{
				TypeNode* actualTypeNode = typeNode->getActualTypeNode(templateArguments);
				if (actualTypeNode->isTemplateParameter())
				{
					typeNode = templateArguments->findTypeNode(actualTypeNode->m_name);
					assert(0 != typeNode);
				}
			}
			result = typeNode;
		}
		else
		{
			std::vector<ScopeNameNode*> scopeNameNodes;
			m_scopeNameList->collectIdentifyNodes(scopeNameNodes);
			TypeNode* initialTypeTreeNode = 0;
			TypeNode* finalTypeTreeNode = 0;
			if (m_startTypeNode->isTemplateClass() && !scopeNameNodes[0]->isTemplateForm())
			{
				assert(m_startTypeNode->m_name == templateArguments->m_className);
				scopeNameNodes.erase(scopeNameNodes.begin());
				if (g_typeTree.findNodeByScopeNames(initialTypeTreeNode, finalTypeTreeNode,
					scopeNameNodes, templateArguments->m_classTypeNode, templateArguments))
				{
					result = finalTypeTreeNode;
				}
			}
			else
			{
				if (g_typeTree.findNodeByScopeNames(initialTypeTreeNode, finalTypeTreeNode,
					scopeNameNodes, m_startTypeNode->m_enclosing, templateArguments))
				{
					result = finalTypeTreeNode;
				}
			}
		}
	}
	else
	{
		assert(m_typeNode->isPredefinedType() ||
			m_typeNode->isEnum() ||
			m_typeNode->isClass() ||
			m_typeNode->isTemplateClassInstance() ||
			m_typeNode->isTypedef() ||
			m_typeNode->isTypeDeclaration());
		result = m_typeNode;
	}

	if(0 == result)
	{
		RaiseError_InvalidTypeName(m_scopeNameList);
	}
	return result;
}