| 19 | import { string } from 'yargs'; |
| 20 | |
| 21 | export function parseTypeName(scopeName: string, typeName: AntlrTypeName): TypeName { |
| 22 | if (typeName.type == 'ElementaryTypeName') return typeName; |
| 23 | if (typeName.type == 'UserDefinedTypeName') { |
| 24 | let namePath = (typeName.namePath.includes('.')) |
| 25 | ? typeName.namePath : `${scopeName}.${typeName.namePath}` |
| 26 | return {...typeName, namePath} |
| 27 | } |
| 28 | if (typeName.type == 'ArrayTypeName') { |
| 29 | const { type, baseTypeName, length } = typeName; |
| 30 | return { |
| 31 | type, |
| 32 | baseTypeName: parseTypeName(scopeName, baseTypeName), |
| 33 | length: length ? { |
| 34 | number: +(length as NumberLiteral).number, |
| 35 | type: 'NumberLiteral' |
| 36 | } : null |
| 37 | } |
| 38 | } |
| 39 | if (typeName.type == 'Mapping') { |
| 40 | throw new Error(`Caught unencodable type Mapping in ${scopeName}`) |
| 41 | } |
| 42 | throw new Error(`Did not recognize type ${typeName.type} in ${scopeName}`) |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param scopeName Name of the scope which contains the member (contract.struct) |