From: kpouer Date: Thu, 1 May 2003 13:19:27 +0000 (+0000) Subject: First try for AST structure. A lot of things to change X-Git-Url: http://secure.phpeclipse.com First try for AST structure. A lot of things to change --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java new file mode 100644 index 0000000..e31da6b --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractCase.java @@ -0,0 +1,13 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public abstract class AbstractCase extends Statement { + public Statement[] statements; + + public AbstractCase(Statement[] statements, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.statements = statements; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java new file mode 100644 index 0000000..0d3f2f0 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractPHPComment.java @@ -0,0 +1,17 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Here are php comment. + * @author Matthieu Casanova + */ +public abstract class AbstractPHPComment extends AstNode { + + /** + * Create a comment giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public AbstractPHPComment(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java new file mode 100644 index 0000000..b429e48 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractSuffixExpression.java @@ -0,0 +1,14 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Variable suffix. + * class access or [something] + * Should it be an expression ? + * @author Matthieu Casanova + */ +public abstract class AbstractSuffixExpression extends Expression { + + public AbstractSuffixExpression(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java index 8df3dfb..9fbe9ae 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java @@ -1,18 +1,30 @@ package net.sourceforge.phpdt.internal.compiler.ast; + /** * An abstract variable declaration. * @author Matthieu Casanova */ -public class AbstractVariableDeclaration extends AstNode { +public abstract class AbstractVariableDeclaration extends Expression { /** The name of the variable. */ public char[] name; /** + * Create a node giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + * @param name the name of the variable + */ + public AbstractVariableDeclaration(char[] name, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.name = name; + } + + /** * Get the name of the field as String. * @return the name of the String */ public String name() { - return String.valueOf(name); + return new String(name); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java index 0af97f8..cffc971 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java @@ -1,5 +1,6 @@ package net.sourceforge.phpdt.internal.compiler.ast; + /** * An argument declaration. * @author Matthieu Casanova @@ -7,19 +8,37 @@ package net.sourceforge.phpdt.internal.compiler.ast; public class ArgumentDeclaration extends VariableDeclaration { public boolean reference; + /** * Create an argument. * @param initialization the initialization * @param name the name * @param sourceStart the start point - * @param sourceEnd the end point */ - public ArgumentDeclaration(Expression initialization, - char[] name, + public ArgumentDeclaration(char[] name, + Expression initialization, int sourceStart, - int sourceEnd, boolean reference) { - super(initialization,name, sourceStart, sourceEnd); - this.reference = reference; + super(name, initialization, sourceStart); + this.reference = reference; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff; + if (reference) { + buff = new StringBuffer("&$"); + } else { + buff = new StringBuffer("$"); + } + buff.append(name); + if (initialization != null) { + buff.append(" = "); + buff.append(initialization.toStringExpression()); + } + return buff.toString(); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java new file mode 100644 index 0000000..9b8fd9d --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayDeclarator.java @@ -0,0 +1,32 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ArrayDeclarator extends AbstractSuffixExpression { + + public Expression prefix; + public Expression vars; + + public ArrayDeclarator(Expression prefix, + Expression vars, + int sourceEnd) { + super(prefix.sourceStart, sourceEnd); + this.prefix = prefix; + this.vars = vars; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(prefix.toStringExpression()); + buff.append('['); + if (vars != null) { + buff.append(vars.toStringExpression()); + } + buff.append(']'); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java new file mode 100644 index 0000000..3d9cb87 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayInitializer.java @@ -0,0 +1,34 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ArrayInitializer extends Expression { + + public ArrayVariableDeclaration[] vars; + + public ArrayInitializer(ArrayVariableDeclaration[] vars, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.vars = vars; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer("array("); + for (int i = 0; i < vars.length; i++) { + ArrayVariableDeclaration var = vars[i]; + if (var != null) { + buff.append(var.toStringExpression()); + } + if (i != 0) { + buff.append(','); + } + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java new file mode 100644 index 0000000..b9a0d6b --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java @@ -0,0 +1,31 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * This variable declaration do not extend AbstractVariableDeclaration because + * it could take Expression as key + * @author Matthieu Casanova + */ +public class ArrayVariableDeclaration extends Expression { + + public Expression key,value; + + public ArrayVariableDeclaration(Expression key,Expression value) { + super(key.sourceStart, value.sourceEnd); + this.key = key; + this.value = value; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(); + buff.append(key.toStringExpression()); + if (value != null) { + buff.append(" => "); + buff.append(value.toStringExpression()); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java index e686abf..9eabb41 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java @@ -6,9 +6,20 @@ package net.sourceforge.phpdt.internal.compiler.ast; */ public abstract class AstNode { + /** Starting and ending position of the node in the sources. */ public int sourceStart, sourceEnd; /** + * Create a node giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public AstNode(int sourceStart, int sourceEnd) { + this.sourceStart = sourceStart; + this.sourceEnd = sourceEnd; + } + + /** * Add some tabulations. * @param tab the number of tabulations * @return a String containing some spaces @@ -20,11 +31,19 @@ public abstract class AstNode { return s.toString(); } + /** + * Return the object into String. + * It should be overriden + * @return a String + */ public String toString() { - return toString(0); - } - - public String toString(int tab) { return "****" + super.toString() + "****"; //$NON-NLS-2$ //$NON-NLS-1$ } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public abstract String toString(int tab); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java new file mode 100644 index 0000000..ff93371 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BinaryExpression.java @@ -0,0 +1,25 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class BinaryExpression extends OperatorExpression { + + /** The two expressions. */ + public Expression left,right; + + public BinaryExpression(Expression left, + Expression right, + int operator) { + super(operator, left.sourceStart, right.sourceEnd); + this.left = left; + this.right = right; + } + + public String toStringExpressionNoParenthesis() { + final StringBuffer buff = new StringBuffer(left.toStringExpression()); + buff.append(operatorToString()); + buff.append(right.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java index 6b131d3..7050649 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java @@ -1,5 +1,8 @@ package net.sourceforge.phpdt.internal.compiler.ast; +import net.sourceforge.phpdt.internal.compiler.ast.AstNode; + + /** * A Block is * { @@ -8,14 +11,27 @@ package net.sourceforge.phpdt.internal.compiler.ast; * @author Matthieu Casanova */ public class Block extends Statement { + + /** An array of statements inside the block. */ public Statement[] statements; + /** + * Create a block. + * @param statements the statements + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public Block(Statement[] statements,int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.statements = statements; + } + public boolean isEmptyBlock() { return statements == null; } public String toString(int tab) { - final String s = tabString(tab); + final String s = AstNode.tabString(tab); final StringBuffer buff = new StringBuffer(s); if (this.statements == null) { buff.append("{\n"); //$NON-NLS-1$ diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java new file mode 100644 index 0000000..f38d816 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/BranchStatement.java @@ -0,0 +1,15 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Here is a branchstatement : break or continue + * @author Matthieu Casanova + */ +public abstract class BranchStatement extends Statement { + + public Expression expression; + + public BranchStatement(Expression expression,int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.expression = expression; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java new file mode 100644 index 0000000..e7ef3ee --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Break.java @@ -0,0 +1,20 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A break statement. + * @author Matthieu Casanova + */ +public class Break extends BranchStatement { + + public Break(Expression expression, int sourceStart, int sourceEnd) { + super(expression, sourceStart, sourceEnd); + } + + public String toString(int tab) { + String s = tabString(tab); + if (expression == null) { + return s + "break " + expression.toString();//$NON-NLS-1$ + } + return s + "break";//$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java new file mode 100644 index 0000000..da70a1e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Case.java @@ -0,0 +1,36 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A Case statement for a Switch. + * @author Matthieu Casanova + */ +public class Case extends AbstractCase { + + public Expression value; + public Statement[] statements; + + public Case(Expression value, + Statement[] statements, + int sourceStart, + int sourceEnd) { + super(statements, sourceStart, sourceEnd); + this.value = value; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("case "); + buff.append(value.toStringExpression()); + buff.append(" :\n"); + for (int i = 0; i < statements.length; i++) { + Statement statement = statements[i]; + buff.append(statement.toString(tab + 1)); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java new file mode 100644 index 0000000..ec518ac --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/CastExpression.java @@ -0,0 +1,42 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * This is a cast expression. + * @author Matthieu Casanova + */ +public class CastExpression extends Expression { + + /** The type in which we cast the expression. */ + public ConstantIdentifier type; + + /** The expression to be casted. */ + public Expression expression; + + /** + * Create a cast expression. + * @param type the type + * @param expression the expression + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public CastExpression(ConstantIdentifier type, + Expression expression, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.type = type; + this.expression = expression; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer('('); + buff.append(type.toStringExpression()); + buff.append(") "); + buff.append(expression.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java new file mode 100644 index 0000000..59b2c23 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassAccess.java @@ -0,0 +1,44 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Any class access. + * @author Matthieu Casanova + */ +public class ClassAccess extends AbstractSuffixExpression { + + public static final int STATIC = 0; + public static final int NORMAL = 1; + + public Expression prefix; + public Expression suffix; + public int type; + + public ClassAccess(Expression prefix, + Expression suffix, + int type) { + super(prefix.sourceStart, suffix.sourceEnd); + this.prefix = prefix; + this.suffix = suffix; + this.type = type; + } + + public String toStringOperator() { + switch (type) { + case STATIC : return "::"; //$NON-NLS-1$ + case NORMAL : return "->"; //$NON-NLS-1$ + } + return "unknown operator"; //$NON-NLS-1$ + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(); + buff.append(prefix); + buff.append(toStringOperator()); + buff.append(suffix.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java new file mode 100644 index 0000000..25fc716 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java @@ -0,0 +1,165 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import org.eclipse.jface.resource.ImageDescriptor; + +import java.util.ArrayList; +import java.util.Enumeration; + + +/** + * This class is my ClassDeclaration declaration for php. + * It is similar to org.eclipse.jdt.internal.compiler.ast.TypeDeclaration + * It directly extends AstNode because a class cannot appear anywhere in php + * @author Matthieu Casanova + */ +public class ClassDeclaration extends Statement implements OutlineableWithChildren { + + /** The name of the class. */ + public char[] name; + /** The superclass. */ + public char[] superclass; + + public int declarationSourceStart; + public int declarationSourceEnd; + public int bodyStart; + public int bodyEnd; + /** The methods of the class. */ + private ArrayList methods = new ArrayList(); + /** The constructor of the class. */ + public MethodDeclaration constructor; + /** The fields of the class. */ + private ArrayList fields = new ArrayList(); + + private Object parent; + /** The outlineable children (those will be in the node array too. */ + private ArrayList children = new ArrayList(); + + /** + * Create a class giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public ClassDeclaration(Object parent, + char[] name, + char[] superclass, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.parent = parent; + this.name = name; + this.superclass = superclass; + } + + /** + * Create a class giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public ClassDeclaration(Object parent, + char[] name, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.parent = parent; + this.name = name; + } + + public void addMethod(MethodDeclaration method) { + method.add(method); + children.add(method); + if (method.name.equals(name)) { + constructor = method; + } + } + + public void addVariable(FieldDeclaration var) { + for (int i = 0; i < var.vars.length; i++) { + VariableDeclaration c = var.vars[i]; + children.add(c); + } + fields.add(var); + } + + /** + * Tell if the class has a constructor. + * @return a boolean + */ + public boolean hasConstructor() { + return constructor != null; + } + + /** + * Return the class as String. + * @param tab how many tabs before the class + * @return the code of this class into String + */ + public String toString(int tab) { + return tabString(tab) + toStringHeader() + toStringBody(tab); + } + + /** + * Return the body of the class as String + * @param tab how many tabs before the body of the class + * @return the body as String + */ + public String toStringBody(int tab) { + final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$ + if (fields != null) { + for (int i = 0; i < fields.size(); i++) { + FieldDeclaration field = (FieldDeclaration) fields.get(i); + buff.append("\n"); //$NON-NLS-1$ + buff.append(field.toString(tab + 1)); + buff.append(";");//$NON-NLS-1$ + } + } + if (methods != null) { + for (int i = 0; i < methods.size(); i++) { + MethodDeclaration o = (MethodDeclaration) methods.get(i); + buff.append("\n");//$NON-NLS-1$ + buff.append(o.toString(tab + 1)); + } + } + buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$ + return buff.toString(); + } + + /** + * Return the header of the class as String. + * @return the header of the class + */ + public String toStringHeader() { + final StringBuffer buff = new StringBuffer("class").append(name);//$NON-NLS-1$ + if (superclass != null) { + buff.append(" extends "); //$NON-NLS-1$ + buff.append(superclass); + } + return buff.toString(); + } + + /** + * Get the image of a class. + * @return the image that represents a php class + */ + public ImageDescriptor getImage() { + return PHPUiImages.DESC_CLASS; + } + + public Object getParent() { + return parent; + } + + public boolean add(Outlineable o) { + return children.add(o); + } + + public Outlineable get(int index) { + return (Outlineable) children.get(index); + } + + public int size() { + return children.size(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java new file mode 100644 index 0000000..d85c89c --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConditionalExpression.java @@ -0,0 +1,29 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A ConditionalExpression is like that : booleanExpression ? trueValue : falseValue; + * @author Matthieu Casanova + */ +public class ConditionalExpression extends OperatorExpression { + + public Expression condition, valueIfTrue, valueIfFalse; + + public ConditionalExpression(Expression condition, + Expression valueIfTrue, + Expression valueIfFalse) { + super(-1, condition.sourceStart, valueIfFalse.sourceEnd); + this.condition = condition; + this.valueIfTrue = valueIfTrue; + this.valueIfFalse = valueIfFalse; + } + + public String toStringExpressionNoParenthesis() { + final StringBuffer buff = new StringBuffer("("); + buff.append(condition.toStringExpression()); + buff.append(") ? "); + buff.append(valueIfTrue.toStringExpression()); + buff.append(" : "); + buff.append(valueIfFalse.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java new file mode 100644 index 0000000..dec383e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ConstantIdentifier.java @@ -0,0 +1,24 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ConstantIdentifier extends Expression { + + public char[] name; + + public ConstantIdentifier(char[] name, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.name = name; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + return new String(name); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java new file mode 100644 index 0000000..a1ca200 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Continue.java @@ -0,0 +1,20 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A break statement. + * @author Matthieu Casanova + */ +public class Continue extends BranchStatement { + + public Continue(Expression expression, int sourceStart, int sourceEnd) { + super(expression, sourceStart, sourceEnd); + } + + public String toString(int tab) { + String s = tabString(tab); + if (expression == null) { + return s + "continue " + expression.toString();//$NON-NLS-1$ + } + return s + "continue";//$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractCase.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractCase.java new file mode 100644 index 0000000..e31da6b --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractCase.java @@ -0,0 +1,13 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public abstract class AbstractCase extends Statement { + public Statement[] statements; + + public AbstractCase(Statement[] statements, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.statements = statements; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractPHPComment.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractPHPComment.java new file mode 100644 index 0000000..0d3f2f0 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractPHPComment.java @@ -0,0 +1,17 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Here are php comment. + * @author Matthieu Casanova + */ +public abstract class AbstractPHPComment extends AstNode { + + /** + * Create a comment giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public AbstractPHPComment(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractSuffixExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractSuffixExpression.java new file mode 100644 index 0000000..b429e48 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de AbstractSuffixExpression.java @@ -0,0 +1,14 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Variable suffix. + * class access or [something] + * Should it be an expression ? + * @author Matthieu Casanova + */ +public abstract class AbstractSuffixExpression extends Expression { + + public AbstractSuffixExpression(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayDeclarator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayDeclarator.java new file mode 100644 index 0000000..9b8fd9d --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayDeclarator.java @@ -0,0 +1,32 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ArrayDeclarator extends AbstractSuffixExpression { + + public Expression prefix; + public Expression vars; + + public ArrayDeclarator(Expression prefix, + Expression vars, + int sourceEnd) { + super(prefix.sourceStart, sourceEnd); + this.prefix = prefix; + this.vars = vars; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(prefix.toStringExpression()); + buff.append('['); + if (vars != null) { + buff.append(vars.toStringExpression()); + } + buff.append(']'); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayInitializer.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayInitializer.java new file mode 100644 index 0000000..3d9cb87 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayInitializer.java @@ -0,0 +1,34 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ArrayInitializer extends Expression { + + public ArrayVariableDeclaration[] vars; + + public ArrayInitializer(ArrayVariableDeclaration[] vars, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.vars = vars; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer("array("); + for (int i = 0; i < vars.length; i++) { + ArrayVariableDeclaration var = vars[i]; + if (var != null) { + buff.append(var.toStringExpression()); + } + if (i != 0) { + buff.append(','); + } + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayVariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayVariableDeclaration.java new file mode 100644 index 0000000..b9a0d6b --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de ArrayVariableDeclaration.java @@ -0,0 +1,31 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * This variable declaration do not extend AbstractVariableDeclaration because + * it could take Expression as key + * @author Matthieu Casanova + */ +public class ArrayVariableDeclaration extends Expression { + + public Expression key,value; + + public ArrayVariableDeclaration(Expression key,Expression value) { + super(key.sourceStart, value.sourceEnd); + this.key = key; + this.value = value; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(); + buff.append(key.toStringExpression()); + if (value != null) { + buff.append(" => "); + buff.append(value.toStringExpression()); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de BinaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de BinaryExpression.java new file mode 100644 index 0000000..ff93371 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de BinaryExpression.java @@ -0,0 +1,25 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class BinaryExpression extends OperatorExpression { + + /** The two expressions. */ + public Expression left,right; + + public BinaryExpression(Expression left, + Expression right, + int operator) { + super(operator, left.sourceStart, right.sourceEnd); + this.left = left; + this.right = right; + } + + public String toStringExpressionNoParenthesis() { + final StringBuffer buff = new StringBuffer(left.toStringExpression()); + buff.append(operatorToString()); + buff.append(right.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de BranchStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de BranchStatement.java new file mode 100644 index 0000000..f38d816 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de BranchStatement.java @@ -0,0 +1,15 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * Here is a branchstatement : break or continue + * @author Matthieu Casanova + */ +public abstract class BranchStatement extends Statement { + + public Expression expression; + + public BranchStatement(Expression expression,int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.expression = expression; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de Break.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de Break.java new file mode 100644 index 0000000..e7ef3ee --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de Break.java @@ -0,0 +1,20 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A break statement. + * @author Matthieu Casanova + */ +public class Break extends BranchStatement { + + public Break(Expression expression, int sourceStart, int sourceEnd) { + super(expression, sourceStart, sourceEnd); + } + + public String toString(int tab) { + String s = tabString(tab); + if (expression == null) { + return s + "break " + expression.toString();//$NON-NLS-1$ + } + return s + "break";//$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de Case.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de Case.java new file mode 100644 index 0000000..da70a1e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Copie de Case.java @@ -0,0 +1,36 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A Case statement for a Switch. + * @author Matthieu Casanova + */ +public class Case extends AbstractCase { + + public Expression value; + public Statement[] statements; + + public Case(Expression value, + Statement[] statements, + int sourceStart, + int sourceEnd) { + super(statements, sourceStart, sourceEnd); + this.value = value; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("case "); + buff.append(value.toStringExpression()); + buff.append(" :\n"); + for (int i = 0; i < statements.length; i++) { + Statement statement = statements[i]; + buff.append(statement.toString(tab + 1)); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java new file mode 100644 index 0000000..7d08200 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DefaultCase.java @@ -0,0 +1,26 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class DefaultCase extends AbstractCase { + + public DefaultCase(Statement[] statements, int sourceStart, int sourceEnd) { + super(statements, sourceStart, sourceEnd); + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("default : \n"); //$NON-NLS-1$ + for (int i = 0; i < statements.length; i++) { + Statement statement = statements[i]; + buff.append(statement.toString(tab + 9)); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java new file mode 100644 index 0000000..1a80333 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/DoStatement.java @@ -0,0 +1,40 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class DoStatement extends Statement { + + + /** The condition expression. */ + public Expression condition; + /** The action of the while. (it could be a block) */ + public Statement action; + + public DoStatement(Expression condition, + Statement action, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.condition = condition; + this.action = action; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final String s = tabString(tab); + final StringBuffer buff = new StringBuffer("do "); //$NON-NLS-1$ + if (action == null) { + buff.append(" {} ;"); //$NON-NLS-1$ + } else { + buff.append("\n").append(action.toString(tab + 1)); //$NON-NLS-1$ + } + buff.append(s).append(" while ("); + buff.append(condition.toStringExpression()).append(")"); //$NON-NLS-1$ + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java new file mode 100644 index 0000000..eb18606 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EchoStatement.java @@ -0,0 +1,35 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class EchoStatement extends Statement { + + /** An array of expressions in this echo statement. */ + public Expression[] expressions; + + public EchoStatement (Expression[] expressions, int sourceStart) { + super(sourceStart, expressions[expressions.length].sourceEnd); + this.expressions = expressions; + } + + public String toString() { + StringBuffer buff = new StringBuffer("echo "); + for (int i = 0; i < expressions.length; i++) { + if (i != 0) { + buff.append(", "); + } + buff.append(expressions[i].toString()); + } + return buff.toString(); + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + return tabString(tab) + toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java new file mode 100644 index 0000000..d0e1ea6 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Else.java @@ -0,0 +1,35 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class Else extends Statement { + + public Statement[] statements; + + public Else(Statement[] statements, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.statements = statements; + } + + public Else(Statement statement, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.statements = new Statement[1]; + this.statements[0] = statement; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("else \n"); + for (int i = 0; i < statements.length; i++) { + Statement statement = statements[i]; + buff.append(statement.toString(tab + 1)).append('\n'); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java new file mode 100644 index 0000000..d2fac29 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ElseIf.java @@ -0,0 +1,34 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ElseIf extends Statement { + + public Expression condition; + + public Statement[] statements; + + public ElseIf(Expression condition, Statement[] statements, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.condition = condition; + this.statements = statements; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("elseif ("); + buff.append(condition.toStringExpression()); + buff.append(") \n"); + for (int i = 0; i < statements.length; i++) { + Statement statement = statements[i]; + buff.append(statement.toString(tab+1)).append('\n'); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java new file mode 100644 index 0000000..1bb0236 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/EmptyStatement.java @@ -0,0 +1,16 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * An empty statement + * @author Matthieu Casanova + */ +public class EmptyStatement extends Statement { + + public EmptyStatement(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } + + public String toString(int tab) { + return tabString(tab) + ";"; //$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java index 76fc023..b5b5947 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java @@ -1,26 +1,33 @@ package net.sourceforge.phpdt.internal.compiler.ast; + /** * An expression. * @author Matthieu Casanova */ -public class Expression extends AstNode { +public abstract class Expression extends Statement { - public String toString(int tab) { - String s = tabString(tab); - return s + toStringExpression(tab); + /** + * Create an expression giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public Expression(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); } - //Subclass re-define toStringExpression -//This method is abstract and should never be called -//but we provide some code that is running.....just in case -//of developpement time (while every thing is not built) - public String toStringExpression() { - return super.toString(0); + /** + * Return the expression with a number of spaces before. + * @param tab how many spaces before the expression + * @return a string representing the expression + */ + public String toString(int tab) { + return tabString(tab) + toStringExpression(); } - public String toStringExpression(int tab) { - // default is regular toString expression (qualified allocation expressions redifine this method) - return this.toStringExpression(); - } + /** + * Return the expression as String. + * @return the expression + */ + public abstract String toStringExpression(); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java new file mode 100644 index 0000000..8d63fb8 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FalseLiteral.java @@ -0,0 +1,29 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class FalseLiteral extends MagicLiteral { + + public static final char[] source = {'f', 'a', 'l', 's', 'e'}; + + public FalseLiteral(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + return "false"; + } + + public char[] source() { + return source; + } + + public String toString() { + return "false";//$NON-NLS-1$ + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java new file mode 100644 index 0000000..dae26ff --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java @@ -0,0 +1,32 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import org.eclipse.jface.resource.ImageDescriptor; + +/** + * @author Matthieu Casanova + */ +public class FieldDeclaration extends Statement { + + public VariableDeclaration[] vars; + + public FieldDeclaration(VariableDeclaration[] vars,int sourceStart,int sourceEnd) { + super(sourceStart,sourceEnd); + this.vars = vars; + } + + + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("var "); + for (int i = 0; i < vars.length; i++) { + VariableDeclaration var = vars[i]; + if (i != 0) { + buff.append(','); + } + buff.append(var.toStringExpression()); + } + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java new file mode 100644 index 0000000..8a16b5e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java @@ -0,0 +1,61 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ForStatement extends Statement { + + public Statement[] initializations; + public Expression condition; + public Statement[] increments; + public Statement action; + + public ForStatement(Statement[] initializations, + Expression condition, + Statement[] increments, + Statement action, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.initializations = initializations; + this.condition = condition; + this.increments = increments; + this.action = action; + } + + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("for ("); //$NON-NLS-1$ + //inits + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + //nice only with expressions + buff.append(initializations[i].toString()); + if (i != (initializations.length - 1)) + buff.append(" , "); //$NON-NLS-1$ + } + } + buff.append( "; "); //$NON-NLS-1$ + //cond + if (condition != null) { + buff.append(condition.toStringExpression()); + } + buff.append( "; "); //$NON-NLS-1$ + //updates + if (increments != null) { + for (int i = 0; i < increments.length; i++) { + //nice only with expressions + buff.append(increments[i].toString()); + if (i != (increments.length - 1)) + buff.append(" , "); //$NON-NLS-1$ + } + } + buff.append(") "); //$NON-NLS-1$ + //block + if (action == null) + buff.append("{}"); //$NON-NLS-1$ + else + buff.append( "\n").append(action.toString(tab + 1)); //$NON-NLS-1$ + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java new file mode 100644 index 0000000..be4229a --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForeachStatement.java @@ -0,0 +1,39 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ForeachStatement extends Statement { + + public Expression expression; + public Expression variable; + public Statement statement; + + public ForeachStatement(Expression expression, + Expression variable, + Statement statement, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.expression = expression; + this.variable = variable; + this.statement = statement; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("foreach ("); + buff.append(expression.toStringExpression()); + buff.append(" as "); + buff.append(variable.toStringExpression()); + buff.append(" {\n"); + buff.append(statement.toString(tab+1)); + buff.append("\n}"); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java new file mode 100644 index 0000000..4aee466 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/FunctionCall.java @@ -0,0 +1,36 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class FunctionCall extends AbstractSuffixExpression { + + public Expression prefix; + public ArgumentDeclaration[] args; + + public FunctionCall(Expression prefix, + ArgumentDeclaration[] args, + int sourceEnd) { + super(prefix.sourceStart, sourceEnd); + this.prefix = prefix; + this.args = args; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(prefix.toStringExpression()); + buff.append('('); + for (int i = 0; i < args.length; i++) { + ArgumentDeclaration arg = args[i]; + if (i != 0) { + buff.append(','); + } + buff.append(arg); + } + buff.append(')'); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java new file mode 100644 index 0000000..8d17144 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/GlobalStatement.java @@ -0,0 +1,50 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import org.eclipse.jface.resource.ImageDescriptor; + +/** + * A GlobalStatement statement in php. + * @author Matthieu Casanova + */ +public class GlobalStatement extends Statement implements Outlineable { + + /** An array of the variables called by this global statement. */ + public String[] variables; + + private Object parent; + + public GlobalStatement(Object parent, String[] variables, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.variables = variables; + this.parent = parent; + } + + public String toString() { + StringBuffer buff = new StringBuffer("global "); + for (int i = 0; i < variables.length; i++) { + if (i != 0) { + buff.append(", "); + } + buff.append(variables[i]); + } + return buff.toString(); + } + + public String toString(int tab) { + return tabString(tab) + toString(); + } + + /** + * This will return the image for the outline of the object. + * @return an image + */ + public ImageDescriptor getImage() { + return PHPUiImages.DESC_INC; + } + + public Object getParent() { + return parent; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java new file mode 100644 index 0000000..4dae9eb --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/HTMLBlock.java @@ -0,0 +1,30 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class HTMLBlock extends Statement { + + public AstNode[] nodes; + + public HTMLBlock(AstNode[] nodes) { + super(nodes[0].sourceStart, nodes[nodes.length-1].sourceEnd); + this.nodes = nodes; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("?>"); + for (int i = 0; i < nodes.length; i++) { + AstNode node = nodes[i]; + buff.append(node.toString(tab +1)); + } + buff.append("="; //$NON-NLS-1$ + case NOT_EQUAL : + return "!="; //$NON-NLS-1$ + case LEFT_SHIFT : + return "<<"; //$NON-NLS-1$ + case RIGHT_SHIFT : + return ">>"; //$NON-NLS-1$ + case UNSIGNED_RIGHT_SHIFT : + return ">>>"; //$NON-NLS-1$ + case OR_OR : + return "||"; //$NON-NLS-1$ + case AND_AND : + return "&&"; //$NON-NLS-1$ + case PLUS : + return "+"; //$NON-NLS-1$ + case MINUS : + return "-"; //$NON-NLS-1$ + case NOT : + return "!"; //$NON-NLS-1$ + case REMAINDER : + return "%"; //$NON-NLS-1$ + case XOR : + return "^"; //$NON-NLS-1$ + case AND : + return "&"; //$NON-NLS-1$ + case MULTIPLY : + return "*"; //$NON-NLS-1$ + case OR : + return "|"; //$NON-NLS-1$ + case TWIDDLE : + return "~"; //$NON-NLS-1$ + case DIVIDE : + return "/"; //$NON-NLS-1$ + case GREATER : + return ">"; //$NON-NLS-1$ + case LESS : + return "<"; //$NON-NLS-1$ + case ORL : + return "OR"; //$NON-NLS-1$ + case ANDL : + return "AND"; //$NON-NLS-1$ + case DOT : + return "."; //$NON-NLS-1$ + case DIF : + return "<>"; //$NON-NLS-1$ + case BANG_EQUAL_EQUAL : + return "!=="; //$NON-NLS-1$ + case EQUAL_EQUAL_EQUAL : + return "==="; //$NON-NLS-1$ + case AT : + return "@"; //$NON-NLS-1$ + }; + return "unknown operator"; //$NON-NLS-1$ + } + + public String toStringExpression(){ + //subclass redefine toStringExpressionNoParenthesis() + return "(" + toStringExpressionNoParenthesis() + ")"; //$NON-NLS-2$ //$NON-NLS-1$ + } + + public abstract String toStringExpressionNoParenthesis(); +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java new file mode 100644 index 0000000..59d1694 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/OperatorIds.java @@ -0,0 +1,41 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * The operators used in php. + * Copied from org.eclipse.jdt.internal.compiler.ast.OperatorIds + * @author Matthieu Casanova + */ +public interface OperatorIds { + static final int AND_AND = 0; // "&&" + static final int OR_OR = 1; // "||" + static final int AND = 2; // "&" + static final int OR = 3; // "|" + static final int LESS = 4; // "<" + static final int LESS_EQUAL = 5; // "<=" + static final int GREATER = 6; // ">" + static final int GREATER_EQUAL = 7; // ">=" + static final int XOR = 8; // "^" + static final int DIVIDE = 9; // "/" + static final int LEFT_SHIFT = 10; // "<<" + static final int NOT = 11; // "!" + static final int TWIDDLE = 12; // "~" + static final int MINUS = 13; // "-" + static final int PLUS = 14; // "+" + static final int MULTIPLY = 15; // "*" + static final int REMAINDER = 16; // "%" + static final int RIGHT_SHIFT = 17; // ">>" + static final int EQUAL_EQUAL = 18; // "==" + static final int UNSIGNED_RIGHT_SHIFT= 19; // ">>>" + static final int ORL = 20; // "OR" + static final int ANDL = 21; // "AND" + static final int DOT = 22; // "." + static final int DIF = 23; // "<>" + static final int BANG_EQUAL_EQUAL = 24; // "!==" + static final int EQUAL_EQUAL_EQUAL = 25; // "===" + static final int AT = 26; // "@" + + static final int NOT_EQUAL = 29; // "!=" + static final int PLUS_PLUS = 32; // "++" + static final int MINUS_MINUS = 33; // "--" + static final int NEW = 34; // "new " +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java new file mode 100644 index 0000000..c01d085 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java @@ -0,0 +1,91 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import org.eclipse.jface.resource.ImageDescriptor; + +import java.util.ArrayList; + +/** + * It's a php document. + * It will contains html and php + * @author Matthieu Casanova + */ +public class PHPDocument implements OutlineableWithChildren { + + /** + * The nodes. + * It will include html nodes or php nodes + */ + public AstNode[] nodes; + + /** The parent of the object */ + public Object parent; + + /** The outlineable children (those will be in the node array too. */ + private ArrayList children = new ArrayList(); + + /** + * Create the PHPDocument. + */ + public PHPDocument(Object parent) { + this.parent = parent; + } + + /** + * Return the php document as String. + * @return a string representation of the object. + */ + public String toString() { + final StringBuffer buff = new StringBuffer(); + AstNode node; + int i; + for (i = 0; i < nodes.length; i++) { + node = nodes[i]; + if (node == null) { + break; + } + buff.append(node); + } + return buff.toString(); + } + + /** + * Add an outlineable object. + * @param o the new outlineable + * @return does the addition worked ? + */ + public boolean add(Outlineable o) { + return children.add(o); + } + + /** + * Return the outlineable at the index. + * @param index the index + * @return an outlineable object + */ + public Outlineable get(int index) { + return (Outlineable) children.get(index); + } + + /** + * The number of outlineable children + * @return + */ + public int size() { + return children.size(); + } + + /** + * This will return the image for the outline of the object. + * @return an image + */ + public ImageDescriptor getImage() { + return PHPUiImages.DESC_CLASS; + } + + public Object getParent() { + return parent; + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java new file mode 100644 index 0000000..80da2cf --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPEchoBlock.java @@ -0,0 +1,27 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class PHPEchoBlock extends AstNode { + + public Expression expr; + + public PHPEchoBlock(Expression expr,int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.expr = expr; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append(""); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java new file mode 100644 index 0000000..c58ea67 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PostfixedUnaryExpression.java @@ -0,0 +1,17 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class PostfixedUnaryExpression extends UnaryExpression { + + public PostfixedUnaryExpression(Expression expression, int operator, int sourceEnd) { + super(expression, operator, expression.sourceStart, sourceEnd); + } + + public String toStringExpressionNoParenthesis() { + StringBuffer buff = new StringBuffer(expression.toStringExpression()); + buff.append(operatorToString()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java new file mode 100644 index 0000000..67dbaee --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrefixedUnaryExpression.java @@ -0,0 +1,17 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class PrefixedUnaryExpression extends UnaryExpression { + + public PrefixedUnaryExpression(Expression expression, int operator, int sourceStart) { + super(expression, operator, sourceStart, expression.sourceEnd); + } + + public String toStringExpressionNoParenthesis() { + StringBuffer buff = new StringBuffer(operatorToString()); + buff.append(expression.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java new file mode 100644 index 0000000..5f6f43e --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PrintExpression.java @@ -0,0 +1,22 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class PrintExpression extends Expression { + + public Expression expression; + + public PrintExpression(Expression expression, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.expression = expression; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + return "print " + expression.toStringExpression(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java new file mode 100644 index 0000000..ea695e4 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ReturnStatement.java @@ -0,0 +1,22 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class ReturnStatement extends Statement { + + public Expression expression; + + public ReturnStatement(Expression expression, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.expression = expression; + } + + public String toString(int tab) { + final String s = tabString(tab); + if (expression == null) { + return s + "return " + expression.toStringExpression(); + } + return s + "return"; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java index c16f91f..a6afa57 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java @@ -1,12 +1,19 @@ package net.sourceforge.phpdt.internal.compiler.ast; + /** * A Statement. * @author Matthieu Casanova */ -public class Statement extends AstNode { +public abstract class Statement extends AstNode { - public Statement() { + /** + * Create a node giving starting and ending offset + * @param sourceStart starting offset + * @param sourceEnd ending offset + */ + public Statement(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); } public boolean isEmptyBlock() { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java new file mode 100644 index 0000000..b600511 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StaticStatement.java @@ -0,0 +1,31 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A GlobalStatement statement in php. + * @author Matthieu Casanova + */ +public class StaticStatement extends Statement { + + /** An array of the variables called by this global statement. */ + public String[] variables; + + public StaticStatement(String[] variables, int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + this.variables = variables; + } + + public String toString() { + StringBuffer buff = new StringBuffer("static "); + for (int i = 0; i < variables.length; i++) { + if (i != 0) { + buff.append(", "); + } + buff.append(variables[i]); + } + return buff.toString(); + } + + public String toString(int tab) { + return tabString(tab) + toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java index f20decb..ec39d6e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java @@ -16,18 +16,16 @@ package net.sourceforge.phpdt.internal.compiler.ast; //import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope; //import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding; -public class StringLiteral { +public class StringLiteral extends Literal { char[] source; - public int sourceStart, sourceEnd; - + public StringLiteral(char[] token, int s, int e) { + super(s,e); source = token; - sourceStart = s; - sourceEnd = e; } + public StringLiteral(int s, int e) { - sourceStart = s; - sourceEnd = e; + super(s,e); } /** @@ -36,8 +34,12 @@ public class StringLiteral { public char[] source() { return source; } - public String toStringExpression() { + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { // handle some special char..... StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$ for (int i = 0; i < source.length; i++) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java new file mode 100644 index 0000000..c13a386 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/SwitchStatement.java @@ -0,0 +1,36 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class SwitchStatement extends Statement { + + public Expression variable; + public AbstractCase[] cases; + + public SwitchStatement(Expression variable, + AbstractCase[] cases, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.variable = variable; + this.cases = cases; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final StringBuffer buff = new StringBuffer(tabString(tab)); + buff.append("switch (").append(variable.toStringExpression()).append(") {\n"); + for (int i = 0; i < cases.length; i++) { + AbstractCase cas = cases[i]; + buff.append(cas.toString(tab +1)); + buff.append('\n'); + } + buff.append('}'); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java new file mode 100644 index 0000000..adb4b09 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/TrueLiteral.java @@ -0,0 +1,25 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class TrueLiteral extends MagicLiteral { + + public static final char[] source = {'t', 'r', 'u', 'e'}; + + public TrueLiteral(int sourceStart, int sourceEnd) { + super(sourceStart, sourceEnd); + } + + public char[] source() { + return source; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + return "true";//$NON-NLS-1$ + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java new file mode 100644 index 0000000..7ca2b35 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Types.java @@ -0,0 +1,19 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public interface Types { + + static final char[] STRING = {'s', 't', 'r', 'i', 'n', 'g'}; + static final char[] BOOL = {'b', 'o', 'o', 'l'}; + static final char[] BOOLEAN = {'b', 'o', 'o', 'l', 'e', 'a', 'n'}; + static final char[] REAL = {'r', 'e', 'a', 'l'}; + static final char[] DOUBLE = {'d', 'o', 'u', 'b', 'l', 'e'}; + static final char[] FLOAT = {'f', 'l', 'o', 'a', 't'}; + static final char[] INT = {'i', 'n', 't'}; + static final char[] INTEGER = {'i', 'n', 't', 'e', 'g', 'e', 'r'}; + static final char[] OBJECT = {'o', 'b', 'j', 'e', 'c', 't'}; + static final char[] ARRAY = {'a', 'r', 'r', 'a', 'y'}; + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java new file mode 100644 index 0000000..fff7021 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/UnaryExpression.java @@ -0,0 +1,14 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public abstract class UnaryExpression extends OperatorExpression { + + public Expression expression; + + public UnaryExpression(Expression expression, int operator, int sourceStart, int sourceEnd) { + super(operator, sourceStart, sourceEnd); + this.expression = expression; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java new file mode 100644 index 0000000..cd32d4b --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VarAssignation.java @@ -0,0 +1,83 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * @author Matthieu Casanova + */ +public class VarAssignation extends Expression { + + public static final int EQUAL = 0; + public static final int PLUS_EQUAL = 1; + public static final int MINUS_EQUAL = 2; + public static final int STAR_EQUAL = 3; + public static final int SLASH_EQUAL = 4; + public static final int AND_EQUAL = 5; + public static final int OR_EQUAL = 6; + public static final int XOR_EQUAL = 7; + public static final int DOT_EQUAL = 8; + public static final int REM_EQUAL = 9; + public static final int TILDE_EQUAL = 10; + public static final int LSHIFT_EQUAL = 11; + public static final int RSIGNEDSHIFT_EQUAL = 12; + + public char[] variable; + public Expression expression; + public int operator; + + + public VarAssignation(char[] variable, + Expression expression, + int operator, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.variable = variable; + this.expression = expression; + this.operator = operator; + } + + public String operatorToString() { + switch (operator) { + case EQUAL: + return "="; //$NON-NLS-1$ + case PLUS_EQUAL: + return "+="; //$NON-NLS-1$ + case MINUS_EQUAL: + return "-="; //$NON-NLS-1$ + case STAR_EQUAL: + return "*="; //$NON-NLS-1$ + case SLASH_EQUAL: + return "/="; //$NON-NLS-1$ + case AND_EQUAL: + return "<="; //$NON-NLS-1$ + case OR_EQUAL: + return "|=";//$NON-NLS-1$ + case XOR_EQUAL: + return "^=";//$NON-NLS-1$ + case DOT_EQUAL: + return ".="; //$NON-NLS-1$ + case REM_EQUAL: + return "%="; //$NON-NLS-1$ + case TILDE_EQUAL: + return " ="; //$NON-NLS-1$ + case LSHIFT_EQUAL: + return "<<="; //$NON-NLS-1$ + case RSIGNEDSHIFT_EQUAL: + return ">>="; //$NON-NLS-1$ + } + return " unknown operator "; + } + + /** + * Return the expression as String. + * @return the expression + */ + public String toStringExpression() { + final StringBuffer buff = new StringBuffer(); + buff.append(variable); + buff.append(' '); + buff.append(operatorToString()); + buff.append(' '); + buff.append(expression.toStringExpression()); + return buff.toString(); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java index bbbf44c..4ba1ba5 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java @@ -1,39 +1,82 @@ package net.sourceforge.phpdt.internal.compiler.ast; +import net.sourceforge.phpdt.internal.compiler.ast.Expression; +import net.sourceforge.phpdt.internal.compiler.ast.AbstractVariableDeclaration; +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import org.eclipse.jface.resource.ImageDescriptor; + /** * A variable declaration. * @author Matthieu Casanova */ -public class VariableDeclaration extends AbstractVariableDeclaration { +public class VariableDeclaration extends AbstractVariableDeclaration implements Outlineable { /** The value for variable initialization. */ public Expression initialization; + private Object parent; + private boolean reference; + /** * Create a variable. * @param initialization the initialization - * @param name the name + * @param name the name of the variable * @param sourceStart the start point - * @param sourceEnd the end point */ - public VariableDeclaration(Expression initialization, + public VariableDeclaration(Object parent, char[] name, - int sourceStart, - int sourceEnd) { + Expression initialization, + int sourceStart) { + super(name, sourceStart, initialization.sourceEnd); this.initialization = initialization; - this.name = name; - //due to some declaration like - // int x, y = 3, z , x ; - //the sourceStart and the sourceEnd is ONLY on the name - this.sourceStart = sourceStart; - this.sourceEnd = sourceEnd; + this.parent = parent; } - public String toString(int tab) { - String s = tabString(tab); + public void setReference(boolean reference) { + this.reference = reference; + } + + /** + * Create a variable. + * @param initialization the initialization + * @param name the name of the variable + * @param sourceStart the start point + */ + public VariableDeclaration(char[] name, + Expression initialization, + int sourceStart) { + super(name, sourceStart, initialization.sourceEnd); + this.initialization = initialization; + } + /** + * Return the variable into String. + * @return a String + */ + public String toStringExpression() { + final StringBuffer buff; + if (reference) { + buff = new StringBuffer('&'); + } else { + buff = new StringBuffer(); + } + buff.append(name); if (initialization != null) { - s += " = " + initialization.toStringExpression(tab); //$NON-NLS-1$ + buff.append(" = "); //$NON-NLS-1$ + buff.append(initialization.toStringExpression()); } - return s; + return buff.toString(); } + + public Object getParent() { + return parent; + } + + /** + * Get the image of a variable. + * @return the image that represents a php variable + */ + public ImageDescriptor getImage() { + return PHPUiImages.DESC_VAR; + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java new file mode 100644 index 0000000..01e956d --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/WhileStatement.java @@ -0,0 +1,46 @@ +package net.sourceforge.phpdt.internal.compiler.ast; + +/** + * A While statement. + * @author Matthieu Casanova + */ +public class WhileStatement extends Statement { + + /** The condition expression. */ + public Expression condition; + /** The action of the while. (it could be a block) */ + public Statement action; + + /** + * Create a While statement. + * @param condition the condition + * @param action the action + * @param sourceStart the starting offset + * @param sourceEnd the ending offset + */ + public WhileStatement(Expression condition, + Statement action, + int sourceStart, + int sourceEnd) { + super(sourceStart, sourceEnd); + this.condition = condition; + this.action = action; + } + + /** + * Return the object into String. + * @param tab how many tabs (not used here + * @return a String + */ + public String toString(int tab) { + final String s = tabString(tab); + final StringBuffer buff = new StringBuffer("while ("); //$NON-NLS-1$ + buff.append(condition.toStringExpression()).append(")"); //$NON-NLS-1$ + if (action == null) { + buff.append(" {} ;"); //$NON-NLS-1$ + } else { + buff.append("\n").append(action.toString(tab + 1)); //$NON-NLS-1$ + } + return buff.toString(); + } +}