// INTRFC_BODY -> {ATTR_INTRFC_ELEMENT} // ATTR_INTRFC_ELEMENT -> [ATTRIBUTES] INTRFC_ELEMENT // INTRFC_ELEMENT -> METHOD_DECL | ENUM_DECL | CONSTANT_DECL func (p *Parser) parseInterfaceBody(mojomInterface *mojom.MojomInterface) bool { if !p.OK() { return p.OK() } p.pushChildNode("interfaceBody") defer p.popNode() // The interface body forms a new scope. p.pushScope(mojomInterface.InitAsScope(p.currentScope)) defer p.popScope() rbraceFound := false for attributes := p.parseAttributes(); !rbraceFound; attributes = p.parseAttributes() { if !p.OK() { return false } nextToken := p.peekNextToken("I was parsing an interface body.") var duplicateNameError error = nil switch nextToken.Kind { case lexer.Name: if method := p.parseMethodDecl(attributes); p.OK() { duplicateNameError = mojomInterface.AddMethod(method) break } return false case lexer.Enum: if mojomEnum := p.parseEnumDecl(attributes); mojomEnum != nil { duplicateNameError = mojomInterface.AddEnum(mojomEnum) } case lexer.Const: constant := p.parseConstDecl(attributes) duplicateNameError = mojomInterface.AddConstant(constant) case lexer.RBrace: rbraceFound = true if attributes != nil { message := "Interface body ends with extraneouss attributes." p.err = &ParseError{ParserErrorCodeBadAttributeLocation, message} } break default: p.unexpectedTokenError(nextToken, "union, enum, const or an identifier") return false } if p.OK() && duplicateNameError != nil { p.err = &ParseError{ParserErrorCodeDuplicateDeclaration, duplicateNameError.Error()} return false } } if p.OK() { if err := mojomInterface.ComputeMethodOrdinals(); err != nil { p.err = &ParseError{ParserErrorCodeBadOrdinal, err.Error()} return false } } return p.OK() }
// INTRFC_BODY -> {ATTR_INTRFC_ELEMENT} // ATTR_INTRFC_ELEMENT -> [ATTRIBUTES] INTRFC_ELEMENT // INTRFC_ELEMENT -> METHOD_DECL | ENUM_DECL | CONSTANT_DECL func (p *Parser) parseInterfaceBody(mojomInterface *mojom.MojomInterface) bool { if !p.OK() { return p.OK() } p.pushChildNode("interfaceBody") defer p.popNode() // The interface body forms a new scope. p.pushScope(mojomInterface.InitAsScope(p.currentScope)) defer p.popScope() rbraceFound := false for attributes := p.parseAttributes(); !rbraceFound; attributes = p.parseAttributes() { if !p.OK() { return false } nextToken := p.peekNextToken("I was parsing an interface body.") dupeMessage := "" switch nextToken.Kind { case lexer.NAME: if method := p.parseMethodDecl(attributes); p.OK() { mojomInterface.AddMethod(method) break } return false case lexer.ENUM: if mojomEnum, nameToken := p.parseEnumDecl(attributes); mojomEnum != nil { dupeMessage = p.duplicateNameMessage(mojomInterface.AddEnum(mojomEnum), nameToken) } case lexer.CONST: constant, nameToken := p.parseConstDecl(attributes) dupeMessage = p.duplicateNameMessage(mojomInterface.AddConstant(constant), nameToken) case lexer.RBRACE: rbraceFound = true if attributes != nil { message := "Interface body ends with extranesous attributes." p.err = &ParseError{E_BAD_ATTRIBUTE_LOCATION, message} } break default: p.unexpectedTokenError(nextToken, "union, enum, const or an identifier") return false } if p.OK() && len(dupeMessage) > 0 { p.err = &ParseError{E_DUPLICATE_DECLARATION, dupeMessage} return false } } if p.OK() { mojomInterface.ComputeMethodOrdinals() } return p.OK() }
func translateMojomInterface(intrfc *mojom.MojomInterface) *mojom_types.UserDefinedTypeInterfaceType { mojomInterface := mojom_types.UserDefinedTypeInterfaceType{} mojomInterface.Value.DeclData = translateDeclarationData(&intrfc.DeclarationData) mojomInterface.Value.DeclData.ContainedDeclarations = translateContainedDeclarations(&intrfc.NestedDeclarations) // TODO(rudominer) The Interface name field need not be the name from the .mojom file. mojomInterface.Value.InterfaceName = intrfc.SimpleName() mojomInterface.Value.Methods = make(map[uint32]mojom_types.MojomMethod) for ordinal, method := range intrfc.MethodsByOrdinal { mojomInterface.Value.Methods[ordinal] = translateMojomMethod(method) } return &mojomInterface }