Exemple #1
0
NamespaceTypeNode* NamespaceTypeNode::addNamespace(NamespaceNode* node)
{
	TypeNode* child = getChildNode(node->m_name->m_str);
	if (0 == child)
	{
		NamespaceTypeNode* result = new NamespaceTypeNode;
		result->m_name = node->m_name->m_str;
		result->m_enclosing = this;
		result->m_identifyNode = node->m_name;
		result->m_sourceFile = g_compiler.m_currentSourceFile;
		m_children.insert(result);
		g_typeTree.m_allNamespaces.push_back(result);
		return result;
	}
	else if (child->isNamespace())
	{
		NamespaceTypeNode* result = static_cast<NamespaceTypeNode*>(child);
		assert(result->m_name == node->m_name->m_str);
		//result->m_syntaxInfos.push_back(std::make_pair(node, g_compiler.m_currentSourceFile));
		return result;
	}
	else
	{
		char buf[512];
		sprintf_s(buf, "\'%s\' : already defined in %s(%d,%d)",
			node->m_name->m_str.c_str(), child->m_sourceFile->m_fileName.c_str(),
			child->m_identifyNode->m_lineNo, child->m_identifyNode->m_columnNo);
		ErrorList_AddItem(getCurrentSourceFileName(), node->m_name->m_lineNo,
			node->m_name->m_columnNo, semantic_error_namespace_redefined, buf);
		return 0;
	}
}
Exemple #2
0
bool TypeNode::isUnderTemplateClass()
{
	TypeNode* enclosing = m_enclosing;
	while (enclosing && !enclosing->isNamespace())
	{
		if (enclosing->isTemplateClass())
		{
			return true;
		}
		enclosing = enclosing->m_enclosing;
	}
	return false;
}
Exemple #3
0
bool TypeTree::findNodeByScopeNames(TypeNode*& initialTypeTreeNode, TypeNode*& finalTypeTreeNode,
	const std::vector<ScopeNameNode*>& scopeNameNodes, TypeNode* enclosingTypeTreeNode, TemplateArguments* templateArguments)
{
	assert(!enclosingTypeTreeNode->isTypedef());
	initialTypeTreeNode = 0;
	finalTypeTreeNode = 0;

	auto it = scopeNameNodes.begin();
	auto end = scopeNameNodes.end();
	initialTypeTreeNode = findNodeByScopeName(*it, enclosingTypeTreeNode, templateArguments);
	TypeNode* currentTypeTreeNode = initialTypeTreeNode;
	while (true)
	{
		if (0 == currentTypeTreeNode)
		{
			return false;
		}
		finalTypeTreeNode = currentTypeTreeNode;
		//currentTypeTreeNode = currentTypeTreeNode->getActualTypeNode(templateArguments);
		//assert(0 != currentTypeTreeNode);
		if (currentTypeTreeNode->isTypedef())
		{
			currentTypeTreeNode = static_cast<TypedefTypeNode*>(currentTypeTreeNode)->m_typedefNode->m_srcTypeNode;
			if (0 == currentTypeTreeNode)
			{
				//under template parameter
				finalTypeTreeNode = 0;
				return true;
			}
			assert(currentTypeTreeNode && !currentTypeTreeNode->isTypedef());
		}
		//if (currentTypeTreeNode->isTemplateParameter())
		//{
		//	currentTypeTreeNode = templateArguments->findTypeNode(currentTypeTreeNode->m_name);
		//	assert(0 != currentTypeTreeNode);
		//}
		++it;
		if (end == it)
		{
			return !(currentTypeTreeNode->isNamespace());
		}
		currentTypeTreeNode = findNodeByScopeName(*it, currentTypeTreeNode, templateArguments);
	}
}