]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/fundeps/Fundep.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / fundeps / Fundep.java
1 package org.simantics.scl.compiler.elaboration.fundeps;
2
3 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
4 import org.simantics.scl.compiler.internal.parsing.declarations.FundepAst;
5
6
7 public class Fundep {
8     public static final Fundep[] EMPTY_ARRAY = new Fundep[0];
9     public final int[] from;
10     public final int[] to;
11
12     public Fundep(int[] from, int[] to) {
13         this.from = from;
14         this.to = to;
15     }
16     
17     public Fundep(int[] from, int to) {
18         this(from, new int[] {to});
19     }
20
21     private static int mapParameterName(String[] parameterNames, String name) {
22         for(int i=0;i<parameterNames.length;++i)
23             if(parameterNames[i].equals(name))
24                 return i;
25         throw new InternalCompilerError("Fundep.mapParameterName error handling missing.");
26     }
27
28     private static int[] mapParameterNames(String[] parameterNames, String[] names) {
29         int[] result = new int[names.length];
30         for(int i=0;i<names.length;++i)
31             result[i] = mapParameterName(parameterNames, names[i]);
32         return result;
33     }
34
35     public static Fundep[] mapFundeps(String[] parameterNames, FundepAst[] fundeps) {
36         Fundep[] result = new Fundep[fundeps.length];
37         for(int i=0;i<fundeps.length;++i)
38             result[i] = new Fundep(
39                     mapParameterNames(parameterNames, fundeps[i].from), 
40                     mapParameterName(parameterNames, fundeps[i].to));
41         return result;
42     }
43 }