Beispiel #1
0
def codeIsEQ(item, objsRefed, returnType, xlator):
    #print '      IsEq item:', item
    [S, retTypeSpec] = codeComparison(item[0], objsRefed, returnType, xlator)
    if len(item) > 1 and len(item[1]) > 0:
        if len(item[1]) > 1:
            print "Error: Chained == or !=.\n"
            exit(1)
        if (isinstance(retTypeSpec, int)):
            cdlog(logLvl(), "Invalid item in ==: {}".format(item[0]))
        leftOwner = owner = progSpec.getTypeSpecOwner(retTypeSpec)
        for i in item[1]:
            #print '      IsEq ', i
            if (i[0] == '=='): op = ' == '
            elif (i[0] == '!='): op = ' != '
            elif (i[0] == '==='): op = ' == '
            else:
                print "ERROR: '==' or '!=' or '===' expected."
                exit(2)
            [S2, retType2] = codeComparison(i[1], objsRefed, returnType,
                                            xlator)
            rightOwner = progSpec.getTypeSpecOwner(retType2)
            if not isinstance(retTypeSpec, basestring) and isinstance(
                    retTypeSpec['fieldType'], basestring) and isinstance(
                        retType2, basestring):
                if retTypeSpec[
                        'fieldType'] == "char" and retType2 == "string" and S2[
                            0] == '"':
                    S2 = "'" + S2[1:-1] + "'"
            if i[0] == '===':
                S = S + " == " + S2
            else:
                S += op + S2
            retTypeSpec = 'bool'
    return [S, retTypeSpec]
Beispiel #2
0
def AddToObjectFromText(ProgSpec, clsNames, inputStr, description):
    macroDefs = {} # This var is not used here. If needed, make it an argument.
    inputStr = comment_remover(inputStr)
    #print '####################\n',inputStr, "\n######################^\n\n\n"
    errLevl=logLvl(); cdlog(errLevl, 'Parsing: '+description)
    progSpec.saveTextToErrFile(inputStr)
    # (map of classes, array of objectNames, string to parse)
    try:
        results = objectList.parseString(inputStr, parseAll = True)
    except ParseException , pe:
        cdErr( "Error parsing generated class {}: {}".format(description, pe))
Beispiel #3
0
def parseCodeDogString(inputString, ProgSpec, clsNames, macroDefs, description):
    tmpMacroDefs={}
    inputString = comment_remover(inputString)
    extractMacroDefs(tmpMacroDefs, inputString)
    inputString = doMacroSubstitutions(tmpMacroDefs, inputString)
    LogLvl=logLvl()
    cdlog(LogLvl, "PARSING: "+description+"...")
    results = parseInput(inputString)
    cdlog(LogLvl, "EXTRACTING: "+description+"...")
    tagStore = extractTagDefs(results.tagDefList)
    buildSpecs = extractBuildSpecs(results.buildSpecList)
    newClasses = extractObjectsOrPatterns(ProgSpec, clsNames, macroDefs, results.objectList)
    classes = [ProgSpec, clsNames]
    return[tagStore, buildSpecs, classes, newClasses]
Beispiel #4
0
def extractFieldDefs(ProgSpec, className, stateType, fieldResults):
    cdlog(logLvl(), "EXTRACTING {}".format(className))
    for fieldResult in fieldResults:
        fieldDef = packFieldDef(fieldResult, className, '')
        progSpec.addField(ProgSpec, className, stateType, fieldDef)