]> gerrit.simantics Code Review - simantics/platform.git/blob
58ec41fd2f74b85dbbaf4ee420601b9638ada5e8
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.expressions;
2
3 import org.simantics.scl.compiler.common.names.Names;
4 import org.simantics.scl.compiler.constants.StringInterpolation;
5 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
6 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
7 import org.simantics.scl.compiler.errors.Locations;
8
9 public class EStringLiteral extends ASTExpression {
10     
11     public String[] strings;
12     public Expression[] expressions;
13    
14     public EStringLiteral(String[] strings, Expression[] expressions) {
15         this.strings = strings;
16         this.expressions = expressions;
17     }
18
19     @Override
20     public Expression resolve(TranslationContext context) {
21         Expression[] components = new Expression[expressions.length];
22         SCLValue showForPrinting = context.getEnvironment().getValue(Names.Prelude_showForPrinting);
23         for(int i=0;i<expressions.length;++i)
24             components[i] = new EApply(new EConstant(showForPrinting), expressions[i]);
25         return new EApply(new ELiteral(new StringInterpolation(strings)), components).resolve(context);
26     }
27
28     @Override
29     public void setLocationDeep(long loc) {
30         if(location == Locations.NO_LOCATION) {
31             location = loc;
32             for(Expression expression : expressions)
33                 expression.setLocationDeep(loc);
34         }
35     }
36     
37     @Override
38     public Expression accept(ExpressionTransformer transformer) {
39         return transformer.transform(this);
40     }
41     
42     @Override
43     public Expression resolveAsPattern(TranslationContext context) {
44         for(int i=0;i<expressions.length;++i)
45             expressions[i] = expressions[i].resolveAsPattern(context);
46         if(expressions.length > 1) {
47             context.getErrorLog().log(location, "String interpolation can be a pattern only if has one hole.");
48             return new EError();
49         }
50         return new EApply(new ELiteral(new StringInterpolation(strings)), expressions);
51     }
52
53     @Override
54     public void accept(ExpressionVisitor visitor) {
55         visitor.visit(this);
56     }
57 }