]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/EStringLiteral.java
Updated release engineering instructions for 1.31.0 release.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / EStringLiteral.java
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         EApply result = new EApply(new ELiteral(new StringInterpolation(strings)), components);
26         result.setLocationDeep(location);
27         return result.resolve(context);
28     }
29
30     @Override
31     public void setLocationDeep(long loc) {
32         if(location == Locations.NO_LOCATION) {
33             location = loc;
34             for(Expression expression : expressions)
35                 expression.setLocationDeep(loc);
36         }
37     }
38     
39     @Override
40     public Expression accept(ExpressionTransformer transformer) {
41         return transformer.transform(this);
42     }
43     
44     @Override
45     public Expression resolveAsPattern(TranslationContext context) {
46         for(int i=0;i<expressions.length;++i)
47             expressions[i] = expressions[i].resolveAsPattern(context);
48         if(expressions.length > 1) {
49             context.getErrorLog().log(location, "String interpolation can be a pattern only if has one hole.");
50             return new EError();
51         }
52         EApply result = new EApply(new ELiteral(new StringInterpolation(strings)), expressions);
53         result.setLocationDeep(location);
54         return result;
55     }
56
57     @Override
58     public void accept(ExpressionVisitor visitor) {
59         visitor.visit(this);
60     }
61 }