First try, not finished
authorkpouer <kpouer>
Thu, 10 Apr 2003 20:41:49 +0000 (20:41 +0000)
committerkpouer <kpouer>
Thu, 10 Apr 2003 20:41:49 +0000 (20:41 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AbstractVariableDeclaration.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ArgumentDeclaration.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/AstNode.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Class.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Expression.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Statement.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java [new file with mode: 0644]

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
new file mode 100644 (file)
index 0000000..8df3dfb
--- /dev/null
@@ -0,0 +1,18 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * An abstract variable declaration.
+ * @author Matthieu Casanova
+ */
+public class AbstractVariableDeclaration extends AstNode {
+  /** The name of the variable. */
+  public char[] name;
+
+  /**
+   * Get the name of the field as String.
+   * @return the name of the String
+   */
+  public String name() {
+    return String.valueOf(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
new file mode 100644 (file)
index 0000000..0af97f8
--- /dev/null
@@ -0,0 +1,25 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * An argument declaration.
+ * @author Matthieu Casanova
+ */
+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,
+                             int sourceStart,
+                             int sourceEnd,
+                             boolean reference) {
+      super(initialization,name, sourceStart, sourceEnd);
+      this.reference = reference;
+  }
+}
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
new file mode 100644 (file)
index 0000000..e686abf
--- /dev/null
@@ -0,0 +1,30 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * It will be the mother of our own ast tree for php just like the ast tree of Eclipse.
+ * @author Matthieu Casanova
+ */
+public abstract class AstNode {
+
+  public int sourceStart, sourceEnd;
+
+  /**
+   * Add some tabulations.
+   * @param tab the number of tabulations
+   * @return a String containing some spaces
+   */
+  public static String tabString(int tab) {
+    StringBuffer s = new StringBuffer();
+    for (int i = tab; i > 0; i--)
+      s.append("  "); //$NON-NLS-1$
+    return s.toString();
+  }
+
+  public String toString() {
+    return toString(0);
+  }
+
+  public String toString(int tab) {
+    return "****" + super.toString() + "****";  //$NON-NLS-2$ //$NON-NLS-1$
+  }
+}
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
new file mode 100644 (file)
index 0000000..6b131d3
--- /dev/null
@@ -0,0 +1,47 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Block is
+ * {
+ * statements
+ * }.
+ * @author Matthieu Casanova
+ */
+public class Block extends Statement {
+  public Statement[] statements;
+
+  public boolean isEmptyBlock() {
+    return statements == null;
+  }
+
+  public String toString(int tab) {
+    final String s = tabString(tab);
+    final StringBuffer buff = new StringBuffer(s);
+    if (this.statements == null) {
+      buff.append("{\n"); //$NON-NLS-1$
+      buff.append(s);
+      buff.append("}"); //$NON-NLS-1$
+      return s;
+    }
+    buff.append("{\n"); //$NON-NLS-1$
+    buff.append(this.toStringStatements(tab));
+    buff.append(s);
+    buff.append("}"); //$NON-NLS-1$
+    return s;
+  }
+
+  public String toStringStatements(int tab) {
+    if (this.statements == null)
+      return ""; //$NON-NLS-1$
+    StringBuffer buffer = new StringBuffer();
+    for (int i = 0; i < statements.length; i++) {
+      buffer.append(statements[i].toString(tab + 1));
+      if (statements[i] instanceof Block) {
+        buffer.append("\n"); //$NON-NLS-1$
+      } else {
+        buffer.append(";\n"); //$NON-NLS-1$
+      }
+    }
+    return buffer.toString();
+  }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Class.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Class.java
new file mode 100644 (file)
index 0000000..cad94c9
--- /dev/null
@@ -0,0 +1,71 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * This class is my Class 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 Class extends AstNode {
+
+  /** The name of the class. */
+  public char[] name;
+  /** The superclass. */
+  public char[] superclass;
+  /** The fields of the class. */
+  public VariableDeclaration[] fields;
+
+  public int declarationSourceStart;
+       public int declarationSourceEnd;
+       public int bodyStart;
+       public int bodyEnd;
+
+  public MethodDeclaration[] methods;
+
+  public MethodDeclaration constructor;
+
+  /**
+   * Tell if the class has a constructor.
+   * @return a boolean
+   */
+  public boolean hasConstructor() {
+    return constructor != null;
+  }
+
+       public String toString(int tab) {
+
+               return tabString(tab) + toStringHeader() + toStringBody(tab);
+       }
+
+       public String toStringBody(int tab) {
+    final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
+               if (fields != null) {
+                       for (int fieldI = 0; fieldI < fields.length; fieldI++) {
+                               if (fields[fieldI] != null) {
+                                       buff.append("\n"); //$NON-NLS-1$
+          buff.append(fields[fieldI].toString(tab + 1));
+          buff.append(";");//$NON-NLS-1$
+                               }
+                       }
+               }
+               if (methods != null) {
+                       for (int i = 0; i < methods.length; i++) {
+                               if (methods[i] != null) {
+                                       buff.append("\n");//$NON-NLS-1$
+          buff.append(methods[i].toString(tab + 1));
+                               }
+                       }
+               }
+               buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
+               return buff.toString();
+       }
+
+       public String toStringHeader() {
+    final StringBuffer buff = new StringBuffer("class").append(name);
+               if (superclass != null) {
+                       buff.append(" extends "); //$NON-NLS-1$
+      buff.append(superclass);
+    }
+               return buff.toString();
+       }
+}
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
new file mode 100644 (file)
index 0000000..76fc023
--- /dev/null
@@ -0,0 +1,26 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * An expression.
+ * @author Matthieu Casanova
+ */
+public class Expression extends AstNode {
+
+  public String toString(int tab) {
+    String s = tabString(tab);
+    return s + toStringExpression(tab);
+  }
+
+  //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);
+  }
+
+  public String toStringExpression(int tab) {
+    // default is regular toString expression (qualified allocation expressions redifine this method)
+    return this.toStringExpression();
+  }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java
new file mode 100644 (file)
index 0000000..9f5bfa0
--- /dev/null
@@ -0,0 +1,58 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Method declaration.
+ * @author Matthieu Casanova
+ */
+public class MethodDeclaration extends Statement {
+
+  public char[] name;
+  public ArgumentDeclaration[] arguments;
+  public Statement[] statements;
+  public int bodyStart;
+  public int bodyEnd = -1;
+  public boolean isConstructor;
+
+  /**
+   * Return method into String, with a number of tabs
+   * @param tab the number of tabs
+   * @return the String containing the method
+   */
+  public String toString(int tab) {
+    String s = tabString(tab);
+    StringBuffer buff = new StringBuffer(s);
+    buff.append(name).append("(");//$NON-NLS-1$
+
+    if (arguments != null) {
+      for (int i = 0; i < arguments.length; i++) {
+        buff.append(arguments[i].toString(0));
+        if (i != (arguments.length - 1)) {
+          buff.append(", "); //$NON-NLS-1$
+        }
+      }
+    }
+    buff.append(")"); //$NON-NLS-1$
+
+    s += toStringStatements(tab + 1);
+    return s;
+  }
+
+  /**
+   * Return the statements of the method into Strings
+   * @param tab the number of tabs
+   * @return the String containing the statements
+   */
+  public String toStringStatements(int tab) {
+    StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
+    if (statements != null) {
+      for (int i = 0; i < statements.length; i++) {
+        buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
+        if (!(statements[i] instanceof Block)) {
+          buff.append(";"); //$NON-NLS-1$
+        }
+      }
+    }
+    buff.append("\n").append(tabString(tab == 0 ? 0 : tab - 1)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
+    return buff.toString();
+  }
+}
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
new file mode 100644 (file)
index 0000000..c16f91f
--- /dev/null
@@ -0,0 +1,15 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Statement.
+ * @author Matthieu Casanova
+ */
+public class Statement extends AstNode {
+
+  public Statement() {
+  }
+
+  public boolean isEmptyBlock() {
+    return false;
+  }
+}
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
new file mode 100644 (file)
index 0000000..bbbf44c
--- /dev/null
@@ -0,0 +1,39 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A variable declaration.
+ * @author Matthieu Casanova
+ */
+public class VariableDeclaration extends AbstractVariableDeclaration {
+
+  /** The value for variable initialization. */
+  public Expression initialization;
+
+  /**
+   * Create a variable.
+   * @param initialization the initialization
+   * @param name the name
+   * @param sourceStart the start point
+   * @param sourceEnd the end point
+   */
+  public VariableDeclaration(Expression initialization,
+                             char[] name,
+                             int sourceStart,
+                             int 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;
+  }
+
+  public String toString(int tab) {
+    String s = tabString(tab);
+    if (initialization != null) {
+      s += " = " + initialization.toStringExpression(tab); //$NON-NLS-1$
+    }
+    return s;
+  }
+}