'Work out variable types according to their namespace
@param jstypelist {list of JSObject} The list of types that shold be
examined
@param scopeStack {list} The scope stack, with the outermost (and
therefore last searched) scope at the lowest index
@returns {None}'

def _lookupVariableTypes(self, jstypelist, scopeStack):

    for jstype in jstypelist:
        if hasattr(jstype, 'classes'):
            self._lookupVariableTypes(jstype.classes.values(), (scopeStack + [jstype]))
        if hasattr(jstype, 'functions'):
            self._lookupVariableTypes(jstype.functions.values(), (scopeStack + [jstype]))
        if hasattr(jstype, 'variables'):
            for jsvariable in jstype.variables.values():
                varType = jsvariable.type
                if varType:
                    actualType = self._lookupVariableType(varType, jsvariable, (scopeStack + [jstype]))
                    if (actualType and (actualType != jsvariable)):
                        if (isinstance(actualType, JSVariable) and (not actualType.hasChildren())):
                            log.debug('variable    %r:    replacing    type    %r    with    %r', jsvariable.name, jsvariable.type, actualType.type)
                            jsvariable.type = actualType.type
                        else:
                            log.debug('variable    %r:    replacing    type    %r    with    %r', jsvariable.name, jsvariable.type, actualType.name)
                            jsvariable.type = actualType.name
        if isinstance(jstype, JSFunction):
            for i in range(len(jstype.returnTypes)):
                returnType = jstype.returnTypes[i]
                if isinstance(returnType, (str, unicode)):
                    actualType = self._lookupVariableType(returnType, jstype, (scopeStack + [jstype]))
                    if (actualType and (actualType != jstype)):
                        if (isinstance(actualType, JSVariable) and (actualType.type != 'Object')):
                            jstype.returnTypes[i] = actualType.type
                        else:
                            jstype.returnTypes[i] = actualType.name
