root / trunk / compiler / ooasCompiler / src / org / momut / ooas / ast / identifiers / FunctionIdentifier.java @ 8
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 |
* Stefan Tiran (AIT)
|
25 |
*
|
26 |
*/
|
27 |
|
28 |
|
29 |
package org.momut.ooas.ast.identifiers; |
30 |
|
31 |
import java.util.ArrayList; |
32 |
import java.util.List; |
33 |
|
34 |
import org.antlr.runtime.Token; |
35 |
import org.momut.ooas.ast.IScope; |
36 |
import org.momut.ooas.ast.statements.Statement; |
37 |
import org.momut.ooas.ast.types.UlyssesType; |
38 |
import org.momut.ooas.utils.exceptions.InternalCompilerException; |
39 |
|
40 |
public abstract class FunctionIdentifier extends Scope |
41 |
{ |
42 |
private Statement m_body; |
43 |
private ArrayList<ParameterIdentifier> m_parameter = new ArrayList<ParameterIdentifier>(); |
44 |
|
45 |
public Statement body() { return m_body; } |
46 |
public List<ParameterIdentifier> parameter() { return m_parameter; } |
47 |
|
48 |
|
49 |
public FunctionIdentifier(Token aToken,
|
50 |
UlyssesType aType, |
51 |
IdentifierKind aKind, |
52 |
IScope aDefiningScope) |
53 |
{ |
54 |
super (aToken, aType, aKind, aDefiningScope);
|
55 |
} |
56 |
|
57 |
public FunctionIdentifier(FunctionIdentifier toCopy)
|
58 |
{ |
59 |
super (toCopy);
|
60 |
m_body = toCopy.m_body; |
61 |
m_parameter = new ArrayList<ParameterIdentifier>(toCopy.m_parameter); |
62 |
} |
63 |
|
64 |
public FunctionIdentifier(
|
65 |
String name,
|
66 |
UlyssesType aType, |
67 |
IdentifierKind aKind, |
68 |
IScope aDefiningScope) |
69 |
{ |
70 |
super(name, aType, aKind, aDefiningScope);
|
71 |
} |
72 |
|
73 |
public void SetBody(Statement body) |
74 |
{ |
75 |
m_body = body; |
76 |
if (m_body instanceof IScope) { |
77 |
final IScope s = (IScope) m_body;
|
78 |
if (s.GetParentScope() == null) |
79 |
s.SetParentScope(this);
|
80 |
else if (s.GetParentScope() != this) |
81 |
throw new InternalCompilerException("Internal Error: Methodbody has parent set to different method than it was added to."); |
82 |
} |
83 |
} |
84 |
|
85 |
public void AddParameter(ParameterIdentifier aParameter) |
86 |
{ |
87 |
m_parameter.add(aParameter); |
88 |
AddIdentifier(aParameter, null);
|
89 |
} |
90 |
} |