Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
deb65e9a
Commit
deb65e9a
authored
Dec 22, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix compiler for threadsafe filesystem API.
parent
9d2ead08
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
29 deletions
+29
-29
capnp.c++
c++/src/capnp/compiler/capnp.c++
+7
-7
error-reporter.h
c++/src/capnp/compiler/error-reporter.h
+1
-1
module-loader.c++
c++/src/capnp/compiler/module-loader.c++
+19
-19
module-loader.h
c++/src/capnp/compiler/module-loader.h
+2
-2
No files found.
c++/src/capnp/compiler/capnp.c++
View file @
deb65e9a
...
...
@@ -1716,7 +1716,7 @@ public:
public
:
// =====================================================================================
void
addError
(
kj
::
ReadableDirectory
&
directory
,
kj
::
PathPtr
path
,
void
addError
(
const
kj
::
ReadableDirectory
&
directory
,
kj
::
PathPtr
path
,
SourcePos
start
,
SourcePos
end
,
kj
::
StringPtr
message
)
override
{
auto
file
=
getDisplayName
(
directory
,
path
);
...
...
@@ -1761,7 +1761,7 @@ private:
struct
SourceDirectory
{
kj
::
Path
path
;
kj
::
Own
<
kj
::
ReadableDirectory
>
dir
;
kj
::
Own
<
const
kj
::
ReadableDirectory
>
dir
;
bool
isSourcePrefix
;
};
...
...
@@ -1770,7 +1770,7 @@ private:
//
// Use via getSourceDirectory().
std
::
map
<
kj
::
ReadableDirectory
*
,
kj
::
String
>
dirPrefixes
;
std
::
map
<
const
kj
::
ReadableDirectory
*
,
kj
::
String
>
dirPrefixes
;
// For each open directory object, maps to a path prefix to add when displaying this path in
// error messages. This keeps track of the original directory name as given by the user, before
// canonicalization.
...
...
@@ -1813,7 +1813,7 @@ private:
bool
hadErrors_
=
false
;
kj
::
Maybe
<
kj
::
ReadableDirectory
&>
getSourceDirectory
(
kj
::
Maybe
<
const
kj
::
ReadableDirectory
&>
getSourceDirectory
(
kj
::
StringPtr
pathStr
,
bool
isSourcePrefix
)
{
auto
cwd
=
disk
->
getCurrentPath
();
auto
path
=
cwd
.
evalNative
(
pathStr
);
...
...
@@ -1837,7 +1837,7 @@ private:
auto
&
result
=
disk
->
getCurrent
();
if
(
isSourcePrefix
)
{
kj
::
PathPtr
key
=
path
;
kj
::
Own
<
kj
::
ReadableDirectory
>
fakeOwn
(
&
result
,
kj
::
NullDisposer
::
instance
);
kj
::
Own
<
const
kj
::
ReadableDirectory
>
fakeOwn
(
&
result
,
kj
::
NullDisposer
::
instance
);
KJ_ASSERT
(
sourceDirectories
.
insert
(
std
::
make_pair
(
key
,
SourceDirectory
{
kj
::
mv
(
path
),
kj
::
mv
(
fakeOwn
),
isSourcePrefix
})).
second
);
}
...
...
@@ -1863,7 +1863,7 @@ private:
}
struct
DirPathPair
{
kj
::
ReadableDirectory
&
dir
;
const
kj
::
ReadableDirectory
&
dir
;
kj
::
Path
path
;
};
...
...
@@ -1906,7 +1906,7 @@ private:
}
}
kj
::
String
getDisplayName
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
kj
::
String
getDisplayName
(
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
auto
iter
=
dirPrefixes
.
find
(
&
dir
);
if
(
iter
!=
dirPrefixes
.
end
())
{
return
kj
::
str
(
iter
->
second
,
path
.
toNativeString
());
...
...
c++/src/capnp/compiler/error-reporter.h
View file @
deb65e9a
...
...
@@ -69,7 +69,7 @@ public:
uint
column
;
};
virtual
void
addError
(
kj
::
ReadableDirectory
&
directory
,
kj
::
PathPtr
path
,
virtual
void
addError
(
const
kj
::
ReadableDirectory
&
directory
,
kj
::
PathPtr
path
,
SourcePos
start
,
SourcePos
end
,
kj
::
StringPtr
message
)
=
0
;
// Report an error at the given location in the given file.
...
...
c++/src/capnp/compiler/module-loader.c++
View file @
deb65e9a
...
...
@@ -42,20 +42,20 @@ struct FileKey {
//
// This is probably over-engineered.
kj
::
ReadableDirectory
&
baseDir
;
const
kj
::
ReadableDirectory
&
baseDir
;
kj
::
PathPtr
path
;
kj
::
ReadableFile
*
file
;
// should be Maybe<ReadableFile&> but annoying const-copy issues come up.
kj
::
Maybe
<
const
kj
::
ReadableFile
&>
file
;
uint64_t
hashCode
;
uint64_t
size
;
kj
::
Date
lastModified
;
FileKey
(
kj
::
ReadableDirectory
&
baseDir
,
kj
::
PathPtr
path
)
FileKey
(
const
kj
::
ReadableDirectory
&
baseDir
,
kj
::
PathPtr
path
)
:
baseDir
(
baseDir
),
path
(
path
),
file
(
nullptr
),
hashCode
(
0
),
size
(
0
),
lastModified
(
kj
::
UNIX_EPOCH
)
{}
FileKey
(
kj
::
ReadableDirectory
&
baseDir
,
kj
::
PathPtr
path
,
kj
::
ReadableFile
&
file
)
FileKey
(
const
kj
::
ReadableDirectory
&
baseDir
,
kj
::
PathPtr
path
,
const
kj
::
ReadableFile
&
file
)
:
FileKey
(
baseDir
,
path
,
file
,
file
.
stat
())
{}
FileKey
(
kj
::
ReadableDirectory
&
baseDir
,
kj
::
PathPtr
path
,
kj
::
ReadableFile
&
file
,
FileKey
(
const
kj
::
ReadableDirectory
&
baseDir
,
kj
::
PathPtr
path
,
const
kj
::
ReadableFile
&
file
,
kj
::
FsNode
::
Metadata
meta
)
:
baseDir
(
baseDir
),
path
(
path
),
file
(
&
file
),
hashCode
(
meta
.
hashCode
),
size
(
meta
.
size
),
lastModified
(
meta
.
lastModified
)
{}
...
...
@@ -77,8 +77,8 @@ struct FileKey {
// Same file hash, but different paths, but same size and modification date. This could be a
// case of two different import paths overlapping and containing the same file. We'll need to
// check the content.
auto
mapping1
=
file
->
mmap
(
0
,
size
);
auto
mapping2
=
other
.
file
->
mmap
(
0
,
size
);
auto
mapping1
=
KJ_ASSERT_NONNULL
(
file
).
mmap
(
0
,
size
);
auto
mapping2
=
KJ_ASSERT_NONNULL
(
other
.
file
).
mmap
(
0
,
size
);
if
(
memcmp
(
mapping1
.
begin
(),
mapping2
.
begin
(),
size
)
!=
0
)
return
false
;
if
(
path
==
other
.
path
)
{
...
...
@@ -127,26 +127,26 @@ public:
Impl
(
GlobalErrorReporter
&
errorReporter
)
:
errorReporter
(
errorReporter
)
{}
void
addImportPath
(
kj
::
ReadableDirectory
&
dir
)
{
void
addImportPath
(
const
kj
::
ReadableDirectory
&
dir
)
{
searchPath
.
add
(
&
dir
);
}
kj
::
Maybe
<
Module
&>
loadModule
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
);
kj
::
Maybe
<
Module
&>
loadModule
(
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
);
kj
::
Maybe
<
Module
&>
loadModuleFromSearchPath
(
kj
::
PathPtr
path
);
kj
::
Maybe
<
kj
::
Array
<
const
byte
>>
readEmbed
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
);
kj
::
Maybe
<
kj
::
Array
<
const
byte
>>
readEmbed
(
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
);
kj
::
Maybe
<
kj
::
Array
<
const
byte
>>
readEmbedFromSearchPath
(
kj
::
PathPtr
path
);
GlobalErrorReporter
&
getErrorReporter
()
{
return
errorReporter
;
}
private
:
GlobalErrorReporter
&
errorReporter
;
kj
::
Vector
<
kj
::
ReadableDirectory
*>
searchPath
;
kj
::
Vector
<
const
kj
::
ReadableDirectory
*>
searchPath
;
std
::
unordered_map
<
FileKey
,
kj
::
Own
<
Module
>
,
FileKeyHash
>
modules
;
};
class
ModuleLoader
::
ModuleImpl
final
:
public
Module
{
public
:
ModuleImpl
(
ModuleLoader
::
Impl
&
loader
,
kj
::
Own
<
kj
::
ReadableFile
>
file
,
kj
::
ReadableDirectory
&
sourceDir
,
kj
::
Path
pathParam
)
ModuleImpl
(
ModuleLoader
::
Impl
&
loader
,
kj
::
Own
<
const
kj
::
ReadableFile
>
file
,
const
kj
::
ReadableDirectory
&
sourceDir
,
kj
::
Path
pathParam
)
:
loader
(
loader
),
file
(
kj
::
mv
(
file
)),
sourceDir
(
sourceDir
),
path
(
kj
::
mv
(
pathParam
)),
sourceNameStr
(
path
.
toString
())
{
KJ_REQUIRE
(
path
.
size
()
>
0
);
...
...
@@ -205,8 +205,8 @@ public:
private
:
ModuleLoader
::
Impl
&
loader
;
kj
::
Own
<
kj
::
ReadableFile
>
file
;
kj
::
ReadableDirectory
&
sourceDir
;
kj
::
Own
<
const
kj
::
ReadableFile
>
file
;
const
kj
::
ReadableDirectory
&
sourceDir
;
kj
::
Path
path
;
kj
::
String
sourceNameStr
;
...
...
@@ -217,7 +217,7 @@ private:
// =======================================================================================
kj
::
Maybe
<
Module
&>
ModuleLoader
::
Impl
::
loadModule
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
auto
iter
=
modules
.
find
(
FileKey
(
dir
,
path
));
if
(
iter
!=
modules
.
end
())
{
// Return existing file.
...
...
@@ -252,7 +252,7 @@ kj::Maybe<Module&> ModuleLoader::Impl::loadModuleFromSearchPath(kj::PathPtr path
}
kj
::
Maybe
<
kj
::
Array
<
const
byte
>>
ModuleLoader
::
Impl
::
readEmbed
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
KJ_IF_MAYBE
(
file
,
dir
.
tryOpenFile
(
path
))
{
return
file
->
get
()
->
mmap
(
0
,
file
->
get
()
->
stat
().
size
);
}
...
...
@@ -274,11 +274,11 @@ ModuleLoader::ModuleLoader(GlobalErrorReporter& errorReporter)
:
impl
(
kj
::
heap
<
Impl
>
(
errorReporter
))
{}
ModuleLoader
::~
ModuleLoader
()
noexcept
(
false
)
{}
void
ModuleLoader
::
addImportPath
(
kj
::
ReadableDirectory
&
dir
)
{
void
ModuleLoader
::
addImportPath
(
const
kj
::
ReadableDirectory
&
dir
)
{
impl
->
addImportPath
(
dir
);
}
kj
::
Maybe
<
Module
&>
ModuleLoader
::
loadModule
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
kj
::
Maybe
<
Module
&>
ModuleLoader
::
loadModule
(
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
)
{
return
impl
->
loadModule
(
dir
,
path
);
}
...
...
c++/src/capnp/compiler/module-loader.h
View file @
deb65e9a
...
...
@@ -45,10 +45,10 @@ public:
~
ModuleLoader
()
noexcept
(
false
);
void
addImportPath
(
kj
::
ReadableDirectory
&
dir
);
void
addImportPath
(
const
kj
::
ReadableDirectory
&
dir
);
// Add a directory to the list of paths that is searched for imports that start with a '/'.
kj
::
Maybe
<
Module
&>
loadModule
(
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
);
kj
::
Maybe
<
Module
&>
loadModule
(
const
kj
::
ReadableDirectory
&
dir
,
kj
::
PathPtr
path
);
// Tries to load a module with the given path inside the given directory. Returns nullptr if the
// file doesn't exist.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment