Пример #1
0
def parseAccess(acDb, accesDict, invEntityDict, attrDict, typedefDict, transInhDict, scope, referenceLinesRecognizedAsAccesses, output_file):
    # TODO this really, really needs to be refactored
    common.famix.cdifReader.buildAttributeCache(output_file)
    common.famix.cdifReader.buildGlobalVarCache(output_file)

    # build local var cache
    localVarCache = EntityCacheFactory.buildAndReturnLocalVarCacheFromDb(acDb)

    accessResolver = AlternativeAccessResolver(scope, transInhDict, typedefDict, invEntityDict, attrDict)

    lineNr = 0
    for line in open(acDb, "r"):
        if not isPotentialAccess(line):
            lineNr += 1
            continue

        access = AccessEntity(line)
        access.decomposeData()

        if accessResolver.resolve(access):
            accesDict.add(access.sourceFile, access.start, access.dst_class)
            aCommandList = RuleChecker.checkAccessEntity(access)

            if not(not aCommandList):
                RuleChecker.generateAccessInfo(aCommandList, access)
                referenceLinesRecognizedAsAccesses.append(lineNr)
        else:
            access.getReport().logIfFlawed()

        lineNr += 1

    return lineNr
Пример #2
0
def parseInvocations(referencesFileName, accessDict, invokeableEntityDict, \
                        typedefDict, transIncludeDict, transInhDict,scope, \
                        referenceLinesRecognizedAsAccesses):
    resolver = AlternativeInvocationResolver(scope, transInhDict, typedefDict, \
                                            invokeableEntityDict, accessDict)
    lineNr = 0

    nrOfLinesProcessed = 0
    for line in open(referencesFileName, "r"):
        if not(lineNr in referenceLinesRecognizedAsAccesses) and isPotentialInvocation(line):
            nrOfLinesProcessed += 1
            inv = InvocationEntity(line, invokeableEntityDict)
            inv.decomposeData()
            #print "------"
            #print line,
            #print inv.dst_class+"|"+inv.dst_name+"|"+inv.dst_type+"|"+inv.actualDstParams+"|"+inv.sourceFile+"|"+inv.start
            #print inv.src_class+"|"+inv.src_name+"|"+inv.src_type+"|"+inv.actualSrcParams+"|"+inv.sourceFile+"|"+inv.start
            #print "-------"
            resolver.resolve(inv)

            if ( inv.isCompletelyResolved() ):
                aCommandList = RuleChecker.checkMethInvEntity(inv)
                RuleChecker.generateMethodInvocationInfo(aCommandList, inv)
            else:
                inv.getReport().logIfFlawed()

        lineNr += 1

    return nrOfLinesProcessed
Пример #3
0
def parseAttributes(attributeDBD, classSelector, attributeDictFiller, namespaceContainmentChecker):

    for line in open(attributeDBD, 'r'):
        attribute = AttributeEntity(line)
        attrRef = attribute.getReference()

        sourceLoc = SourceLocation(attrRef.getSourceFile(),\
                                        attrRef.getLineNr(),\
                                        attrRef.getLineNr())
        namespaceName = namespaceContainmentChecker.getSurroundingNamespaceName(sourceLoc)

        attribute.setNamespaceName(namespaceName)
        attrRef = attribute.getReference()

        parentRef = attribute.getParentReference()
        potentialTargets = classSelector.selectClasses(parentRef.getReferencedName(), attrRef.getSourceFile(), attrRef.getLineNr())
        nrOfTargets = len(potentialTargets)

        if ( nrOfTargets > 1 ):
            log.warn("Attribute-owner-problem: ",nrOfTargets," classes with name \"" + parentRef.getReferencedName() + ".")
            continue # ignore containment link since we can't pinpoint the target.
        elif ( nrOfTargets == 0 ):
            log.warn("Attribute-owner-problem: no class with name \"" + parentRef.getReferencedName() + "\" known from file ",attrRef.getSourceFile(),"@",attrRef.getLineNr(),".")
            # seems to happen for inner-classes, e.g. owner named SpreadsheetApp::Group
            continue # ignore containment link since we can't find the declaration of the owner.
        else:
            # get the data on the sole left-over attribute-owner
            classReference = potentialTargets[0]
            parentRef.setSourceFile(classReference.getSourceFile())
            parentRef.setLineNr(classReference.getLineNr())
            attribute.ownerTemplateParameters=classReference.getTemplateParameters()

        # resolve the attribute type
        typeRef = attribute.getTypeReference()

        if not(typeRef.isPrimitive()):
            potentialTargets = classSelector.selectClasses(typeRef.getCleanName(),\
                                                     attrRef.getSourceFile(), attrRef.getLineNr())
            nrOfTargets = len(potentialTargets)

            if ( nrOfTargets > 1 ):
                pass
                #log.warn("Attribute-type-problem: ",nrOfTargets," classes with name \""\
                #         + typeRef.getCleanName() + ".")
                typeRef.setResolvedName(typeRef.getCleanName())
            elif ( nrOfTargets == 0 ):
                pass
                #log.warn("Attribute-type-problem: no class with name \"" \
                #        + typeRef.getCleanName() + "\" known from file ",\
                #        attrRef.getSourceFile(),"@",attrRef.getLineNr(),".")
                typeRef.setResolvedName(typeRef.getCleanName())
            else:
                # get the data on the sole left-over method-type
                classReference = potentialTargets[0]

                typeRef.setResolvedName(classReference.getUniqueName())
                typeRef.setSourceFile(classReference.getSourceFile())
                typeRef.setLineNr(classReference.getLineNr())

                # TODO: fill in the attribute type template parameters
        else:
            typeRef.setResolvedName(typeRef.getCleanName())
        
        attrRef = attribute.getReference()

        # TODO: also put the attribute type in the attribute dictionary, so that it can be passed
        # on to the access-dictionary when accesses are resolved. That way, the resolution of
        # further accesses invocations

        aCommandList = RuleChecker.checkAttributeEntity(attribute)
        RuleChecker.generateAttributeInfo(aCommandList, attribute)
        attributeDictFiller.add(attribute)