[Nice-commit] Nice/src/bossa/syntax GlobalVarDeclaration.java,1.19,1.20 AST.java,1.48,1.49
Brought to you by:
bonniot
From: <bo...@us...> - 2003-07-31 22:44:53
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv21461/src/bossa/syntax Modified Files: GlobalVarDeclaration.java AST.java Log Message: Statically initialize globals in the order in which they depend on each other. Now, a global is always initialized before use, except if there is a mutual dependency, or a hiden dependency (through a method call). Index: GlobalVarDeclaration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/GlobalVarDeclaration.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** GlobalVarDeclaration.java 25 Jul 2003 16:13:10 -0000 1.19 --- GlobalVarDeclaration.java 31 Jul 2003 21:59:39 -0000 1.20 *************** *** 133,145 **** ****************************************************************/ ! public void compile() { gnu.expr.Declaration declaration = left.getDeclaration(); if (constant) declaration.setFlag(Declaration.IS_CONSTANT); ! if (value == null) ! declaration.noteValue(null); ! else ! declaration.noteValue(value.compile()); } --- 133,151 ---- ****************************************************************/ ! public void precompile() { + // Compute the value first, and this might use another global value, + // which will then be properly initialized before use. + gnu.expr.Expression value = + this.value != null ? this.value.compile() : null; + gnu.expr.Declaration declaration = left.getDeclaration(); if (constant) declaration.setFlag(Declaration.IS_CONSTANT); ! declaration.noteValue(value); ! } ! ! public void compile() ! { } Index: AST.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/AST.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** AST.java 22 Jul 2003 16:55:31 -0000 1.48 --- AST.java 31 Jul 2003 21:59:39 -0000 1.49 *************** *** 42,45 **** --- 42,46 ---- ArrayList classes = new ArrayList(children.size()); ArrayList methods = new ArrayList(children.size()); + ArrayList globals = new ArrayList(10); for(Iterator i = children.iterator(); i.hasNext();) *************** *** 52,55 **** --- 53,58 ---- else if (node instanceof EnumDefinition) classes.add(((EnumDefinition)node).classDef); + else if (node instanceof GlobalVarDeclaration) + globals.add(node); } *************** *** 59,62 **** --- 62,68 ---- this.methods = (MethodDeclaration[]) methods.toArray(new MethodDeclaration[methods.size()]); + + this.globals = (GlobalVarDeclaration[]) + globals.toArray(new GlobalVarDeclaration[globals.size()]); } *************** *** 177,180 **** --- 183,191 ---- 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].precompile(); + for(Iterator i = children.iterator();i.hasNext();) ((Definition)i.next()).compile(); *************** *** 195,198 **** --- 206,210 ---- private ClassDefinition[] classes; private MethodDeclaration[] methods; + private GlobalVarDeclaration[] globals; } |