Skip to content

Commit e1b48ad

Browse files
committed
WIP on storage tags and improved error handling
1 parent e0e6b5b commit e1b48ad

356 files changed

Lines changed: 4501 additions & 3318 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public Void visitVariant(VariantDefinition variant) {
195195
for (int i = 0; i < option.types.length; i++) {
196196
if (i > 0)
197197
output.append(", ");
198-
output.append(option.types[i].accept(typeFormatter));
198+
output.append(typeFormatter.format(option.types[i]));
199199
}
200200
}
201201
}

‎CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public ExpressionString visitCast(CastExpression expression) {
312312
result.append(expression.target.accept(this).value);
313313
if (!expression.isImplicit) {
314314
result.append(" as ");
315-
result.append(expression.member.toType.accept(typeFormatter));
315+
result.append(typeFormatter.format(expression.member.toType));
316316
}
317317
return new ExpressionString(result.toString(), ZenScriptOperator.PRIMARY);
318318
}
@@ -341,7 +341,7 @@ public ExpressionString visitConditional(ConditionalExpression expression) {
341341
@Override
342342
public ExpressionString visitConst(ConstExpression expression) {
343343
StringBuilder result = new StringBuilder();
344-
result.append(expression.type.accept(typeFormatter));
344+
result.append(typeFormatter.format(expression.type));
345345
result.append('.');
346346
result.append(expression.constant.member.name);
347347
return new ExpressionString(result.toString(), ZenScriptOperator.MEMBER);
@@ -440,7 +440,7 @@ public ExpressionString visitConstructorSuperCall(ConstructorSuperCallExpression
440440

441441
@Override
442442
public ExpressionString visitEnumConstant(EnumConstantExpression expression) {
443-
return new ExpressionString(expression.type.accept(typeFormatter) + "." + expression.value.name, ZenScriptOperator.MEMBER);
443+
return new ExpressionString(typeFormatter.format(expression.type) + "." + expression.value.name, ZenScriptOperator.MEMBER);
444444
}
445445

446446
@Override
@@ -497,7 +497,7 @@ public ExpressionString visitGetMatchingVariantField(GetMatchingVariantField exp
497497
@Override
498498
public ExpressionString visitGetStaticField(GetStaticFieldExpression expression) {
499499
StringBuilder result = new StringBuilder();
500-
result.append(expression.type.accept(typeFormatter));
500+
result.append(typeFormatter.format(expression.type));
501501
result.append('.');
502502
result.append(expression.field.member.name);
503503
return new ExpressionString(result.toString(), ZenScriptOperator.MEMBER);
@@ -530,7 +530,7 @@ public ExpressionString visitInterfaceCast(InterfaceCastExpression expression) {
530530
StringBuilder result = new StringBuilder();
531531
result.append(expression.value.accept(this).value);
532532
result.append(" as ");
533-
result.append(expression.type.accept(typeFormatter));
533+
result.append(typeFormatter.format(expression.type));
534534
return new ExpressionString(result.toString(), ZenScriptOperator.CAST);
535535
}
536536

@@ -539,7 +539,7 @@ public ExpressionString visitIs(IsExpression expression) {
539539
StringBuilder result = new StringBuilder();
540540
result.append(expression.value.accept(this).value);
541541
result.append(" is ");
542-
result.append(expression.type.accept(typeFormatter));
542+
result.append(typeFormatter.format(expression.type));
543543
return new ExpressionString(result.toString(), ZenScriptOperator.IS);
544544
}
545545

@@ -577,7 +577,7 @@ public ExpressionString visitMatch(MatchExpression expression) {
577577
public ExpressionString visitNew(NewExpression expression) {
578578
StringBuilder result = new StringBuilder();
579579
result.append("new ");
580-
result.append(expression.type.accept(typeFormatter));
580+
result.append(typeFormatter.format(expression.type));
581581
FormattingUtils.formatCall(result, typeFormatter, this, expression.arguments);
582582
return new ExpressionString(result.toString(), ZenScriptOperator.PRIMARY);
583583
}
@@ -636,7 +636,7 @@ public ExpressionString visitSetLocalVariable(SetLocalVariableExpression express
636636
@Override
637637
public ExpressionString visitSetStaticField(SetStaticFieldExpression expression) {
638638
return new ExpressionString(
639-
expression.type.accept(typeFormatter) + "." + expression.field.member.name + " = " + expression.value.accept(this).value,
639+
typeFormatter.format(expression.type) + "." + expression.field.member.name + " = " + expression.value.accept(this).value,
640640
ZenScriptOperator.ASSIGN);
641641
}
642642

@@ -650,14 +650,14 @@ public ExpressionString visitSetter(SetterExpression expression) {
650650
@Override
651651
public ExpressionString visitStaticGetter(StaticGetterExpression expression) {
652652
return new ExpressionString(
653-
expression.type.accept(typeFormatter) + "." + expression.getter.member.name,
653+
typeFormatter.format(expression.type) + "." + expression.getter.member.name,
654654
ZenScriptOperator.MEMBER);
655655
}
656656

657657
@Override
658658
public ExpressionString visitStaticSetter(StaticSetterExpression expression) {
659659
return new ExpressionString(
660-
expression.type.accept(typeFormatter) + "." + expression.setter.member.name + " = " + expression.setter.member.name,
660+
typeFormatter.format(expression.type) + "." + expression.setter.member.name + " = " + expression.setter.member.name,
661661
ZenScriptOperator.ASSIGN);
662662
}
663663

‎CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.openzen.zenscript.codemodel.statement.VarStatement;
3131
import org.openzen.zenscript.codemodel.statement.WhileStatement;
3232
import org.openzen.zenscript.codemodel.type.BasicTypeID;
33-
import org.openzen.zenscript.codemodel.type.ITypeID;
33+
import org.openzen.zenscript.codemodel.type.TypeID;
3434

3535
/**
3636
*
@@ -78,17 +78,17 @@ public static void formatHeader(StringBuilder result, ScriptFormattingSettings s
7878
if (parameter.variadic)
7979
result.append("...");
8080

81-
if (!settings.showAnyInFunctionHeaders || parameter.type != BasicTypeID.UNDETERMINED) {
81+
if (!settings.showAnyInFunctionHeaders || !parameter.type.isBasic(BasicTypeID.UNDETERMINED)) {
8282
result.append(" as ");
83-
result.append(header.getReturnType().accept(typeFormatter));
83+
result.append(typeFormatter.format(header.getReturnType()));
8484
}
8585

8686
parameterIndex++;
8787
}
8888
result.append(")");
89-
if (!settings.showAnyInFunctionHeaders || header.getReturnType() != BasicTypeID.UNDETERMINED) {
89+
if (!settings.showAnyInFunctionHeaders || !header.getReturnType().isBasic(BasicTypeID.UNDETERMINED)) {
9090
result.append(" as ");
91-
result.append(header.getReturnType().accept(typeFormatter));
91+
result.append(typeFormatter.format(header.getReturnType()));
9292
}
9393
}
9494

@@ -128,7 +128,7 @@ public static void formatCall(StringBuilder result, TypeFormatter typeFormatter,
128128
result.append("<");
129129

130130
int index = 0;
131-
for (ITypeID typeArgument : arguments.typeArguments) {
131+
for (TypeID typeArgument : arguments.typeArguments) {
132132
if (index > 0)
133133
result.append(", ");
134134
result.append(typeArgument.accept(typeFormatter));

‎CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Void visitConst(ConstMember member) {
6262
output.append("const")
6363
.append(member.name)
6464
.append(" as ")
65-
.append(member.type.accept(typeFormatter))
65+
.append(typeFormatter.format(member.type))
6666
.append(" = ")
6767
.append(member.value.accept(new ExpressionFormatter(settings, typeFormatter, indent)))
6868
.append(";\n");
@@ -76,7 +76,7 @@ public Void visitField(FieldMember member) {
7676
output.append(member.isFinal() ? "val " : "var ")
7777
.append(member.name)
7878
.append(" as ")
79-
.append(member.type.accept(typeFormatter));
79+
.append(typeFormatter.format(member.type));
8080

8181
if (member.initializer != null) {
8282
output.append(" = ")
@@ -122,7 +122,7 @@ public Void visitGetter(GetterMember member) {
122122
output.append("get ");
123123
output.append(member.name);
124124
output.append(" as ");
125-
output.append(member.type.accept(typeFormatter));
125+
output.append(typeFormatter.format(member.type));
126126
formatBody(member.body);
127127
return null;
128128
}
@@ -134,7 +134,7 @@ public Void visitSetter(SetterMember member) {
134134
output.append("set ");
135135
output.append(member.name);
136136
output.append(" as ");
137-
output.append(member.type.accept(typeFormatter));
137+
output.append(typeFormatter.format(member.type));
138138
formatBody(member.body);
139139
return null;
140140
}
@@ -186,7 +186,7 @@ public Void visitCaster(CasterMember member) {
186186
visit(false);
187187
FormattingUtils.formatModifiers(output, member.modifiers & ~Modifiers.FINAL);
188188
output.append(" as ");
189-
output.append(member.toType.accept(typeFormatter));
189+
output.append(typeFormatter.format(member.toType));
190190
formatBody(member.body);
191191
return null;
192192
}

‎CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public Void visitTryCatch(TryCatchStatement statement) {
252252
for (CatchClause catchClause : statement.catchClauses) {
253253
output.append(indent).append("catch ");
254254
if (catchClause.exceptionVariable != null)
255-
output.append(catchClause.exceptionVariable.name).append(" as ").append(catchClause.exceptionVariable.type.accept(expressionFormatter.typeFormatter));
255+
output.append(catchClause.exceptionVariable.name).append(" as ").append(expressionFormatter.typeFormatter.format(catchClause.exceptionVariable.type));
256256

257257
format(ParentStatementType.CATCH, catchClause.content);
258258
}
@@ -274,7 +274,7 @@ public Void visitVar(VarStatement statement) {
274274

275275
if (statement.initializer == null || statement.initializer.type != statement.type) {
276276
output.append(" as ");
277-
output.append(statement.type.accept(expressionFormatter.typeFormatter));
277+
output.append(expressionFormatter.typeFormatter.format(statement.type));
278278
}
279279
if (statement.initializer != null) {
280280
output.append(" = ");

‎CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java‎

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import org.openzen.zenscript.codemodel.type.FunctionTypeID;
1919
import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
2020
import org.openzen.zenscript.codemodel.type.GenericTypeID;
21-
import org.openzen.zenscript.codemodel.type.ITypeID;
2221
import org.openzen.zenscript.codemodel.type.IteratorTypeID;
2322
import org.openzen.zenscript.codemodel.type.RangeTypeID;
23+
import org.openzen.zenscript.codemodel.type.StoredType;
2424
import org.openzen.zenscript.codemodel.type.StringTypeID;
25+
import org.openzen.zenscript.codemodel.type.TypeID;
2526
import stdlib.Chars;
2627
import org.openzen.zenscript.codemodel.type.TypeVisitor;
2728

@@ -37,6 +38,14 @@ public TypeFormatter(ScriptFormattingSettings settings, Importer importer) {
3738
this.settings = settings;
3839
this.importer = importer;
3940
}
41+
42+
public String format(TypeID type) {
43+
return type.accept(this);
44+
}
45+
46+
public String format(StoredType type) {
47+
return type.type.accept(this) + "`" + type.storage.toString();
48+
}
4049

4150
@Override
4251
public String visitBasic(BasicTypeID basic) {
@@ -45,34 +54,24 @@ public String visitBasic(BasicTypeID basic) {
4554

4655
@Override
4756
public String visitString(StringTypeID string) {
48-
if (string.storage == null)
49-
return "string";
50-
else
51-
return "string`" + string.storage.toString();
57+
return "string";
5258
}
5359

5460
@Override
5561
public String visitArray(ArrayTypeID array) {
56-
String element = array.elementType.accept(this);
62+
String element = format(array.elementType);
5763
String result;
5864
if (array.dimension == 1) {
5965
result = element + "[]";
6066
} else {
6167
result = element + "[" + Chars.times(',', array.dimension - 1) + "]";
6268
}
63-
if (array.storage == null)
64-
return result;
65-
66-
return result + '`' + array.storage.toString();
69+
return result;
6770
}
6871

6972
@Override
7073
public String visitAssoc(AssocTypeID assoc) {
71-
String result = assoc.valueType.accept(this) + "[" + assoc.keyType.accept(this) + "]";
72-
if (assoc.storage == null)
73-
return result;
74-
75-
return result + '`' + assoc.storage.toString();
74+
return format(assoc.valueType) + "[" + format(assoc.keyType) + "]";
7675
}
7776

7877
@Override
@@ -85,12 +84,6 @@ public String visitFunction(FunctionTypeID function) {
8584
StringBuilder result = new StringBuilder();
8685
result.append("function");
8786
FormattingUtils.formatHeader(result, settings, function.header, this);
88-
89-
if (function.storage != null) {
90-
result.append('`');
91-
result.append(function.storage.toString());
92-
}
93-
9487
return result.toString();
9588
}
9689

@@ -104,33 +97,24 @@ public String visitDefinition(DefinitionTypeID definition) {
10497
result.append(importedName);
10598
result.append("<");
10699
int index = 0;
107-
for (ITypeID typeParameter : definition.typeArguments) {
100+
for (TypeID typeParameter : definition.typeArguments) {
108101
if (index > 0)
109102
result.append(", ");
110103

111104
result.append(typeParameter.accept(this));
112105
}
113106
result.append(">");
114-
115-
if (definition.storage != null) {
116-
result.append('`');
117-
result.append(definition.storage.toString());
118-
}
119-
120107
return result.toString();
121108
}
122109

123110
@Override
124111
public String visitGeneric(GenericTypeID generic) {
125-
if (generic.storage == null)
126-
return generic.parameter.name;
127-
128-
return generic.parameter.name + '`' + generic.storage.toString();
112+
return generic.parameter.name;
129113
}
130114

131115
@Override
132116
public String visitRange(RangeTypeID range) {
133-
return range.baseType.accept(this) + " .. " + range.baseType.accept(this);
117+
return format(range.baseType) + " .. " + format(range.baseType);
134118
}
135119

136120
@Override
@@ -160,16 +144,10 @@ public String visitType(ParameterTypeBound bound) {
160144
@Override
161145
public String visitGenericMap(GenericMapTypeID map) {
162146
StringBuilder result = new StringBuilder();
163-
result.append(map.value.accept(this));
147+
result.append(format(map.value));
164148
result.append("[<");
165149
FormattingUtils.formatTypeParameters(result, new TypeParameter[] { map.key }, this);
166150
result.append("]>");
167-
168-
if (map.storage != null) {
169-
result.append('`');
170-
result.append(map.storage.toString());
171-
}
172-
173151
return result.toString();
174152
}
175153
}

0 commit comments

Comments
 (0)