[Nice-commit] Nice/src/bossa/syntax globalvar.nice,NONE,1.1 AST.java,1.58,1.59 Definition.java,1.22,
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7531/F:/nice/src/bossa/syntax Modified Files: AST.java Definition.java overloadedsymbol.nice pattern.nice tools.nice Added Files: globalvar.nice Removed Files: GlobalVarDeclaration.java Log Message: Converted GlobalVarDeclaration. Index: Definition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Definition.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Definition.java 15 Dec 2003 14:04:13 -0000 1.22 --- Definition.java 7 Nov 2004 01:07:26 -0000 1.23 *************** *** 78,81 **** --- 78,86 ---- } + boolean isGlobalVarDeclaration() + { + return false; + } + /**************************************************************** * Name and location of the definition Index: AST.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/AST.java,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** AST.java 5 Mar 2004 14:07:14 -0000 1.58 --- AST.java 7 Nov 2004 01:07:26 -0000 1.59 *************** *** 53,57 **** for(Iterator i = children.iterator(); i.hasNext();) { ! Object node = i.next(); if (node instanceof ClassDefinition) classes.add(node); --- 53,57 ---- for(Iterator i = children.iterator(); i.hasNext();) { ! Definition node = (Definition)i.next(); if (node instanceof ClassDefinition) classes.add(node); *************** *** 67,71 **** else if (node instanceof EnumDefinition) classes.add(((EnumDefinition)node).classDef); ! else if (node instanceof GlobalVarDeclaration) globals.add(node); else if (node instanceof DefaultMethodImplementation) --- 67,71 ---- else if (node instanceof EnumDefinition) classes.add(((EnumDefinition)node).classDef); ! else if (node.isGlobalVarDeclaration()) globals.add(node); else if (node instanceof DefaultMethodImplementation) *************** *** 79,84 **** methods.toArray(new MethodDeclaration[methods.size()]); ! this.globals = (GlobalVarDeclaration[]) ! globals.toArray(new GlobalVarDeclaration[globals.size()]); this.customConstructors = (CustomConstructor[]) --- 79,84 ---- methods.toArray(new MethodDeclaration[methods.size()]); ! this.globals = (Definition[]) ! globals.toArray(new Definition[globals.size()]); this.customConstructors = (CustomConstructor[]) *************** *** 234,238 **** private MethodDeclaration[] methods; private MethodBodyDefinition[] methodImplementations; ! private GlobalVarDeclaration[] globals; private CustomConstructor[] customConstructors; } --- 234,238 ---- private MethodDeclaration[] methods; private MethodBodyDefinition[] methodImplementations; ! private Definition[] globals; private CustomConstructor[] customConstructors; } Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pattern.nice 13 Oct 2004 23:22:22 -0000 1.7 --- pattern.nice 7 Nov 2004 01:07:26 -0000 1.8 *************** *** 467,471 **** { for (sym : Node.getGlobalScope().lookup(refName)) ! if (sym instanceof GlobalVarDeclaration.GlobalVarSymbol || sym instanceof EnumDefinition.EnumSymbol ) return sym; --- 467,471 ---- { for (sym : Node.getGlobalScope().lookup(refName)) ! if (sym instanceof GlobalVarSymbol || sym instanceof EnumDefinition.EnumSymbol ) return sym; *************** *** 484,490 **** { let symbol = findRefSymbol(notNull(pattern.refName)); ! if (symbol instanceof GlobalVarDeclaration.GlobalVarSymbol) { ! if (symbol.getValue() instanceof ConstantExp && symbol.constant) { ConstantExp val = cast(symbol.getValue()); --- 484,490 ---- { let symbol = findRefSymbol(notNull(pattern.refName)); ! if (symbol instanceof GlobalVarSymbol) { ! if (symbol.getValue() instanceof ConstantExp && !symbol.isAssignable()) { ConstantExp val = cast(symbol.getValue()); *************** *** 515,524 **** } ! if (! (symbol instanceof GlobalVarDeclaration.GlobalVarSymbol)) return pattern; if (symbol.getValue() instanceof ConstantExp) { ! if (!symbol.constant) User.error(pattern.name, "" + pattern.name + " is not constant"); --- 515,524 ---- } ! if (! (symbol instanceof GlobalVarSymbol)) return pattern; if (symbol.getValue() instanceof ConstantExp) { ! if (symbol.isAssignable()) User.error(pattern.name, "" + pattern.name + " is not constant"); Index: overloadedsymbol.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/overloadedsymbol.nice,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** overloadedsymbol.nice 6 Nov 2004 19:39:50 -0000 1.6 --- overloadedsymbol.nice 7 Nov 2004 01:07:26 -0000 1.7 *************** *** 298,302 **** List<VarSymbol> globalvars = symbols.filter(VarSymbol sym => ! sym instanceof GlobalVarDeclaration.GlobalVarSymbol); // If there are global variables, give them the priority --- 298,302 ---- List<VarSymbol> globalvars = symbols.filter(VarSymbol sym => ! sym instanceof GlobalVarSymbol); // If there are global variables, give them the priority Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** tools.nice 6 Nov 2004 19:39:50 -0000 1.58 --- tools.nice 7 Nov 2004 01:07:26 -0000 1.59 *************** *** 41,45 **** //don't allow nullness inference on global variables. ! if (sym instanceof GlobalVarDeclaration.GlobalVarSymbol && sym.isAssignable()) return null; --- 41,45 ---- //don't allow nullness inference on global variables. ! if (sym instanceof GlobalVarSymbol && sym.isAssignable()) return null; *************** *** 234,237 **** --- 234,239 ---- ?LinkedList<MethodDeclaration.Symbol> getConstructors(TypeConstructor) = native LinkedList TypeConstructors.getConstructors(TypeConstructor); ?gnu.bytecode.Attribute get(gnu.bytecode.AttrContainer, String) = native gnu.bytecode.Attribute gnu.bytecode.Attribute.get(gnu.bytecode.AttrContainer, String); + void printInterface(Definition, java.io.PrintWriter) = native void Definition.printInterface(java.io.PrintWriter); + ?gnu.expr.Declaration getDeclaration(VarSymbol) = native gnu.expr.Declaration VarSymbol.getDeclaration(); // Retypings needed since java types are not strict. --- NEW FILE: globalvar.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.*; /** Declaration of a global variable */ public class GlobalVarDeclaration extends Definition { GlobalVarSymbol left; Expression value; boolean constant; isGlobalVarDeclaration() = true; resolve() { value = analyse(value, notNull(scope), notNull(typeScope)); } typecheck() { try{ value = value.resolveOverloading(left.getType()); typecheck(value); Typing.leq(value.getType(),left.getType()); } catch(TypingEx e){ User.error(this,"Typing error : "+left+" cannot be assigned value "+value+ " of type "+value.getType()+" : \n"+ e); } } printInterface(s) { s.print((constant? "let ": "var ") +left +" = " +value.toString() +";\n"); } compile() { left.getDeclaration(); } ?gnu.expr.Expression compileValue() = value.compile(); toString() = left + " = " + value; } class GlobalVarSymbol extends MonoSymbol { GlobalVarDeclaration definition; isAssignable() = ! definition.constant; getDeclaration() { ?gnu.expr.Declaration res = super; if (res == null) { res = new gnu.expr.Declaration (name.toString(), nice.tools.code.Types.javaType(type)); this.setDeclaration(res); if (! definition.inInterfaceFile()) { // Compute the value first, which might use another global value, // which will then be properly initialized before use. notNull(res).noteValue(definition.compileValue()); } definition.module.addGlobalVar(res, definition.constant); } return res; } Expression getValue() = definition.value; getDefinition() = definition; } public GlobalVarDeclaration createGlobalVarDeclaration(LocatedString name, Monotype type, Expression value, boolean constant) { let res = new GlobalVarDeclaration(name, Node.global, left: cast(null), value: value, constant: constant); res.left = new GlobalVarSymbol(name, type, definition: res); res.addChild(res.left); return res; } --- GlobalVarDeclaration.java DELETED --- |