src/share/classes/com/sun/tools/javac/comp/Infer.java

changeset 2047
5f915a0c9615
parent 2000
4a6acc42c3a1
child 2157
963c57175e40
equal deleted inserted replaced
2046:1fe358ea75ff 2047:5f915a0c9615
275 275
276 /** 276 /**
277 * Infer cyclic inference variables as described in 15.12.2.8. 277 * Infer cyclic inference variables as described in 15.12.2.8.
278 */ 278 */
279 private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) { 279 private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) {
280 ListBuffer<Type> todo = ListBuffer.lb(); 280 ListBuffer<Type> todo = new ListBuffer<>();
281 //step 1 - create fresh tvars 281 //step 1 - create fresh tvars
282 for (Type t : vars) { 282 for (Type t : vars) {
283 UndetVar uv = (UndetVar)inferenceContext.asFree(t); 283 UndetVar uv = (UndetVar)inferenceContext.asFree(t);
284 List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER); 284 List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
285 if (Type.containsAny(upperBounds, vars)) { 285 if (Type.containsAny(upperBounds, vars)) {
1830 } 1830 }
1831 }); 1831 });
1832 } 1832 }
1833 1833
1834 private List<Type> filterVars(Filter<UndetVar> fu) { 1834 private List<Type> filterVars(Filter<UndetVar> fu) {
1835 ListBuffer<Type> res = ListBuffer.lb(); 1835 ListBuffer<Type> res = new ListBuffer<>();
1836 for (Type t : undetvars) { 1836 for (Type t : undetvars) {
1837 UndetVar uv = (UndetVar)t; 1837 UndetVar uv = (UndetVar)t;
1838 if (fu.accepts(uv)) { 1838 if (fu.accepts(uv)) {
1839 res.append(uv.qtype); 1839 res.append(uv.qtype);
1840 } 1840 }
1858 1858
1859 /** 1859 /**
1860 * Returns a list of free variables in a given type 1860 * Returns a list of free variables in a given type
1861 */ 1861 */
1862 final List<Type> freeVarsIn(Type t) { 1862 final List<Type> freeVarsIn(Type t) {
1863 ListBuffer<Type> buf = ListBuffer.lb(); 1863 ListBuffer<Type> buf = new ListBuffer<>();
1864 for (Type iv : inferenceVars()) { 1864 for (Type iv : inferenceVars()) {
1865 if (t.contains(iv)) { 1865 if (t.contains(iv)) {
1866 buf.add(iv); 1866 buf.add(iv);
1867 } 1867 }
1868 } 1868 }
1869 return buf.toList(); 1869 return buf.toList();
1870 } 1870 }
1871 1871
1872 final List<Type> freeVarsIn(List<Type> ts) { 1872 final List<Type> freeVarsIn(List<Type> ts) {
1873 ListBuffer<Type> buf = ListBuffer.lb(); 1873 ListBuffer<Type> buf = new ListBuffer<>();
1874 for (Type t : ts) { 1874 for (Type t : ts) {
1875 buf.appendList(freeVarsIn(t)); 1875 buf.appendList(freeVarsIn(t));
1876 } 1876 }
1877 ListBuffer<Type> buf2 = ListBuffer.lb(); 1877 ListBuffer<Type> buf2 = new ListBuffer<>();
1878 for (Type t : buf) { 1878 for (Type t : buf) {
1879 if (!buf2.contains(t)) { 1879 if (!buf2.contains(t)) {
1880 buf2.add(t); 1880 buf2.add(t);
1881 } 1881 }
1882 } 1882 }
1891 final Type asFree(Type t) { 1891 final Type asFree(Type t) {
1892 return types.subst(t, inferencevars, undetvars); 1892 return types.subst(t, inferencevars, undetvars);
1893 } 1893 }
1894 1894
1895 final List<Type> asFree(List<Type> ts) { 1895 final List<Type> asFree(List<Type> ts) {
1896 ListBuffer<Type> buf = ListBuffer.lb(); 1896 ListBuffer<Type> buf = new ListBuffer<>();
1897 for (Type t : ts) { 1897 for (Type t : ts) {
1898 buf.append(asFree(t)); 1898 buf.append(asFree(t));
1899 } 1899 }
1900 return buf.toList(); 1900 return buf.toList();
1901 } 1901 }
1902 1902
1903 List<Type> instTypes() { 1903 List<Type> instTypes() {
1904 ListBuffer<Type> buf = ListBuffer.lb(); 1904 ListBuffer<Type> buf = new ListBuffer<>();
1905 for (Type t : undetvars) { 1905 for (Type t : undetvars) {
1906 UndetVar uv = (UndetVar)t; 1906 UndetVar uv = (UndetVar)t;
1907 buf.append(uv.inst != null ? uv.inst : uv.qtype); 1907 buf.append(uv.inst != null ? uv.inst : uv.qtype);
1908 } 1908 }
1909 return buf.toList(); 1909 return buf.toList();
1917 Type asInstType(Type t) { 1917 Type asInstType(Type t) {
1918 return types.subst(t, inferencevars, instTypes()); 1918 return types.subst(t, inferencevars, instTypes());
1919 } 1919 }
1920 1920
1921 List<Type> asInstTypes(List<Type> ts) { 1921 List<Type> asInstTypes(List<Type> ts) {
1922 ListBuffer<Type> buf = ListBuffer.lb(); 1922 ListBuffer<Type> buf = new ListBuffer<>();
1923 for (Type t : ts) { 1923 for (Type t : ts) {
1924 buf.append(asInstType(t)); 1924 buf.append(asInstType(t));
1925 } 1925 }
1926 return buf.toList(); 1926 return buf.toList();
1927 } 1927 }
1965 1965
1966 /** 1966 /**
1967 * Save the state of this inference context 1967 * Save the state of this inference context
1968 */ 1968 */
1969 List<Type> save() { 1969 List<Type> save() {
1970 ListBuffer<Type> buf = ListBuffer.lb(); 1970 ListBuffer<Type> buf = new ListBuffer<>();
1971 for (Type t : undetvars) { 1971 for (Type t : undetvars) {
1972 UndetVar uv = (UndetVar)t; 1972 UndetVar uv = (UndetVar)t;
1973 UndetVar uv2 = new UndetVar((TypeVar)uv.qtype, types); 1973 UndetVar uv2 = new UndetVar((TypeVar)uv.qtype, types);
1974 for (InferenceBound ib : InferenceBound.values()) { 1974 for (InferenceBound ib : InferenceBound.values()) {
1975 for (Type b : uv.getBounds(ib)) { 1975 for (Type b : uv.getBounds(ib)) {

mercurial