@@ -60,46 +60,97 @@ def CallSiteLoc : Builtin_LocationAttr<"CallSiteLoc"> {
6060}
6161
6262//===----------------------------------------------------------------------===//
63- // FileLineColLoc
63+ // FileLineColRange
6464//===----------------------------------------------------------------------===//
6565
66- def FileLineColLoc : Builtin_LocationAttr<"FileLineColLoc "> {
67- let summary = "A file:line:column source location";
66+ def FileLineColRange : Builtin_LocationAttr<"FileLineColRange "> {
67+ let summary = "A file:line:column source location range ";
6868 let description = [{
6969 Syntax:
7070
7171 ```
7272 filelinecol-location ::= string-literal `:` integer-literal `:`
7373 integer-literal
74+ (`to` (integer-literal ?) `:` integer-literal ?)
7475 ```
7576
76- An instance of this location represents a tuple of file, line number, and
77- column number. This is similar to the type of location that you get from
78- most source languages.
77+ An instance of this location represents a tuple of file, start and end line
78+ number, and start and end column number. It allows for the following
79+ configurations:
80+
81+ * A single file line location: `file:line`;
82+ * A single file line col location: `file:line:column`;
83+ * A single line range: `file:line:column to :column`;
84+ * A single file range: `file:line:column to line:column`;
7985
8086 Example:
8187
8288 ```mlir
83- loc("mysource.cc":10:8)
89+ loc("mysource.cc":10:8 to 12:18 )
8490 ```
8591 }];
86- let parameters = (ins "StringAttr":$filename, "unsigned":$line,
87- "unsigned":$column);
92+
93+ // Note: this only shows the parameters for which accessors are generated. The
94+ // locations are only set in storage.
95+ let parameters = (ins "StringAttr":$filename);
8896 let builders = [
97+
98+ AttrBuilderWithInferredContext<(ins "StringAttr":$filename), [{
99+ return $_get(filename.getContext(), filename, ArrayRef<unsigned>{});
100+ }]>,
101+ AttrBuilderWithInferredContext<(ins "StringAttr":$filename,
102+ "unsigned":$line), [{
103+ return $_get(filename.getContext(), filename,
104+ ArrayRef<unsigned>{line});
105+ }]>,
89106 AttrBuilderWithInferredContext<(ins "StringAttr":$filename,
90107 "unsigned":$line,
91108 "unsigned":$column), [{
92- return $_get(filename.getContext(), filename, line, column);
109+ return $_get(filename.getContext(), filename,
110+ ArrayRef<unsigned>{line, column});
93111 }]>,
94- AttrBuilder<(ins "StringRef":$filename, "unsigned":$line,
95- "unsigned":$column), [{
112+ AttrBuilder<(ins "::llvm::StringRef":$filename,
113+ "unsigned":$start_line,
114+ "unsigned":$start_column), [{
96115 return $_get($_ctxt,
97- StringAttr::get($_ctxt, filename.empty() ? "-" : filename),
98- line, column);
99- }]>
116+ StringAttr::get($_ctxt, filename.empty() ? "-" : filename),
117+ ArrayRef<unsigned>{start_line, start_column});
118+ }]>,
119+ AttrBuilderWithInferredContext<(ins "::mlir::StringAttr":$filename,
120+ "unsigned":$line,
121+ "unsigned":$start_column,
122+ "unsigned":$end_column), [{
123+ return $_get(filename.getContext(), filename,
124+ ArrayRef<unsigned>{line, start_column, end_column});
125+ }]>,
126+ AttrBuilderWithInferredContext<(ins "::mlir::StringAttr":$filename,
127+ "unsigned":$start_line,
128+ "unsigned":$start_column,
129+ "unsigned":$end_line,
130+ "unsigned":$end_column), [{
131+ return $_get(filename.getContext(), filename,
132+ ArrayRef<unsigned>{start_line, start_column, end_column, end_line});
133+ }]>,
134+ AttrBuilder<(ins "::llvm::StringRef":$filename,
135+ "unsigned":$start_line,
136+ "unsigned":$start_column,
137+ "unsigned":$end_line,
138+ "unsigned":$end_column), [{
139+ return $_get($_ctxt,
140+ StringAttr::get($_ctxt, filename.empty() ? "-" : filename),
141+ ArrayRef<unsigned>{start_line, start_column, end_column, end_line});
142+ }]>,
100143 ];
144+
145+ let extraClassDeclaration = [{
146+ std::optional<unsigned> getStartLine() const;
147+ std::optional<unsigned> getStartColumn() const;
148+ std::optional<unsigned> getEndColumn() const;
149+ std::optional<unsigned> getEndLine() const;
150+ }];
101151 let skipDefaultBuilders = 1;
102- let attrName = "builtin.file_line_loc";
152+ let genStorageClass = 0;
153+ let attrName = "builtin.file_line_range";
103154}
104155
105156//===----------------------------------------------------------------------===//
0 commit comments