Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
protobuf
Commits
d8a926eb
Commit
d8a926eb
authored
Oct 14, 2015
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #824 from jtattermusch/expose_get_output_file
Expose GetOutputFile in csharp_names.h
parents
8894d1fe
c31f11de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
39 deletions
+58
-39
csharp_generator.cc
src/google/protobuf/compiler/csharp/csharp_generator.cc
+1
-36
csharp_helpers.cc
src/google/protobuf/compiler/csharp/csharp_helpers.cc
+35
-0
csharp_helpers.h
src/google/protobuf/compiler/csharp/csharp_helpers.h
+0
-2
csharp_names.h
src/google/protobuf/compiler/csharp/csharp_names.h
+22
-1
No files found.
src/google/protobuf/compiler/csharp/csharp_generator.cc
View file @
d8a926eb
...
...
@@ -50,41 +50,6 @@ namespace protobuf {
namespace
compiler
{
namespace
csharp
{
std
::
string
GetOutputFile
(
const
google
::
protobuf
::
FileDescriptor
*
file
,
const
std
::
string
file_extension
,
const
bool
generate_directories
,
const
std
::
string
base_namespace
,
string
*
error
)
{
string
relative_filename
=
GetUmbrellaClassUnqualifiedName
(
file
)
+
file_extension
;
if
(
!
generate_directories
)
{
return
relative_filename
;
}
string
ns
=
GetFileNamespace
(
file
);
string
namespace_suffix
=
ns
;
if
(
!
base_namespace
.
empty
())
{
// Check that the base_namespace is either equal to or a leading part of
// the file namespace. This isn't just a simple prefix; "Foo.B" shouldn't
// be regarded as a prefix of "Foo.Bar". The simplest option is to add "."
// to both.
string
extended_ns
=
ns
+
"."
;
if
(
extended_ns
.
find
(
base_namespace
+
"."
)
!=
0
)
{
*
error
=
"Namespace "
+
ns
+
" is not a prefix namespace of base namespace "
+
base_namespace
;
return
""
;
// This will be ignored, because we've set an error.
}
namespace_suffix
=
ns
.
substr
(
base_namespace
.
length
());
if
(
namespace_suffix
.
find
(
"."
)
==
0
)
{
namespace_suffix
=
namespace_suffix
.
substr
(
1
);
}
}
string
namespace_dir
=
StringReplace
(
namespace_suffix
,
"."
,
"/"
,
true
);
if
(
!
namespace_dir
.
empty
())
{
namespace_dir
+=
"/"
;
}
return
namespace_dir
+
relative_filename
;
}
void
GenerateFile
(
const
google
::
protobuf
::
FileDescriptor
*
file
,
io
::
Printer
*
printer
)
{
UmbrellaClassGenerator
umbrellaGenerator
(
file
);
...
...
@@ -123,7 +88,7 @@ bool Generator::Generate(
string
filename_error
=
""
;
std
::
string
filename
=
GetOutputFile
(
file
,
file_extension
,
generate_directories
,
base_namespace
,
&
filename_error
);
if
(
!
filename_error
.
empty
())
{
if
(
filename
.
empty
())
{
*
error
=
filename_error
;
return
false
;
}
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.cc
View file @
d8a926eb
...
...
@@ -269,6 +269,41 @@ std::string GetPropertyName(const FieldDescriptor* descriptor) {
return
property_name
;
}
std
::
string
GetOutputFile
(
const
google
::
protobuf
::
FileDescriptor
*
descriptor
,
const
std
::
string
file_extension
,
const
bool
generate_directories
,
const
std
::
string
base_namespace
,
string
*
error
)
{
string
relative_filename
=
GetUmbrellaClassUnqualifiedName
(
descriptor
)
+
file_extension
;
if
(
!
generate_directories
)
{
return
relative_filename
;
}
string
ns
=
GetFileNamespace
(
descriptor
);
string
namespace_suffix
=
ns
;
if
(
!
base_namespace
.
empty
())
{
// Check that the base_namespace is either equal to or a leading part of
// the file namespace. This isn't just a simple prefix; "Foo.B" shouldn't
// be regarded as a prefix of "Foo.Bar". The simplest option is to add "."
// to both.
string
extended_ns
=
ns
+
"."
;
if
(
extended_ns
.
find
(
base_namespace
+
"."
)
!=
0
)
{
*
error
=
"Namespace "
+
ns
+
" is not a prefix namespace of base namespace "
+
base_namespace
;
return
""
;
// This will be ignored, because we've set an error.
}
namespace_suffix
=
ns
.
substr
(
base_namespace
.
length
());
if
(
namespace_suffix
.
find
(
"."
)
==
0
)
{
namespace_suffix
=
namespace_suffix
.
substr
(
1
);
}
}
string
namespace_dir
=
StringReplace
(
namespace_suffix
,
"."
,
"/"
,
true
);
if
(
!
namespace_dir
.
empty
())
{
namespace_dir
+=
"/"
;
}
return
namespace_dir
+
relative_filename
;
}
// TODO: c&p from Java protoc plugin
// For encodings with fixed sizes, returns that size in bytes. Otherwise
// returns -1.
...
...
src/google/protobuf/compiler/csharp/csharp_helpers.h
View file @
d8a926eb
...
...
@@ -76,8 +76,6 @@ std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor);
// not including the GetFileNamespace part).
std
::
string
GetUmbrellaClassNestedNamespace
(
const
FileDescriptor
*
descriptor
);
std
::
string
GetClassName
(
const
Descriptor
*
descriptor
);
std
::
string
GetClassName
(
const
EnumDescriptor
*
descriptor
);
std
::
string
GetFieldName
(
const
FieldDescriptor
*
descriptor
);
...
...
src/google/protobuf/compiler/csharp/csharp_names.h
View file @
d8a926eb
...
...
@@ -72,7 +72,28 @@ string GetClassName(const Descriptor* descriptor);
// The fully-qualified name of the C# class that provides
// access to the file descriptor. Proto compiler generates
// such class for each .proto file processed.
std
::
string
GetUmbrellaClassName
(
const
FileDescriptor
*
descriptor
);
string
GetUmbrellaClassName
(
const
FileDescriptor
*
descriptor
);
// Generates output file name for given file descriptor. If generate_directories
// is true, the output file will be put under directory corresponding to file's
// namespace. base_namespace can be used to strip some of the top level
// directories. E.g. for file with namespace "Bar.Foo" and base_namespace="Bar",
// the resulting file will be put under directory "Foo" (and not "Bar/Foo").
//
// Requires:
// descriptor != NULL
// error != NULL
//
// Returns:
// The file name to use as output file for given file descriptor. In case
// of failure, this function will return empty string and error parameter
// will contain the error message.
string
GetOutputFile
(
const
google
::
protobuf
::
FileDescriptor
*
descriptor
,
const
string
file_extension
,
const
bool
generate_directories
,
const
string
base_namespace
,
string
*
error
);
}
// namespace csharp
}
// namespace compiler
...
...
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