()
| 799 | boolean readonly = !writable && match("~"); |
| 800 | // Only type with a leading `{` is a function pointer... |
| 801 | if( peek('{') ) return typeFunPtr(); |
| 802 | |
| 803 | // Otherwise you get a type name |
| 804 | String tname = _lexer.matchId(); |
| 805 | if( tname==null ) return posT(old1); |
| 806 | |
| 807 | // Convert the type name to a type. |
| 808 | Type t0 = TYPES.get(tname); |
| 809 | // No new types as keywords |
| 810 | if( t0 == null && KEYWORDS.contains(tname) ) |
| 811 | return posT(old1); |
| 812 | if( t0 == Type.BOTTOM || t0 == Type.TOP ) return t0; // var/val type inference |
| 813 | Type t1 = t0 == null ? TypeMemPtr.make(TypeStruct.makeFRef(tname)) :t0; // Null: assume a forward ref type |
| 814 | // A qualifier before the name applies to the struct reference, not |
| 815 | // to an enclosing array. Arrays have their own [] / [~] qualifier. |
| 816 | if( t1 instanceof TypeMemPtr tmp ) { |
| 817 | if( readonly || !writable ) t1 = tmp.makeRO(); |
| 818 | } else if( writable || readonly ) |
| 819 | return posT(old1); |
| 820 | |
| 821 | // Nest arrays and '?' as needed |
| 822 | Type t2 = t1; |
| 823 | while( true ) { |
| 824 | if( match("?") ) { |
| 825 | if( !(t2 instanceof TypeMemPtr tmp) ) |
| 826 | throw error("Type "+t0+" cannot be null"); |
| 827 | if( tmp.nullable() ) throw error("Type "+t2+" already allows null"); |
| 828 | t2 = tmp.makeNullable(); |
| 829 | } else if( match("[~]") ) { |
| 830 | TypeMemPtr ary = typeAry(t2); |
| 831 | t2 = ary.makeFrom(ary._obj.makeRO()).makeRO(); |
| 832 | } else if( match("[]") ) { |
| 833 | t2 = typeAry(t2); |
| 834 | } else |
| 835 | break; |
| 836 | } |
| 837 | |
| 838 | // Check no forward ref |
| 839 | if( t0 != null ) return t2; |
| 840 | // Check valid forward ref, after parsing all the type extra bits. |
| 841 | // Cannot check earlier, because cannot find required 'id' until after "[]?" syntax |
| 842 | int old2 = pos(); |
| 843 | if( !match("!") ) match("~"); |
| 844 | String id = _lexer.matchId(); |
| 845 | if( !(peek(',') || peek(';')) ) |
| 846 | return posT(old1); |
| 847 | pos(old2); // Reset lexer to reparse |
| 848 | if( id==null ) |
| 849 | return posT(old1); // Reset lexer to reparse |
no test coverage detected