Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dstep/translator/Context.d
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ class Context
if (options.collisionAction != CollisionAction.ignore)
{
auto collision = spelling in macroIndex.globalCursors;
if (collision && collision.kind == CXCursorKind.typedefDecl)
{
auto underlying = collision.underlyingCursor();
if (cursor.canonical == underlying.canonical)
collision = null;
}
Comment thread
davispuh marked this conversation as resolved.

while (collision &&
collision.canonical != cursor.canonical &&
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/nocollision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "structs.h"

typedef D Z;
20 changes: 20 additions & 0 deletions tests/unit/Common.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ TranslationUnit makeTranslationUnit(string source)
return TranslationUnit.parseString(index, source, arguments);
}

TranslationUnit makeTranslationUnitFromFile(
string sourceFilename,
const string[] commandLineArgs = ["-Wno-missing-declarations"],
uint options = CXTranslationUnit_Flags.detailedPreprocessingRecord)
{
import std.algorithm;
import std.array;

Compiler compiler;

auto index = Index(false, false);

return TranslationUnit.parse(
index,
sourceFilename,
commandLineArgs ~ compiler.internalFlags,
compiler.internalHeaders,
options);
}

CommentIndex makeCommentIndex(string c)
{
TranslationUnit translUnit = makeTranslationUnit(c);
Expand Down
26 changes: 3 additions & 23 deletions tests/unit/IncludeGraphTests.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,9 @@ import clang.Util;

import dstep.translator.HeaderIndex;

static TranslationUnit makeTranslationUnit(
string sourceFilename,
const string[] commandLineArgs = ["-Wno-missing-declarations"],
uint options = CXTranslationUnit_Flags.detailedPreprocessingRecord)
{
import std.algorithm;
import std.array;

Compiler compiler;

auto index = Index(false, false);

return TranslationUnit.parse(
index,
sourceFilename,
commandLineArgs ~ compiler.internalFlags,
compiler.internalHeaders,
options);
}

static IncludeGraph makeIncludeGraph(string sourceFilename)
{
return new IncludeGraph(makeTranslationUnit(sourceFilename));
return new IncludeGraph(makeTranslationUnitFromFile(sourceFilename));
}

unittest
Expand Down Expand Up @@ -72,7 +52,7 @@ unittest
{
import std.algorithm;

auto translationUnit = makeTranslationUnit(
auto translationUnit = makeTranslationUnitFromFile(
"tests/functional/clang-c/Index.h",
["-Wno-missing-declarations", "-Itests/functional"]);
auto headerIndex = new HeaderIndex(translationUnit);
Expand All @@ -84,7 +64,7 @@ unittest

unittest
{
auto translationUnit = makeTranslationUnit(
auto translationUnit = makeTranslationUnitFromFile(
"tests/functional/graph/self_including_main.h",
["-Wno-missing-declarations", "-Itests/functional"]);

Expand Down
52 changes: 52 additions & 0 deletions tests/unit/UnitTests.d
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,21 @@ struct foo_
}

extern __gshared int foo;
D");

assertTranslates(q"C
typedef void foo;

struct foo { int x; };
C", q"D
extern (C):

alias foo = void;

struct foo_
{
int x;
}
D");

assertTranslates(q"C
Expand Down Expand Up @@ -946,6 +961,43 @@ D", options));
}
}

// Test abort on spelling collision (another case).
unittest
{
import std.exception : assertThrown;

Options options;
options.collisionAction = CollisionAction.abort;

assertThrown!TranslationException(assertTranslates(q"C
struct foo { int x; } foo;
C", q"D
extern (C):

struct foo
{
int x;
}

extern __gshared foo foo;
D", options));
}

// Test that no false collision is detected.
unittest
{
auto translUnit = makeTranslationUnitFromFile("tests/functional/nocollision.h");

Options options;
options.collisionAction = CollisionAction.abort;

assertTranslates(q"D
extern (C):

alias Z = D;
D", translUnit, options, false);
}

// Put or don't put a space after the 'function' keyword when
// --space-after-function-name is or isn't specified.
unittest
Expand Down