diff options
author | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 17:58:03 +0000 |
---|---|---|
committer | noelallen@chromium.org <noelallen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 17:58:03 +0000 |
commit | 692eaf1f663bf853781f66995e583defe1cbf954 (patch) | |
tree | a937f02c1c0f6d27d6872f6b915057419539f252 | |
parent | ae57a18e11170253cf2515738bbdd09c37000c8f (diff) | |
download | chromium_src-692eaf1f663bf853781f66995e583defe1cbf954.zip chromium_src-692eaf1f663bf853781f66995e583defe1cbf954.tar.gz chromium_src-692eaf1f663bf853781f66995e583defe1cbf954.tar.bz2 |
PPAPI IDL support fixes
Fixes to support current PPAPI IDL files.
1- Fix optional comment in ExtendedAttributesList for Typedef
2- Adds "struct"
3- Adds typedef Type ident ( args ) : callback ident = Type ( args )
4- Add struct test for ppapi parser.
5- Add filename to failure message for easier debugging.
BUG=224150
TEST=test_parser.py (for general parser)
TEST=idl_ppapi_parser.py ../../ppapi/api/*.idl (to verify we now handle pepper IDL)
R=nfullagar@chromium.org
Review URL: https://codereview.chromium.org/20805002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214776 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | tools/idl_parser/idl_parser.py | 12 | ||||
-rwxr-xr-x | tools/idl_parser/idl_parser_test.py | 17 | ||||
-rwxr-xr-x | tools/idl_parser/idl_ppapi_lexer.py | 2 | ||||
-rwxr-xr-x | tools/idl_parser/idl_ppapi_parser.py | 64 | ||||
-rw-r--r-- | tools/idl_parser/test_parser/struct_ppapi.idl | 52 | ||||
-rw-r--r-- | tools/idl_parser/test_parser/typedef_ppapi.idl | 11 |
6 files changed, 148 insertions, 10 deletions
diff --git a/tools/idl_parser/idl_parser.py b/tools/idl_parser/idl_parser.py index f1ec51e..10428de 100755 --- a/tools/idl_parser/idl_parser.py +++ b/tools/idl_parser/idl_parser.py @@ -359,7 +359,7 @@ class IDLParser(object): # [24] def p_Typedef(self, p): - """Typedef : TYPEDEF ExtendedAttributeList Type identifier ';'""" + """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) # [24.1] Error recovery for Typedefs @@ -571,7 +571,15 @@ class IDLParser(object): """ExceptionField : error""" p[0] = self.BuildError(p, 'ExceptionField') - # [49] Add optional comment field + # [49] No comment version for mid statement attributes. + def p_ExtendedAttributeListNoComments(self, p): + """ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttributes ']' + | """ + if len(p) > 2: + items = ListFromConcat(p[2], p[3]) + p[0] = self.BuildProduction('ExtAttributes', p, 1, items) + + # [49.1] Add optional comment field for start of statements. def p_ExtendedAttributeList(self, p): """ExtendedAttributeList : Comments '[' ExtendedAttribute ExtendedAttributes ']' | Comments """ diff --git a/tools/idl_parser/idl_parser_test.py b/tools/idl_parser/idl_parser_test.py index ad48f23..76a9571 100755 --- a/tools/idl_parser/idl_parser_test.py +++ b/tools/idl_parser/idl_parser_test.py @@ -63,29 +63,32 @@ class PepperIDLParser(unittest.TestCase): self.parser = IDLPPAPIParser(IDLPPAPILexer(), mute_error=True) self.filenames = glob.glob('test_parser/*_ppapi.idl') - def _TestNode(self, node): + def _TestNode(self, filename, node): comments = node.GetListOf('Comment') for comment in comments: check, value = ParseCommentTest(comment.GetName()) if check == 'BUILD': - msg = 'Expecting %s, but found %s.\n' % (value, str(node)) + msg = '%s - Expecting %s, but found %s.\n' % ( + filename, value, str(node)) self.assertEqual(value, str(node), msg) if check == 'ERROR': - msg = node.GetLogLine('Expecting\n\t%s\nbut found \n\t%s\n' % ( - value, str(node))) + msg = node.GetLogLine('%s - Expecting\n\t%s\nbut found \n\t%s\n' % ( + filename, value, str(node))) self.assertEqual(value, node.GetName(), msg) if check == 'PROP': key, expect = value.split('=') actual = str(node.GetProperty(key)) - msg = 'Mismatched property %s: %s vs %s.\n' % (key, expect, actual) + msg = '%s - Mismatched property %s: %s vs %s.\n' % ( + filename, key, expect, actual) self.assertEqual(expect, actual, msg) if check == 'TREE': quick = '\n'.join(node.Tree()) lineno = node.GetProperty('LINENO') - msg = 'Mismatched tree at line %d:\n%sVS\n%s' % (lineno, value, quick) + msg = '%s - Mismatched tree at line %d:\n%sVS\n%s' % ( + filename, lineno, value, quick) self.assertEqual(value, quick, msg) def testExpectedNodes(self): @@ -96,7 +99,7 @@ class PepperIDLParser(unittest.TestCase): filename) for node in filenode.GetChildren()[2:]: - self._TestNode(node) + self._TestNode(filename, node) if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/tools/idl_parser/idl_ppapi_lexer.py b/tools/idl_parser/idl_ppapi_lexer.py index 9261399..2595f1c 100755 --- a/tools/idl_parser/idl_ppapi_lexer.py +++ b/tools/idl_parser/idl_ppapi_lexer.py @@ -42,7 +42,7 @@ class IDLPPAPILexer(IDLLexer): def __init__(self): IDLLexer.__init__(self) self._AddTokens(['INLINE', 'LSHIFT', 'RSHIFT']) - self._AddKeywords(['label']) + self._AddKeywords(['label', 'struct']) # Add number types self._AddKeywords(['char', 'int8_t', 'int16_t', 'int32_t', 'int64_t']); diff --git a/tools/idl_parser/idl_ppapi_parser.py b/tools/idl_parser/idl_ppapi_parser.py index 0e5116c..33eb503 100755 --- a/tools/idl_parser/idl_ppapi_parser.py +++ b/tools/idl_parser/idl_ppapi_parser.py @@ -65,6 +65,7 @@ class IDLPPAPIParser(IDLParser): # [2] Add INLINE definition def p_Definition(self, p): """Definition : CallbackOrInterface + | Struct | Partial | Dictionary | Exception @@ -109,6 +110,32 @@ class IDLPPAPIParser(IDLParser): """LabelCont : error LabelCont""" p[0] = p[2] + # [5.1] Add "struct" style interface + def p_Struct(self, p): + """Struct : STRUCT identifier Inheritance '{' StructMembers '}' ';'""" + p[0] = self.BuildNamed('Struct', p, 2, ListFromConcat(p[3], p[5])) + + def p_StructMembers(self, p): + """StructMembers : StructMember StructMembers + |""" + if len(p) > 1: + p[0] = ListFromConcat(p[1], p[2]) + + def p_StructMember(self, p): + """StructMember : ExtendedAttributeList Type identifier ';'""" + p[0] = self.BuildNamed('Member', p, 3, ListFromConcat(p[1], p[2])) + + # [24] + def p_Typedef(self, p): + """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" + p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) + + # [24.1] + def p_TypedefFunc(self, p): + """Typedef : TYPEDEF ExtendedAttributeListNoComments ReturnType identifier '(' ArgumentList ')' ';'""" + args = self.BuildProduction('Arguments', p, 5, p[6]) + p[0] = self.BuildNamed('Callback', p, 4, ListFromConcat(p[2], p[3], args)) + # [27] def p_ConstValue(self, p): """ConstValue : integer @@ -211,6 +238,43 @@ class IDLPPAPIParser(IDLParser): """ """ pass + # We only support: + # [ identifier ] + # [ identifier = identifier ] + # [ identifier ( ArgumentList )] + # [ identifier ( ValueList )] + # [ identifier = identifier ( ArgumentList )] + # [51] map directly to 74-77 + # [52-54, 56] are unsupported + def p_ExtendedAttribute(self, p): + """ExtendedAttribute : ExtendedAttributeNoArgs + | ExtendedAttributeArgList + | ExtendedAttributeValList + | ExtendedAttributeIdent + | ExtendedAttributeIdentConst + | ExtendedAttributeNamedArgList""" + p[0] = p[1] + + def p_ExtendedAttributeValList(self, p): + """ExtendedAttributeValList : identifier '(' ValueList ')'""" + arguments = self.BuildProduction('Values', p, 2, p[3]) + p[0] = self.BuildNamed('ExtAttribute', p, 1, arguments) + + # [76] + def p_ExtendedAttributeIdentConst(self, p): + """ExtendedAttributeIdentConst : identifier '=' ConstValue""" + p[0] = self.BuildNamed('ExtAttribute', p, 1, p[3]) + + def p_ValueListCont(self, p): + """ValueListCont : ConstValue ValueListCont + |""" + if len(p) > 1: + p[0] = ListFromConcat(p[1], p[2]) + + def p_ValueList(self, p): + """ValueList : ConstValue ValueListCont""" + values = self.BuildProduction('Values', p, 2, ListFromConcat(p[1], p[2])) + def __init__(self, lexer, verbose=False, debug=False, mute_error=False): IDLParser.__init__(self, lexer, verbose, debug, mute_error) diff --git a/tools/idl_parser/test_parser/struct_ppapi.idl b/tools/idl_parser/test_parser/struct_ppapi.idl new file mode 100644 index 0000000..dd017ac --- /dev/null +++ b/tools/idl_parser/test_parser/struct_ppapi.idl @@ -0,0 +1,52 @@ +/* Copyright (c) 2013 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. */ + +/* Test Struct productions + +Run with --test to generate an AST and verify that all comments accurately +reflect the state of the Nodes. + +BUILD Type(Name) +This comment signals that a node of type <Type> is created with the +name <Name>. + +ERROR Error String +This comment signals that a error of <Error String> is generated. The error +is not assigned to a node, but are expected in order. + +PROP Key=Value +This comment signals that a property has been set on the Node such that +<Key> = <Value>. + +TREE +Type(Name) + Type(Name) + Type(Name) + Type(Name) + ... +This comment signals that a tree of nodes matching the BUILD comment +symatics should exist. This is an exact match. +*/ + +/* TREE + *Struct(MyStruct) + * Member(x) + * Type() + * PrimitiveType(uint32_t) + * Member(y) + * Type() + * PrimitiveType(uint64_t) + * Member(string) + * ExtAttributes() + * ExtAttribute(fake_attribute) + * Type() + * PrimitiveType(str_t) + * ExtAttributes() + * ExtAttribute(union) + */ +[union] struct MyStruct { + uint32_t x; + uint64_t y; + [fake_attribute] str_t string; +}; diff --git a/tools/idl_parser/test_parser/typedef_ppapi.idl b/tools/idl_parser/test_parser/typedef_ppapi.idl index 72ac110..1a80415 100644 --- a/tools/idl_parser/test_parser/typedef_ppapi.idl +++ b/tools/idl_parser/test_parser/typedef_ppapi.idl @@ -41,6 +41,17 @@ symatics should exist. This is an exact match. callback foo = void (int32_t x); /* TREE + *Callback(foo) + * Type() + * PrimitiveType(void) + * Arguments() + * Argument(x) + * Type() + * PrimitiveType(int32_t) + */ +typedef void foo(int32_t x); + +/* TREE *Typedef(MyLong) * Type() * PrimitiveType(int32_t) |