Example #1
0
  def __init__(self, paths = None, header = None):

    KLManager.__instance = self
    self.__klExtensions = {}
    self.__klFiles = {}
    self.__constants = {}
    self.__aliases = {}
    self.__types = {}
    self.__freeFunctions = {}
    self.__freeFunctionLookup = {}
    self.__header = header
    if self.__header is None:
      self.__header = []
      self.__header += [".. image:: /images/FE_logo_345_60.*"]
      self.__header += ["   :width: 345px"]
      self.__header += ["   :height: 60px"]
      self.__header += [""]
      self.__header += ["| |FABRIC_PRODUCT_NAME| version |FABRIC_VERSION|"]
      self.__header += ["| |FABRIC_COPYRIGHT|"]
    self.__unresolvedMethods = []

    if paths is None:
      paths = [os.environ['FABRIC_EXTS_PATH'].split(os.pathsep)[0]]

    for path in paths:
      for root, dirnames, filenames in os.walk(path):
        for filename in fnmatch.filter(filenames, '*.fpm.json'):
          fullpath = os.path.join(root, filename)
          if self.__klExtensions.has_key(fullpath):
            continue
          if fullpath.find('NoRedist') > -1:
            continue
          if fullpath.find('NoInstaller') > -1:
            continue
          self.__klExtensions[fullpath] = KLExtension(fullpath, self)
          self.__klFiles.update(self.__klExtensions[fullpath]._getKLFilesDict())

    for m in self.__unresolvedMethods:

      thisType = m.getThisType()
      if thisType == None:
        continue

      T = self.getType(thisType)
      if T is None:
        T = KLStruct({'name': thisType, 'members': []})
        T.setExtension(m.getExtension())
        T.setKLFile(m.getKLFile())
        F = self.getKLFile(m.getKLFile())
        if F:
          F._registerType(T)
        self._registerType(T)
        
      elif m.getKLFile() != T.getKLFile():
        F = self.getKLFile(m.getKLFile())
        if F:
          F._registerType(T)

      T._addMethod(m)
Example #2
0
    def __init__(self, fileName, extension=None, manager=None):

        self.__fileName = fileName

        # try if this file exists as an original
        jsonFolder = os.path.split(extension.getFilePath())[0]
        relFolder = jsonFolder
        try:
            relFolder = os.path.relpath(
                jsonFolder,
                os.environ['FABRIC_EXTS_PATH'].split(os.pathsep)[0])
        except ValueError as e:
            pass

        # hmathee: FE-4549: disabling this - doesn't seem to be required anymore
        # sgDir = os.path.join(os.environ['FABRIC_SCENE_GRAPH_DIR'], 'Native', 'Exts', relFolder)
        # if os.path.exists(sgDir):
        #   relPath = os.path.relpath(self.__fileName, jsonFolder)
        #   fullPath = os.path.join(sgDir, relPath)
        #   if os.path.exists(fullPath):
        #     self.__fileName = fullPath

        self.__extension = extension
        self.__manager = manager

        if KLFile.__client is None:
            KLFile.__client = FabricEngine.Core.createClient()

        if KLFile.__tableLine is None:
            KLFile.__nameLine = '------------------------------'
            KLFile.__tableLine = '=============================='

        content = open(self.__fileName).read()
        try:
            data = json.loads(
                KLFile.__client.getKLJSONAST(self.__fileName, content,
                                             False).getStringCString())
        except Exception as e:
            message = 'Failed to parse "%s"\n%s' % (self.__fileName, e)
            if manager:
                manager.reportError(message)
                return
            else:
                raise Exception(message)

        data = [
            data
        ]  # we are not expanding into requires, so let's make a double list

        self.__decls = []
        self.__types = {}
        self.__constants = {}
        self.__requires = []
        self.__aliases = {}

        allTypes = KLStruct.getAll()

        elementListIndex = 0
        while elementListIndex < len(data):
            elementList = data[elementListIndex]
            elementListIndex = elementListIndex + 1
            ast = elementList['ast']
            for element in ast:
                et = element['type']
                if et == 'RequireGlobal':
                    self.__requires += [element['requires'][0]['name']]
                elif et == 'GlobalConstDecl':
                    if not element.has_key('name'):
                        continue
                    decl = KLConstant(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__decls += [decl]
                    self.__constants[decl.getName()] = decl
                    if self.__manager:
                        self.__manager._registerConstant(decl)
                elif et == "ComparisonOpImpl" or et == "AssignOpImpl" or et == "BinOpImpl" or et == "ASTUniOpDecl":
                    decl = KLTypeOp(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    thisType = decl.getLhs()
                    if thisType and self.__types.has_key(thisType):
                        self.__types[thisType]._addOperator(decl)
                    self.__decls += [decl]
                elif et == "ASTStructDecl":
                    if not element.has_key(
                            'members'):  # filter out forward decl
                        continue
                    decl = KLStruct(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__types[decl.getName()] = decl
                    if self.__manager:
                        self.__manager._registerType(decl)
                elif et == "ASTObjectDecl":
                    if not element.has_key(
                            'members'):  # filter out forward decl
                        continue
                    decl = KLObject(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__types[decl.getName()] = decl
                    if self.__manager:
                        self.__manager._registerType(decl)
                elif et == "ASTInterfaceDecl":
                    decl = KLInterface(element)
                    if not element.has_key(
                            'members'):  # filter out forward decl
                        continue
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__types[decl.getName()] = decl
                    if self.__manager:
                        self.__manager._registerType(decl)
                elif et == "Function":
                    decl = KLFunction(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)

                    # check if this is a constructor
                    thisType = decl.getName().strip('~')
                    if allTypes.has_key(thisType):
                        decl = KLMethod(element, thisType=thisType)
                        decl.setExtension(self.__extension)
                        decl.setKLFile(self.__fileName)
                        allTypes[thisType]._addMethod(decl)
                    elif self.__manager:
                        self.__manager._registerFreeFunction(decl)
                    self.__decls += [decl]
                elif et == "MethodOpImpl":
                    decl = KLMethod(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__decls += [decl]
                    thisType = decl.getThisType()

                    # deal with standard types
                    if thisType == 'String' and not allTypes.has_key(thisType):
                        stringDecl = KLStruct({
                            'name': 'String',
                            'members': []
                        })
                        stringDecl.setExtension(self.__extension)
                        stringDecl.setKLFile(self.__fileName)
                        self.__types[thisType] = stringDecl
                        self.__decls += [stringDecl]
                        if self.__manager:
                            self.__manager._registerType(stringDecl)

                    if thisType and allTypes.has_key(thisType):
                        allTypes[thisType]._addMethod(decl)

                        if self.__fileName != allTypes[thisType].getKLFile(
                        ) and self.__manager:
                            self._registerType(allTypes[thisType])

                    else:
                        manager.registerUnresolvedMethod(decl)

                elif et == "Destructor":
                    decl = KLFunction(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    thisType = decl.getName().strip('~')
                    decl = KLMethod(element, thisType=thisType)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__types[thisType]._addMethod(decl)
                    self.__decls += [decl]
                elif et == "Operator":
                    decl = KLOperator(element)
                    decl.setExtension(self.__extension)
                    decl.setKLFile(self.__fileName)
                    self.__decls += [decl]
                elif et == "Alias":
                    self.__aliases[
                        element['newUserName']] = element['oldUserName']
                    if self.__manager:
                        self.__manager._registerAlias(element['oldUserName'],
                                                      element['newUserName'])
                elif et == 'ASTFileGlobal':
                    globalElements = {"ast": element['globalList']}
                    data += [globalElements]
                else:
                    print "Unsupported type: " + et
                    pass