Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv22745/F:/nice/src/bossa/syntax
Modified Files:
EnumDefinition.java
Log Message:
Implemented user defined fields for enums.
Index: EnumDefinition.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/EnumDefinition.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** EnumDefinition.java 27 Nov 2003 23:37:08 -0000 1.6
--- EnumDefinition.java 15 Dec 2003 00:04:48 -0000 1.7
***************
*** 26,30 ****
public class EnumDefinition extends Definition
{
! public EnumDefinition(LocatedString name, List/*LocatedString*/ elements, List globalDefs)
{
super(name, Node.global);
--- 26,32 ----
public class EnumDefinition extends Definition
{
! public EnumDefinition(LocatedString name, List/*LocatedString*/ elements,
! List/*MonoSymbol*/ fields, List/*List<Expression>*/ argsList,
! List globalDefs)
{
super(name, Node.global);
***************
*** 35,39 ****
null,null);
NiceClass impl = new NiceClass(classDef);
! impl.setFields(null);
impl.setOverrides(null);
--- 37,53 ----
null,null);
NiceClass impl = new NiceClass(classDef);
! int fieldsCount = fields.size();
! if (fieldsCount > 0)
! {
! List newFields = new ArrayList(fieldsCount);
! for (Iterator it = fields.iterator(); it.hasNext(); )
! newFields.add(impl.makeField((MonoSymbol)it.next(), null, true,
! false, false, null));
!
! impl.setFields(newFields);
! }
! else
! impl.setFields(null);
!
impl.setOverrides(null);
***************
*** 57,69 ****
this.elements = elements;
symbols = new LinkedList();
! int ord = 0;
! for (Iterator it = elements.iterator(); it.hasNext(); )
{
Monotype type = new TypeIdent(name);
type.nullness = Monotype.absent;
! symbols.add(new EnumSymbol(name, (LocatedString)it.next(), type, ord));
! ord++;
}
addChildren(symbols);
--- 71,88 ----
this.elements = elements;
+ this.fields = fields;
+ this.elementsArgs = argsList;
symbols = new LinkedList();
! for (int ord = 0; ord<elements.size(); ord++ )
{
+ List args = (List) argsList.get(ord);
+ LocatedString elemName = (LocatedString)elements.get(ord);
+ if (args.size() != fieldsCount)
+ User.error(elemName, "the number of arguments doesn't match the number of enum fields");
+
Monotype type = new TypeIdent(name);
type.nullness = Monotype.absent;
! symbols.add(new EnumSymbol(name, elemName, type, ord, fields, args));
}
addChildren(symbols);
***************
*** 73,80 ****
class EnumSymbol extends MonoSymbol
{
! EnumSymbol(LocatedString enumName, LocatedString name, Monotype type, int ordinal)
{
super(name, type);
! List args = new ArrayList(2);
args.add(new Arguments.Argument(new StringConstantExp(name.toString()),
new LocatedString("name",name.location)));
--- 92,100 ----
class EnumSymbol extends MonoSymbol
{
! EnumSymbol(LocatedString enumName, LocatedString name, Monotype type,
! int ordinal, List fields, List argExps)
{
super(name, type);
! List args = new ArrayList(2 + fields.size());
args.add(new Arguments.Argument(new StringConstantExp(name.toString()),
new LocatedString("name",name.location)));
***************
*** 83,86 ****
--- 103,110 ----
val.toString(), name.location()),
new LocatedString("ordinal",name.location)));
+ for (int i = 0; i < fields.size(); i++)
+ args.add(new Arguments.Argument((Expression)argExps.get(i),
+ ((MonoSymbol)fields.get(i)).getName()));
+
this.value = new NewExp(new TypeIdent(enumName), new Arguments(args));
}
***************
*** 181,185 ****
public String toString()
{
! return "enum " + shortName + Util.map(" {", " , ", " }", elements);
}
--- 205,221 ----
public String toString()
{
! if (fields.isEmpty())
! return "enum " + shortName + Util.map(" {", " , ", " }", elements);
!
! String res = "enum " + shortName + Util.map("(", ", ", ")", fields) + " {";
! for (int i = 0; i < elements.size(); i++)
! {
! if (i != 0)
! res += ", ";
!
! res += elements.get(i) + Util.map("(", ", ", ")", (List)elementsArgs.get(i));
! }
!
! return res + "}";
}
***************
*** 188,190 ****
--- 224,228 ----
List elements;
List symbols;
+ List fields;
+ List elementsArgs;
}
|