Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / json_schema_compiler / idl_schema.py
index 62d31ed..a913756 100644 (file)
@@ -56,19 +56,20 @@ def ProcessComment(comment):
       }
     )
   '''
+  def add_paragraphs(content):
+    paragraphs = content.split('\n\n')
+    if len(paragraphs) < 2:
+      return content
+    return '<p>' + '</p><p>'.join(p.strip() for p in paragraphs) + '</p>'
+
   # Find all the parameter comments of the form '|name|: comment'.
   parameter_starts = list(re.finditer(r' *\|([^|]*)\| *: *', comment))
 
   # Get the parent comment (everything before the first parameter comment.
   first_parameter_location = (parameter_starts[0].start()
                               if parameter_starts else len(comment))
-  parent_comment = comment[:first_parameter_location]
-
-  # We replace \n\n with <br/><br/> here and below, because the documentation
-  # needs to know where the newlines should be, and this is easier than
-  # escaping \n.
-  parent_comment = (parent_comment.strip().replace('\n\n', '<br/><br/>')
-                                          .replace('\n', ''))
+  parent_comment = (add_paragraphs(comment[:first_parameter_location].strip())
+                    .replace('\n', ''))
 
   params = OrderedDict()
   for (cur_param, next_param) in itertools.izip_longest(parameter_starts,
@@ -79,9 +80,10 @@ def ProcessComment(comment):
     # beginning of the next parameter's introduction.
     param_comment_start = cur_param.end()
     param_comment_end = next_param.start() if next_param else len(comment)
-    params[param_name] = (comment[param_comment_start:param_comment_end
-                                  ].strip().replace('\n\n', '<br/><br/>')
-                                           .replace('\n', ''))
+    params[param_name] = (
+        add_paragraphs(comment[param_comment_start:param_comment_end].strip())
+        .replace('\n', ''))
+
   return (parent_comment, params)
 
 
@@ -146,7 +148,9 @@ class Dictionary(object):
     result = {'id': self.node.GetName(),
               'properties': properties,
               'type': 'object'}
-    if self.node.GetProperty('inline_doc'):
+    if self.node.GetProperty('nodoc'):
+      result['nodoc'] = True
+    elif self.node.GetProperty('inline_doc'):
       result['inline_doc'] = True
     elif self.node.GetProperty('noinline_doc'):
       result['noinline_doc'] = True
@@ -168,6 +172,8 @@ class Member(object):
     name = self.node.GetName()
     if self.node.GetProperty('deprecated'):
       properties['deprecated'] = self.node.GetProperty('deprecated')
+    if self.node.GetProperty('allowAmbiguousOptionalArguments'):
+      properties['allowAmbiguousOptionalArguments'] = True
     for property_name in ('OPTIONAL', 'nodoc', 'nocompile', 'nodart'):
       if self.node.GetProperty(property_name):
         properties[property_name.lower()] = True
@@ -216,7 +222,7 @@ class Typeref(object):
   function parameter, converts into a Python dictionary that the JSON schema
   compiler expects to see.
   '''
-  def __init__(self, typeref, parent, additional_properties=OrderedDict()):
+  def __init__(self, typeref, parent, additional_properties):
     self.typeref = typeref
     self.parent = parent
     self.additional_properties = additional_properties
@@ -225,7 +231,7 @@ class Typeref(object):
     properties = self.additional_properties
     result = properties
 
-    if self.parent.GetProperty('OPTIONAL'):
+    if self.parent.GetPropertyLocal('OPTIONAL'):
       properties['optional'] = True
 
     # The IDL parser denotes array types by adding a child 'Array' node onto
@@ -264,6 +270,13 @@ class Typeref(object):
       if 'additionalProperties' not in properties:
         properties['additionalProperties'] = OrderedDict()
       properties['additionalProperties']['type'] = 'any'
+    elif self.parent.GetPropertyLocal('Union'):
+      choices = []
+      properties['choices'] = [Typeref(node.GetProperty('TYPEREF'),
+                                       node,
+                                       OrderedDict()).process(callbacks)
+                               for node in self.parent.GetChildren()
+                               if node.cls == 'Option']
     elif self.typeref is None:
       properties['type'] = 'function'
     else:
@@ -309,9 +322,10 @@ class Enum(object):
               'description': self.description,
               'type': 'string',
               'enum': enum}
-    for property_name in ('inline_doc', 'noinline_doc', 'nodoc'):
+    for property_name in (
+        'inline_doc', 'noinline_doc', 'nodoc', 'cpp_enum_prefix_override',):
       if self.node.GetProperty(property_name):
-        result[property_name] = True
+        result[property_name] = self.node.GetProperty(property_name)
     if self.node.GetProperty('deprecated'):
         result[deprecated] = self.node.GetProperty('deprecated')
     return result
@@ -397,7 +411,7 @@ class IDLSchema(object):
     internal = False
     description = None
     platforms = None
-    compiler_options = None
+    compiler_options = {}
     deprecated = None
     for node in self.idl:
       if node.cls == 'Namespace':
@@ -408,7 +422,7 @@ class IDLSchema(object):
           description = ''
         namespace = Namespace(node, description, nodoc, internal,
                               platforms=platforms,
-                              compiler_options=compiler_options,
+                              compiler_options=compiler_options or None,
                               deprecated=deprecated)
         namespaces.append(namespace.process())
         nodoc = False
@@ -427,7 +441,9 @@ class IDLSchema(object):
         elif node.name == 'platforms':
           platforms = list(node.value)
         elif node.name == 'implemented_in':
-          compiler_options = {'implemented_in': node.value}
+          compiler_options['implemented_in'] = node.value
+        elif node.name == 'camel_case_enum_to_string':
+          compiler_options['camel_case_enum_to_string'] = node.value
         elif node.name == 'deprecated':
           deprecated = str(node.value)
         else:
@@ -457,8 +473,14 @@ def Main():
   Dump a json serialization of parse result for the IDL files whose names
   were passed in on the command line.
   '''
-  for filename in sys.argv[1:]:
-    schema = Load(filename)
+  if len(sys.argv) > 1:
+    for filename in sys.argv[1:]:
+      schema = Load(filename)
+      print json.dumps(schema, indent=2)
+  else:
+    contents = sys.stdin.read()
+    idl = idl_parser.IDLParser().ParseData(contents, '<stdin>')
+    schema = IDLSchema(idl).process()
     print json.dumps(schema, indent=2)