@@ -53,29 +53,29 @@ namespace attributes {
53
53
std::string path () const { return path_; }
54
54
bool exists () const { return exists_; }
55
55
time_t lastModified () const { return lastModified_; }
56
-
56
+
57
57
std::string extension () const {
58
58
std::string::size_type pos = path_.find_last_of (' .' );
59
59
if (pos != std::string::npos)
60
60
return path_.substr (pos);
61
61
else
62
62
return " " ;
63
63
}
64
-
64
+
65
65
bool operator <(const FileInfo& other) const {
66
66
return path_ < other.path_ ;
67
67
};
68
-
68
+
69
69
bool operator ==(const FileInfo& other) const {
70
70
return path_ == other.path_ &&
71
71
exists_ == other.exists_ &&
72
72
lastModified_ == other.lastModified_ ;
73
73
};
74
-
74
+
75
75
bool operator !=(const FileInfo& other) const {
76
76
return ! (*this == other);
77
77
};
78
-
78
+
79
79
std::ostream& operator <<(std::ostream& os) const {
80
80
os << path_;
81
81
return os;
@@ -151,17 +151,17 @@ namespace attributes {
151
151
{
152
152
}
153
153
bool empty () const { return name ().empty (); }
154
-
154
+
155
155
bool operator ==(const Type& other) const {
156
156
return name_ == other.name_ &&
157
157
isConst_ == other.isConst_ &&
158
158
isReference_ == other.isReference_ ;
159
159
};
160
-
160
+
161
161
bool operator !=(const Type& other) const {
162
162
return !(*this == other);
163
163
};
164
-
164
+
165
165
const std::string& name () const { return name_; }
166
166
std::string full_name () const {
167
167
std::string res ;
@@ -193,17 +193,17 @@ namespace attributes {
193
193
}
194
194
195
195
bool empty () const { return type ().empty (); }
196
-
196
+
197
197
bool operator ==(const Argument& other) const {
198
198
return name_ == other.name_ &&
199
199
type_ == other.type_ &&
200
200
defaultValue_ == other.defaultValue_ ;
201
201
};
202
-
202
+
203
203
bool operator !=(const Argument& other) const {
204
204
return !(*this == other);
205
205
};
206
-
206
+
207
207
208
208
const std::string& name () const { return name_; }
209
209
const Type& type () const { return type_; }
@@ -238,21 +238,21 @@ namespace attributes {
238
238
}
239
239
240
240
bool empty () const { return name ().empty (); }
241
-
241
+
242
242
bool operator ==(const Function& other) const {
243
243
return type_ == other.type_ &&
244
244
name_ == other.name_ &&
245
245
arguments_ == other.arguments_ ;
246
246
};
247
-
247
+
248
248
bool operator !=(const Function& other) const {
249
249
return !(*this == other);
250
250
};
251
251
252
252
const Type& type () const { return type_; }
253
253
const std::string& name () const { return name_; }
254
254
const std::vector<Argument>& arguments () const { return arguments_; }
255
-
255
+
256
256
private:
257
257
Type type_;
258
258
std::string name_;
@@ -265,16 +265,16 @@ namespace attributes {
265
265
Param () {}
266
266
explicit Param (const std::string& paramText);
267
267
bool empty () const { return name ().empty (); }
268
-
268
+
269
269
bool operator ==(const Param& other) const {
270
270
return name_ == other.name_ &&
271
271
value_ == other.value_ ;
272
272
};
273
-
273
+
274
274
bool operator !=(const Param& other) const {
275
275
return !(*this == other);
276
276
};
277
-
277
+
278
278
279
279
const std::string& name () const { return name_; }
280
280
const std::string& value () const { return value_; }
@@ -297,18 +297,18 @@ namespace attributes {
297
297
}
298
298
299
299
bool empty () const { return name ().empty (); }
300
-
300
+
301
301
bool operator ==(const Attribute& other) const {
302
302
return name_ == other.name_ &&
303
303
params_ == other.params_ &&
304
304
function_ == other.function_ &&
305
305
roxygen_ == other.roxygen_ ;
306
306
};
307
-
307
+
308
308
bool operator !=(const Attribute& other) const {
309
309
return !(*this == other);
310
310
};
311
-
311
+
312
312
313
313
const std::string& name () const { return name_; }
314
314
@@ -471,7 +471,7 @@ namespace attributes {
471
471
const std::vector<std::string>& embeddedR () const {
472
472
return embeddedR_;
473
473
}
474
-
474
+
475
475
// Get source dependencies
476
476
const std::vector<FileInfo>& sourceDependencies () const {
477
477
return sourceDependencies_;
@@ -782,25 +782,25 @@ namespace attributes {
782
782
pLines->push_back (line);
783
783
}
784
784
}
785
-
786
- bool addUniqueDependency (Rcpp::CharacterVector include,
785
+
786
+ bool addUniqueDependency (Rcpp::CharacterVector include,
787
787
std::vector<FileInfo>* pDependencies) {
788
-
788
+
789
789
// return false if we already have this include
790
790
std::string path = Rcpp::as<std::string>(include);
791
791
for (size_t i = 0 ; i<pDependencies->size (); ++i) {
792
792
if (pDependencies->at (i).path () == path)
793
793
return false ;
794
794
}
795
-
795
+
796
796
// add it and return true
797
797
pDependencies->push_back (FileInfo (path));
798
798
return true ;
799
799
}
800
-
800
+
801
801
void parseSourceDependencies (const std::string& sourceFile,
802
802
std::vector<FileInfo>* pDependencies) {
803
-
803
+
804
804
// import R functions
805
805
Rcpp::Environment baseEnv = Rcpp::Environment::base_env ();
806
806
Rcpp::Function dirname = baseEnv[" dirname" ];
@@ -810,25 +810,25 @@ namespace attributes {
810
810
Rcpp::Environment toolsEnv = Rcpp::Environment::namespace_env (
811
811
" tools" );
812
812
Rcpp::Function filePathSansExt = toolsEnv[" file_path_sans_ext" ];
813
-
813
+
814
814
// get the path to the source file's directory
815
815
Rcpp::CharacterVector sourceDir = dirname (sourceFile);
816
-
816
+
817
817
// read the source file into a buffer
818
818
std::stringstream buffer;
819
819
readFile (sourceFile, buffer);
820
-
820
+
821
821
// Now read into a list of strings (which we can pass to regexec)
822
822
// First read into a std::deque (which will handle lots of append
823
823
// operations efficiently) then copy into an R chracter vector
824
824
std::deque<std::string> lines;
825
825
readLines (buffer, &lines);
826
- Rcpp::CharacterVector linesVector = Rcpp::wrap (lines);
827
-
826
+ Rcpp::CharacterVector linesVector = Rcpp::wrap (lines);
827
+
828
828
// look for local includes
829
829
Rcpp::List matches = regexMatches (
830
830
linesVector, " ^\\ s*#include\\ s*\" ([^\" ]+)\"\\ s*$" );
831
-
831
+
832
832
// accumulate local includes (skip commented sections)
833
833
CommentState commentState;
834
834
std::vector<FileInfo> newDependencies;
@@ -840,7 +840,7 @@ namespace attributes {
840
840
const Rcpp::CharacterVector match = matches[i];
841
841
if (match.size () == 2 ) {
842
842
// compose a full file path for the match
843
- Rcpp::CharacterVector include =
843
+ Rcpp::CharacterVector include =
844
844
filepath (sourceDir, std::string (match[1 ]));
845
845
// if it exists then normalize and add to our list
846
846
LogicalVector exists = fileExists (include);
@@ -850,19 +850,19 @@ namespace attributes {
850
850
newDependencies.push_back (
851
851
FileInfo (Rcpp::as<std::string>(include)));
852
852
}
853
-
853
+
854
854
std::vector<std::string> exts;
855
855
exts.push_back (" .cc" );
856
856
exts.push_back (" .cpp" );
857
857
for (size_t i = 0 ; i<exts.size (); ++i) {
858
-
858
+
859
859
// look for corresponding cpp file and add it
860
860
std::string file = Rcpp::as<std::string>(
861
861
filePathSansExt (include)) + exts[i];
862
-
862
+
863
863
exists = fileExists (file);
864
864
if (exists[0 ]) {
865
- if (addUniqueDependency (file,
865
+ if (addUniqueDependency (file,
866
866
pDependencies)) {
867
867
FileInfo fileInfo (file);
868
868
newDependencies.push_back (fileInfo);
@@ -873,28 +873,28 @@ namespace attributes {
873
873
}
874
874
}
875
875
}
876
-
876
+
877
877
// look for dependencies recursively
878
878
for (size_t i = 0 ; i<newDependencies.size (); i++) {
879
879
FileInfo dependency = newDependencies[i];
880
880
parseSourceDependencies (dependency.path (), pDependencies);
881
881
}
882
882
}
883
-
883
+
884
884
// parse the source dependencies from the passed lines
885
885
std::vector<FileInfo> parseSourceDependencies (
886
886
const std::string& sourceFile) {
887
-
887
+
888
888
// parse dependencies
889
889
std::vector<FileInfo> dependencies;
890
890
parseSourceDependencies (sourceFile, &dependencies);
891
-
891
+
892
892
// remove main source file
893
- dependencies.erase (std::remove (dependencies.begin (),
894
- dependencies.end (),
895
- FileInfo (sourceFile)),
896
- dependencies.end ());
897
-
893
+ dependencies.erase (std::remove (dependencies.begin (),
894
+ dependencies.end (),
895
+ FileInfo (sourceFile)),
896
+ dependencies.end ());
897
+
898
898
return dependencies;
899
899
}
900
900
@@ -1002,8 +1002,8 @@ namespace attributes {
1002
1002
}
1003
1003
1004
1004
// Print argument
1005
- void printArgument (std::ostream& os,
1006
- const Argument& argument,
1005
+ void printArgument (std::ostream& os,
1006
+ const Argument& argument,
1007
1007
bool printDefault = true ) {
1008
1008
if (!argument.empty ()) {
1009
1009
os << argument.type ();
@@ -1023,10 +1023,10 @@ namespace attributes {
1023
1023
}
1024
1024
1025
1025
// Print function
1026
- void printFunction (std::ostream& os,
1027
- const Function& function,
1028
- bool printArgDefaults = true ) {
1029
-
1026
+ void printFunction (std::ostream& os,
1027
+ const Function& function,
1028
+ bool printArgDefaults = true ) {
1029
+
1030
1030
if (!function.empty ()) {
1031
1031
if (!function.type ().empty ()) {
1032
1032
os << function.type ();
@@ -1175,30 +1175,30 @@ namespace attributes {
1175
1175
1176
1176
// Parse embedded R
1177
1177
embeddedR_ = parseEmbeddedR (lines_, lines);
1178
-
1178
+
1179
1179
// Recursively parse dependencies if requested
1180
1180
if (parseDependencies) {
1181
-
1181
+
1182
1182
// get source dependencies
1183
1183
sourceDependencies_ = parseSourceDependencies (sourceFile);
1184
-
1184
+
1185
1185
// parse attributes and modules from each dependent file
1186
1186
for (size_t i = 0 ; i<sourceDependencies_.size (); i++) {
1187
-
1187
+
1188
1188
// perform parse
1189
1189
std::string dependency = sourceDependencies_[i].path ();
1190
1190
SourceFileAttributesParser parser (dependency, false );
1191
-
1191
+
1192
1192
// copy to base attributes (if it's a new attribute)
1193
- for (SourceFileAttributesParser::const_iterator
1193
+ for (SourceFileAttributesParser::const_iterator
1194
1194
it = parser.begin (); it != parser.end (); ++it) {
1195
1195
if (std::find (attributes_.begin (),
1196
1196
attributes_.end (),
1197
1197
*it) == attributes_.end ()) {
1198
1198
attributes_.push_back (*it);
1199
1199
}
1200
1200
}
1201
-
1201
+
1202
1202
// copy to base modules
1203
1203
std::copy (parser.modules ().begin (),
1204
1204
parser.modules ().end (),
@@ -1273,7 +1273,7 @@ namespace attributes {
1273
1273
}
1274
1274
// rng that isn't true or false
1275
1275
else if (name == kExportRng ) {
1276
- if (value != kParamValueFalse &&
1276
+ if (value != kParamValueFalse &&
1277
1277
value != kParamValueTrue &&
1278
1278
value != kParamValueFALSE &&
1279
1279
value != kParamValueTRUE ) {
@@ -2833,7 +2833,7 @@ namespace {
2833
2833
cppSourcePath_);
2834
2834
if (sourceDependencies != sourceDependencies_)
2835
2835
return true ;
2836
-
2836
+
2837
2837
// not dirty
2838
2838
return false ;
2839
2839
}
@@ -2911,7 +2911,7 @@ namespace {
2911
2911
2912
2912
// capture embededded R
2913
2913
embeddedR_ = sourceAttributes.embeddedR ();
2914
-
2914
+
2915
2915
// capture source dependencies
2916
2916
sourceDependencies_ = sourceAttributes.sourceDependencies ();
2917
2917
}
@@ -2923,7 +2923,7 @@ namespace {
2923
2923
const std::string& cppSourcePath () const {
2924
2924
return cppSourcePath_;
2925
2925
}
2926
-
2926
+
2927
2927
const std::vector<std::string> cppDependencySourcePaths () {
2928
2928
std::vector<std::string> dependencies;
2929
2929
for (size_t i = 0 ; i<sourceDependencies_.size (); ++i) {
0 commit comments