示例#1
0
文件: Block.py 项目: csdms/cca-bocca
    def computeSignature(self, symbol, language, sourcekey, withcomment=False):
        """return attempted guess at the number of lines at the end of the
block that constitute a babel impl method signature.
The block being checked is the block before the block with the symbol code body.
@param language one of python, java, c, cxx, f77, f90. 
@param sourceKey the key, not symbol, of interest.
@param withcomment try to include the comment block if any.
"""
        result = 0
        lines = self.getLines()
        p = len(lines)-1
        if p < 1:
            return 0
        line = lines[p]
        if language == "python":
            while p >= 0 and line[0:4] != "####" and line[0:6] != "  def " and \
                  not Line.keyEnds(sourcekey, line) and \
                  not Line.keyBegins(sourcekey,line):
                # break on 2 blank lines
                if len(line) == 0:
                    q = p -1
                    if q >= 0 and len(lines[q]) == 0:
                        break
                # else keep line, move on to next
                result += 1
                p -= 1
                line = lines[p]
            result += 1 ; # include '  def ' line.
            # python comment blocks are embedded, not extra.
        if language == "java":
            while p > 0 and len(line) != 0 and \
                line[0:6] != "import" and \
                line[0:8] != "  public" and \
                line[0:4] != "////" and \
                line[0:3] != "/**" and \
                line[0:5] != "   */" and \
                line[0:8] != "  static" and \
                not Line.keyEnds(sourcekey, line) and \
                not Line.keyBegins(sourcekey,line):
                result += 1
                p -= 1
                line = lines[p]
            result += 1 ; # include '  public' line.
            if withcomment:
                while p > 0 and len(line) != 0 and \
                    line[0:5] != "  /**" and \
                    not Line.keyEnds(sourcekey, line) and \
                    not Line.keyBegins(sourcekey,line):
                    result +=1
                    p -= 1
                    line = lines[p]

        if language == "c" or language == "cxx":
            while p > 0 and \
                not Line.cppDirective(line) and \
                line[0:15] != "// user defined" and \
                line[0:15] != "// static class"  and \
                line[0:3] != "/**"  and \
                line[0:3] != " */"  and \
                line[0:5] != "   */"  and \
                line[0:22] != "// special constructor"  and \
                line[0:22] != "// speical constructor" and \
                line[0:1] != "}"  and \
                line[0:8] != "////////"  and \
                line[0:8] != "/**//**/" and \
                not Line.keyEnds(sourcekey, line) and \
                not Line.keyBegins(sourcekey,line):

                # two blank lines, or 1 if _tail symbol
                if len(line) == 0:
                    mname = Line.methodName(symbol)
                    if mname[0] == "_":
                        break
                    q = p-1
                    if q >= 0 and len(lines[q]) == 0:
                        break
                # else keep line and move on
                result += 1
                p -= 1
                line = lines[p]
            if withcomment:
                while p > 0 and len(line) != 0 and \
                    line[0:5] != "  /**" and \
                    line[0:2] != "/*" and \
                    not Line.keyEnds(sourcekey, line) and \
                    not Line.keyBegins(sourcekey,line):
                    result +=1
                    p -= 1
                    line = lines[p]
                result += 1 ; # include '(  )/*(*)' line.

        if language == "f77" or language == "f77_31":
            while p > 0 and \
                line[0:19] != "        subroutine " and \
                line[0:4] != "CCCC" and \
                not Line.keyEnds(sourcekey, line) and \
                not Line.keyBegins(sourcekey,line):

                # break on 2 blank lines
                if len(line) == 0:
                    q = p -1
                    if q >= 0 and len(lines[q]) == 0:
                        break
                # else keep line and move on
                result += 1
                p -= 1
                line = lines[p]
            result += 1 ; # include subroutine
            if withcomment:
                while p > 0 and len(line) != 0 and \
                    line[0:15] != "C       Method:" and \
                    not Line.keyEnds(sourcekey, line) and \
                    not Line.keyBegins(sourcekey,line):
                    result +=1
                    p -= 1
                    line = lines[p]

        if language == "f90":
            while p > 0 and \
                line[0:21] != "recursive subroutine " and \
                line[0:5] != "!!!!" and \
                not Line.keyEnds(sourcekey, line) and \
                not Line.keyBegins(sourcekey,line):

                # break on 2 blank lines
                if len(line) == 0:
                    q = p -1
                    if q >= 0 and len(lines[q]) == 0:
                        break
                # else keep line and move on
                result += 1
                p -= 1
                line = lines[p]
            result += 1 ; # include subroutine
            if withcomment:
                while p > 0 and len(line) != 0 and \
                    line[0:9] != "! Method:" and \
                    not Line.keyEnds(sourcekey, line) and \
                    not Line.keyBegins(sourcekey,line):
                    result +=1
                    p -= 1
                    line = lines[p]

        return result
示例#2
0
文件: Misc.py 项目: csdms/cca-bocca
def isCommon(sym, commonSuppressions):
    """returns True if symbol matches commonSuppressions entry."""
    method = Line.methodName(sym)
    if method in commonSuppressions:
        return True
    return False