Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/declarationbuilder.cpp
Show First 20 Lines • Show All 1619 Lines • ▼ Show 20 Line(s) | |||||
1620 | } | 1620 | } | ||
1621 | 1621 | | |||
1622 | void DeclarationBuilder::closeNamespace(NamespaceDeclarationStatementAst* parent, IdentifierAst* node, const IdentifierPair& identifier) | 1622 | void DeclarationBuilder::closeNamespace(NamespaceDeclarationStatementAst* parent, IdentifierAst* node, const IdentifierPair& identifier) | ||
1623 | { | 1623 | { | ||
1624 | DeclarationBuilderBase::closeNamespace(parent, node, identifier); | 1624 | DeclarationBuilderBase::closeNamespace(parent, node, identifier); | ||
1625 | closeDeclaration(); | 1625 | closeDeclaration(); | ||
1626 | } | 1626 | } | ||
1627 | 1627 | | |||
1628 | void DeclarationBuilder::visitUseStatement(UseStatementAst* node) | ||||
1629 | { | ||||
1630 | if ( node->useFunction != -1 ) | ||||
1631 | { | ||||
1632 | m_useNamespaceType = FunctionDeclarationType; | ||||
1633 | } | ||||
1634 | else if ( node->useConst != -1 ) | ||||
1635 | { | ||||
1636 | m_useNamespaceType = ConstantDeclarationType; | ||||
1637 | } | ||||
1638 | else | ||||
1639 | { | ||||
1640 | m_useNamespaceType = ClassDeclarationType; | ||||
1641 | } | ||||
1642 | DeclarationBuilderBase::visitUseStatement(node); | ||||
1643 | } | ||||
1644 | | ||||
1628 | void DeclarationBuilder::visitUseNamespace(UseNamespaceAst* node) | 1645 | void DeclarationBuilder::visitUseNamespace(UseNamespaceAst* node) | ||
1629 | { | 1646 | { | ||
1630 | DUChainWriteLocker lock; | 1647 | DUChainWriteLocker lock; | ||
1648 | bool isConstIdentifier = ( m_useNamespaceType == ConstantDeclarationType ); | ||||
1631 | 1649 | | |||
1632 | if ( currentContext()->type() != DUContext::Namespace && | 1650 | if ( currentContext()->type() != DUContext::Namespace && | ||
1633 | !node->aliasIdentifier && node->identifier->namespaceNameSequence->count() == 1 ) { | 1651 | !node->aliasIdentifier && node->identifier->namespaceNameSequence->count() == 1 ) { | ||
1634 | reportError(i18n("The use statement with non-compound name '%1' has no effect.", | 1652 | reportError(i18n("The use statement with non-compound name '%1' has no effect.", | ||
1635 | identifierForNode(node->identifier->namespaceNameSequence->front()->element).toString()), | 1653 | identifierForNode(node->identifier->namespaceNameSequence->front()->element).toString()), | ||
1636 | node->identifier, IProblem::Warning); | 1654 | node->identifier, IProblem::Warning); | ||
1637 | return; | 1655 | return; | ||
1638 | } | 1656 | } | ||
1639 | IdentifierAst* idNode = node->aliasIdentifier ? node->aliasIdentifier : node->identifier->namespaceNameSequence->back()->element; | 1657 | IdentifierAst* idNode = node->aliasIdentifier ? node->aliasIdentifier : node->identifier->namespaceNameSequence->back()->element; | ||
1640 | IdentifierPair id = identifierPairForNode(idNode); | 1658 | IdentifierPair id = identifierPairForNode(idNode, isConstIdentifier); | ||
1641 | 1659 | | |||
1642 | ///TODO: case insensitive! | 1660 | ///TODO: case insensitive! | ||
1643 | QualifiedIdentifier qid = identifierForNamespace(node->identifier, m_editor); | 1661 | QualifiedIdentifier qid = identifierForNamespace(node->identifier, m_editor, isConstIdentifier); | ||
1644 | | ||||
1645 | DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, qid); | | |||
1646 | 1662 | | |||
1663 | DeclarationPointer dec = findDeclarationImport(m_useNamespaceType, qid); | ||||
1647 | if (!dec && !qid.explicitlyGlobal()) { | 1664 | if (!dec && !qid.explicitlyGlobal()) { | ||
1648 | QualifiedIdentifier globalQid = qid; | 1665 | QualifiedIdentifier globalQid = qid; | ||
1649 | globalQid.setExplicitlyGlobal(true); | 1666 | globalQid.setExplicitlyGlobal(true); | ||
1650 | dec = findDeclarationImport(ClassDeclarationType, globalQid); | 1667 | dec = findDeclarationImport(m_useNamespaceType, globalQid); | ||
1651 | } | 1668 | } | ||
1652 | 1669 | | |||
1653 | if (dec) | 1670 | if (dec) | ||
1654 | { | 1671 | { | ||
1655 | // Check for a name conflict | 1672 | // Check for a name conflict | ||
1656 | DeclarationPointer dec2 = findDeclarationImport(ClassDeclarationType, id.second); | 1673 | DeclarationPointer dec2 = findDeclarationImport(m_useNamespaceType, id.second); | ||
1657 | 1674 | | |||
1658 | if (dec2 && dec2->context()->scopeIdentifier() == currentContext()->scopeIdentifier() && | 1675 | if (dec2 && dec2->context()->scopeIdentifier() == currentContext()->scopeIdentifier() && | ||
1659 | dec2->context()->topContext() == currentContext()->topContext() && | 1676 | dec2->context()->topContext() == currentContext()->topContext() && | ||
1660 | dec2->identifier().toString() == id.second.toString()) | 1677 | dec2->identifier().toString() == id.second.toString()) | ||
1661 | { | 1678 | { | ||
1662 | reportError(i18n("Cannot use '%1' as '%2' because the name is already in use.", | 1679 | reportError(i18n("Cannot use '%1' as '%2' because the name is already in use.", | ||
1663 | dec.data()->identifier().toString(), id.second.toString()), | 1680 | dec.data()->identifier().toString(), id.second.toString()), | ||
1664 | node->identifier, IProblem::Error); | 1681 | node->identifier, IProblem::Error); | ||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |