<commit_before># <NAME> (<EMAIL>)
# Verify obligations to ensure that they compile. 
# If they do not, comment them out and replace with dummy score.

# Command line options:
# -s <program filename>
# -o <output filename, if different from suite filename>

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import getopt
import sys
import os
from subprocess import Popen, call, PIPE, STDOUT

class Verifier(): 

    # Text of instrumented program
    program = []

    # Imports the instrumented program
    def importProgram(self,fileName):
        code = open(fileName, "r")

        for line in code:
            self.program.append(line)

        code.close()

    # Write the program to a file
    def writeProgram(self,outFile):
        where = open(outFile, "w")

        for line in self.program:
            where.write(line)
 
        where.close()

    # Identify the obligations to fix
    def getObligationList(self, errorMessage):
        obligations = []
        # Get each line with the word error in it.
        lines = errorMessage.split("error:")
        for line in lines:
            words = line.split(" ")
            for word in words:
                # Look for the obligation expression
                if "obligation" in word and "=" in word:
                    parts = word.split("=")
                    if parts[0] not in obligations:
                        obligations.append(parts[0])

        return obligations

    # Fix obligations in program
    def fixObligations(self, obligations):
        for entry in range(0,len(self.program)):
            if "obligations[" in self.program[entry]:
                words = self.program[entry].split("=")
                if words[0] in obligations:
                    self.program[entry] = "// Removed as non-compiling\n" + "// " + self.program[entry] + words[0] + " = 1000000;\n"

    # Performs verification on a suite already in-memory
    def verify(self, fileName, outFile):
        self.importProgram(fileName)

        # Compile and attempt to run the suite.
        (output, error) = self.compileProgram(outFile)

        while error != "":
            if "obligations" in error:
                print "Compilation error - attempting to fix obligations"
                obligations = self.getObligationList(error)
                print obligations
                self.fixObligations(obligations)
                (output, error) = self.compileProgram(outFile)
            else:
                raise Exception("Compilation error due to non-obligation issue:\n" + error)

    # Compiles and runs suite
    def compileProgram(self, fileName):
        self.writeProgram(fileName)

        if os.path.isfile(fileName):
            path = os.path.dirname(fileName)
            rmProcess = Popen("rm a.out", stdout = PIPE, stderr = PIPE, shell = True)
            (rOutput, eError) = rmProcess.communicate()
            compileProcess = Popen("gcc " + fileName, stdout = PIPE, stderr = PIPE, shell=True)
            (cOutput, cError) = compileProcess.communicate()
            return (cOutput, cError)        
        else:
            raise Exception("The program file does not exist.")
<commit_msg>Adjusts instrumentation verification to ignore warnings<commit_after># <NAME> (<EMAIL>)
# Verify obligations to ensure that they compile. 
# If they do not, comment them out and replace with dummy score.

# Command line options:
# -s <program filename>
# -o <output filename, if different from suite filename>

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import getopt
import sys
import os
from subprocess import Popen, call, PIPE, STDOUT

class Verifier(): 

    # Text of instrumented program
    program = []

    # Imports the instrumented program
    def importProgram(self,fileName):
        code = open(fileName, "r")

        for line in code:
            self.program.append(line)

        code.close()

    # Write the program to a file
    def writeProgram(self,outFile):
        where = open(outFile, "w")

        for line in self.program:
            where.write(line)
 
        where.close()

    # Identify the obligations to fix
    def getObligationList(self, errorMessage):
        obligations = []
        # Get each line with the word error in it.
        lines = errorMessage.split("error:")
        for line in lines:
            words = line.split(" ")
            for word in words:
                # Look for the obligation expression
                if "obligation" in word and "=" in word:
                    parts = word.split("=")
                    if parts[0] not in obligations:
                        obligations.append(parts[0])

        return obligations

    # Fix obligations in program
    def fixObligations(self, obligations):
        for entry in range(0,len(self.program)):
            if "obligations[" in self.program[entry]:
                words = self.program[entry].split("=")
                if words[0] in obligations:
                    self.program[entry] = "// Removed as non-compiling\n" + "// " + self.program[entry] + words[0] + " = 1000000;\n"

    # Performs verification on a suite already in-memory
    def verify(self, fileName, outFile):
        self.importProgram(fileName)

        # Compile and attempt to run the suite.
        (output, error) = self.compileProgram(outFile)

        while error != "" and "error:" in error:
            if "obligations" in error:
                print "Compilation error - attempting to fix obligations"
                obligations = self.getObligationList(error)
                print obligations
                self.fixObligations(obligations)
                (output, error) = self.compileProgram(outFile)
            else:
                print "Compilation error due to non-obligation issue:\n" + error
                error = ""

    # Compiles and runs suite
    def compileProgram(self, fileName):
        self.writeProgram(fileName)

        if os.path.isfile(fileName):
            path = os.path.dirname(fileName)
            compileProcess = Popen("gcc " + fileName + " -lm", stdout = PIPE, stderr = PIPE, shell=True)
            (cOutput, cError) = compileProcess.communicate()
            rmProcess = Popen("rm a.out", stdout = PIPE, stderr = PIPE, shell = True)
            (rOutput, eError) = rmProcess.communicate()
            return (cOutput, cError)        
        else:
            raise Exception("The program file does not exist.")

{'fraction_non_alphanumeric': 0.09482886353533856, 'fraction_numerical': 0.004741443176766928, 'mean_word_length': 2.1149053991693587, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5661271', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1797, 'n_words': 611}