Revision 9
Added by Willibald K. over 8 years ago
CadpType.java | ||
---|---|---|
51 | 51 |
import org.momut.ooas.ast.types.OoActionSystemInstance; |
52 | 52 |
import org.momut.ooas.ast.types.OoActionSystemType; |
53 | 53 |
import org.momut.ooas.ast.types.OpaqueType; |
54 |
import org.momut.ooas.ast.types.QrType; |
|
55 | 54 |
import org.momut.ooas.ast.types.TupleType; |
56 | 55 |
import org.momut.ooas.ast.types.TypeKind; |
57 |
import org.momut.ooas.ast.types.UlyssesType;
|
|
56 |
import org.momut.ooas.ast.types.Type; |
|
58 | 57 |
import org.momut.ooas.ast.types.ValuedEnumType; |
59 | 58 |
import org.momut.ooas.codegen.OoasCodeEmitter; |
60 | 59 |
import org.momut.ooas.parser.SymbolTable; |
... | ... | |
154 | 153 |
{ |
155 | 154 |
throw new UnsupportedOperationException(); |
156 | 155 |
} |
157 |
@Override |
|
158 |
public void visit(QrType qrType) |
|
159 |
{ |
|
160 |
throw new UnsupportedOperationException(); |
|
161 |
} |
|
162 | 156 |
|
163 | 157 |
@Override |
164 | 158 |
public void visit(FunctionType functionType) |
... | ... | |
189 | 183 |
super(null); |
190 | 184 |
} |
191 | 185 |
|
192 |
public static String DumpType(UlyssesType atype)
|
|
186 |
public static String DumpType(Type atype) |
|
193 | 187 |
{ |
194 | 188 |
final CadpType newtype = new CadpType(); |
195 | 189 |
atype.Accept(newtype); |
... | ... | |
199 | 193 |
|
200 | 194 |
private static HashSet<String> emittedTypes = new HashSet<String>(); |
201 | 195 |
|
202 |
private static void EmitType(UlyssesType aType, OoasCodeEmitter emitter)
|
|
196 |
private static void EmitType(Type aType, OoasCodeEmitter emitter) |
|
203 | 197 |
{ |
204 | 198 |
final String typename = CadpIdentifier.GetIdentifierString(aType.identifier()); |
205 | 199 |
if (!emittedTypes.contains(typename)) |
... | ... | |
559 | 553 |
emitter.AppendLine("#endif"); |
560 | 554 |
emitter.AppendLineIncIndent(String.format("struct struct_%1$s {", typeName)); |
561 | 555 |
int i = 0; |
562 |
for (final UlyssesType it: atupleType.innerTypes())
|
|
556 |
for (final Type it: atupleType.innerTypes()) |
|
563 | 557 |
{ |
564 | 558 |
EmitType(it); |
565 | 559 |
emitter.AppendLine(String.format("%1$s elem_%2$s;", DumpType(it), i)); |
... | ... | |
575 | 569 |
emitter.AppendLine(String.format("/*%1$s%2$s*/", constructorString, typeName)); |
576 | 570 |
emitter.Append(String.format("%1$s %2$s%1$s (", typeName, constructorString)); |
577 | 571 |
i = 0; |
578 |
for (final UlyssesType it: atupleType.innerTypes())
|
|
572 |
for (final Type it: atupleType.innerTypes()) |
|
579 | 573 |
{ |
580 | 574 |
if (!emittedTypes.contains(CadpIdentifier.GetIdentifierString(it.identifier()))) |
581 | 575 |
EmitType(it, result); |
... | ... | |
587 | 581 |
emitter.AppendLineIncIndent(") {"); |
588 | 582 |
emitter.AppendLine(String.format("%1$s result;", typeName)); |
589 | 583 |
i = 0; |
590 |
for (final UlyssesType it: atupleType.innerTypes())
|
|
584 |
for (final Type it: atupleType.innerTypes()) |
|
591 | 585 |
{ |
592 | 586 |
emitter.AppendLine(String.format("result.elem_%1$s = arg_%1$s;", i)); |
593 | 587 |
/*do range checking on ints and floats*/ |
... | ... | |
623 | 617 |
emitter.AppendLine(String.format("/*%1$s%2$s*/", highString, typeName)); |
624 | 618 |
emitter.Append(String.format("long long int %2$s%1$s (void) { return ", typeName, highString)); |
625 | 619 |
i = 0; |
626 |
for (final UlyssesType x : atupleType.innerTypes())
|
|
620 |
for (final Type x : atupleType.innerTypes()) |
|
627 | 621 |
{ |
628 | 622 |
if (i != 0) |
629 | 623 |
emitter.Append(" * "); |
... | ... | |
640 | 634 |
emitter.Append(String.format("return %2$s%1$s (", typeName, constructorString)); |
641 | 635 |
i = 0; |
642 | 636 |
final StringBuilder divisor = new StringBuilder("value"); |
643 |
for (final UlyssesType it: atupleType.innerTypes())
|
|
637 |
for (final Type it: atupleType.innerTypes()) |
|
644 | 638 |
{ |
645 | 639 |
if (i != 0) |
646 | 640 |
emitter.Append(","); |
... | ... | |
656 | 650 |
emitter.AppendLine(String.format("void %1$s%2$s (CAESAR_TYPE_FILE CAESAR_FILE, %2$s A_VALUE)", printString, typeName)); |
657 | 651 |
emitter.AppendLine("{"); |
658 | 652 |
emitter.AppendLine(String.format(" fprintf(CAESAR_FILE,\" (\");")); |
659 |
final Iterator<UlyssesType> iter = atupleType.innerTypes().iterator();
|
|
653 |
final Iterator<Type> iter = atupleType.innerTypes().iterator(); |
|
660 | 654 |
for (i = 0; i < atupleType.innerTypes().size(); i++) |
661 | 655 |
{ |
662 | 656 |
if (i != 0) |
... | ... | |
831 | 825 |
|
832 | 826 |
|
833 | 827 |
|
834 |
public static String GetMaxVal(UlyssesType atype)
|
|
828 |
public static String GetMaxVal(Type atype) |
|
835 | 829 |
{ |
836 | 830 |
return String.format(" (%2$s%1$s() - 1) ", GetIdentifierString(atype.identifier()), highString); |
837 | 831 |
} |
838 | 832 |
|
839 |
public static String GetMinVal(UlyssesType atype)
|
|
833 |
public static String GetMinVal(Type atype) |
|
840 | 834 |
{ |
841 | 835 |
return String.format(" %2$s%1$s() ", GetIdentifierString(atype.identifier()), lowString); |
842 | 836 |
} |
843 | 837 |
|
844 |
public static String GetEnumVal(UlyssesType atype, String indexvar)
|
|
838 |
public static String GetEnumVal(Type atype, String indexvar) |
|
845 | 839 |
{ |
846 | 840 |
return String.format(" %2$s%1$s(%3$s)", GetIdentifierString(atype.identifier()), enumString, indexvar); |
847 | 841 |
} |
848 |
public static String GetEnumVal(UlyssesType atype)
|
|
842 |
public static String GetEnumVal(Type atype) |
|
849 | 843 |
{ |
850 | 844 |
return String.format(" %2$s%1$s", GetIdentifierString(atype.identifier()), enumString); |
851 | 845 |
} |
... | ... | |
856 | 850 |
private static OoasCodeEmitter m_classTypeDefinitions = new OoasCodeEmitter(); |
857 | 851 |
private static OoasCodeEmitter m_typeDefinitions = new OoasCodeEmitter(); |
858 | 852 |
|
859 |
public static void EmitType(UlyssesType aType)
|
|
853 |
public static void EmitType(Type aType) |
|
860 | 854 |
{ |
861 | 855 |
EmitType(aType, m_typeDefinitions); |
862 | 856 |
} |
... | ... | |
875 | 869 |
return result.toString(); |
876 | 870 |
} |
877 | 871 |
|
878 |
public static boolean IsNumeric(UlyssesType ulyssesType)
|
|
872 |
public static boolean IsNumeric(Type ulyssesType) |
|
879 | 873 |
{ |
880 | 874 |
switch (ulyssesType.kind()) |
881 | 875 |
{ |
Also available in: Unified diff
remove support for Qualitative Action Systems, rename UlyssesType to Type