Commit 957d90b7 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixed a bug in PyXASM token collector



If 'for' is the very *first* token, the check for `kw_for` may be missed hence causing tokens to be cramped.

Hence, processing the loop from the first token rather than the next.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent fbe1ccf3
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -55,9 +55,8 @@ void PyXasmTokenCollector::collect(clang::Preprocessor &PP,
  std::vector<std::pair<std::string, int>> lines;
  std::string line = "";
  auto current_line_number = sm.getSpellingLineNumber(Toks[0].getLocation());
  line += PP.getSpelling(Toks[0]);
  int last_col_number = 0;
  for (int i = 1; i < Toks.size(); i++) {
  for (int i = 0; i < Toks.size(); i++) {
    // std::cout << PP.getSpelling(Toks[i]) << "\n";
    auto location = Toks[i].getLocation();
    auto col_number = sm.getSpellingColumnNumber(location);
+12 −1
Original line number Diff line number Diff line
@@ -120,5 +120,16 @@ class TestSimpleKernelJIT(unittest.TestCase):
        comp = kernelExpVar.extract_composite(q, theta)
        self.assertEqual(comp.nInstructions(), 14)

    # Test of edge case where the first statement is a for loop
    def test_for_loop(self):
        @qjit
        def testFor(q : qreg):
            for i in range(q.size()):
                H(q[i])
        
        q = qalloc(5)
        comp = testFor.extract_composite(q)
        self.assertEqual(comp.nInstructions(), 5)   

if __name__ == '__main__':
  unittest.main()
 No newline at end of file