Project

General

Profile

root / trunk / compiler / ooasCompiler / src / org / momut / ooas / codegen / java / JavaType.java @ 7

1
/**
2
  *
3
  *                      OOAS Compiler
4
  *
5
  *       Copyright 2015, AIT Austrian Institute of Technology.
6
  * This code is based on the C# Version of the OOAS Compiler, which is
7
  * copyright 2015 by the Institute of Software Technology, Graz University
8
  * of Technology with portions copyright by the AIT Austrian Institute of
9
  * Technology. All rights reserved.
10
  *
11
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
12
  *
13
  * If you modify the file please update the list of contributors below to in-
14
  * clude your name. Please also stick to the coding convention of using TABs
15
  * to do the basic (block-level) indentation and spaces for anything after
16
  * that. (Enable the display of special chars and it should be pretty obvious
17
  * what this means.) Also, remove all trailing whitespace.
18
  *
19
  * Contributors:
20
  *               Willibald Krenn (AIT)
21
  *               Stephan Zimmerer (AIT)
22
  *               Markus Demetz (AIT)
23
  *               Christoph Czurda (AIT)
24
  *
25
  */
26

    
27

    
28
package org.momut.ooas.codegen.java;
29

    
30
import org.momut.ooas.ast.types.BoolType;
31
import org.momut.ooas.ast.types.CharType;
32
import org.momut.ooas.ast.types.EnumType;
33
import org.momut.ooas.ast.types.FloatType;
34
import org.momut.ooas.ast.types.FunctionType;
35
import org.momut.ooas.ast.types.IntType;
36
import org.momut.ooas.ast.types.ListType;
37
import org.momut.ooas.ast.types.MapType;
38
import org.momut.ooas.ast.types.OoActionSystemType;
39
import org.momut.ooas.ast.types.OpaqueType;
40
import org.momut.ooas.ast.types.QrType;
41
import org.momut.ooas.ast.types.TupleType;
42
import org.momut.ooas.codegen.OoasCodeEmitter;
43
import org.momut.ooas.utils.exceptions.NotImplementedException;
44
import org.momut.ooas.visitors.OoaTypeVisitor;
45

    
46
public final class JavaType extends OoaTypeVisitor
47
{
48
        private final OoasCodeEmitter m_emitter = new OoasCodeEmitter();
49

    
50
        private String GetIdentifierString(String anIdentifier)
51
        {
52
                return JavaIdentifier.GetIdentifierString(anIdentifier);
53
        }
54

    
55

    
56

    
57
        @Override
58
        public void visit(CharType charType)
59
        {
60
                m_emitter.Append("int"); // ToDo: map to char?
61
        }
62

    
63
        @Override
64
        public void visit(IntType intType)
65
        {
66
                m_emitter.Append("int");
67
        }
68

    
69
        @Override
70
        public void visit(BoolType boolType)
71
        {
72
                m_emitter.Append("boolean");
73
        }
74

    
75
        @Override
76
        public void visit(FloatType floatType)
77
        {
78
                m_emitter.Append("double");
79
        }
80

    
81
        @Override
82
        public void visit(EnumType enumType)
83
        {
84
                m_emitter.Append(GetIdentifierString(enumType.identifier().tokenText()));
85
        }
86

    
87
        @Override
88
        public void visit(ListType listType)
89
        {
90
                m_emitter.Append("org.momut.ooas.codegen.java.runtime.CustomList<Object>");
91
        }
92

    
93
        @Override
94
        public void visit(MapType mapType)
95
        {
96
                throw new NotImplementedException();
97
//                m_emitter.Append("UlyssesDictionary<Object,Object>");
98
        }
99

    
100
        @Override
101
        public void visit(QrType qrType)
102
        {
103
                m_emitter.Append("QualitativeValue");
104
        }
105

    
106
        @Override
107
        public void visit(TupleType tupleType)
108
        {
109
                // we map a tuple to a struct
110
                m_emitter.Append(GetIdentifierString(tupleType.identifier().tokenText()));
111
        }
112

    
113
        @Override
114
        public void visit(FunctionType functionType)
115
        {
116
                throw new NotImplementedException();
117
        }
118

    
119
        @Override
120
        public void visit(OoActionSystemType ooActionSystemType)
121
        {
122
                m_emitter.Append(GetIdentifierString(ooActionSystemType.identifier().tokenText()));
123
        }
124

    
125
        @Override
126
        public void visit(OpaqueType opaqueType)
127
        {
128
                throw new NotImplementedException();
129
        }
130

    
131

    
132
        @Override
133
        public String toString()
134
        {
135
                return m_emitter.toString();
136
        }
137
}