Project

General

Profile

Revision 7

Added by Willibald K. over 8 years ago

changing java, cpp, hpp files to unix line endings

View differences:

ListConstructor.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.expressions;
29

  
30
import java.util.ArrayList;
28
package org.momut.ooas.ast.expressions;
31 29

  
30
import java.util.ArrayList;
31

  
32 32
import org.momut.ooas.ast.IAstVisitor;
33 33
import org.momut.ooas.ast.IScope;
34 34
import org.momut.ooas.ast.identifiers.Identifier;
35 35
import org.momut.ooas.parser.SymbolTable;
36

  
37
///////////////////////////////////////////////
38
///  Constructor: List
39
///
40
public final class ListConstructor extends TypeConstructionExpression implements IScope
41
{
42
	private ArrayList<Expression> m_elements;
43
	private IScope m_parentScope;
44
	private final SymbolTable m_comprehensionVars;
45
	private Expression m_comprehension;
46
	private boolean m_hasComprehension = false;
47

  
48
	public ArrayList<Expression> elements() { return m_elements; }
49
	public Expression comprehension() { return m_comprehension; }
50
	public boolean hasComprehension() { return m_hasComprehension; }
51
	public SymbolTable comprehensionVariables() { return m_comprehensionVars; }
52

  
53
	public ListConstructor(int line, int pos)
54
	{
55
		super (ExpressionKind.ListConstr, line, pos);
56
		m_elements = new ArrayList<Expression>();
57
		m_comprehensionVars = new SymbolTable();
58
	}
59

  
60
	public ListConstructor(ListConstructor toCopy)
61
	{
62
		super (toCopy);
63
		m_elements = new ArrayList<Expression>(toCopy.m_elements);
64
		m_parentScope = toCopy.m_parentScope;
65
		m_comprehensionVars = new SymbolTable(toCopy.m_comprehensionVars);
66
		m_comprehension = toCopy.m_comprehension;
67
		m_hasComprehension = toCopy.m_hasComprehension;
68
	}
69

  
70
	@Override
71
	public /*override*/ Expression Clone()
72
	{
73
		return new ListConstructor(this);
74
	}
75

  
76
	public void AddElement(Expression anElement)
77
	{
78
		m_elements.add(anElement);
79
	}
80

  
81
	public void SetComprehension(Expression comprehension)
82
	{
83
		m_comprehension = comprehension;
84
	}
85

  
86
	public void SetHasComprehension(boolean flag)
87
	{
88
		m_hasComprehension = flag;
89
	}
90

  
91
	@Override
92
	public Identifier ResolveIdentifier(String aName)
93
	{
94
		if (m_comprehensionVars.Defined(aName))
95
			return m_comprehensionVars.Get(aName);
96
		else
97
			return null;
98
	}
99

  
100
	@Override
101
	public IScope GetParentScope()
102
	{
103
		return m_parentScope;
104
	}
105

  
106
	@Override
107
	public void SetParentScope(IScope parentScope)
108
	{
109
		m_parentScope = parentScope;
110
	}
111

  
112
	@Override
113
	public void AddIdentifier(Identifier anIdentifier, Object tag)
114
	{
115
		m_comprehensionVars.AddIdentifier(anIdentifier);
116
	}
117

  
118
	@Override
119
	public /*override*/ void Accept(IAstVisitor visitor)
120
	{
121
		visitor.visit(this);
122
	}
123

  
124
	public void SetElements(ArrayList<Expression> newElements)
125
	{
126
		m_elements = newElements;
127
	}
128

  
129
}
36

  
37
///////////////////////////////////////////////
38
///  Constructor: List
39
///
40
public final class ListConstructor extends TypeConstructionExpression implements IScope
41
{
42
	private ArrayList<Expression> m_elements;
43
	private IScope m_parentScope;
44
	private final SymbolTable m_comprehensionVars;
45
	private Expression m_comprehension;
46
	private boolean m_hasComprehension = false;
47

  
48
	public ArrayList<Expression> elements() { return m_elements; }
49
	public Expression comprehension() { return m_comprehension; }
50
	public boolean hasComprehension() { return m_hasComprehension; }
51
	public SymbolTable comprehensionVariables() { return m_comprehensionVars; }
52

  
53
	public ListConstructor(int line, int pos)
54
	{
55
		super (ExpressionKind.ListConstr, line, pos);
56
		m_elements = new ArrayList<Expression>();
57
		m_comprehensionVars = new SymbolTable();
58
	}
59

  
60
	public ListConstructor(ListConstructor toCopy)
61
	{
62
		super (toCopy);
63
		m_elements = new ArrayList<Expression>(toCopy.m_elements);
64
		m_parentScope = toCopy.m_parentScope;
65
		m_comprehensionVars = new SymbolTable(toCopy.m_comprehensionVars);
66
		m_comprehension = toCopy.m_comprehension;
67
		m_hasComprehension = toCopy.m_hasComprehension;
68
	}
69

  
70
	@Override
71
	public /*override*/ Expression Clone()
72
	{
73
		return new ListConstructor(this);
74
	}
75

  
76
	public void AddElement(Expression anElement)
77
	{
78
		m_elements.add(anElement);
79
	}
80

  
81
	public void SetComprehension(Expression comprehension)
82
	{
83
		m_comprehension = comprehension;
84
	}
85

  
86
	public void SetHasComprehension(boolean flag)
87
	{
88
		m_hasComprehension = flag;
89
	}
90

  
91
	@Override
92
	public Identifier ResolveIdentifier(String aName)
93
	{
94
		if (m_comprehensionVars.Defined(aName))
95
			return m_comprehensionVars.Get(aName);
96
		else
97
			return null;
98
	}
99

  
100
	@Override
101
	public IScope GetParentScope()
102
	{
103
		return m_parentScope;
104
	}
105

  
106
	@Override
107
	public void SetParentScope(IScope parentScope)
108
	{
109
		m_parentScope = parentScope;
110
	}
111

  
112
	@Override
113
	public void AddIdentifier(Identifier anIdentifier, Object tag)
114
	{
115
		m_comprehensionVars.AddIdentifier(anIdentifier);
116
	}
117

  
118
	@Override
119
	public /*override*/ void Accept(IAstVisitor visitor)
120
	{
121
		visitor.visit(this);
122
	}
123

  
124
	public void SetElements(ArrayList<Expression> newElements)
125
	{
126
		m_elements = newElements;
127
	}
128

  
129
}

Also available in: Unified diff