def _add_symbols(self, nestedName: ASTNestedName, templateDecls: List[Any], declaration: ASTDeclaration, docname: str) -> 'Symbol':
    if Symbol.debug_lookup:
        Symbol.debug_indent += 1
        Symbol.debug_print('_add_symbols:')
        Symbol.debug_indent += 1
        Symbol.debug_print('tdecls:', templateDecls)
        Symbol.debug_print('nn:    ', nestedName)
        Symbol.debug_print('decl:  ', declaration)
        Symbol.debug_print('doc:   ', docname)

    def onMissingQualifiedSymbol(parentSymbol: 'Symbol', identOrOp: Union[(ASTIdentifier, ASTOperator)], templateParams: Any, templateArgs: ASTTemplateArgs) -> 'Symbol':
        if Symbol.debug_lookup:
            Symbol.debug_indent += 1
            Symbol.debug_print('_add_symbols, onMissingQualifiedSymbol:')
            Symbol.debug_indent += 1
            Symbol.debug_print('templateParams:', templateParams)
            Symbol.debug_print('identOrOp:     ', identOrOp)
            Symbol.debug_print('templateARgs:  ', templateArgs)
            Symbol.debug_indent -= 2
        return Symbol(parent=parentSymbol, identOrOp=identOrOp, templateParams=templateParams, templateArgs=templateArgs, declaration=None, docname=None)
    lookupResult = self._symbol_lookup(nestedName, templateDecls, onMissingQualifiedSymbol, strictTemplateParamArgLists=True, ancestorLookupType=None, templateShorthand=False, matchSelf=False, recurseInAnon=False, correctPrimaryTemplateArgs=True, searchInSiblings=False)
    assert (lookupResult is not None)
    symbols = list(lookupResult.symbols)
    if (len(symbols) == 0):
        if Symbol.debug_lookup:
            Symbol.debug_print('_add_symbols, result, no symbol:')
            Symbol.debug_indent += 1
            Symbol.debug_print('templateParams:', lookupResult.templateParams)
            Symbol.debug_print('identOrOp:     ', lookupResult.identOrOp)
            Symbol.debug_print('templateArgs:  ', lookupResult.templateArgs)
            Symbol.debug_print('declaration:   ', declaration)
            Symbol.debug_print('docname:       ', docname)
            Symbol.debug_indent -= 1
        symbol = Symbol(parent=lookupResult.parentSymbol, identOrOp=lookupResult.identOrOp, templateParams=lookupResult.templateParams, templateArgs=lookupResult.templateArgs, declaration=declaration, docname=docname)
        if Symbol.debug_lookup:
            Symbol.debug_indent -= 2
        return symbol
    if Symbol.debug_lookup:
        Symbol.debug_print('_add_symbols, result, symbols:')
        Symbol.debug_indent += 1
        Symbol.debug_print('number symbols:', len(symbols))
        Symbol.debug_indent -= 1
    if (not declaration):
        if Symbol.debug_lookup:
            Symbol.debug_print('no delcaration')
            Symbol.debug_indent -= 2
        return symbols[0]
    noDecl = []
    withDecl = []
    dupDecl = []
    for s in symbols:
        if (s.declaration is None):
            noDecl.append(s)
        elif s.isRedeclaration:
            dupDecl.append(s)
        else:
            withDecl.append(s)
    if Symbol.debug_lookup:
        Symbol.debug_print('#noDecl:  ', len(noDecl))
        Symbol.debug_print('#withDecl:', len(withDecl))
        Symbol.debug_print('#dupDecl: ', len(dupDecl))

    def makeCandSymbol() -> 'Symbol':
        if Symbol.debug_lookup:
            Symbol.debug_print('begin: creating candidate symbol')
        symbol = Symbol(parent=lookupResult.parentSymbol, identOrOp=lookupResult.identOrOp, templateParams=lookupResult.templateParams, templateArgs=lookupResult.templateArgs, declaration=declaration, docname=docname)
        if Symbol.debug_lookup:
            Symbol.debug_print('end:   creating candidate symbol')
        return symbol
    if (len(withDecl) == 0):
        candSymbol = None
    else:
        candSymbol = makeCandSymbol()

        def handleDuplicateDeclaration(symbol: 'Symbol', candSymbol: 'Symbol') -> None:
            if Symbol.debug_lookup:
                Symbol.debug_indent += 1
                Symbol.debug_print('redeclaration')
                Symbol.debug_indent -= 1
                Symbol.debug_indent -= 2
            candSymbol.isRedeclaration = True
            raise _DuplicateSymbolError(symbol, declaration)
        if (declaration.objectType != 'function'):
            assert (len(withDecl) <= 1)
            handleDuplicateDeclaration(withDecl[0], candSymbol)
        candId = declaration.get_newest_id()
        if Symbol.debug_lookup:
            Symbol.debug_print('candId:', candId)
        for symbol in withDecl:
            oldId = symbol.declaration.get_newest_id()
            if Symbol.debug_lookup:
                Symbol.debug_print('oldId: ', oldId)
            if (candId == oldId):
                handleDuplicateDeclaration(symbol, candSymbol)
    if (len(noDecl) == 0):
        if Symbol.debug_lookup:
            Symbol.debug_print('no match, no empty, candSybmol is not None?:', (candSymbol is not None))
            Symbol.debug_indent -= 2
        if (candSymbol is not None):
            return candSymbol
        else:
            return makeCandSymbol()
    else:
        if Symbol.debug_lookup:
            Symbol.debug_print('no match, but fill an empty declaration, candSybmol is not None?:', (candSymbol is not None))
            Symbol.debug_indent -= 2
        if (candSymbol is not None):
            candSymbol.remove()
        symbol = noDecl[0]
        symbol._fill_empty(declaration, docname)
        return symbol
def _add_symbols(self, nestedName: ASTNestedName, templateDecls: List[Any], declaration: ASTDeclaration, docname: str) -> 'Symbol':
    if Symbol.debug_lookup:
        Symbol.debug_indent += 1
        Symbol.debug_print('_add_symbols:')
        Symbol.debug_indent += 1
        Symbol.debug_print('tdecls:', templateDecls)
        Symbol.debug_print('nn:    ', nestedName)
        Symbol.debug_print('decl:  ', declaration)
        Symbol.debug_print('doc:   ', docname)

    def onMissingQualifiedSymbol(parentSymbol: 'Symbol', identOrOp: Union[(ASTIdentifier, ASTOperator)], templateParams: Any, templateArgs: ASTTemplateArgs) -> 'Symbol':
        if Symbol.debug_lookup:
            Symbol.debug_indent += 1
            Symbol.debug_print('_add_symbols, onMissingQualifiedSymbol:')
            Symbol.debug_indent += 1
            Symbol.debug_print('templateParams:', templateParams)
            Symbol.debug_print('identOrOp:     ', identOrOp)
            Symbol.debug_print('templateARgs:  ', templateArgs)
            Symbol.debug_indent -= 2
        return Symbol(parent=parentSymbol, identOrOp=identOrOp, templateParams=templateParams, templateArgs=templateArgs, declaration=None, docname=None)
    lookupResult = self._symbol_lookup(nestedName, templateDecls, onMissingQualifiedSymbol, strictTemplateParamArgLists=True, ancestorLookupType=None, templateShorthand=False, matchSelf=False, recurseInAnon=False, correctPrimaryTemplateArgs=True, searchInSiblings=False)
    assert (lookupResult is not None)
    symbols = list(lookupResult.symbols)
    if (len(symbols) == 0):
        if Symbol.debug_lookup:
            Symbol.debug_print('_add_symbols, result, no symbol:')
            Symbol.debug_indent += 1
            Symbol.debug_print('templateParams:', lookupResult.templateParams)
            Symbol.debug_print('identOrOp:     ', lookupResult.identOrOp)
            Symbol.debug_print('templateArgs:  ', lookupResult.templateArgs)
            Symbol.debug_print('declaration:   ', declaration)
            Symbol.debug_print('docname:       ', docname)
            Symbol.debug_indent -= 1
        symbol = Symbol(parent=lookupResult.parentSymbol, identOrOp=lookupResult.identOrOp, templateParams=lookupResult.templateParams, templateArgs=lookupResult.templateArgs, declaration=declaration, docname=docname)
        if Symbol.debug_lookup:
            Symbol.debug_indent -= 2
        return symbol
    if Symbol.debug_lookup:
        Symbol.debug_print('_add_symbols, result, symbols:')
        Symbol.debug_indent += 1
        Symbol.debug_print('number symbols:', len(symbols))
        Symbol.debug_indent -= 1
    if (not declaration):
        if Symbol.debug_lookup:
            Symbol.debug_print('no delcaration')
            Symbol.debug_indent -= 2
        return symbols[0]
    noDecl = []
    withDecl = []
    dupDecl = []
    for s in symbols:
        if (s.declaration is None):
            noDecl.append(s)
        elif s.isRedeclaration:
            dupDecl.append(s)
        else:
            withDecl.append(s)
    if Symbol.debug_lookup:
        Symbol.debug_print('#noDecl:  ', len(noDecl))
        Symbol.debug_print('#withDecl:', len(withDecl))
        Symbol.debug_print('#dupDecl: ', len(dupDecl))

    def makeCandSymbol() -> 'Symbol':
        if Symbol.debug_lookup:
            Symbol.debug_print('begin: creating candidate symbol')
        symbol = Symbol(parent=lookupResult.parentSymbol, identOrOp=lookupResult.identOrOp, templateParams=lookupResult.templateParams, templateArgs=lookupResult.templateArgs, declaration=declaration, docname=docname)
        if Symbol.debug_lookup:
            Symbol.debug_print('end:   creating candidate symbol')
        return symbol
    if (len(withDecl) == 0):
        candSymbol = None
    else:
        candSymbol = makeCandSymbol()

        def handleDuplicateDeclaration(symbol: 'Symbol', candSymbol: 'Symbol') -> None:
            if Symbol.debug_lookup:
                Symbol.debug_indent += 1
                Symbol.debug_print('redeclaration')
                Symbol.debug_indent -= 1
                Symbol.debug_indent -= 2
            candSymbol.isRedeclaration = True
            raise _DuplicateSymbolError(symbol, declaration)
        if (declaration.objectType != 'function'):
            assert (len(withDecl) <= 1)
            handleDuplicateDeclaration(withDecl[0], candSymbol)
        candId = declaration.get_newest_id()
        if Symbol.debug_lookup:
            Symbol.debug_print('candId:', candId)
        for symbol in withDecl:
            oldId = symbol.declaration.get_newest_id()
            if Symbol.debug_lookup:
                Symbol.debug_print('oldId: ', oldId)
            if (candId == oldId):
                handleDuplicateDeclaration(symbol, candSymbol)
    if (len(noDecl) == 0):
        if Symbol.debug_lookup:
            Symbol.debug_print('no match, no empty, candSybmol is not None?:', (candSymbol is not None))
            Symbol.debug_indent -= 2
        if (candSymbol is not None):
            return candSymbol
        else:
            return makeCandSymbol()
    else:
        if Symbol.debug_lookup:
            Symbol.debug_print('no match, but fill an empty declaration, candSybmol is not None?:', (candSymbol is not None))
            Symbol.debug_indent -= 2
        if (candSymbol is not None):
            candSymbol.remove()
        symbol = noDecl[0]
        symbol._fill_empty(declaration, docname)
        return symbol