]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/declarations/DInstanceAst.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / parsing / declarations / DInstanceAst.java
1 package org.simantics.scl.compiler.internal.parsing.declarations;
2
3 import java.util.ArrayList;
4
5 import org.simantics.scl.compiler.elaboration.expressions.EVar;
6 import org.simantics.scl.compiler.internal.parsing.types.TypeAst;
7
8 public class DInstanceAst extends DeclarationAst {
9     public final TypeAst[] context;
10     public final EVar name;
11     public final TypeAst[] types;
12     public final DeclarationAst[] declarations;
13     
14     public DInstanceAst(long loc, TypeAst[] context, EVar name, TypeAst[] types) {
15         this.location = loc;
16         this.context = context;
17         this.name = name;
18         this.types = types;
19         this.declarations = DeclarationAst.EMPTY_ARRAY;
20     }
21
22     public DInstanceAst(ArrayList<TypeAst> context, EVar name, 
23             TypeAst[] types, ArrayList<DeclarationAst> declarations) {
24         this.context = context.toArray(new TypeAst[context.size()]);
25         this.name = name;
26         this.types = types;
27         this.declarations = declarations == null ? EMPTY_ARRAY : declarations.toArray(new DeclarationAst[declarations.size()]);
28     }
29     
30     @Override
31     public void toString(int indentation, StringBuilder b) {
32         for(int i=0;i<indentation;++i) b.append("    ");
33         b.append("instance ");
34         if(context.length > 0) {
35             b.append("(");
36             for(int i=0;i<context.length;++i) {
37                 if(i>0)
38                     b.append(", ");
39                 context[i].toString(b);
40             }
41             b.append(") => ");
42             
43         }
44         b.append(name);
45         for(TypeAst type : types) {
46             b.append(' ');
47             type.toString(b, 1);
48         }
49         if(declarations.length > 0) {
50             b.append(" where");
51             for(DeclarationAst declaration : declarations) {
52                 b.append('\n');
53                 declaration.toString(indentation+1, b);
54             }
55         }
56     }
57 }