Changeset 2163
- Timestamp:
- 07/01/08 15:01:57 (3 months ago)
- Files:
-
- trunk/Library/FortressLibrary.fss (modified) (11 diffs)
- trunk/Library/List.fss (modified) (1 diff)
- trunk/Library/PureList.fss (modified) (1 diff)
- trunk/Library/Sparse.fss (modified) (1 diff)
- trunk/ProjectFortress/LibraryBuiltin/FortressBuiltin.fss (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/Shell.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/Disambiguator.java (modified) (5 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticJUTest.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticTestSuite.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/SelfParamDisambiguator.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/FnTypeEnv.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Init.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/types/FTypeGeneric.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/unit_tests/FileTests.java (modified) (5 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/unit_tests/ParserJUTest.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/unit_tests/SystemJUTest.java (modified) (1 diff)
- trunk/ProjectFortress/static_tests/DXXEqualityTesting.fss (modified) (1 diff)
- trunk/ProjectFortress/static_tests/DXXMutualSeparateLetFn.fss (deleted)
- trunk/ProjectFortress/static_tests/SimpleTrait.fss (modified) (1 diff)
- trunk/ProjectFortress/tests/atomicList.fss (modified) (1 diff)
- trunk/ProjectFortress/tests/conditionalExtension.fss (modified) (2 diffs)
- trunk/SpecData/examples/basic/Expr.Assign.b.fss (modified) (1 diff)
- trunk/SpecData/examples/basic/Object.Decl.ConsFn.fss (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Library/FortressLibrary.fss
r2155 r2163 1355 1355 immutableArray[\E\](x:ZZ32):ImmutableArray[\E,ZZ32\] = 1356 1356 __imm1(__Proxy[\E\],reflect(x)) 1357 (* 1357 1358 immutableArray[\E\](x:ZZ32,y:ZZ32):ImmutableArray[\E,(ZZ32,ZZ32)\] = 1358 1359 __imm2(__Proxy[\E\],reflect(x), reflect(y)) 1359 1360 immutableArray[\E\](x:ZZ32,y:ZZ32,z:ZZ32):ImmutableArray[\E,(ZZ32,ZZ32,ZZ32)\] = 1360 1361 __imm3(__Proxy[\E\],reflect(x), reflect(y), reflect(z)) 1362 *) 1361 1363 1362 1364 (* This should be local to immutableArray, but we don't support local … … 1782 1784 opr |self| : ZZ32 = s0 s1 1783 1785 (* Translate from b0,b1-indexing to 0-indexing, checking bounds. *) 1784 offset(t :(ZZ32,ZZ32)):(ZZ32,ZZ32) = do1785 (a0,a1) = t 1786 offset(t_1:(ZZ32,ZZ32)):(ZZ32,ZZ32) = do 1787 (a0,a1) = t_1 1786 1788 c0 = a0 - b0 1787 1789 c1 = a1 - b1 … … 1794 1796 end 1795 1797 end 1796 toIndex(t :(ZZ32,ZZ32)):(ZZ32,ZZ32) = do (a0,a1)=t; (a0+b0,a1+b1) end1798 toIndex(t_1:(ZZ32,ZZ32)):(ZZ32,ZZ32) = do (a0,a1)=t_1; (a0+b0,a1+b1) end 1797 1799 opr[x:ZZ32,y:ZZ32]:=(v:T):() = do self[ (x,y) ] := v end 1798 1800 opr[r:Range[\(ZZ32,ZZ32)\]]: Array[\T,(ZZ32,ZZ32)\] = do … … 1807 1809 opr[_:OpenRange[\Any\]] : Array2[\T,0,s0,0,s1\] = 1808 1810 subarray[\0,s0,0,s1,0,0\]() 1809 shift(t :(ZZ32,ZZ32)): Array[\T,(ZZ32,ZZ32)\] = do1810 (o0,o1)=t 1811 shift(t_1:(ZZ32,ZZ32)): Array[\T,(ZZ32,ZZ32)\] = do 1812 (o0,o1)=t_1 1811 1813 if o0=0 AND o1=0 then 1812 1814 self … … 1861 1863 extends Array2[\T, b0, s0, b1, s1\] 1862 1864 mem:PrimitiveArray[\T, (s0 s1) \] = PrimitiveArray[\T, (s0 s1) \]() 1863 init0(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0(i s1 + j, v) end1864 put(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put(i s1 + j, v) end1865 get(t :(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(i s1 + j) end1865 init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0(i s1 + j, v) end 1866 put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put(i s1 + j, v) end 1867 get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(i s1 + j) end 1866 1868 end 1867 1869 … … 1873 1875 replica[\U\]():Array2[\U,b0,s0,b1,s1\] = mem.replica[\U\]().t() 1874 1876 1875 init0(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0((j,i),v) end1876 put(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put((j,i),v) end1877 get(t :(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(j,i) end1877 init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0((j,i),v) end 1878 put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put((j,i),v) end 1879 get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(j,i) end 1878 1880 t() = mem 1879 1881 end … … 1892 1894 extends Array2[\T,b0,s0,b1,s1\] 1893 1895 index(a0:ZZ32, a1:ZZ32): (ZZ32,ZZ32) = (m0 a0 + o0, m1 a1 + o1) 1894 init0(t :(ZZ32,ZZ32), v:T): () = mem.init0(index(t),v)1895 put(t :(ZZ32,ZZ32), v:T): () = mem.put(index(t),v)1896 get(t :(ZZ32,ZZ32)): T = mem.get(index(t))1896 init0(t_1:(ZZ32,ZZ32), v:T): () = mem.init0(index(t_1),v) 1897 put(t_1:(ZZ32,ZZ32), v:T): () = mem.put(index(t_1),v) 1898 get(t_1:(ZZ32,ZZ32)): T = mem.get(index(t_1)) 1897 1899 end 1898 1900 … … 1905 1907 ivmap[\T\](fn (i:(ZZ32,ZZ32),e:T):T => e - v.get(i)) 1906 1908 opr -(self): Matrix[\T,s0,s1\] = map[\T\](fn (e:T):T => - e) 1907 scale(t : T): Matrix[\T,s0,s1\] = map[\T\](fn (e:T):T => te)1909 scale(t_1: T): Matrix[\T,s0,s1\] = map[\T\](fn (e:T):T => t_1 e) 1908 1910 mul[\ nat s2 \](other: Matrix[\T,s1,s2\]): Matrix[\T,s0,s2\] = do 1909 1911 res = matrix[\T,s0,s2\]() … … 1966 1968 extends Matrix[\T, s0, s1\] 1967 1969 mem:PrimitiveArray[\T, (s0 s1) \] = PrimitiveArray[\T, (s0 s1) \]() 1968 init0(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0(i s1 + j, v) end1969 put(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put(i s1 + j, v) end1970 get(t :(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(i s1 + j) end1970 init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0(i s1 + j, v) end 1971 put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put(i s1 + j, v) end 1972 get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(i s1 + j) end 1971 1973 end 1972 1974 … … 1975 1977 replica[\U\]():Array2[\U,0,s0,0,s1\] = mem.replica[\U\]().t() 1976 1978 1977 init0(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.init0((j,i),v) end1978 put(t :(ZZ32,ZZ32), v:T) : () = do (i,j)=t; mem.put((j,i),v) end1979 get(t :(ZZ32,ZZ32)):T = do (i,j)=t; mem.get(j,i) end1979 init0(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.init0((j,i),v) end 1980 put(t_1:(ZZ32,ZZ32), v:T) : () = do (i,j)=t_1; mem.put((j,i),v) end 1981 get(t_1:(ZZ32,ZZ32)):T = do (i,j)=t_1; mem.get(j,i) end 1980 1982 t(): Matrix[\T,s1,s0\] = mem 1981 1983 add(v:TransposedMatrix[\T,s0,s1\]): Matrix[\T,s0,s1\] = mem.add(v.t()).t() … … 3169 3171 opr :[\I extends Integral\](lo:I, hi:I): ParRange[\I\] = 3170 3172 ParRange[\I\](lo,hi-lo+1) 3171 opr :(lo:IntLiteral, ex:IntLiteral): ParRange[\ZZ32\] =3173 opr :(lo:IntLiteral, hi:IntLiteral): ParRange[\ZZ32\] = 3172 3174 ParRange[\ZZ32\](lo,hi-lo+1) 3173 3175 opr :[\I extends Integral, J extends Integral\] trunk/Library/List.fss
r2155 r2163 379 379 fresh.appendR[\T\](other) 380 380 end 381 appendL[\T\](left :List[\T\]): List[\E\] = do382 lsz = |left |381 appendL[\T\](left_1:List[\T\]): List[\E\] = do 382 lsz = |left_1| 383 383 fstUsed = firstUsed - lsz 384 left .fill[\E\](fstUsed,underlying)384 left_1.fill[\E\](fstUsed,underlying) 385 385 ArrayList(underlying,fstUsed,oneShot(),firstUnused,canExtendRight) 386 386 end 387 appendLC[\T\](left :List[\T\]): List[\E\] =388 if leftSpace() >= |left | AND: canExtendLeft.tryOnce() then389 appendL[\T\](left )390 else 391 fresh = enlargeLeft[\E\](|left |)392 fresh.appendL[\T\](left )387 appendLC[\T\](left_1:List[\T\]): List[\E\] = 388 if leftSpace() >= |left_1| AND: canExtendLeft.tryOnce() then 389 appendL[\T\](left_1) 390 else 391 fresh = enlargeLeft[\E\](|left_1|) 392 fresh.appendL[\T\](left_1) 393 393 end 394 394 trunk/Library/PureList.fss
r2155 r2163 151 151 it.generate[\R\](r,body) 152 152 seq(self): SequentialGenerator[\E\] = SeqListGenerator[\E\](it) 153 opr ||(self, other:List[\E\]): List[\E\] =153 opr ||(self, f:List[\E\]): List[\E\] = 154 154 self || f.generate[\PureList[\E\]\](PLConcat[\E\],singleton[\E\]) 155 155 opr ||(self, f:PureList[\E\]): PureList[\E\] = trunk/Library/Sparse.fss
r1756 r2163 177 177 replica[\U\]() = fail("Csc replica undefined") 178 178 indexValuePairs():Generator[\((ZZ32,ZZ32),N)\] = 179 SparseGen[\N,((ZZ32,ZZ32),N)\]( rows,179 SparseGen[\N,((ZZ32,ZZ32),N)\](cols, 180 180 fn (i:ZZ32,j:ZZ32,n:N):((ZZ32,ZZ32),N) => ((j,i),n)) 181 181 zeroIndices():Generator[\(ZZ32,ZZ32)\] = 182 SparseGen[\N,(ZZ32,ZZ32)\]( rows,182 SparseGen[\N,(ZZ32,ZZ32)\](cols, 183 183 fn (i:ZZ32,j:ZZ32,n:N):((ZZ32,ZZ32),N) => (j,i)) 184 184 t() = Csr[\N,m,n\](cols) trunk/ProjectFortress/LibraryBuiltin/FortressBuiltin.fss
r2155 r2163 185 185 getter toString() : String = 186 186 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.String$ToString") 187 getter indices() : FullRange[\ZZ32\] = bounds()187 getter indices() : FullRange[\ZZ32\] = self.bounds() 188 188 getter generator() : Generator[\Char\] = 189 189 indices().map[\Char\](fn (i:ZZ32):Char => self[i]) … … 208 208 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.String$Index") 209 209 opr[r0:Range[\ZZ32\]] : String = do 210 r1 = ( bounds())[r0]210 r1 = (self.bounds())[r0] 211 211 l = r1.lower() 212 212 self.substr(l, l + |r1|) trunk/ProjectFortress/src/com/sun/fortress/Shell.java
r2160 r2163 469 469 // step, the rawApiEnv is stale and needs to be rebuilt with the new API ASTs. 470 470 Disambiguator.ApiResult apiDR = 471 Disambiguator.disambiguateApis(apis, rawApiEnv );471 Disambiguator.disambiguateApis(apis, rawApiEnv, _repository.apis()); 472 472 if (!apiDR.isSuccessful()) { return apiDR.errors(); } 473 474 Disambiguator.ComponentResult componentDR =475 Disambiguator.disambiguateComponents(components, env,476 rawComponentIR.components());477 if (!componentDR.isSuccessful()) { return componentDR.errors(); }478 479 if (phase.equals("disambiguate"))480 return IterUtil.empty();481 473 482 474 // Rebuild ApiIndices. … … 484 476 IndexBuilder.buildApis(apiDR.apis(), System.currentTimeMillis()); 485 477 if (!apiIR.isSuccessful()) { return apiIR.errors(); } 478 479 // Rebuild GlobalEnvironment. 480 GlobalEnvironment apiEnv = 481 new GlobalEnvironment.FromMap(CollectUtil.union(_repository.apis(), 482 apiIR.apis())); 483 484 Disambiguator.ComponentResult componentDR = 485 Disambiguator.disambiguateComponents(components, apiEnv, 486 rawComponentIR.components()); 487 if (!componentDR.isSuccessful()) { return componentDR.errors(); } 488 489 if (phase.equals("disambiguate")) 490 return IterUtil.empty(); 486 491 487 492 // Rebuild ComponentIndices. … … 490 495 System.currentTimeMillis()); 491 496 if (!componentIR.isSuccessful()) { return componentIR.errors(); } 492 493 // Rebuild GlobalEnvironment.494 GlobalEnvironment apiEnv =495 new GlobalEnvironment.FromMap(CollectUtil.union(_repository.apis(),496 apiIR.apis()));497 497 498 498 // Rewrite grammars, see GrammarRewriter for more details. trunk/ProjectFortress/src/com/sun/fortress/compiler/Disambiguator.java
r1912 r2163 30 30 31 31 import edu.rice.cs.plt.collect.CollectUtil; 32 import edu.rice.cs.plt.collect.Relation; 32 33 import edu.rice.cs.plt.iter.IterUtil; 33 34 … … 82 83 */ 83 84 public class Disambiguator { 84 85 /** Result of {@link #disambiguateApis}. */86 public static class ApiResult extends StaticPhaseResult {87 private final Iterable<Api> _apis;88 89 public ApiResult(Iterable<Api> apis,90 Iterable<? extends StaticError> errors) {91 super(errors);92 _apis = apis;93 }94 95 public Iterable<Api> apis() { return _apis; }96 }97 98 /**99 * Disambiguate the given apis. To support circular references,100 * the apis should appear in the given environment.101 */102 public static ApiResult disambiguateApis(Iterable<Api> apis,103 GlobalEnvironment globalEnv) {104 List<Api> results = new ArrayList<Api>();105 List<StaticError> errors = new ArrayList<StaticError>();106 for (Api api : apis) {107 ApiIndex index = globalEnv.api(api.getName());108 NameEnv env = new TopLevelEnv(globalEnv, index, errors);109 Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>();110 111 SelfParamDisambiguator self_disambig = new SelfParamDisambiguator();112 Api spd_result = (Api)api.accept(self_disambig);113 114 List<StaticError> newErrs = new ArrayList<StaticError>();115 TypeDisambiguator td =116 new TypeDisambiguator(env, onDemandImports, newErrs);117 Api tdResult = (Api) spd_result.accept(td);118 if (newErrs.isEmpty()) {119 ExprDisambiguator ed =120 new ExprDisambiguator(env, onDemandImports, newErrs);121 Api edResult = (Api) tdResult.accept(ed);122 if (newErrs.isEmpty()) { results.add(edResult); }123 }124 125 if (!newErrs.isEmpty()) {126 errors.addAll(newErrs);127 }128 }129 results = disambiguateGrammarMembers(results, errors, globalEnv);130 return new ApiResult(results, errors);131 }132 133 134 85 /** 135 86 * Disambiguate the names of nonterminals. … … 153 104 } 154 105 106 /** Result of {@link #disambiguateApis}. */ 107 public static class ApiResult extends StaticPhaseResult { 108 private final Iterable<Api> _apis; 109 110 public ApiResult(Iterable<Api> apis, 111 Iterable<? extends StaticError> errors) { 112 super(errors); 113 _apis = apis; 114 } 115 116 public Iterable<Api> apis() { return _apis; } 117 } 118 119 /** 120 * Disambiguate the given apis. To support circular references, 121 * the apis should appear in the given environment. 122 * @param apis_to_disambiguate Apis currently being disambiguated. 123 * @param globalEnv The current global environment. 124 * @param repository_apis Apis that already exist in the repository. 125 */ 126 public static ApiResult disambiguateApis(Iterable<Api> apis_to_disambiguate, 127 GlobalEnvironment globalEnv, Map<APIName, ApiIndex> repository_apis) { 128 129 List<StaticError> errors = new ArrayList<StaticError>(); 130 131 // First, loop through apis disambiguating types. 132 List<Api> new_apis = new ArrayList<Api>(); 133 for( Api api : apis_to_disambiguate ) { 134 ApiIndex index = globalEnv.api(api.getName()); 135 NameEnv env = new TopLevelEnv(globalEnv, index, errors); 136 Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 137 138 SelfParamDisambiguator self_disambig = new SelfParamDisambiguator(); 139 Api spd_result = (Api)api.accept(self_disambig); 140 141 List<StaticError> newErrs = new ArrayList<StaticError>(); 142 TypeDisambiguator td = 143 new TypeDisambiguator(env, onDemandImports, newErrs); 144 Api tdResult = (Api) spd_result.accept(td); 145 146 if( newErrs.isEmpty() ) 147 new_apis.add(tdResult); 148 else 149 errors.addAll(newErrs); 150 } 151 152 // then, rebuild the indices 153 IndexBuilder.ApiResult rebuilt_indx = IndexBuilder.buildApis(new_apis, System.currentTimeMillis()); 154 GlobalEnvironment new_global_env = new GlobalEnvironment.FromMap(CollectUtil.union(repository_apis, 155 rebuilt_indx.apis())); 156 157 // Finally, disambiguate the expressions using the rebuild indices. 158 List<Api> results = new ArrayList<Api>(); 159 for( Api api : new_apis ) { 160 ApiIndex index = new_global_env.api(api.getName()); 161 NameEnv env = new TopLevelEnv(new_global_env, index, errors); 162 Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 163 164 List<StaticError> newErrs = new ArrayList<StaticError>(); 165 ExprDisambiguator ed = 166 new ExprDisambiguator(env, onDemandImports, newErrs); 167 Api edResult = (Api) api.accept(ed); 168 if (newErrs.isEmpty()) 169 results.add(edResult); 170 else 171 errors.addAll(newErrs); 172 } 173 174 results = disambiguateGrammarMembers(results, errors, globalEnv); 175 return new ApiResult(results, errors); 176 } 155 177 156 178 /** Result of {@link #disambiguateComponents}. */ … … 166 188 167 189 /** Disambiguate the given components. */ 168 public static ComponentResult 169 disambiguateComponents(Iterable<Component> components, 170 GlobalEnvironment globalEnv, 171 Map<APIName, ComponentIndex> indices) { 190 public static ComponentResult disambiguateComponents(Iterable<Component> components, 191 GlobalEnvironment globalEnv, 192 Map<APIName, ComponentIndex> indices) { 193 194 172 195 List<Component> results = new ArrayList<Component>(); 173 196 List<StaticError> errors = new ArrayList<StaticError>(); 197 198 // First, disambiguate the types 199 List<Component> new_comps = new ArrayList<Component>(); 174 200 for (Component comp : components) { 175 201 ComponentIndex index = indices.get(comp.getName()); … … 187 213 new TypeDisambiguator(env, onDemandImports, newErrs); 188 214 Component tdResult = (Component) spdResult.accept(td); 189 if (newErrs.isEmpty()) { 190 ExprDisambiguator ed = 191 new ExprDisambiguator(env, onDemandImports, newErrs); 192 Component edResult = (Component) tdResult.accept(ed); 193 if (newErrs.isEmpty()) { results.add(edResult); } 215 if (newErrs.isEmpty()) 216 new_comps.add(tdResult); 217 else 218 errors.addAll(newErrs); 219 } 220 221 // Then, rebuild the component indices based on disambiguated types 222 IndexBuilder.ComponentResult new_comp_ir = 223 IndexBuilder.buildComponents(new_comps, System.currentTimeMillis()); 224 225 // Finall, disambiguate the expressions 226 for( Component comp : new_comps ) { 227 ComponentIndex index = new_comp_ir.components().get(comp.getName()); 228 if (index == null) { 229 throw new IllegalArgumentException("Missing component index"); 194 230 } 195 196 if (!newErrs.isEmpty()) { 197 errors.addAll(newErrs); 198 } 231 NameEnv env = new TopLevelEnv(globalEnv, index, errors); 232 Set<IdOrOpOrAnonymousName> onDemandImports = new HashSet<IdOrOpOrAnonymousName>(); 233 234 List<StaticError> newErrs = new ArrayList<StaticError>(); 235 ExprDisambiguator ed = 236 new ExprDisambiguator(env, onDemandImports, newErrs); 237 Component edResult = (Component) comp.accept(ed); 238 if (newErrs.isEmpty()) 239 results.add(edResult); 240 else 241 errors.addAll(newErrs); 199 242 } 200 243 return new ComponentResult(results, errors); trunk/ProjectFortress/src/com/sun/fortress/compiler/StaticJUTest.java
r2119 r2163 29 29 30 30 private final static String STATIC_TESTS_DIR = ProjectProperties.BASEDIR + "static_tests/"; 31 private final static List<String> FAILING_DISAMBIGUATOR = Arrays.asList( 32 "XXXMultipleRefErrors.fss", 33 "XXXUndefinedArrayRef.fss", 34 "XXXUndefinedInitializer.fss", 35 "XXXUndefinedNestedRef.fss", 36 "XXXUndefinedRefInLoop.fss", 37 "XXXUndefinedVar.fss", 38 "XXXUndefinedTopLevelVar.fss" 39 ); 31 private final static List<String> FAILING_DISAMBIGUATOR = Arrays.asList(); 40 32 private final static List<String> FAILING_TYPE_CHECKER = Arrays.asList( 33 /* "XXXMultipleRefErrors.fss", 41 34 "GenericFunctionCall.fss", 42 35 "CrossOverloaded.fss", … … 47 40 "CaseExpr.fss", 48 41 "DXXMutualSeparateLetFn.fss", 49 "XXXMultipleRefErrors.fss", 50 "XXXUndefinedArrayRef.fss", 51 "XXXUndefinedInitializer.fss", 52 "XXXUndefinedNestedRef.fss", 53 "XXXUndefinedRefInLoop.fss", 54 "XXXUndefinedVar.fss", 55 "XXXUndefinedTopLevelVar.fss", 42 "XXXMultipleRefErrors.fss", */ 56 43 // This test the accumulator which is not desugared yet 57 44 "Sum.fss", … … 70 57 } 71 58 } 72 //"GenericSingleton.fss" // FIXMEtrunk/ProjectFortress/src/com/sun/fortress/compiler/StaticTestSuite.java
r2151 r2163 22 22 import java.io.IOException; 23 23 import java.util.ArrayList; 24 import java.util.Arrays; 24 25 import java.util.List; 25 26 import java.util.Set; … … 64 65 }; 65 66 66 for (String filename : new File(testCase.getTestDir()).list(fssFilter)) { 67 //Permute filenames for randomness 68 String[] files = new File(testCase.getTestDir()).list(fssFilter); 69 Iterable<String> shuffled = IterUtil.shuffle(Arrays.asList(files)); 70 for (String filename : shuffled) { 67 71 File f = new File(testCase.getTestDir() + filename); 68 72 trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java
r2112 r2163 18 18 package com.sun.fortress.compiler.disambiguator; 19 19 20 import static edu.rice.cs.plt.tuple.Option.wrap; 21 22 import java.util.Collections; 23 import java.util.HashSet; 24 import java.util.LinkedList; 20 25 import java.util.List; 21 import java.util.ArrayList;22 26 import java.util.Set; 23 import java.util.HashSet; 24 import edu.rice.cs.plt.iter.IterUtil; 25 import edu.rice.cs.plt.tuple.Option; 26 import edu.rice.cs.plt.collect.ConsList; 27 import edu.rice.cs.plt.collect.CollectUtil; 28 29 import com.sun.fortress.nodes.*; 27 28 import com.sun.fortress.compiler.index.TraitIndex; 29 import com.sun.fortress.compiler.index.TypeConsIndex; 30 import com.sun.fortress.exceptions.StaticError; 31 import com.sun.fortress.nodes.APIName; 32 import com.sun.fortress.nodes.AbsDecl; 33 import com.sun.fortress.nodes.AbsFnDecl; 34 import com.sun.fortress.nodes.AbsObjectDecl; 35 import com.sun.fortress.nodes.AbsTraitDecl; 36 import com.sun.fortress.nodes.AbsVarDecl; 37 import com.sun.fortress.nodes.Accumulator; 38 import com.sun.fortress.nodes.BaseType; 39 import com.sun.fortress.nodes.Block; 40 import com.sun.fortress.nodes.BoolParam; 41 import com.sun.fortress.nodes.Catch; 42 import com.sun.fortress.nodes.Contract; 43 import com.sun.fortress.nodes.Decl; 44 import com.sun.fortress.nodes.DimDecl; 45 import com.sun.fortress.nodes.Do; 46 import com.sun.fortress.nodes.DoFront; 47 import com.sun.fortress.nodes.Exit; 48 import com.sun.fortress.nodes.Expr; 49 import com.sun.fortress.nodes.FnDef; 50 import com.sun.fortress.nodes.FnExpr; 51 import com.sun.fortress.nodes.FnRef; 52 import com.sun.fortress.nodes.For; 53 import com.sun.fortress.nodes.GeneratedExpr; 54 import com.sun.fortress.nodes.GeneratorClause; 55 import com.sun.fortress.nodes.GrammarDef; 56 import com.sun.fortress.nodes.Id; 57 import com.sun.fortress.nodes.IdOrOpOrAnonymousName; 58 import com.sun.fortress.nodes.IdStaticParam; 59 import com.sun.fortress.nodes.IfClause; 60 import com.sun.fortress.nodes.IntParam; 61 import com.sun.fortress.nodes.LValue; 62 import com.sun.fortress.nodes.LValueBind; 63 import com.sun.fortress.nodes.Label; 64 import com.sun.fortress.nodes.LetFn; 65 import com.sun.fortress.nodes.LocalVarDecl; 66 import com.sun.fortress.nodes.Modifier; 67 import com.sun.fortress.nodes.ModifierGetter; 68 import com.sun.fortress.nodes.ModifierSetter; 69 import com.sun.fortress.nodes.NatParam; 70 import com.sun.fortress.nodes.Node; 71 import com.sun.fortress.nodes.NodeDepthFirstVisitor; 72 import com.sun.fortress.nodes.NodeUpdateVisitor; 73 import com.sun.fortress.nodes.ObjectDecl; 74 import com.sun.fortress.nodes.ObjectExpr; 75 import com.sun.fortress.nodes.OpName; 76 import com.sun.fortress.nodes.OpRef; 77 import com.sun.fortress.nodes.Param; 78 import com.sun.fortress.nodes.StaticParam; 79 import com.sun.fortress.nodes.TaggedDimType; 80 import com.sun.fortress.nodes.TaggedUnitType; 81 import com.sun.fortress.nodes.TraitDecl; 82 import com.sun.fortress.nodes.TraitType; 83 import com.sun.fortress.nodes.TraitTypeWhere; 84 import com.sun.fortress.nodes.Type; 85 import com.sun.fortress.nodes.Typecase; 86 import com.sun.fortress.nodes.UnitDecl; 87 import com.sun.fortress.nodes.UnitParam; 88 import com.sun.fortress.nodes.UnpastingBind; 89 import com.sun.fortress.nodes.UnpastingSplit; 90 import com.sun.fortress.nodes.VarDecl; 91 import com.sun.fortress.nodes.VarRef; 92 import com.sun.fortress.nodes.VarType; 93 import com.sun.fortress.nodes.VoidLiteralExpr; 94 import com.sun.fortress.nodes.WhereClause; 95 import com.sun.fortress.nodes.While; 96 import com.sun.fortress.nodes._RewriteObjectRef; 97 import com.sun.fortress.nodes_util.ExprFactory; 98 import com.sun.fortress.nodes_util.NodeFactory; 99 import com.sun.fortress.nodes_util.NodeUtil; 100 import com.sun.fortress.nodes_util.Span; 30 101 import com.sun.fortress.useful.HasAt; 31 102 import com.sun.fortress.useful.NI; 32 import com.sun.fortress.nodes_util.NodeUtil; 33 import com.sun.fortress.nodes_util.ExprFactory; 34 import com.sun.fortress.nodes_util.NodeFactory; 35 import com.sun.fortress.nodes_util.Span; 36 import com.sun.fortress.compiler.GlobalEnvironment; 37 import com.sun.fortress.compiler.index.ApiIndex; 38 import com.sun.fortress.compiler.typechecker.TypeEnv; 39 import com.sun.fortress.exceptions.StaticError; 40 41 import static edu.rice.cs.plt.tuple.Option.*; 103 import com.sun.fortress.useful.Useful; 104 105 import edu.rice.cs.plt.collect.CollectUtil; 106 import edu.rice.cs.plt.collect.ConsList; 107 import edu.rice.cs.plt.iter.IterUtil; 108 import edu.rice.cs.plt.lambda.Lambda2; 109 import edu.rice.cs.plt.tuple.Option; 110 import edu.rice.cs.plt.tuple.Pair; 42 111 43 112 /** … … 65 134 public class ExprDisambiguator extends NodeUpdateVisitor { 66 135 67 private NameEnv _env; 68 private Set<IdOrOpOrAnonymousName> _onDemandImports; 69 private List<StaticError> _errors; 70 private Option<Id> _innerMostLabel; 71 72 public ExprDisambiguator(NameEnv env, Set<IdOrOpOrAnonymousName> onDemandImports, 73 List<StaticError> errors) { 74 _env = env; 75 _onDemandImports = onDemandImports; 76 _errors = errors; 77 _innerMostLabel = Option.<Id>none(); 78 } 79 80 private ExprDisambiguator(NameEnv env, Set<IdOrOpOrAnonymousName> onDemandImports, 81 List<StaticError> errors, Option<Id> innerMostLabel) { 82 this(env, onDemandImports, errors); 83 _innerMostLabel = innerMostLabel; 84 } 85 86 private ExprDisambiguator extend(Set<Id> vars) { 87 NameEnv newEnv = new LocalVarEnv(_env, vars); 88 return new ExprDisambiguator(newEnv, _onDemandImports, _errors); 89 } 90 91 private ExprDisambiguator extendWithSelf(Span span) { 92 Set<Id> selfSet = new HashSet<Id>(); 93 selfSet.add(new Id(span, "self")); 94 return extend(selfSet); 95 } 96 97 private void error(String msg, HasAt loc) { 98 _errors.add(StaticError.make(msg, loc)); 99 } 100 101 /** LocalVarDecls introduce local variables while visiting the body. */ 102 @Override public Node forLocalVarDecl(LocalVarDecl that) { 103 List<LValue> lhsResult = recurOnListOfLValue(that.getLhs()); 104 Option<Expr> rhsResult = recurOnOptionOfExpr(that.getRhs()); 105 Set<Id> definedNames = extractDefinedVarNames(lhsResult); 106 NameEnv newEnv = new LocalVarEnv(_env, definedNames); 107 ExprDisambiguator v = new ExprDisambiguator(newEnv, _onDemandImports, _errors); 108 List<Expr> bodyResult = v.recurOnListOfExpr(that.getBody()); 109 return forLocalVarDeclOnly(that, bodyResult, lhsResult, rhsResult); 110 } 111 112 private Set<Id> extractDefinedVarNames(Iterable<? extends LValue> lvalues) { 113 Set<Id> result = new HashSet<Id>(); 114 extractDefinedVarNames(lvalues, result); 115 return result; 116 } 117 118 private void extractDefinedVarNames(Iterable<? extends LValue> lvalues, 119 Set<Id> result) { 120 for (LValue lv : lvalues) { 121 boolean valid = true; 122 if (lv instanceof LValueBind) { 123 Id id = ((LValueBind)lv).getName(); 124 valid = (result.add(id) || id.getText().equals("_")); 125 } 126 else if (lv instanceof UnpastingBind) { 127 Id id = ((UnpastingBind)lv).getName(); 128 valid = (result.add(id) || id.getText().equals("_")); 129 } 130 else { // lv instanceof UnpastingSplit 131 extractDefinedVarNames(((UnpastingSplit)lv).getElems(), result); 132 } 133 if (!valid) { error("Duplicate local variable name", lv); } 134 } 135 } 136 137 /** 138 * Pull out all static variables that can be used in expression contexts, 139 * and return them as a Set<Id>. 140 * TODO: Collect OpParams as well. 141 */ 142 private Set<Id> extractStaticExprVars(List<StaticParam> staticParams) { 143 Set<Id> result = new HashSet<Id>(); 144 for (StaticParam staticParam: staticParams) { 145 if (staticParam instanceof BoolParam || 146 staticParam instanceof NatParam || 147 staticParam instanceof IntParam || 148 staticParam instanceof UnitParam) 149 { 150 result.add(((IdStaticParam)staticParam).getName()); 151 } 152 } 153 return result; 154 } 155 156 /** 157 * Convenience method that unwraps its argument and passes it 158 * to the overloaded definition of extractParamNames on lists. 159 */ 160 private Set<Id> extractParamNames(Option<List<Param>> params) { 161 Set<Id> result = new HashSet<Id>(); 162 if (params.isNone()) { return new HashSet<Id>(); } 163 else { return extractParamNames(params.unwrap()); } 164 } 165 166 /** 167 * Returns a list of Ids of the given list of Params. 168 */ 169 private Set<Id> extractParamNames(List<Param> params) { 170 Set<Id> result = new HashSet<Id>(); 171 172 for (Param param: params) { 173 result.add(param.getName()); 174 } 175 return result; 176 } 177 178 /** 179 * When recurring on an AbsTraitDecl, we first need to extend the 180 * environment with all the newly bound static parameters that can 181 * be used in an expression context. 182 * TODO: Handle variables bound in where clauses. 183 * TODO: Insert inherited method names into the environment. 184 */ 185 @Override public Node forAbsTraitDecl(final AbsTraitDecl that) { 186 ExprDisambiguator v = this.extend(extractStaticExprVars 187 (that.getStaticParams())). 188 extendWithSelf(that.getSpan()); 189 190 return forAbsTraitDeclOnly(that, 191 v.recurOnListOfModifier(that.getMods()), 192 (Id) that.getName().accept(v), 193 v.recurOnListOfStaticParam(that.getStaticParams()), 194 v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 195 (WhereClause) that.getWhere().accept(v), 196 v.recurOnListOfBaseType(that.getExcludes()), 197 v.recurOnOptionOfListOfBaseType(that.getComprises()), 198 v.recurOnListOfAbsDecl(that.getDecls())); 199 } 200 201 /** 202 * When recurring on a TraitDecl, we first need to extend the 203 * environment with all the newly bound static parameters that 204 * can be used in an expression context. 205 * TODO: Handle variables bound in where clauses. 206 * TODO: Insert inherited method names into the environment. 207 */ 208 @Override public Node forTraitDecl(final TraitDecl that) { 209 ExprDisambiguator v = this.extend(extractStaticExprVars 210 (that.getStaticParams())). 211 extendWithSelf(that.getSpan()); 212 213 return forTraitDeclOnly(that, 214 v.recurOnListOfModifier(that.getMods()), 215 (Id) that.getName().accept(v), 216 v.recurOnListOfStaticParam(that.getStaticParams()), 217 v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 218 (WhereClause) that.getWhere().accept(v), 219 v.recurOnListOfBaseType(that.getExcludes()), 220 v.recurOnOptionOfListOfBaseType(that.getComprises()), 221 v.recurOnListOfDecl(that.getDecls())); 222 } 223 224 225 /** 226 * When recurring on an AbsObjectDecl, we first need to extend the 227 * environment with all the newly bound static parameters that can 228 * be used in an expression context. 229 * TODO: Handle variables bound in where clauses. 230 * TODO: Insert inherited method names into the environment. 231 */ 232 @Override public Node forAbsObjectDecl(final AbsObjectDecl that) { 233 Set<Id> staticExprVars = extractStaticExprVars(that.getStaticParams()); 234 Set<Id> params = extractParamNames(that.getParams()); 235 ExprDisambiguator v = extend(staticExprVars). 236 extendWithSelf(that.getSpan()). 237 extend(params); 238 239 return forAbsObjectDeclOnly(that, 240 v.recurOnListOfModifier(that.getMods()), 241 (Id) that.getName().accept(v), 242 v.recurOnListOfStaticParam(that.getStaticParams()), 243 v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 244 (WhereClause) that.getWhere().accept(v), 245 v.recurOnOptionOfListOfParam(that.getParams()), 246 v.recurOnOptionOfListOfBaseType(that.getThrowsClause()), 247 (Contract) that.getContract().accept(v), 248 v.recurOnListOfAbsDecl(that.getDecls())); 249 } 250 251 /** 252 * When recurring on an ObjectDecl, we first need to extend the 253 * environment with all the newly bound static parameters that can 254 * be used in an expression context, along with all the object parameters. 255 * TODO: Handle variables bound in where clauses. 256 * TODO: Insert inherited method names into the environment. 257 */ 258 @Override public Node forObjectDecl(final ObjectDecl that) { 259 Set<Id> staticExprVars = extractStaticExprVars(that.getStaticParams()); 260 Set<Id> params = extractParamNames(that.getParams()); 261 ExprDisambiguator v = extend(staticExprVars). 262 extendWithSelf(that.getSpan()). 263 extend(params); 264 265 return forObjectDeclOnly(that, 266 v.recurOnListOfModifier(that.getMods()), 267 (Id) that.getName().accept(v), 268 v.recurOnListOfStaticParam(that.getStaticParams()), 269 v.recurOnListOfTraitTypeWhere(that.getExtendsClause()), 270 (WhereClause) that.getWhere().accept(v), 271 v.recurOnOptionOfListOfParam(that.getParams()), 272 v.recurOnOptionOfListOfBaseType(that.getThrowsClause()), 273 (Contract) that.getContract().accept(v), 274 v.recurOnListOfDecl(that.getDecls())); 275 } 276 277 278 /** 279 * When recurring on an AbsFnDecl, we first need to extend the 280 * environment with all the newly bound static parameters that 281 * can be used in an expression context, along with all function 282 * parameters and 'self'. 283 * TODO: Handle variables bound in where clauses. 284 */ 285 @Override public Node forAbsFnDecl(final AbsFnDecl that) { 286 Set<Id> staticExprVars = extractStaticExprVars(that.getStaticParams()); 287 Set<Id> params = extractParamNames(that.getParams()); 288 ExprDisambiguator v = extend(staticExprVars).extend(params); 289 290 return forAbsFnDeclOnly(that, 291 v.recurOnListOfModifier(that.getMods()), 292 (IdOrOpOrAnonymousName) that.getName().accept(v), 293 v.recurOnListOfStaticParam(that.getStaticParams()), 294 v.recurOnListOfParam(that.getParams()), 295 v.recurOnOptionOfType(that.getReturnType()), 296 v.recurOnOptionOfListOfBaseType(that.getThrowsClause()), 297 (WhereClause) that.getWhere().accept(v), 298 (Contract) that.getContract().accept(v)); 299 } 300 301 302 /** 303 * When recurring on a FnDef, we first need to extend the 304 * environment with all the newly bound static parameters that 305 * can be used in an expression context, along with all function 306 * parameters and
