throw new ParseException("packet.header expects a type specifier"); //$NON-NLS-1$
}
- IDeclaration packetHeaderDecl = parseTypeSpecifierList(
- typeSpecifier, null);
+ IDeclaration packetHeaderDecl = parseTypeSpecifierList(typeSpecifier);
if (!(packetHeaderDecl instanceof StructDeclaration)) {
throw new ParseException("packet.header expects a struct"); //$NON-NLS-1$
throw new ParseException("event.header expects a type specifier"); //$NON-NLS-1$
}
- IDeclaration eventHeaderDecl = parseTypeSpecifierList(
- typeSpecifier, null);
+ IDeclaration eventHeaderDecl = parseTypeSpecifierList(typeSpecifier);
DeclarationScope scope = getCurrentScope();
DeclarationScope eventHeaderScope = scope.lookupChildRecursive(MetadataStrings.STRUCT);
if (eventHeaderScope == null) {
throw new ParseException("event.context expects a type specifier"); //$NON-NLS-1$
}
- IDeclaration eventContextDecl = parseTypeSpecifierList(
- typeSpecifier, null);
+ IDeclaration eventContextDecl = parseTypeSpecifierList(typeSpecifier);
if (!(eventContextDecl instanceof StructDeclaration)) {
throw new ParseException("event.context expects a struct"); //$NON-NLS-1$
throw new ParseException("packet.context expects a type specifier"); //$NON-NLS-1$
}
- IDeclaration packetContextDecl = parseTypeSpecifierList(
- typeSpecifier, null);
+ IDeclaration packetContextDecl = parseTypeSpecifierList(typeSpecifier);
if (!(packetContextDecl instanceof StructDeclaration)) {
throw new ParseException("packet.context expects a struct"); //$NON-NLS-1$
throw new ParseException("context expects a type specifier"); //$NON-NLS-1$
}
- IDeclaration contextDecl = parseTypeSpecifierList(typeSpecifier,
- null);
+ IDeclaration contextDecl = parseTypeSpecifierList(typeSpecifier);
if (!(contextDecl instanceof StructDeclaration)) {
throw new ParseException("context expects a struct"); //$NON-NLS-1$
}
IDeclaration fieldsDecl;
- fieldsDecl = parseTypeSpecifierList(typeSpecifier, null);
+ fieldsDecl = parseTypeSpecifierList(typeSpecifier);
if (!(fieldsDecl instanceof StructDeclaration)) {
throw new ParseException("fields expects a struct"); //$NON-NLS-1$
parseTypealias(child);
break;
case CTFParser.TYPE_SPECIFIER_LIST:
- parseTypeSpecifierList(child, null);
+ parseTypeSpecifierList(child);
break;
default:
throw childTypeError(child);
* Parse the type specifier list, which is the "base" type. For example,
* it would be int in int a[3][len].
*/
- declaration = parseTypeSpecifierList(typeSpecifierList, pointers);
+ declaration = parseTypeSpecifierList(typeSpecifierList, pointers, identifier);
/*
* Each length subscript means that we must create a nested array or
private void registerType(IDeclaration declaration, String identifier) throws ParseException {
final DeclarationScope currentScope = getCurrentScope();
- if (declaration instanceof StructDeclaration) {
- currentScope.registerStruct(identifier, (StructDeclaration) declaration);
- } else if (declaration instanceof EnumDeclaration) {
+ if (declaration instanceof EnumDeclaration) {
currentScope.registerEnum(identifier, (EnumDeclaration) declaration);
} else if (declaration instanceof VariantDeclaration) {
currentScope.registerVariant(identifier, (VariantDeclaration) declaration);
}
+ private IDeclaration parseTypeSpecifierList(CommonTree typeSpecifierList) throws ParseException {
+ return parseTypeSpecifierList(typeSpecifierList, null, null);
+ }
+
/**
* Parses a type specifier list and returns the corresponding declaration.
*
* creating the declaration.
*/
private IDeclaration parseTypeSpecifierList(CommonTree typeSpecifierList,
- List<CommonTree> pointerList) throws ParseException {
+ List<CommonTree> pointerList, CommonTree identifier) throws ParseException {
IDeclaration declaration = null;
/*
declaration = parseString(firstChild);
break;
case CTFParser.STRUCT:
- declaration = parseStruct(firstChild);
+ declaration = parseStruct(firstChild, identifier);
StructDeclaration structDeclaration = (StructDeclaration) declaration;
IDeclaration idEnumDecl = structDeclaration.getFields().get("id"); //$NON-NLS-1$
if (idEnumDecl instanceof EnumDeclaration) {
* @return The corresponding struct declaration.
* @throws ParseException
*/
- private StructDeclaration parseStruct(CommonTree struct)
+ private StructDeclaration parseStruct(CommonTree struct, CommonTree identifier)
throws ParseException {
List<CommonTree> children = struct.getChildren();
}
}
+ if (!hasName && identifier != null) {
+ structName = identifier.getText();
+ hasName = true;
+ }
+
/*
* If a struct has just a body and no name (just like the song,
* "A Struct With No Name" by America (sorry for that...)), it's a
break;
case CTFParser.TYPEDEF:
parseTypedef(declarationNode);
+ parseStructDeclaration(declarationNode, structDeclaration);
break;
case CTFParser.SV_DECLARATION:
parseStructDeclaration(declarationNode, structDeclaration);
CommonTree typeSpecifierList = (CommonTree) enumContainerType.getChild(0);
/* Parse it and get the corresponding declaration */
- IDeclaration decl = parseTypeSpecifierList(typeSpecifierList, null);
+ IDeclaration decl = parseTypeSpecifierList(typeSpecifierList);
/* If is is an integer, return it, else throw an error */
if (decl instanceof IntegerDeclaration) {