Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6195/F:/nice/src/bossa/syntax
Modified Files:
AST.java Definition.java dispatch.java.bootstrap enum.nice
globalvar.nice tools.nice
Added Files:
ast.nice
Log Message:
Converted AST.
Index: Definition.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Definition.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** Definition.java 25 Nov 2004 19:28:18 -0000 1.25
--- Definition.java 26 Nov 2004 20:26:02 -0000 1.26
***************
*** 78,96 ****
}
- boolean isGlobalVarDeclaration()
- {
- return false;
- }
-
- boolean isEnumDefinition()
- {
- return false;
- }
-
- TypeDefinition getEnumClass()
- {
- return null;
- }
-
/****************************************************************
* Name and location of the definition
--- 78,81 ----
Index: AST.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/AST.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -d -r1.61 -r1.62
*** AST.java 25 Nov 2004 19:28:17 -0000 1.61
--- AST.java 26 Nov 2004 20:26:01 -0000 1.62
***************
*** 2,6 ****
/* N I C E */
/* A high-level object-oriented research language */
! /* (c) Daniel Bonniot 2000 */
/* */
/* This program is free software; you can redistribute it and/or modify */
--- 2,6 ----
/* N I C E */
/* A high-level object-oriented research language */
! /* (c) Daniel Bonniot 2004 */
/* */
/* This program is free software; you can redistribute it and/or modify */
***************
*** 21,39 ****
@see Definition
-
- @version $Date$
- @author Daniel Bonniot (d.bonniot@xxxxxxxxxxxxxx)
*/
! public class AST extends Node
{
! public AST(Module module, List defs)
{
! super(defs,Node.global);
! if (children == null)
! children = new LinkedList();
!
! this.module = module;
!
! findElements();
}
--- 21,30 ----
@see Definition
*/
! public abstract class AST extends Node
{
! AST(List children, int propagate)
{
! super(children, propagate);
}
***************
*** 43,193 ****
}
! private void findElements()
! {
! ArrayList classes = new ArrayList(children.size());
! ArrayList methods = new ArrayList(children.size());
! ArrayList globals = new ArrayList(10);
! ArrayList customConstructors = new ArrayList(10);
! ArrayList methodImplementations = new ArrayList(10);
!
! for(Iterator i = children.iterator(); i.hasNext();)
! {
! Definition node = (Definition)i.next();
! if (node instanceof TypeDefinition)
! classes.add(node);
! else if (node instanceof CustomConstructor)
! {
! customConstructors.add(node);
! methods.add(node);
! }
! else if (node instanceof MethodDeclaration)
! methods.add(node);
! else if (node instanceof MethodBodyDefinition)
! methodImplementations.add(node);
! else if (node.isEnumDefinition())
! classes.add(node.getEnumClass());
! else if (node.isGlobalVarDeclaration())
! globals.add(node);
! else if (node instanceof DefaultMethodImplementation)
! methods.add(((DefaultMethodImplementation) node).getDeclaration());
! }
!
! this.classes = (TypeDefinition[])
! classes.toArray(new TypeDefinition[classes.size()]);
!
! this.methods = (MethodDeclaration[])
! methods.toArray(new MethodDeclaration[methods.size()]);
!
! this.globals = (Definition[])
! globals.toArray(new Definition[globals.size()]);
!
! this.customConstructors = (CustomConstructor[])
! customConstructors.toArray(new
CustomConstructor[customConstructors.size()]);
!
! this.methodImplementations = (MethodBodyDefinition[])
! methodImplementations.toArray(new
MethodBodyDefinition[methodImplementations.size()]);
! }
!
! public void buildScope()
! {
! buildScope(module);
! }
!
! private void resolve(Node n)
! {
! try{
! n.doResolve();
! }
! catch(UserError ex){
! module.compilation().error(ex);
! }
! }
!
! public void resolveScoping()
! {
! Node.setModule(module);
!
! // Resolve custom constructors early, classes depend on them
! for(int i = 0; i < customConstructors.length; i++)
! resolve(customConstructors[i]);
!
! // Classes are then resolved, since code can depend on them
! for(int i = 0; i < classes.length; i++)
! resolve(classes[i]);
!
! // Resolve all the rest
! for(Iterator i = children.iterator();i.hasNext();)
! {
! Node n = (Node) i.next();
! resolve(n);
! }
!
! module.compilation().exitIfErrors();
! }
!
! public void typedResolve()
! {
! Node.setModule(module);
!
! for (int i = 0; i < methods.length; i++)
! try{
! methods[i].typedResolve();
! }
! catch(UserError ex){
! module.compilation().error(ex);
! }
!
! for (int i = 0; i < methodImplementations.length; i++)
! try{
! methodImplementations[i].lateBuildScope();
! }
! catch(UserError ex){
! module.compilation().error(ex);
! }
!
! module.compilation().exitIfErrors();
! }
!
! public void localResolve()
! {
! Node.setModule(module);
!
! for (Iterator i = children.iterator(); i.hasNext();)
! {
! Definition d = (Definition) i.next();
! try{
! d.resolveBody();
! }
! catch(UserError ex){
! module.compilation().error(ex);
! }
! }
!
! module.compilation().exitIfErrors();
!
! for (int i = 0; i < classes.length; i++)
! classes[i].precompile();
! }
!
! public void typechecking(boolean compiling)
! {
! Node.setModule(module);
!
! // Classes are typechecked first, since code can depend on them.
! for (int i = 0; i < classes.length; i++)
! classes[i].typecheckClass();
! if (! compiling)
! {
! for (int i = 0; i < methods.length; i++)
! methods[i].typecheckCompiled();
! return;
! }
! doTypecheck();
! module.compilation().exitIfErrors();
! }
public void printInterface(java.io.PrintWriter s)
--- 34,46 ----
}
! abstract public void buildScope();
! abstract public void resolveScoping();
! abstract public void typedResolve();
! abstract public void localResolve();
! abstract public void typechecking(boolean compiling);
public void printInterface(java.io.PrintWriter s)
***************
*** 197,228 ****
}
! /**
! @param generateCode
! false if the current module was already compiled and up-to-date.
! */
! public void compile(boolean generateCode)
! {
! if (! generateCode)
! {
! for (int i = 0; i < classes.length; i++)
! classes[i].recompile();
! }
! else
! {
! // Globals are compiled first, so that we can find out their
! // dependencies, and initialize them in the right order.
! for (int i = 0; i < globals.length; i++)
! globals[i].compile();
!
! for (Iterator i = children.iterator();i.hasNext();)
! ((Definition) i.next()).compile();
! }
! }
- public String toString()
- {
- return "Abstract Syntax Tree (" + numberOfDeclarations() +"
declarations)";
- }
-
public int numberOfDeclarations()
{
--- 50,55 ----
}
! abstract public void compile(boolean generateCode);
public int numberOfDeclarations()
{
***************
*** 230,239 ****
}
- private Module module;
- private TypeDefinition[] classes;
- private MethodDeclaration[] methods;
- private MethodBodyDefinition[] methodImplementations;
- private Definition[] globals;
- private CustomConstructor[] customConstructors;
}
--- 57,60 ----
Index: dispatch.java.bootstrap
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** dispatch.java.bootstrap 25 Nov 2004 19:28:18 -0000 1.27
--- dispatch.java.bootstrap 26 Nov 2004 20:26:02 -0000 1.28
***************
*** 95,98 ****
--- 95,101 ----
{ return null; }
+ public static AST createAST(Module module, List defs)
+ { return null; }
+
static bossa.util.UserError unknownIdent(LocatedString ident)
{
Index: tools.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** tools.nice 25 Nov 2004 19:28:19 -0000 1.63
--- tools.nice 26 Nov 2004 20:26:02 -0000 1.64
***************
*** 245,248 ****
--- 245,249 ----
MethodBodyDefinition MethodBodyDefinition(NiceClass, LocatedString,
?Collection<LocatedString>, List<Pattern>, Statement) = native new
MethodBodyDefinition(NiceClass, LocatedString, Collection, List, Statement);
?FormalParameters getFormalParameters(VarSymbol) = native FormalParameters
VarSymbol.getFormalParameters();
+ List<Node> children(Node) = native Node.children;
// Retypings needed since java types are not strict.
Index: enum.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/enum.nice,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** enum.nice 25 Nov 2004 19:28:18 -0000 1.3
--- enum.nice 26 Nov 2004 20:26:02 -0000 1.4
***************
*** 34,40 ****
}
- isEnumDefinition() = true;
- getEnumClass() = classDef;
-
resolve()
{
--- 34,37 ----
Index: globalvar.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/globalvar.nice,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** globalvar.nice 7 Nov 2004 01:07:26 -0000 1.1
--- globalvar.nice 26 Nov 2004 20:26:02 -0000 1.2
***************
*** 25,30 ****
boolean constant;
- isGlobalVarDeclaration() = true;
-
resolve()
{
--- 25,28 ----
--- NEW FILE: ast.nice ---
/**************************************************************************/
/* N I C E */
/* A high-level object-oriented research language */
/* (c) Daniel Bonniot 2004 */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/**************************************************************************/
package bossa.syntax;
import bossa.util.*;
/**
The Abstract Syntax Tree : a collection of definitions.
@see Definition
*/
public class CAST extends AST
{
private Module module;
private ArrayList<TypeDefinition> classes = new ArrayList();
private ArrayList<MethodDeclaration> methods = new ArrayList();
private ArrayList<MethodBodyDefinition> methodImplementations = new
ArrayList();
private ArrayList<GlobalVarDeclaration> globals = new ArrayList();
private ArrayList<CustomConstructor> customConstructors = new ArrayList();
void findElements()
{
for (node : children)
{
if (node instanceof TypeDefinition)
classes.add(node);
else if (node instanceof CustomConstructor)
{
customConstructors.add(node);
methods.add(node);
}
else if (node instanceof MethodDeclaration)
methods.add(node);
else if (node instanceof MethodBodyDefinition)
methodImplementations.add(node);
else if (node instanceof EnumDefinition)
classes.add(node.classDef);
else if (node instanceof GlobalVarDeclaration)
globals.add(node);
else if (node instanceof DefaultMethodImplementation)
methods.add(node.getDeclaration());
}
}
buildScope()
{
this.buildScope(module);
}
private void resolve(Node n)
{
try {
n.doResolve();
} catch(UserError ex) {
module.compilation().error(ex);
}
}
resolveScoping()
{
Node.setModule(module);
// Resolve custom constructors early, classes depend on them
for (cc : customConstructors)
this.resolve(cc);
// Classes are then resolved, since code can depend on them
for (c : classes)
this.resolve(c);
// Resolve all the rest
for (node : children)
this.resolve(node);
module.compilation().exitIfErrors();
}
typedResolve()
{
Node.setModule(module);
for (m : methods)
try {
m.typedResolve();
} catch(UserError ex) {
module.compilation().error(ex);
}
for (mi : methodImplementations)
try {
mi.lateBuildScope();
} catch(UserError ex) {
module.compilation().error(ex);
}
module.compilation().exitIfErrors();
}
localResolve()
{
Node.setModule(module);
for (d : children)
try {
assert (d instanceof Definition);
d.resolveBody();
} catch(UserError ex) {
module.compilation().error(ex);
}
module.compilation().exitIfErrors();
for (c : classes)
c.precompile();
}
typechecking(compiling)
{
Node.setModule(module);
// Classes are typechecked first, since code can depend on them.
for (c : classes)
c.typecheckClass();
if (! compiling)
{
for (m : methods)
m.typecheckCompiled();
return;
}
this.doTypecheck();
module.compilation().exitIfErrors();
}
/**
@param generateCode
false if the current module was already compiled and up-to-date.
*/
compile(generateCode)
{
if (! generateCode)
{
for (c : classes)
c.recompile();
}
else
{
// Globals are compiled first, so that we can find out their
// dependencies, and initialize them in the right order.
for (g : globals)
g.compile();
for (d : children)
{
assert (d instanceof Definition);
d.compile();
}
}
}
toString() = "Abstract Syntax Tree (" + this.numberOfDeclarations() +"
declarations)";
}
public AST createAST(Module module, ?List<Definition> defs)
{
let res = new CAST(defs || new ArrayList(), Node.global, module: module);
res.findElements();
return res;
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
|