When the lexer parses pragma directive with the first keyword once, it adds current File.FilePath to the HashSet.
Then when the lexer parses include directive it checks if it Containsinclude.FilePath and doesn't invoke PushIncludeContext (doesn't include the file content).
Added test for #pragma once but without path aliases, because InMemoryFileSystem can't handle it properly.
objects:
header.hlsli:
#pragma once
object.hlsl:
#include "header.hlsli" // valid
#include "header.hlsli" // valid, skip
shading.hlsl:
#include "objects/header.hlsli" // valid, skip
#include "objects/object.hlsl" // skip header, but not object
#include "objects/Header.hlsli" // redefinition, because don't do that
// dxc bug
#include "fake/../objects/header.hlsli" // on no, redefinition
#include "fake/../objects/object.hlsl" // on no, another redefinition of header
If you don't know how to resolve the conflict with VariadicArgument, just put OnceKeyword after WarningKeyword but before VariadicArgument.
once
, it adds currentFile.FilePath
to theHashSet
.include.FilePath
and doesn't invokePushIncludeContext
(doesn't include the file content).#pragma once
but without path aliases, becauseInMemoryFileSystem
can't handle it properly.If you don't know how to resolve the conflict with
VariadicArgument
, just putOnceKeyword
afterWarningKeyword
but beforeVariadicArgument
.