Project

General

Profile

Revision 7

Added by Willibald K. over 8 years ago

changing java, cpp, hpp files to unix line endings

View differences:

EnumType.java
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
  */

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 26

  
27 27

  
28
package org.momut.ooas.ast.types;

29

  
30
import java.util.ArrayList;

31
import java.util.Collections;

32
import java.util.Comparator;

33

  
28
package org.momut.ooas.ast.types;
29

  
30
import java.util.ArrayList;
31
import java.util.Collections;
32
import java.util.Comparator;
33

  
34 34
import org.momut.ooas.ast.IAstVisitor;
35 35
import org.momut.ooas.ast.identifiers.EnumIdentifier;
36 36
import org.momut.ooas.ast.identifiers.TypeIdentifier;
37 37
import org.momut.ooas.parser.SymbolTable;
38 38
import org.momut.ooas.utils.exceptions.SymbolAlreadyDefinedException;
39

  
40
///////////////////////////////////////////////
41
///  Simple Type: Enumeration
42
///
43
public class EnumType extends UlyssesType
44
{
45
	protected SymbolTable m_enumSymbols;
46
	protected ArrayList<EnumIdentifier> m_listOfEnumSymbols;
47

  
48
	public SymbolTable symbolTable() { return m_enumSymbols; }
49
	public ArrayList<EnumIdentifier> listOfEnumSymbols() { return m_listOfEnumSymbols; }
50

  
51
	public EnumType(TypeIdentifier anIdentifier)
52
	{
53
		super (TypeKind.EnumeratedType, anIdentifier);
54
		m_enumSymbols = new SymbolTable();
55
		m_listOfEnumSymbols = new ArrayList<EnumIdentifier>();
56
	}
57

  
58
	public void AddEnumSymbol(EnumIdentifier aSymbol)
59
	{
60
		if (m_enumSymbols.Defined(aSymbol.tokenText()))
61
			throw new SymbolAlreadyDefinedException(aSymbol.tokenText());
62

  
63
		m_enumSymbols.AddIdentifier(aSymbol);
64
		m_listOfEnumSymbols.add(aSymbol);
65
		Collections.sort(m_listOfEnumSymbols, new Comparator<EnumIdentifier>() {
66
			@Override
67
			public int compare(EnumIdentifier o1, EnumIdentifier o2) {
68
				return o1.tokenText().compareTo(o2.tokenText());
69
			}
70
		});
71
	}
72

  
73
	@Override
74
	public void Accept(IAstVisitor visitor)
75
	{
76
		visitor.visit(this);
77
	}
78

  
79
	@Override
80
	public /*override*/ String AnonymousName()
81
	{
82
		final StringBuilder result = new StringBuilder();
83
		result.append("enum_");
84
		for (final EnumIdentifier sym: m_listOfEnumSymbols)
85
		{
86
			result.append(sym.tokenText());
87
			result.append("_");
88
		}
89
		return result.toString();
90
	}
91

  
92
	@Override
93
	public int valueCount() {
94
		return m_listOfEnumSymbols.size();
95
	}
96
	
97
}
39

  
40
///////////////////////////////////////////////
41
///  Simple Type: Enumeration
42
///
43
public class EnumType extends UlyssesType
44
{
45
	protected SymbolTable m_enumSymbols;
46
	protected ArrayList<EnumIdentifier> m_listOfEnumSymbols;
47

  
48
	public SymbolTable symbolTable() { return m_enumSymbols; }
49
	public ArrayList<EnumIdentifier> listOfEnumSymbols() { return m_listOfEnumSymbols; }
50

  
51
	public EnumType(TypeIdentifier anIdentifier)
52
	{
53
		super (TypeKind.EnumeratedType, anIdentifier);
54
		m_enumSymbols = new SymbolTable();
55
		m_listOfEnumSymbols = new ArrayList<EnumIdentifier>();
56
	}
57

  
58
	public void AddEnumSymbol(EnumIdentifier aSymbol)
59
	{
60
		if (m_enumSymbols.Defined(aSymbol.tokenText()))
61
			throw new SymbolAlreadyDefinedException(aSymbol.tokenText());
62

  
63
		m_enumSymbols.AddIdentifier(aSymbol);
64
		m_listOfEnumSymbols.add(aSymbol);
65
		Collections.sort(m_listOfEnumSymbols, new Comparator<EnumIdentifier>() {
66
			@Override
67
			public int compare(EnumIdentifier o1, EnumIdentifier o2) {
68
				return o1.tokenText().compareTo(o2.tokenText());
69
			}
70
		});
71
	}
72

  
73
	@Override
74
	public void Accept(IAstVisitor visitor)
75
	{
76
		visitor.visit(this);
77
	}
78

  
79
	@Override
80
	public /*override*/ String AnonymousName()
81
	{
82
		final StringBuilder result = new StringBuilder();
83
		result.append("enum_");
84
		for (final EnumIdentifier sym: m_listOfEnumSymbols)
85
		{
86
			result.append(sym.tokenText());
87
			result.append("_");
88
		}
89
		return result.toString();
90
	}
91

  
92
	@Override
93
	public int valueCount() {
94
		return m_listOfEnumSymbols.size();
95
	}
96
	
97
}

Also available in: Unified diff