We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error when parsing type which refers to an aliased import
The following contracts will cause slither to error:

Main.sol:
```
import {Dependency as x} from "./Dependency.sol";

contract Main {
    x y;
}
```

Dependency.sol:
```
contract Dependency {
    uint y;
}
```

Error:
```
ERROR:TypeParsing:Type not found x
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `slither/solc_parsing/solidity_types/type_parsing.py`
Content:
```
1 import logging
2 
3 from slither.core.solidity_types.elementary_type import ElementaryType, ElementaryTypeName
4 from slither.core.solidity_types.user_defined_type import UserDefinedType
5 from slither.core.solidity_types.array_type import ArrayType
6 from slither.core.solidity_types.mapping_type import MappingType
7 from slither.core.solidity_types.function_type import FunctionType
8 
9 from slither.core.variables.function_type_variable import FunctionTypeVariable
10 
11 from slither.core.declarations.contract import Contract
12 from slither.core.declarations.function import Function
13 
14 from slither.core.expressions.literal import Literal
15 
16 import re
17 
18 logger = logging.getLogger('TypeParsing')
19 
20 class UnknownType:
21     def __init__(self, name):
22         self._name = name
23 
24     @property
25     def name(self):
26         return self._name
27 
28 def _find_from_type_name(name, contract, contracts, structures, enums):
29     name_elementary = name.split(' ')[0]
30     if '[' in name_elementary:
31         name_elementary = name_elementary[0:name_elementary.find('[')]
32     if name_elementary in ElementaryTypeName:
33         depth = name.count('[')
34         if depth:
35             return ArrayType(ElementaryType(name_elementary), Literal(depth))
36         else:
37             return ElementaryType(name_elementary)
38     # We first look for contract
39     # To avoid collision 
40     # Ex: a structure with the name of a contract
41     name_contract = name
42     if name_contract.startswith('contract '):
43         name_contract = name_contract[len('contract '):]
44     if name_contract.startswith('library '):
45         name_contract = name_contract[len('library '):]
46     var_type = next((c for c in contracts if c.name == name_contract), None)
47 
48     if not var_type:
49         var_type = next((st for st in structures if st.name == name), None)
50     if not var_type:
51         var_type = next((e for e in enums if e.name == name), None)
52     if not var_type:
53         # any contract can refer to another contract's enum
54         enum_name = name
55         if enum_name.startswith('enum '):
56             enum_name = enum_name[len('enum '):]
57         all_enums = [c.enums for c in contracts]
58         all_enums = [item for sublist in all_enums for item in sublist]
59         var_type = next((e for e in all_enums if e.name == enum_name), None)
60         if not var_type:
61             var_type = next((e for e in all_enums if  e.contract.name+"."+e.name == enum_name), None)
62     if not var_type:
63         # any contract can refer to another contract's structure
64         name_struct = name
65         if name_struct.startswith('struct '):
66             name_struct = name_struct[len('struct '):]
67             name_struct = name_struct.split(' ')[0] # remove stuff like storage pointer at the end
68         all_structures = [c.structures for c in contracts]
69         all_structures = [item for sublist in all_structures for item in sublist]
70         var_type = next((st for st in all_structures if st.name == name_struct), None)
71         if not var_type:
72             var_type = next((st for st in all_structures if  st.contract.name+"."+st.name == name_struct), None)
73         # case where struct xxx.xx[] where not well formed in the AST
74         if not var_type:
75             depth = 0
76             while name_struct.endswith('[]'):
77                 name_struct = name_struct[0:-2]
78                 depth+=1
79             var_type = next((st for st in all_structures if st.contract.name+"."+st.name == name_struct), None)
80             if var_type:
81                 return ArrayType(UserDefinedType(var_type), Literal(depth))
82 
83     if not var_type:
84         var_type = next((f for f in contract.functions if f.name == name), None)
85     if not var_type:
86         if name.startswith('function '):
87             found = re.findall('function \(([ ()a-zA-Z0-9\.,]*)\) returns \(([a-zA-Z0-9\.,]*)\)', name)
88             assert len(found) == 1
89             params = found[0][0].split(',')
90             return_values = found[0][1].split(',')
91             params = [_find_from_type_name(p, contract, contracts, structures, enums) for p in params]
92             return_values = [_find_from_type_name(r, contract, contracts, structures, enums) for r in return_values]
93             params_vars = []
94             return_vars = []
95             for p in params:
96                var = FunctionTypeVariable()
97                var.set_type(p)
98                params_vars.append(var)
99             for r in return_values:
100                var = FunctionTypeVariable()
101                var.set_type(r)
102                return_vars.append(var)
103             return FunctionType(params_vars, return_vars)
104     if not var_type:
105         if name.startswith('mapping('):
106             # nested mapping declared with var
107             if name.count('mapping(') == 1 :
108                 found = re.findall('mapping\(([a-zA-Z0-9\.]*) => ([a-zA-Z0-9\.\[\]]*)\)', name)
109             else:
110                 found = re.findall('mapping\(([a-zA-Z0-9\.]*) => (mapping\([=> a-zA-Z0-9\.\[\]]*\))\)', name)
111             assert len(found) == 1
112             from_ = found[0][0]
113             to_ = found[0][1]
114             
115             from_type = _find_from_type_name(from_, contract, contracts, structures, enums)
116             to_type = _find_from_type_name(to_, contract, contracts, structures, enums)
117 
118             return MappingType(from_type, to_type)
119 
120     if not var_type:
121         logger.error('Type not found '+str(name))
122         exit(-1)
123     return UserDefinedType(var_type)
124 
125 
126 
127 def parse_type(t, caller_context):
128     # local import to avoid circular dependency 
129     from slither.solc_parsing.expressions.expression_parsing import parse_expression
130     from slither.solc_parsing.variables.function_type_variable import FunctionTypeVariableSolc
131 
132     if isinstance(caller_context, Contract):
133         contract = caller_context
134     elif isinstance(caller_context, Function):
135         contract = caller_context.contract
136     else:
137         logger.error('Incorrect caller context')
138         exit(-1)
139 
140 
141     is_compact_ast = caller_context.is_compact_ast
142 
143     if is_compact_ast:
144         key = 'nodeType'
145     else:
146         key = 'name'
147 
148     structures = contract.structures
149     enums = contract.enums
150     contracts = contract.slither.contracts
151 
152     if isinstance(t, UnknownType):
153         return _find_from_type_name(t.name, contract, contracts, structures, enums)
154 
155     elif t[key] == 'ElementaryTypeName':
156         if is_compact_ast:
157             return ElementaryType(t['name'])
158         return ElementaryType(t['attributes'][key])
159 
160     elif t[key] == 'UserDefinedTypeName':
161         if is_compact_ast:
162             return _find_from_type_name(t['typeDescriptions']['typeString'], contract, contracts, structures, enums)
163         return _find_from_type_name(t['attributes'][key], contract, contracts, structures, enums)
164 
165     elif t[key] == 'ArrayTypeName':
166         length = None
167         if is_compact_ast:
168             if t['length']:
169                 length = parse_expression(t['length'], caller_context)
170             array_type = parse_type(t['baseType'], contract)
171         else:
172             if len(t['children']) == 2:
173                 length = parse_expression(t['children'][1], caller_context)
174             else:
175                 assert len(t['children']) == 1
176             array_type = parse_type(t['children'][0], contract)
177         return ArrayType(array_type, length)
178 
179     elif t[key] == 'Mapping':
180 
181         if is_compact_ast:
182             mappingFrom = parse_type(t['keyType'], contract)
183             mappingTo = parse_type(t['valueType'], contract)
184         else:
185             assert len(t['children']) == 2
186 
187             mappingFrom = parse_type(t['children'][0], contract)
188             mappingTo = parse_type(t['children'][1], contract)
189 
190         return MappingType(mappingFrom, mappingTo)
191 
192     elif t[key] == 'FunctionTypeName':
193 
194         if is_compact_ast:
195             params = t['parameterTypes']
196             return_values = t['returnParameterTypes']
197             index =  'parameters'
198         else:
199             assert len(t['children']) == 2
200             params = t['children'][0]
201             return_values = t['children'][1]
202             index = 'children'
203 
204         assert params[key] == 'ParameterList'
205         assert return_values[key] == 'ParameterList'
206 
207         params_vars = []
208         return_values_vars = []
209         for p in params[index]:
210             var = FunctionTypeVariableSolc(p)
211             var.set_offset(p['src'], caller_context.slither)
212             var.analyze(caller_context)
213             params_vars.append(var)
214         for p in return_values[index]:
215             var = FunctionTypeVariableSolc(p)
216 
217             var.set_offset(p['src'], caller_context.slither)
218             var.analyze(caller_context)
219             return_values_vars.append(var)
220 
221         return FunctionType(params_vars, return_values_vars)
222 
223     logger.error('Type name not found '+str(t))
224     exit(-1)
225
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/slither/solc_parsing/solidity_types/type_parsing.py b/slither/solc_parsing/solidity_types/type_parsing.py
--- a/slither/solc_parsing/solidity_types/type_parsing.py
+++ b/slither/solc_parsing/solidity_types/type_parsing.py
@@ -160,7 +160,10 @@
     elif t[key] == 'UserDefinedTypeName':
         if is_compact_ast:
             return _find_from_type_name(t['typeDescriptions']['typeString'], contract, contracts, structures, enums)
-        return _find_from_type_name(t['attributes'][key], contract, contracts, structures, enums)
+
+        # Determine if we have a type node (otherwise we use the name node, as some older solc did not have 'type').
+        type_name_key = 'type' if 'type' in t['attributes'] else key
+        return _find_from_type_name(t['attributes'][type_name_key], contract, contracts, structures, enums)
 
     elif t[key] == 'ArrayTypeName':
         length = None

{"golden_diff": "diff --git a/slither/solc_parsing/solidity_types/type_parsing.py b/slither/solc_parsing/solidity_types/type_parsing.py\n--- a/slither/solc_parsing/solidity_types/type_parsing.py\n+++ b/slither/solc_parsing/solidity_types/type_parsing.py\n@@ -160,7 +160,10 @@\n     elif t[key] == 'UserDefinedTypeName':\n         if is_compact_ast:\n             return _find_from_type_name(t['typeDescriptions']['typeString'], contract, contracts, structures, enums)\n-        return _find_from_type_name(t['attributes'][key], contract, contracts, structures, enums)\n+\n+        # Determine if we have a type node (otherwise we use the name node, as some older solc did not have 'type').\n+        type_name_key = 'type' if 'type' in t['attributes'] else key\n+        return _find_from_type_name(t['attributes'][type_name_key], contract, contracts, structures, enums)\n \n     elif t[key] == 'ArrayTypeName':\n         length = None\n", "issue": "Error when parsing type which refers to an aliased import\nThe following contracts will cause slither to error:\r\n\r\nMain.sol:\r\n```\r\nimport {Dependency as x} from \"./Dependency.sol\";\r\n\r\ncontract Main {\r\n    x y;\r\n}\r\n```\r\n\r\nDependency.sol:\r\n```\r\ncontract Dependency {\r\n    uint y;\r\n}\r\n```\r\n\r\nError:\r\n```\r\nERROR:TypeParsing:Type not found x\r\n```\n", "before_files": [{"content": "import logging\n\nfrom slither.core.solidity_types.elementary_type import ElementaryType, ElementaryTypeName\nfrom slither.core.solidity_types.user_defined_type import UserDefinedType\nfrom slither.core.solidity_types.array_type import ArrayType\nfrom slither.core.solidity_types.mapping_type import MappingType\nfrom slither.core.solidity_types.function_type import FunctionType\n\nfrom slither.core.variables.function_type_variable import FunctionTypeVariable\n\nfrom slither.core.declarations.contract import Contract\nfrom slither.core.declarations.function import Function\n\nfrom slither.core.expressions.literal import Literal\n\nimport re\n\nlogger = logging.getLogger('TypeParsing')\n\nclass UnknownType:\n    def __init__(self, name):\n        self._name = name\n\n    @property\n    def name(self):\n        return self._name\n\ndef _find_from_type_name(name, contract, contracts, structures, enums):\n    name_elementary = name.split(' ')[0]\n    if '[' in name_elementary:\n        name_elementary = name_elementary[0:name_elementary.find('[')]\n    if name_elementary in ElementaryTypeName:\n        depth = name.count('[')\n        if depth:\n            return ArrayType(ElementaryType(name_elementary), Literal(depth))\n        else:\n            return ElementaryType(name_elementary)\n    # We first look for contract\n    # To avoid collision \n    # Ex: a structure with the name of a contract\n    name_contract = name\n    if name_contract.startswith('contract '):\n        name_contract = name_contract[len('contract '):]\n    if name_contract.startswith('library '):\n        name_contract = name_contract[len('library '):]\n    var_type = next((c for c in contracts if c.name == name_contract), None)\n\n    if not var_type:\n        var_type = next((st for st in structures if st.name == name), None)\n    if not var_type:\n        var_type = next((e for e in enums if e.name == name), None)\n    if not var_type:\n        # any contract can refer to another contract's enum\n        enum_name = name\n        if enum_name.startswith('enum '):\n            enum_name = enum_name[len('enum '):]\n        all_enums = [c.enums for c in contracts]\n        all_enums = [item for sublist in all_enums for item in sublist]\n        var_type = next((e for e in all_enums if e.name == enum_name), None)\n        if not var_type:\n            var_type = next((e for e in all_enums if  e.contract.name+\".\"+e.name == enum_name), None)\n    if not var_type:\n        # any contract can refer to another contract's structure\n        name_struct = name\n        if name_struct.startswith('struct '):\n            name_struct = name_struct[len('struct '):]\n            name_struct = name_struct.split(' ')[0] # remove stuff like storage pointer at the end\n        all_structures = [c.structures for c in contracts]\n        all_structures = [item for sublist in all_structures for item in sublist]\n        var_type = next((st for st in all_structures if st.name == name_struct), None)\n        if not var_type:\n            var_type = next((st for st in all_structures if  st.contract.name+\".\"+st.name == name_struct), None)\n        # case where struct xxx.xx[] where not well formed in the AST\n        if not var_type:\n            depth = 0\n            while name_struct.endswith('[]'):\n                name_struct = name_struct[0:-2]\n                depth+=1\n            var_type = next((st for st in all_structures if st.contract.name+\".\"+st.name == name_struct), None)\n            if var_type:\n                return ArrayType(UserDefinedType(var_type), Literal(depth))\n\n    if not var_type:\n        var_type = next((f for f in contract.functions if f.name == name), None)\n    if not var_type:\n        if name.startswith('function '):\n            found = re.findall('function \\(([ ()a-zA-Z0-9\\.,]*)\\) returns \\(([a-zA-Z0-9\\.,]*)\\)', name)\n            assert len(found) == 1\n            params = found[0][0].split(',')\n            return_values = found[0][1].split(',')\n            params = [_find_from_type_name(p, contract, contracts, structures, enums) for p in params]\n            return_values = [_find_from_type_name(r, contract, contracts, structures, enums) for r in return_values]\n            params_vars = []\n            return_vars = []\n            for p in params:\n               var = FunctionTypeVariable()\n               var.set_type(p)\n               params_vars.append(var)\n            for r in return_values:\n               var = FunctionTypeVariable()\n               var.set_type(r)\n               return_vars.append(var)\n            return FunctionType(params_vars, return_vars)\n    if not var_type:\n        if name.startswith('mapping('):\n            # nested mapping declared with var\n            if name.count('mapping(') == 1 :\n                found = re.findall('mapping\\(([a-zA-Z0-9\\.]*) => ([a-zA-Z0-9\\.\\[\\]]*)\\)', name)\n            else:\n                found = re.findall('mapping\\(([a-zA-Z0-9\\.]*) => (mapping\\([=> a-zA-Z0-9\\.\\[\\]]*\\))\\)', name)\n            assert len(found) == 1\n            from_ = found[0][0]\n            to_ = found[0][1]\n            \n            from_type = _find_from_type_name(from_, contract, contracts, structures, enums)\n            to_type = _find_from_type_name(to_, contract, contracts, structures, enums)\n\n            return MappingType(from_type, to_type)\n\n    if not var_type:\n        logger.error('Type not found '+str(name))\n        exit(-1)\n    return UserDefinedType(var_type)\n\n\n\ndef parse_type(t, caller_context):\n    # local import to avoid circular dependency \n    from slither.solc_parsing.expressions.expression_parsing import parse_expression\n    from slither.solc_parsing.variables.function_type_variable import FunctionTypeVariableSolc\n\n    if isinstance(caller_context, Contract):\n        contract = caller_context\n    elif isinstance(caller_context, Function):\n        contract = caller_context.contract\n    else:\n        logger.error('Incorrect caller context')\n        exit(-1)\n\n\n    is_compact_ast = caller_context.is_compact_ast\n\n    if is_compact_ast:\n        key = 'nodeType'\n    else:\n        key = 'name'\n\n    structures = contract.structures\n    enums = contract.enums\n    contracts = contract.slither.contracts\n\n    if isinstance(t, UnknownType):\n        return _find_from_type_name(t.name, contract, contracts, structures, enums)\n\n    elif t[key] == 'ElementaryTypeName':\n        if is_compact_ast:\n            return ElementaryType(t['name'])\n        return ElementaryType(t['attributes'][key])\n\n    elif t[key] == 'UserDefinedTypeName':\n        if is_compact_ast:\n            return _find_from_type_name(t['typeDescriptions']['typeString'], contract, contracts, structures, enums)\n        return _find_from_type_name(t['attributes'][key], contract, contracts, structures, enums)\n\n    elif t[key] == 'ArrayTypeName':\n        length = None\n        if is_compact_ast:\n            if t['length']:\n                length = parse_expression(t['length'], caller_context)\n            array_type = parse_type(t['baseType'], contract)\n        else:\n            if len(t['children']) == 2:\n                length = parse_expression(t['children'][1], caller_context)\n            else:\n                assert len(t['children']) == 1\n            array_type = parse_type(t['children'][0], contract)\n        return ArrayType(array_type, length)\n\n    elif t[key] == 'Mapping':\n\n        if is_compact_ast:\n            mappingFrom = parse_type(t['keyType'], contract)\n            mappingTo = parse_type(t['valueType'], contract)\n        else:\n            assert len(t['children']) == 2\n\n            mappingFrom = parse_type(t['children'][0], contract)\n            mappingTo = parse_type(t['children'][1], contract)\n\n        return MappingType(mappingFrom, mappingTo)\n\n    elif t[key] == 'FunctionTypeName':\n\n        if is_compact_ast:\n            params = t['parameterTypes']\n            return_values = t['returnParameterTypes']\n            index =  'parameters'\n        else:\n            assert len(t['children']) == 2\n            params = t['children'][0]\n            return_values = t['children'][1]\n            index = 'children'\n\n        assert params[key] == 'ParameterList'\n        assert return_values[key] == 'ParameterList'\n\n        params_vars = []\n        return_values_vars = []\n        for p in params[index]:\n            var = FunctionTypeVariableSolc(p)\n            var.set_offset(p['src'], caller_context.slither)\n            var.analyze(caller_context)\n            params_vars.append(var)\n        for p in return_values[index]:\n            var = FunctionTypeVariableSolc(p)\n\n            var.set_offset(p['src'], caller_context.slither)\n            var.analyze(caller_context)\n            return_values_vars.append(var)\n\n        return FunctionType(params_vars, return_values_vars)\n\n    logger.error('Type name not found '+str(t))\n    exit(-1)\n", "path": "slither/solc_parsing/solidity_types/type_parsing.py"}], "after_files": [{"content": "import logging\n\nfrom slither.core.solidity_types.elementary_type import ElementaryType, ElementaryTypeName\nfrom slither.core.solidity_types.user_defined_type import UserDefinedType\nfrom slither.core.solidity_types.array_type import ArrayType\nfrom slither.core.solidity_types.mapping_type import MappingType\nfrom slither.core.solidity_types.function_type import FunctionType\n\nfrom slither.core.variables.function_type_variable import FunctionTypeVariable\n\nfrom slither.core.declarations.contract import Contract\nfrom slither.core.declarations.function import Function\n\nfrom slither.core.expressions.literal import Literal\n\nimport re\n\nlogger = logging.getLogger('TypeParsing')\n\nclass UnknownType:\n    def __init__(self, name):\n        self._name = name\n\n    @property\n    def name(self):\n        return self._name\n\ndef _find_from_type_name(name, contract, contracts, structures, enums):\n    name_elementary = name.split(' ')[0]\n    if '[' in name_elementary:\n        name_elementary = name_elementary[0:name_elementary.find('[')]\n    if name_elementary in ElementaryTypeName:\n        depth = name.count('[')\n        if depth:\n            return ArrayType(ElementaryType(name_elementary), Literal(depth))\n        else:\n            return ElementaryType(name_elementary)\n    # We first look for contract\n    # To avoid collision \n    # Ex: a structure with the name of a contract\n    name_contract = name\n    if name_contract.startswith('contract '):\n        name_contract = name_contract[len('contract '):]\n    if name_contract.startswith('library '):\n        name_contract = name_contract[len('library '):]\n    var_type = next((c for c in contracts if c.name == name_contract), None)\n\n    if not var_type:\n        var_type = next((st for st in structures if st.name == name), None)\n    if not var_type:\n        var_type = next((e for e in enums if e.name == name), None)\n    if not var_type:\n        # any contract can refer to another contract's enum\n        enum_name = name\n        if enum_name.startswith('enum '):\n            enum_name = enum_name[len('enum '):]\n        all_enums = [c.enums for c in contracts]\n        all_enums = [item for sublist in all_enums for item in sublist]\n        var_type = next((e for e in all_enums if e.name == enum_name), None)\n        if not var_type:\n            var_type = next((e for e in all_enums if  e.contract.name+\".\"+e.name == enum_name), None)\n    if not var_type:\n        # any contract can refer to another contract's structure\n        name_struct = name\n        if name_struct.startswith('struct '):\n            name_struct = name_struct[len('struct '):]\n            name_struct = name_struct.split(' ')[0] # remove stuff like storage pointer at the end\n        all_structures = [c.structures for c in contracts]\n        all_structures = [item for sublist in all_structures for item in sublist]\n        var_type = next((st for st in all_structures if st.name == name_struct), None)\n        if not var_type:\n            var_type = next((st for st in all_structures if  st.contract.name+\".\"+st.name == name_struct), None)\n        # case where struct xxx.xx[] where not well formed in the AST\n        if not var_type:\n            depth = 0\n            while name_struct.endswith('[]'):\n                name_struct = name_struct[0:-2]\n                depth+=1\n            var_type = next((st for st in all_structures if st.contract.name+\".\"+st.name == name_struct), None)\n            if var_type:\n                return ArrayType(UserDefinedType(var_type), Literal(depth))\n\n    if not var_type:\n        var_type = next((f for f in contract.functions if f.name == name), None)\n    if not var_type:\n        if name.startswith('function '):\n            found = re.findall('function \\(([ ()a-zA-Z0-9\\.,]*)\\) returns \\(([a-zA-Z0-9\\.,]*)\\)', name)\n            assert len(found) == 1\n            params = found[0][0].split(',')\n            return_values = found[0][1].split(',')\n            params = [_find_from_type_name(p, contract, contracts, structures, enums) for p in params]\n            return_values = [_find_from_type_name(r, contract, contracts, structures, enums) for r in return_values]\n            params_vars = []\n            return_vars = []\n            for p in params:\n               var = FunctionTypeVariable()\n               var.set_type(p)\n               params_vars.append(var)\n            for r in return_values:\n               var = FunctionTypeVariable()\n               var.set_type(r)\n               return_vars.append(var)\n            return FunctionType(params_vars, return_vars)\n    if not var_type:\n        if name.startswith('mapping('):\n            # nested mapping declared with var\n            if name.count('mapping(') == 1 :\n                found = re.findall('mapping\\(([a-zA-Z0-9\\.]*) => ([a-zA-Z0-9\\.\\[\\]]*)\\)', name)\n            else:\n                found = re.findall('mapping\\(([a-zA-Z0-9\\.]*) => (mapping\\([=> a-zA-Z0-9\\.\\[\\]]*\\))\\)', name)\n            assert len(found) == 1\n            from_ = found[0][0]\n            to_ = found[0][1]\n            \n            from_type = _find_from_type_name(from_, contract, contracts, structures, enums)\n            to_type = _find_from_type_name(to_, contract, contracts, structures, enums)\n\n            return MappingType(from_type, to_type)\n\n    if not var_type:\n        logger.error('Type not found '+str(name))\n        exit(-1)\n    return UserDefinedType(var_type)\n\n\n\ndef parse_type(t, caller_context):\n    # local import to avoid circular dependency \n    from slither.solc_parsing.expressions.expression_parsing import parse_expression\n    from slither.solc_parsing.variables.function_type_variable import FunctionTypeVariableSolc\n\n    if isinstance(caller_context, Contract):\n        contract = caller_context\n    elif isinstance(caller_context, Function):\n        contract = caller_context.contract\n    else:\n        logger.error('Incorrect caller context')\n        exit(-1)\n\n\n    is_compact_ast = caller_context.is_compact_ast\n\n    if is_compact_ast:\n        key = 'nodeType'\n    else:\n        key = 'name'\n\n    structures = contract.structures\n    enums = contract.enums\n    contracts = contract.slither.contracts\n\n    if isinstance(t, UnknownType):\n        return _find_from_type_name(t.name, contract, contracts, structures, enums)\n\n    elif t[key] == 'ElementaryTypeName':\n        if is_compact_ast:\n            return ElementaryType(t['name'])\n        return ElementaryType(t['attributes'][key])\n\n    elif t[key] == 'UserDefinedTypeName':\n        if is_compact_ast:\n            return _find_from_type_name(t['typeDescriptions']['typeString'], contract, contracts, structures, enums)\n\n        # Determine if we have a type node (otherwise we use the name node, as some older solc did not have 'type').\n        type_name_key = 'type' if 'type' in t['attributes'] else key\n        return _find_from_type_name(t['attributes'][type_name_key], contract, contracts, structures, enums)\n\n    elif t[key] == 'ArrayTypeName':\n        length = None\n        if is_compact_ast:\n            if t['length']:\n                length = parse_expression(t['length'], caller_context)\n            array_type = parse_type(t['baseType'], contract)\n        else:\n            if len(t['children']) == 2:\n                length = parse_expression(t['children'][1], caller_context)\n            else:\n                assert len(t['children']) == 1\n            array_type = parse_type(t['children'][0], contract)\n        return ArrayType(array_type, length)\n\n    elif t[key] == 'Mapping':\n\n        if is_compact_ast:\n            mappingFrom = parse_type(t['keyType'], contract)\n            mappingTo = parse_type(t['valueType'], contract)\n        else:\n            assert len(t['children']) == 2\n\n            mappingFrom = parse_type(t['children'][0], contract)\n            mappingTo = parse_type(t['children'][1], contract)\n\n        return MappingType(mappingFrom, mappingTo)\n\n    elif t[key] == 'FunctionTypeName':\n\n        if is_compact_ast:\n            params = t['parameterTypes']\n            return_values = t['returnParameterTypes']\n            index =  'parameters'\n        else:\n            assert len(t['children']) == 2\n            params = t['children'][0]\n            return_values = t['children'][1]\n            index = 'children'\n\n        assert params[key] == 'ParameterList'\n        assert return_values[key] == 'ParameterList'\n\n        params_vars = []\n        return_values_vars = []\n        for p in params[index]:\n            var = FunctionTypeVariableSolc(p)\n            var.set_offset(p['src'], caller_context.slither)\n            var.analyze(caller_context)\n            params_vars.append(var)\n        for p in return_values[index]:\n            var = FunctionTypeVariableSolc(p)\n\n            var.set_offset(p['src'], caller_context.slither)\n            var.analyze(caller_context)\n            return_values_vars.append(var)\n\n        return FunctionType(params_vars, return_values_vars)\n\n    logger.error('Type name not found '+str(t))\n    exit(-1)\n", "path": "slither/solc_parsing/solidity_types/type_parsing.py"}]}