Beispiel #1
0
def is_same_line(loc1, loc2):
    """Return True iff loc1 and loc2 point to the same line in the
    same file."""
    fe = thin.Location_To_File(loc1)
    if fe != thin.Location_To_File(loc2):
        return False
    line = thin.Location_File_To_Line(loc1, fe)
    return line == thin.Location_File_To_Line(loc2, fe)
Beispiel #2
0
 def chk_line_or_col(self, n, def_loc, loc):
     fe = thin.Location_To_File(def_loc)
     l_fe = thin.Location_To_File(loc)
     assert fe == l_fe, "non-matching file location {} vs {}".format(
         def_loc, loc)
     def_line = thin.Location_File_To_Line(def_loc, fe)
     line = thin.Location_File_To_Line(loc, fe)
     if line == def_line:
         return
     def_col = thin.Location_File_Line_To_Col(def_loc, fe, def_line)
     col = thin.Location_File_Line_To_Col(loc, fe, line)
     if def_col != col:
         self.error(
             utils.Location.from_location(loc),
             "indentation: must be at col {} instead of {}".format(
                 def_col, col))
 def check_parenthesis(self, expr):
     if expr == thin.Null_Iir:
         # For else clause.
         return
     if iirs.Get_Kind(expr) != iirs.Iir_Kind.Parenthesis_Expression:
         return
     left_loc = iirs.Get_Location(expr)
     right_loc = elocations.Get_Right_Paren_Location(expr)
     fe = thin.Location_To_File(left_loc)
     assert fe == thin.Location_To_File(right_loc)
     left_line = thin.Location_File_To_Line(left_loc, fe)
     right_line = thin.Location_File_To_Line(right_loc, fe)
     if left_line != right_line:
         # Assume that's for grouping
         return
     self.error(Location.from_node(expr),
                "useless parenthesis around expression")
Beispiel #4
0
 def chk_level(self, n, loc, level):
     if loc == thin.No_Location:
         return
     fe = thin.Location_To_File(loc)
     line = thin.Location_File_To_Line(loc, fe)
     col = thin.Location_File_Line_To_Col(loc, fe, line)
     if col != level:
         self.error(
             utils.Location.from_location(loc),
             "indentation: must be at col {} instead of {}".format(
                 level, col))
Beispiel #5
0
def get_identifier_str(n):
    """Return the identifier (as it appears in the sources) for node n.

    The node n must have an identifier field.  There is no case conversion."""
    ident = iirs.Get_Identifier(n)
    id_len = thin.Get_Name_Length(ident)
    loc = iirs.Get_Location(n)
    fe = thin.Location_To_File(loc)
    pos = thin.Location_File_To_Pos(loc, fe)
    fptr = thin.Get_File_Buffer(fe)
    return ctypes.string_at(fptr + pos, id_len).decode('latin-1')
 def check(self, input, ast):
     for node in thinutils.concurrent_stmts_iter(ast):
         if iirs.Get_Kind(node) not in iirs.Iir_Kinds.Process_Statement:
             continue
         if iirs.Get_Label(node) != thin.Null_Identifier:
             continue
         loc = iirs.Get_Location(node)
         fil = thin.Location_To_File(loc)
         line = thin.Location_File_To_Line(loc, fil)
         if input.comments.get(line - 1, None) is None:
             self.error(
                 Location.from_node(node),
                 "missing label or comment for process")
Beispiel #7
0
 def find_handler(self, n):
     """Return the function to comparse the definition with the
        reference."""
     dfn_loc = iirs.Get_Location(n)
     dfn_file = thin.Location_To_File(dfn_loc)
     handler = self._handlers.get(dfn_file, None)
     if handler:
         return handler
     if dfn_loc == thin.Library_Location.value:
         handler = self.get_lower
     else:
         while iirs.Get_Kind(n) != iirs.Iir_Kind.Library_Declaration:
             n = iirs.Get_Parent(n)
         lib_id = iirs.Get_Identifier(n)
         if lib_id == std_names.Name.Std:
             handler = self.get_standard
         elif lib_id == std_names.Name.Ieee:
             handler = self.get_lower
         else:
             handler = self.get_user
     self._handlers[dfn_file] = handler
     return handler
Beispiel #8
0
def Location_To_File_Line_Col(loc):
    fe = thin.Location_To_File(loc)
    line = thin.Location_File_To_Line(loc, fe)
    col = thin.Location_File_Line_To_Col(loc, fe, line)
    return (fe, line, col)