Beispiel #1
0
 def __init__(self, name, sname, desc):
   self.name = name
   self.run_switch = Option(sname, desc)
   self.opt_switch = Option(sname + '_opt', 'Options for %s.' % sname,
                            default='')
   GeneratorList.append(self)
   self.errors = 0
   self.skip_list = []
Beispiel #2
0
# Copyright (c) 2012 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.
""" Lint for IDL """

import os
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLAttribute, IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_outfile import IDLOutFile
from idl_visitor import IDLVisitor

Option('wcomment', 'Disable warning for missing comment.')
Option('wenum', 'Disable warning for missing enum value.')
Option('winline', 'Disable warning for inline blocks.')
Option('wname', 'Disable warning for inconsistent interface name.')
Option('wnone', 'Disable all warnings.')
Option('wparam', 'Disable warning for missing [in|out|inout] on param.')
Option('wpass', 'Disable warning for mixed passByValue and returnByValue.')


#
# IDLLinter
#
# Once the AST is build, we need to resolve the namespace and version
# information.
#
class IDLLinter(IDLVisitor):
Beispiel #3
0
between C# and the C++ PepperPlugin interface.  """

from datetime import datetime
import difflib
import glob
import os
import sys

from idl_c_proto import CGen
from idl_gen_wrapper import Interface, WrapperGen
from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles

Option('pepperfile',
       'Name of the pepper file.',
       default='../pepper/pepper_entrypoints.cpp ')

Option('disable_pepper_opt', 'Turn off optimization of pepper.')
Option('disable_region_gen', 'Turn off #pragma region generation.')

# Remap default values
RemapDefaultValue = {
    'PP_Bool': 'PP_FromBool(false)',
    'void': '',
    'PP_ImageDataFormat': 'PP_IMAGEDATAFORMAT_BGRA_PREMUL',
    'PP_InputEvent_MouseButton': 'PP_INPUTEVENT_MOUSEBUTTON_NONE',
    'PP_InputEvent_Type': 'PP_INPUTEVENT_TYPE_UNDEFINED',
    'PP_FloatPoint': 'PP_MakeFloatPoint(0,0)',
    'struct PP_FloatPoint': 'PP_MakeFloatPoint(0,0)',
    'PP_Point': 'PP_MakePoint(0,0)',
import glob
import os
import re
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLAttribute, IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_outfile import IDLOutFile
from idl_parser import ParseFiles
from idl_c_proto import CGen, GetNodeComments, CommentLines, Comment
from idl_generator import Generator, GeneratorByFile
from idl_visitor import IDLVisitor

Option('dstroot', 'Base directory of output', default=os.path.join('..', 'c'))
Option('guard', 'Include guard prefix', default=os.path.join('ppapi', 'c'))


#
# PrototypeResolver
#
# A specialized visitor which traverses the AST, building a mapping of
# Release names to Versions numbers and calculating a min version.
# The mapping is applied to the File nodes within the AST.
#
class ProtoResolver(IDLVisitor):
    def __init__(self):
        IDLVisitor.__init__(self)
        self.struct_map = {}
        self.interface_map = {}
Beispiel #5
0
import subprocess
import sys

from idl_option import GetOption, Option, ParseOptions
from idl_outfile import IDLOutFile
#
# IDLDiff
#
# IDLDiff is a tool for comparing sets of IDL generated header files
# with the standard checked in headers.  It does this by capturing the
# output of the standard diff tool, parsing it into separate changes, then
# ignoring changes that are know to be safe, such as adding or removing
# blank lines, etc...
#

Option('gen', 'IDL generated files', default='hdir')
Option('src', 'Original ".h" files', default='../c')
Option('halt', 'Stop if a difference is found')
Option('diff', 'Directory holding acceptable diffs', default='diff')
Option('ok', 'Write out the diff file.')
# Change
#
# A Change object contains the previous lines, new news and change type.
#
class Change(object):
  def __init__(self, mode, was, now):
    self.mode = mode
    self.was = was
    self.now = now

  def Dump(self):
Beispiel #6
0
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
""" Generator for C-Sharp style binding definitions """

import glob
import os
import sys
import string

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles

Option('csgen_debug', 'Debug generate.')
Option('cs-enum_prefix', 'Suppress the enum prefix when generating.')


class CGenError(Exception):
    def __init__(self, msg):
        self.value = msg

    def __str__(self):
        return repr(self.value)


def CommentLines(lines, tabs=0):
    # Generate a C style comment block by prepending the block with '<tab>/*'
    # and adding a '<tab> *' per line.
    tab = '  ' * tabs
Beispiel #7
0
import glob
import os
import re
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLAttribute, IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_outfile import IDLOutFile
from idl_parser import ParseFiles
from idl_c_proto import CGen, GetNodeComments, CommentLines, Comment
from idl_generator import Generator, GeneratorByFile

Option('thunkroot', 'Base directory of output',
       default=os.path.join('..', 'thunk'))


class TGenError(Exception):
  def __init__(self, msg):
    self.value = msg

  def __str__(self):
    return repr(self.value)


class ThunkBodyMetadata(object):
  """Metadata about thunk body. Used for selecting which headers to emit."""
  def __init__(self):
    self._apis = set()
    self._includes = set()
Beispiel #8
0
#
# Try to load the ply module, if not, then assume it is in the third_party
# directory, relative to ppapi
#
try:
  from ply import lex
except:
  module_path, module_name = os.path.split(__file__)
  third_party = os.path.join(module_path, '..', '..', 'third_party')
  sys.path.append(third_party)
  from ply import lex

from idl_option import GetOption, Option, ParseOptions


Option('output', 'Generate output.')

#
# IDL Lexer
#
class IDLLexer(object):
  # 'tokens' is a value required by lex which specifies the complete list
  # of valid token types.
  tokens = [
    # Symbol and keywords types
      'COMMENT',
      'DESCRIBE',
      'ENUM',
      'LABEL',
      'SYMBOL',
      'INLINE',
Beispiel #9
0
import glob
import os
import re
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles
from idl_c_proto import CGen
from idl_c_header import GetHeaderFromNode, GenerateHeader
from idl_outfile import IDLOutFile

Option('debug', 'Debug generate.')

#API = namedtuple('API', ['interface', 'member', 'param'])

customAPIs = {
    ('PPB_CharSet_Dev', 'CharSetToUTF16', 'input'): {
        'array': True,
        'arrayType': 'uint8_t',
        'arraySize': 'input_len'
    },
    ('PPB_CharSet_Dev', 'CharSetToUTF16', 'rval'): {
        'convert':
        '  size_t length = iterator.expectArrayAndGotoFirstItem();\n  rval = new uint16_t[length];\n  for (size_t i = 0; i < length; ++i) {\n    FromJSON_uint16_t(iterator, rval[i]);\n  }\n'
    },
    ('PPB_Core', 'IsMainThread', None): {
        'maybeNonMainThread': True
Beispiel #10
0
class Generator(object):
  def __init__(self, name, sname, desc):
    self.name = name
    self.run_switch = Option(sname, desc)
    self.opt_switch = Option(sname + '_opt', 'Options for %s.' % sname,
                             default='')
    GeneratorList.append(self)
    self.errors = 0
    self.skip_list = []

  def Error(self, msg):
    ErrOut.Log('Error %s : %s' % (self.name, msg))
    self.errors += 1

  def GetRunOptions(self):
    options = {}
    option_list = self.opt_switch.Get()
    if option_list:
      option_list = option_list.split(',')
      for opt in option_list:
        offs = opt.find('=')
        if offs > 0:
          options[opt[:offs]] = opt[offs+1:]
        else:
          options[opt] = True
      return options
    if self.run_switch.Get():
      return options
    return None

  def Generate(self, ast, options):
    self.errors = 0

    rangestr = GetOption('range')
    releasestr = GetOption('release')

    print "Found releases: %s" % ast.releases

    # Generate list of files to ignore due to errors
    for filenode in ast.GetListOf('File'):
      # If this file has errors, skip it
      if filenode.GetProperty('ERRORS') > 0:
        self.skip_list.append(filenode)
        continue

    # Check for a range option which over-rides a release option
    if not releasestr and rangestr:
      range_list = rangestr.split(',')
      if len(range_list) != 2:
        self.Error('Failed to generate for %s, incorrect range: "%s"' %
                   (self.name, rangestr))
      else:
        vmin = range_list[0]
        vmax = range_list[1]

        # Generate 'start' and 'end' represent first and last found.
        if vmin == 'start':
            vmin = ast.releases[0]
        if vmax == 'end':
            vmax = ast.releases[-1]

        vmin = ast.releases.index(vmin)
        vmax = ast.releases.index(vmax) + 1
        releases = ast.releases[vmin:vmax]
        InfoOut.Log('Generate range %s of %s.' % (rangestr, self.name))
        ret = self.GenerateRange(ast, releases, options)
        if ret < 0:
          self.Error('Failed to generate range %s : %s.' %(vmin, vmax))
        else:
          InfoOut.Log('%s wrote %d files.' % (self.name, ret))
    # Otherwise this should be a single release generation
    else:
      if releasestr == 'start':
        releasestr = ast.releases[0]
      if releasestr == 'end':
        releasestr = ast.releases[-1]
      if releasestr:
        InfoOut.Log('Generate release %s of %s.' % (releasestr, self.name))
        ret = self.GenerateRelease(ast, releasestr, options)
        if ret < 0:
          self.Error('Failed to generate release %s.' % releasestr)
        else:
          InfoOut.Log('%s wrote %d files.' % (self.name, ret))

      else:
        self.Error('No range or release specified for %s.' % releasestr)
    return self.errors

  def GenerateRelease(self, ast, release, options):
    __pychecker__ = 'unusednames=ast,release,options'
    self.Error("Undefined release generator.")
    return 0

  def GenerateRange(self, ast, releases, options):
    __pychecker__ = 'unusednames=ast,releases,options'
    self.Error("Undefined range generator.")
    return 0

  @staticmethod
  def Run(ast):
    fail_count = 0

    # Check all registered generators if they should run.
    for gen in GeneratorList:
      options = gen.GetRunOptions()
      if options is not None:
        if gen.Generate(ast, options):
          fail_count += 1
    return fail_count
Beispiel #11
0
#!/usr/bin/env python
# Copyright (c) 2012 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.

import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles

GeneratorList = []

Option('release', 'Which release to generate.', default='')
Option('range', 'Which ranges in the form of MIN,MAX.', default='start,end')


#
# Generator
#
# Base class for generators.  This class provides a mechanism for
# adding new generator objects to the IDL driver.  To use this class
# override the GenerateRelease and GenerateRange members, and
# instantiate one copy of the class in the same module which defines it to
# register the generator.  After the AST is generated, call the static Run
# member which will check every registered generator to see which ones have
# been enabled through command-line options.  To enable a generator use the
# switches:
#  --<sname> : To enable with defaults
#  --<sname>_opt=<XXX,YYY=y> : To enable with generator specific options.
#
Beispiel #12
0
# Copyright (c) 2012 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.
""" Output file objects for generator. """

import difflib
import os
import time
import subprocess
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions
from stat import *

Option('diff', 'Generate a DIFF when saving the file.')


#
# IDLOutFile
#
# IDLOutFile provides a temporary output file.  By default, the object will
# not write the output if the file already exists, and matches what will be
# written.  This prevents the timestamp from changing to optimize cases where
# the output files are used by a timestamp dependent build system
#
class IDLOutFile(object):
    def __init__(self, filename, always_write=False, create_dir=True):
        self.filename = filename
        self.always_write = always_write
        self.create_dir = create_dir
Beispiel #13
0
import glob
import os
import re
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLAttribute, IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_outfile import IDLOutFile
from idl_parser import ParseFiles
from idl_cs_proto import CSGen, GetNodeComments, CommentLines, Comment
from idl_generator import Generator, GeneratorByFile
from idl_visitor import IDLVisitor

Option('cs_root', 'Base directory of output', default=os.path.join('..', 'peppersharp'))
Option('cs_guard', 'Include guard prefix', default=os.path.join('PepperSharp', 'c'))
Option('cs_namespace', 'Debug generate.', default='PepperSharp' )

#
# PrototypeResolver
#
# A specialized visitor which traverses the AST, building a mapping of
# Release names to Versions numbers and calculating a min version.
# The mapping is applied to the File nodes within the AST.
#
class ProtoResolver(IDLVisitor):
  def __init__(self):
    IDLVisitor.__init__(self)
    self.struct_map = {}
    self.interface_map = {}
Beispiel #14
0
between GCC and PNaCl.  """

from datetime import datetime
import difflib
import glob
import os
import sys

from idl_c_proto import CGen
from idl_gen_wrapper import Interface, WrapperGen
from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles

Option('pnaclshim',
       'Name of the pnacl shim file.',
       default='temp_pnacl_shim.c')

Option('disable_pnacl_opt', 'Turn off optimization of pnacl shim.')


class PnaclGen(WrapperGen):
    """PnaclGen generates shim code to bridge the Gcc ABI with PNaCl.

  This subclass of WrapperGenerator takes the IDL sources and
  generates shim methods for bridging the calling conventions between GCC
  and PNaCl (LLVM). Some of the PPAPI methods do not need shimming, so
  this will also detect those situations and provide direct access to the
  original PPAPI methods (rather than the shim methods).
  """
    def __init__(self):
Beispiel #15
0
#!/usr/bin/env python
# Copyright (c) 2012 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.

import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles

GeneratorList = []

Option('out', 'List of output files', default='')
Option('release', 'Which release to generate.', default='')
Option('range', 'Which ranges in the form of MIN,MAX.', default='start,end')


class Generator(object):
    """Base class for generators.

  This class provides a mechanism for adding new generator objects to the IDL
  driver.  To use this class override the GenerateRelease and GenerateRange
  members, and instantiate one copy of the class in the same module which
  defines it to register the generator.  After the AST is generated, call the
  static Run member which will check every registered generator to see which
  ones have been enabled through command-line options.  To enable a generator
  use the switches:
    --<sname> : To enable with defaults
    --<sname>_opt=<XXX,YYY=y> : To enable with generator specific options.
Beispiel #16
0
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
IDLNamespace for PPAPI

This file defines the behavior of the AST namespace which allows for resolving
a symbol as one or more AST nodes given a release or range of releases.
"""

import sys

from idl_option import GetOption, Option, ParseOptions
from idl_log import ErrOut, InfoOut, WarnOut
from idl_release import IDLRelease, IDLReleaseList

Option('label', 'Use the specifed label blocks.', default='Chrome')
Option('namespace_debug', 'Use the specified release')


#
# IDLNamespace
#
# IDLNamespace provides a mapping between a symbol name and an IDLReleaseList
# which contains IDLRelease objects.  It provides an interface for fetching
# one or more IDLNodes based on a release or range of releases.
#
class IDLNamespace(object):
    def __init__(self, parent):
        self.namespace = {}
        self.parent = parent
Beispiel #17
0
class Generator(object):
    """Base class for generators.

  This class provides a mechanism for adding new generator objects to the IDL
  driver.  To use this class override the GenerateRelease and GenerateRange
  members, and instantiate one copy of the class in the same module which
  defines it to register the generator.  After the AST is generated, call the
  static Run member which will check every registered generator to see which
  ones have been enabled through command-line options.  To enable a generator
  use the switches:
    --<sname> : To enable with defaults
    --<sname>_opt=<XXX,YYY=y> : To enable with generator specific options.

  NOTE:  Generators still have access to global options
  """
    def __init__(self, name, sname, desc):
        self.name = name
        self.run_switch = Option(sname, desc)
        self.opt_switch = Option(sname + '_opt',
                                 'Options for %s.' % sname,
                                 default='')
        GeneratorList.append(self)
        self.errors = 0
        self.skip_list = []

    def Error(self, msg):
        ErrOut.Log('Error %s : %s' % (self.name, msg))
        self.errors += 1

    def GetRunOptions(self):
        options = {}
        option_list = self.opt_switch.Get()
        if option_list:
            option_list = option_list.split(',')
            for opt in option_list:
                offs = opt.find('=')
                if offs > 0:
                    options[opt[:offs]] = opt[offs + 1:]
                else:
                    options[opt] = True
            return options
        if self.run_switch.Get():
            return options
        return None

    def Generate(self, ast, options):
        self.errors = 0

        rangestr = GetOption('range')
        releasestr = GetOption('release')

        print "Found releases: %s" % ast.releases

        # Generate list of files to ignore due to errors
        for filenode in ast.GetListOf('File'):
            # If this file has errors, skip it
            if filenode.GetProperty('ERRORS') > 0:
                self.skip_list.append(filenode)
                continue

        # Check for a range option which over-rides a release option
        if not releasestr and rangestr:
            range_list = rangestr.split(',')
            if len(range_list) != 2:
                self.Error('Failed to generate for %s, incorrect range: "%s"' %
                           (self.name, rangestr))
            else:
                vmin = range_list[0]
                vmax = range_list[1]

                # Generate 'start' and 'end' represent first and last found.
                if vmin == 'start':
                    vmin = ast.releases[0]
                if vmax == 'end':
                    vmax = ast.releases[-1]

                vmin = ast.releases.index(vmin)
                vmax = ast.releases.index(vmax) + 1
                releases = ast.releases[vmin:vmax]
                InfoOut.Log('Generate range %s of %s.' % (rangestr, self.name))
                ret = self.GenerateRange(ast, releases, options)
                if ret < 0:
                    self.Error('Failed to generate range %s : %s.' %
                               (vmin, vmax))
                else:
                    InfoOut.Log('%s wrote %d files.' % (self.name, ret))
        # Otherwise this should be a single release generation
        else:
            if releasestr == 'start':
                releasestr = ast.releases[0]
            if releasestr == 'end':
                releasestr = ast.releases[-1]

            if releasestr > ast.releases[-1]:
                InfoOut.Log(
                    'There is no unique release for %s, using last release.' %
                    releasestr)
                releasestr = ast.releases[-1]

            if releasestr not in ast.releases:
                self.Error('Release %s not in [%s].' %
                           (releasestr, ', '.join(ast.releases)))

            if releasestr:
                InfoOut.Log('Generate release %s of %s.' %
                            (releasestr, self.name))
                ret = self.GenerateRelease(ast, releasestr, options)
                if ret < 0:
                    self.Error('Failed to generate release %s.' % releasestr)
                else:
                    InfoOut.Log('%s wrote %d files.' % (self.name, ret))

            else:
                self.Error('No range or release specified for %s.' %
                           releasestr)
        return self.errors

    def GenerateRelease(self, ast, release, options):
        __pychecker__ = 'unusednames=ast,release,options'
        self.Error("Undefined release generator.")
        return 0

    def GenerateRange(self, ast, releases, options):
        __pychecker__ = 'unusednames=ast,releases,options'
        self.Error("Undefined range generator.")
        return 0

    @staticmethod
    def Run(ast):
        fail_count = 0

        # Check all registered generators if they should run.
        for gen in GeneratorList:
            options = gen.GetRunOptions()
            if options is not None:
                if gen.Generate(ast, options):
                    fail_count += 1
        return fail_count
Beispiel #18
0
# Copyright (c) 2012 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.
"""
IDLRelease for PPAPI

This file defines the behavior of the AST namespace which allows for resolving
a symbol as one or more AST nodes given a Release or range of Releases.
"""

import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions

Option('release_debug', 'Debug Release data')
Option('wgap', 'Ignore Release gap warning')

#
# Module level functions and data used for testing.
#
error = None
warning = None


def ReportReleaseError(msg):
    global error
    error = msg


def ReportReleaseWarning(msg):
Beispiel #19
0
# Copyright (c) 2011 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.
""" Generator for C style prototypes and definitions """

import glob
import os
import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_node import IDLNode
from idl_ast import IDLAst
from idl_option import GetOption, Option, ParseOptions
from idl_parser import ParseFiles

Option('cgen_debug', 'Debug generate.')


class CGenError(Exception):
    def __init__(self, msg):
        self.value = value

    def __str__(self):
        return repr(self.value)


def CommentLines(lines, tabs=0):
    # Generate a C style comment block by prepending the block with '<tab>/*'
    # and adding a '<tab> *' per line.
    tab = '  ' * tabs
import os.path
import re
import sys
import time

from idl_ast import IDLAst
from idl_log import ErrOut, InfoOut, WarnOut
from idl_lexer import IDLLexer
from idl_node import IDLAttribute, IDLFile, IDLNode
from idl_option import GetOption, Option, ParseOptions
from idl_lint import Lint

from ply import lex
from ply import yacc

Option('build_debug', 'Debug tree building.')
Option('parse_debug', 'Debug parse reduction steps.')
Option('token_debug', 'Debug token generation.')
Option('dump_tree', 'Dump the tree.')
Option('srcroot', 'Working directory.', default=os.path.join('..', 'api'))
Option('include_private',
       'Include private IDL directory in default API paths.')

#
# ERROR_REMAP
#
# Maps the standard error formula into a more friendly error message.
#
ERROR_REMAP = {
    'Unexpected ")" after "(".': 'Empty argument list.',
    'Unexpected ")" after ",".': 'Missing argument.',
Beispiel #21
0
#!/usr/bin/python
#
# Copyright (c) 2011 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.

import sys

from idl_log import ErrOut, InfoOut, WarnOut
from idl_option import GetOption, Option, ParseOptions

GeneratorList = []

Option('release', 'Which release to generate.', default='')
Option('range', 'Which ranges in the form of MIN,MAX.', default='M13,M16')

#
# Generator
#
# Base class for generators.  This class provides a mechanism for
# adding new generator objects to the IDL driver.  To use this class
# override the GenerateRelease and GenerateRange members, and
# instantiate one copy of the class in the same module which defines it to
# register the generator.  After the AST is generated, call the static Run
# member which will check every registered generator to see which ones have
# been enabled through command-line options.  To enable a generator use the
# switches:
#  --<sname> : To enable with defaults
#  --<sname>_opt=<XXX,YYY=y> : To enable with generator specific options.
#
# NOTE:  Generators still have access to global options