raster@16367
|
1 |
/*
|
raster@16367
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
raster@16367
|
3 |
*
|
raster@16367
|
4 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
raster@16367
|
5 |
*
|
raster@16367
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
raster@16367
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
raster@16367
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
raster@16367
|
9 |
* "License"). You may not use this file except in compliance with the
|
raster@16367
|
10 |
* License. You can obtain a copy of the License at
|
raster@16367
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
raster@16367
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
raster@16367
|
13 |
* specific language governing permissions and limitations under the
|
raster@16367
|
14 |
* License. When distributing the software, include this License Header
|
raster@16367
|
15 |
* Notice in each file and include the License file at
|
raster@16367
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
raster@16367
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
raster@16367
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
raster@16367
|
19 |
* accompanied this code. If applicable, add the following below the
|
raster@16367
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
raster@16367
|
21 |
* your own identifying information:
|
raster@16367
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
raster@16367
|
23 |
*
|
raster@16367
|
24 |
* If you wish your version of this file to be governed by only the CDDL
|
raster@16367
|
25 |
* or only the GPL Version 2, indicate your decision by adding
|
raster@16367
|
26 |
* "[Contributor] elects to include this software in this distribution
|
raster@16367
|
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
raster@16367
|
28 |
* single choice of license, a recipient has the option to distribute
|
raster@16367
|
29 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
raster@16367
|
30 |
* to extend the choice of license to its licensees as provided above.
|
raster@16367
|
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
raster@16367
|
32 |
* Version 2 license, then the option applies only if the new code is
|
raster@16367
|
33 |
* made subject to such option by the copyright holder.
|
raster@16367
|
34 |
*
|
raster@16367
|
35 |
* Contributor(s):
|
raster@16367
|
36 |
*
|
raster@16367
|
37 |
* Portions Copyrighted 2008 Sun Microsystems, Inc.
|
raster@16367
|
38 |
*/
|
raster@16367
|
39 |
package org.netbeans.modules.ada.editor.ast.nodes;
|
raster@16367
|
40 |
|
raster@16367
|
41 |
import org.netbeans.modules.ada.editor.ast.nodes.visitors.Visitor;
|
raster@16367
|
42 |
|
raster@16367
|
43 |
/**
|
raster@16367
|
44 |
* Based on org.netbeans.modules.php.editor.parser.astnodes.InfixExpression
|
raster@16367
|
45 |
*
|
raster@16367
|
46 |
* Represents an infix expression
|
raster@16367
|
47 |
* <pre>e.g.<pre> $a + 1,
|
raster@16367
|
48 |
* 3 - 2,
|
raster@16367
|
49 |
* foo() * $a->bar(),
|
raster@16367
|
50 |
* 'string'.$c
|
raster@16367
|
51 |
*/
|
raster@16367
|
52 |
public class InfixExpression extends Expression {
|
raster@16367
|
53 |
|
raster@16367
|
54 |
public enum OperatorType {
|
raster@16367
|
55 |
IS_EQUAL, // '='
|
raster@16367
|
56 |
IS_NOT_EQUAL, // '/='
|
raster@16367
|
57 |
RGREATER, // '<'
|
raster@16367
|
58 |
IS_SMALLER_OR_EQUAL, // '<='
|
raster@16367
|
59 |
LGREATER, // '>'
|
raster@16367
|
60 |
IS_GREATER_OR_EQUAL, // '>='
|
raster@16367
|
61 |
BOOL_OR, // 'or'
|
raster@16367
|
62 |
BOOL_AND, // 'and'
|
raster@16367
|
63 |
BOOL_XOR, // 'xor'
|
raster@16367
|
64 |
STRING_AND, // '&'
|
raster@16367
|
65 |
OR, // '|'
|
raster@16367
|
66 |
EXPON, // '**'
|
raster@16367
|
67 |
PLUS, // '+'
|
raster@16367
|
68 |
MINUS, // '-'
|
raster@16367
|
69 |
MUL, // '*'
|
raster@16367
|
70 |
DIV, // '/'
|
raster@16367
|
71 |
MOD, // 'mod'
|
raster@16367
|
72 |
REM, // 'rem'
|
raster@16367
|
73 |
IN, // 'in'
|
raster@16367
|
74 |
NOT_IN // 'not in'
|
raster@16367
|
75 |
}
|
raster@16367
|
76 |
|
raster@16367
|
77 |
private Expression left;
|
raster@16367
|
78 |
private InfixExpression.OperatorType operator;
|
raster@16367
|
79 |
private Expression right;
|
raster@16367
|
80 |
|
raster@16367
|
81 |
public InfixExpression(int start, int end, Expression left, InfixExpression.OperatorType operator, Expression right) {
|
raster@16367
|
82 |
super(start, end);
|
raster@16367
|
83 |
|
raster@16367
|
84 |
if (right == null || left == null ) {
|
raster@16367
|
85 |
throw new IllegalArgumentException();
|
raster@16367
|
86 |
}
|
raster@16367
|
87 |
|
raster@16367
|
88 |
this.left = left;
|
raster@16367
|
89 |
this.right = right;
|
raster@16367
|
90 |
this.operator = operator;
|
raster@16367
|
91 |
}
|
raster@16367
|
92 |
|
raster@16367
|
93 |
|
raster@16367
|
94 |
|
raster@16367
|
95 |
/**
|
raster@16367
|
96 |
* Returns the operator of this infix expression.
|
raster@16367
|
97 |
*
|
raster@16367
|
98 |
* @return the infix operator
|
raster@16367
|
99 |
*/
|
raster@16367
|
100 |
public InfixExpression.OperatorType getOperator() {
|
raster@16367
|
101 |
return this.operator;
|
raster@16367
|
102 |
}
|
raster@16367
|
103 |
|
raster@16367
|
104 |
/**
|
raster@16367
|
105 |
* Returns the left operand of this infix expression.
|
raster@16367
|
106 |
*
|
raster@16367
|
107 |
* @return the left operand node
|
raster@16367
|
108 |
*/
|
raster@16367
|
109 |
public Expression getLeft() {
|
raster@16367
|
110 |
return this.left;
|
raster@16367
|
111 |
}
|
raster@16367
|
112 |
|
raster@16367
|
113 |
/**
|
raster@16367
|
114 |
* Returns the right operand of this infix expression.
|
raster@16367
|
115 |
*
|
raster@16367
|
116 |
* @return the right operand node
|
raster@16367
|
117 |
*/
|
raster@16367
|
118 |
public Expression getRight() {
|
raster@16367
|
119 |
return this.right;
|
raster@16367
|
120 |
}
|
raster@16367
|
121 |
|
raster@16367
|
122 |
@Override
|
raster@16367
|
123 |
public void accept(Visitor visitor) {
|
raster@16367
|
124 |
visitor.visit(this);
|
raster@16367
|
125 |
}
|
raster@16367
|
126 |
}
|