mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Expose SourceLoc to C++ interface (#20980)
This commit is contained in:
parent
d2ee11364c
commit
8c9769fef4
4 changed files with 40 additions and 2 deletions
|
@ -377,6 +377,22 @@ enum class MessageStyle : uint8_t
|
||||||
sarif = 2u,
|
sarif = 2u,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SourceLoc final
|
||||||
|
{
|
||||||
|
_d_dynamicArray< const char > filename;
|
||||||
|
uint32_t line;
|
||||||
|
uint32_t column;
|
||||||
|
uint32_t fileOffset;
|
||||||
|
const char* toChars(bool showColumns = Loc::showColumns, MessageStyle messageStyle = Loc::messageStyle) const;
|
||||||
|
SourceLoc() :
|
||||||
|
filename(),
|
||||||
|
line(),
|
||||||
|
column(),
|
||||||
|
fileOffset()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Loc final
|
struct Loc final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -390,7 +406,8 @@ public:
|
||||||
uint32_t linnum() const;
|
uint32_t linnum() const;
|
||||||
const char* filename() const;
|
const char* filename() const;
|
||||||
const char* toChars(bool showColumns = Loc::showColumns, MessageStyle messageStyle = Loc::messageStyle) const;
|
const char* toChars(bool showColumns = Loc::showColumns, MessageStyle messageStyle = Loc::messageStyle) const;
|
||||||
bool equals(const Loc& loc) const;
|
SourceLoc toSourceLoc() const;
|
||||||
|
bool equals(Loc loc) const;
|
||||||
Loc() :
|
Loc() :
|
||||||
index(0u)
|
index(0u)
|
||||||
{
|
{
|
||||||
|
|
|
@ -413,6 +413,14 @@ typedef unsigned long long uinteger_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// file location
|
// file location
|
||||||
|
struct SourceLoc
|
||||||
|
{
|
||||||
|
DString filename;
|
||||||
|
uint32_t line;
|
||||||
|
uint32_t column;
|
||||||
|
uint32_t fileOffset;
|
||||||
|
};
|
||||||
|
|
||||||
struct Loc
|
struct Loc
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -438,6 +446,7 @@ public:
|
||||||
uint32_t charnum() const;
|
uint32_t charnum() const;
|
||||||
uint32_t linnum() const;
|
uint32_t linnum() const;
|
||||||
const char *filename() const;
|
const char *filename() const;
|
||||||
|
SourceLoc toSourceLoc() const;
|
||||||
|
|
||||||
const char *toChars(
|
const char *toChars(
|
||||||
bool showColumns = Loc::showColumns,
|
bool showColumns = Loc::showColumns,
|
||||||
|
|
|
@ -124,6 +124,12 @@ nothrow:
|
||||||
return this.index - locFileTable[i].startIndex;
|
return this.index - locFileTable[i].startIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns: this location as a SourceLoc
|
||||||
|
extern (C++) SourceLoc toSourceLoc() const @nogc @safe
|
||||||
|
{
|
||||||
|
return SourceLoc(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for equivalence by comparing the filename contents (not the pointer) and character location.
|
* Checks for equivalence by comparing the filename contents (not the pointer) and character location.
|
||||||
*
|
*
|
||||||
|
@ -131,7 +137,7 @@ nothrow:
|
||||||
* - Uses case-insensitive comparison on Windows
|
* - Uses case-insensitive comparison on Windows
|
||||||
* - Ignores `charnum` if `Columns` is false.
|
* - Ignores `charnum` if `Columns` is false.
|
||||||
*/
|
*/
|
||||||
extern (C++) bool equals(ref const(Loc) loc) const
|
extern (C++) bool equals(Loc loc) const
|
||||||
{
|
{
|
||||||
SourceLoc lhs = SourceLoc(this);
|
SourceLoc lhs = SourceLoc(this);
|
||||||
SourceLoc rhs = SourceLoc(loc);
|
SourceLoc rhs = SourceLoc(loc);
|
||||||
|
|
|
@ -394,6 +394,12 @@ void test_location()
|
||||||
Loc loc = Loc::singleFilename("app.d");
|
Loc loc = Loc::singleFilename("app.d");
|
||||||
assert(strcmp(loc.toChars(true, MessageStyle::digitalmars), "app.d") == 0);
|
assert(strcmp(loc.toChars(true, MessageStyle::digitalmars), "app.d") == 0);
|
||||||
assert(strcmp(loc.toChars(true, MessageStyle::gnu), "app.d") == 0);
|
assert(strcmp(loc.toChars(true, MessageStyle::gnu), "app.d") == 0);
|
||||||
|
|
||||||
|
Loc loc2 = Loc::singleFilename("app2.d");
|
||||||
|
assert(!loc2.equals(loc));
|
||||||
|
|
||||||
|
SourceLoc sloc = loc.toSourceLoc();
|
||||||
|
assert(strcmp(sloc.filename.ptr, loc.filename()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************/
|
/**********************************/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue