class Clangc::SourceLocation
Identifies a specific source location within a translation unit.
Use Clangc::SourceLocation#expansion or #spelling to map a source location to a particular file, line, and column.
Public Instance Methods
Retrieve the file, line, column, and offset represented by the given source location.
If the location refers into a macro instantiation, return where the location was originally spelled in the source file.
The returned array contains four values:
array will be set to the file to which the given source location points.(Clangc::File)
array will be set to the line to which the given source location points.
array will be set to the column to which the given source location points.
array will be set to the offset into the buffer to which the given source location points. (the position in the file)
VALUE c_SourceLocation_get_file_location(VALUE self) { VALUE ret = rb_ary_new(); SourceLocation_t *s; Data_Get_Struct(self, SourceLocation_t, s); CXFile cxf = NULL; unsigned int line; unsigned int column; unsigned int offset; clang_getFileLocation(s->data, &cxf, &line, &column, &offset); VALUE file; File_t *f; R_GET_CLASS_DATA("Clangc", File, file, f); f->data = cxf; f->parent = self; rb_ary_push(ret, file); rb_ary_push(ret, CUINT_2_NUM(line)); rb_ary_push(ret, CUINT_2_NUM(column)); rb_ary_push(ret, CUINT_2_NUM(offset)); return ret; }
Determine whether two source locations, which must refer into the same translation unit, refer to exactly the same point in the source code.
true if the source locations refer to the same location, false if they refer to different locations.
VALUE c_SourceLocation_is_equal(VALUE self, VALUE source_location) { SourceLocation_t *s; SourceLocation_t *sl; Data_Get_Struct(self, SourceLocation_t, s); CHECK_ARG_TYPE(source_location, SourceLocation); Data_Get_Struct(source_location, SourceLocation_t, sl); return NOT_0_2_RVAL(clang_equalLocations(s->data, sl->data)); }
Returns true if the given source location is in the main file of the corresponding translation unit.
VALUE c_SourceLocation_is_from_main_file(VALUE self) { SourceLocation_t *s; Data_Get_Struct(self, SourceLocation_t, s); return NOT_0_2_RVAL(clang_Location_isFromMainFile(s->data)); }
Returns true if the given source location is in a system header.
VALUE c_SourceLocation_is_in_system_header(VALUE self) { SourceLocation_t *s; Data_Get_Struct(self, SourceLocation_t, s); return NOT_0_2_RVAL(clang_Location_isInSystemHeader(s->data)); }
Retrieve the file, line, column, and offset represented by the given source location.
If the location refers into a macro instantiation, return where the location was originally spelled in the source file.
The returned array contains four values:
array will be set to the file to which the given source location points.(Clangc::File)
array will be set to the line to which the given source location points.
array will be set to the column to which the given source location points.
array will be set to the offset into the buffer to which the given source location points. (the position in the file)
VALUE c_SourceLocation_get_spelling(VALUE self) { VALUE ret = rb_ary_new(); SourceLocation_t *s; Data_Get_Struct(self, SourceLocation_t, s); CXFile cxf = NULL; unsigned int line = 0; unsigned int column = 0; unsigned int offset = 0; clang_getSpellingLocation(s->data, &cxf, &line, &column, &offset); VALUE file; File_t *f; R_GET_CLASS_DATA("Clangc", File, file, f); f->data = cxf; f->parent = self; rb_ary_push(ret, file); rb_ary_push(ret, CUINT_2_NUM(line)); rb_ary_push(ret, CUINT_2_NUM(column)); rb_ary_push(ret, CUINT_2_NUM(offset)); return ret; }