enumspecifier.java
来自「plugin for eclipse」· Java 代码 · 共 161 行
JAVA
161 行
/*
* Created on May 5, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package isis.anp.nesc.ot;
import isis.anp.common.CodeLocation;
import isis.anp.common.ObjectTreeBuilderContext;
import isis.anp.common.ParserMessage;
import isis.anp.nesc.ot.scope.Symbol;
import isis.anp.nesc.ot.types.EnumType;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author sallai
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class EnumSpecifier extends CompoundTypeSpecifier {
EnumType type;
ArrayList enumeratorList;
ArrayList attributeList = new ArrayList();
/**
* @param ctx
*/
public EnumSpecifier(ObjectTreeBuilderContext ctx) {
super(ctx);
}
public String toString() {
return getSpecifierName();
}
public EnumType getType() {
return type;
}
public void addEnumerator(Enumerator e) {
if(enumeratorList==null) {
enumeratorList = new ArrayList();
}
enumeratorList.add(e);
}
/*
public void buildType(NesCObjectTreeBuilderContext ctx) {
String symbolName = null;
if(specifierName != null) {
symbolName = "enum " + specifierName;
}
// complete declaration with name given
if(symbolName!=null && enumeratorList != null) {
// build type
type = new EnumType(this);
type.setNameNode(this.specifierNameNode);
// set enumerators
type.setEnumeratorList(this.enumeratorList);
// look for a previous declaration/definition in current scope
EnumType prevTypeName = (EnumType)ctx.getCurrentScope().findSymbolInCurrentScope(symbolName);
if(prevTypeName!=null && prevTypeName.isComplete()) {
// error: this enum is already defined
NameConflictException ex = new NameConflictException(prevTypeName, this.getType());
ctx.addError(new Error(ex, ex.getMessage(), new CodeLocation(type.getNameNode()))) ;
} else {
// add it to the scope
ctx.getCurrentScope().addSymbol(this.getType());
}
addEnumeratorConstantsToScope(ctx);
return;
}
// complete declaration with no name given
if(symbolName==null && enumeratorList != null) {
// build type
type = new EnumType(this);
// set enumerators
type.setEnumeratorList(this.enumeratorList);
addEnumeratorConstantsToScope(ctx);
return;
}
// incomplete declaration
if(symbolName!=null && enumeratorList == null) {
// look for a previous declaration/definition in scope
EnumType typeName = (EnumType) ctx.getCurrentScope().findSymbol(symbolName);
if(typeName == null) {
// this enum is declared here first
type = new EnumType(this);
type.setNameNode(this.specifierNameNode);
ctx.getCurrentScope().addSymbol(getType());
} else {
// this enum already exists: use type object from previous declaration
type = this.getType();
}
return;
}
// we should never get here...
}
*/
public void addEnumeratorConstantsToScope(ObjectTreeBuilderContext ctx) {
if(enumeratorList==null) return;
Iterator i = enumeratorList.iterator();
while (i.hasNext()) {
Enumerator e = (Enumerator) i.next();
Symbol prevSymbol = ctx.getCurrentScope().findSymbolInCurrentScope(e.getName());
Symbol newSymbol = e;
if(prevSymbol==null) {
ctx.getCurrentScope().addSymbol(newSymbol);
} else {
NameConflictException ex = new NameConflictException(prevSymbol, newSymbol);
// ctx.addMsg(new ParserMessage(ex, ex.getMessage(), new CodeLocation(newSymbol.getNameNode())));
ctx.addMsg(new ParserMessage(ParserMessage.ERROR, ex.getMessage(), new CodeLocation(newSymbol.getNameNode()), ex));
}
}
}
/**
* @return Returns the enumeratorList.
*/
public ArrayList getEnumeratorList() {
return enumeratorList;
}
/* (non-Javadoc)
* @see parser.nesc.ot.CompoundTypeSpecifier#isComplete()
*/
public boolean isComplete() {
return (enumeratorList!=null);
}
public void addAttribute(Attribute attr) {
this.attributeList.add(attr);
}
/**
* @return Returns the attributeList.
*/
public ArrayList getAttributeList() {
return attributeList;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?