* Parse .cpp, .rc, and .s files * #include_next support Modified: branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/test.h Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/automaticdepende ncy_include.xml Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile1/sour cefile_includenext.h Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.c Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.h Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu denext.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/tests/sourcefiletest.cpp _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/automaticdependency.cpp 2005-02-02 22:30:55 UTC (rev 13390) @@ -87,15 +87,31 @@
}
bool -SourceFile::ReadInclude ( string& filename ) +SourceFile::ReadInclude ( string& filename, + bool& includeNext) { while ( p < end ) { - if ( ( *p == '#') && ( end - p > 8 ) ) + if ( ( *p == '#') && ( end - p > 13 ) ) { - if ( strncmp ( p, "#include", 8 ) == 0 ) + bool include = false; + p++; + SkipWhitespace (); + if ( strncmp ( p, "include ", 8 ) == 0 ) { p += 8; + includeNext = false; + include = true; + } + if ( strncmp ( p, "include_next ", 13 ) == 0 ) + { + p += 13; + includeNext = true; + include = true; + } + + if ( include ) + { SkipWhitespace (); if ( p < end && *p == '<' || *p == '"' ) { @@ -112,6 +128,7 @@ p++; } filename = ""; + includeNext = false; return false; }
@@ -162,11 +179,27 @@ return this; }
+bool +SourceFile::CanProcessFile ( const string& extension ) +{ + if ( extension == ".h" || extension == ".H" ) + return true; + if ( extension == ".c" || extension == ".C" ) + return true; + if ( extension == ".cpp" || extension == ".CPP" ) + return true; + if ( extension == ".rc" || extension == ".RC" ) + return true; + if ( extension == ".s" || extension == ".S" ) + return true; + return false; +} + SourceFile* SourceFile::ParseFile ( const string& normalizedFilename ) { string extension = GetExtension ( normalizedFilename ); - if ( extension == ".c" || extension == ".C" || extension == ".h" || extension == ".H" ) + if ( CanProcessFile ( extension ) ) { if ( IsIncludedFrom ( normalizedFilename ) ) return NULL; @@ -188,11 +221,15 @@ string includedFilename ( "" ); //printf ( "Parsing '%s'\n", filename.c_str () ); - while ( ReadInclude ( includedFilename )) + bool includeNext; + while ( ReadInclude ( includedFilename, + includeNext ) ) { string resolvedFilename ( "" ); - bool locatedFile = automaticDependency->LocateIncludedFile ( module, + bool locatedFile = automaticDependency->LocateIncludedFile ( this, + module,
includedFilename, + includeNext,
resolvedFilename ); if ( locatedFile ) { @@ -275,9 +312,22 @@ return false; }
+string +AutomaticDependency::GetFilename ( const string& filename ) +{ + size_t index = filename.find_last_of ( CSEP ); + if (index == string::npos) + return filename; + else + return filename.substr ( index + 1, + filename.length () - index - 1); +} + bool -AutomaticDependency::LocateIncludedFile ( Module& module, +AutomaticDependency::LocateIncludedFile ( SourceFile* sourceFile, + Module& module, const string& includedFilename, + bool includeNext, string& resolvedFilename ) { size_t i; @@ -287,7 +337,12 @@ if ( LocateIncludedFile ( include->directory, includedFilename, resolvedFilename ) ) + { + if ( includeNext && stricmp ( resolvedFilename.c_str (), + sourceFile->filename.c_str () ) == 0 ) + continue; return true; + } }
/* FIXME: Ifs */ @@ -298,7 +353,12 @@ if ( LocateIncludedFile ( include->directory, includedFilename, resolvedFilename ) ) + { + if ( includeNext && stricmp ( resolvedFilename.c_str (), + sourceFile->filename.c_str () ) == 0 ) + continue; return true; + } }
resolvedFilename = ""; _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h --- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h 2005-02-02 22:30:55 UTC (rev 13390) @@ -63,7 +63,6 @@
std::vector<Property*> properties; std::vector<If*> ifs;
- //Project (); Project ( const std::string& filename ); ~Project (); void ProcessXML ( const std::string& path ); @@ -385,9 +384,11 @@ void Close (); void Open (); void SkipWhitespace (); - bool ReadInclude ( std::string& filename ); + bool ReadInclude ( std::string& filename, + bool& includeNext ); bool IsIncludedFrom ( const std::string& normalizedFilename ); SourceFile* GetParentSourceFile (); + bool CanProcessFile ( const std::string& extension ); bool IsParentOf ( const SourceFile* parent, const SourceFile* child ); std::string buf; @@ -405,11 +406,14 @@ AutomaticDependency ( const Project& project ); ~AutomaticDependency (); void Process (); + std::string GetFilename ( const std::string& filename ); bool LocateIncludedFile ( const std::string& directory, const std::string& includedFilename, std::string& resolvedFilename ); - bool LocateIncludedFile ( Module& module, + bool LocateIncludedFile ( SourceFile* sourceFile, + Module& module, const std::string& includedFilename, + bool includeNext, std::string& resolvedFilename ); SourceFile* RetrieveFromCacheOrParse ( Module& module, const std::string& filename, _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/test.h --- branches/xmlbuildsystem/reactos/tools/rbuild/test.h 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/test.h 2005-02-02 22:30:55 UTC (rev 13390) @@ -8,37 +8,38 @@
{ public: bool Failed; - BaseTest(); - virtual ~BaseTest(); - virtual void Run() = 0; + BaseTest (); + virtual ~BaseTest (); + virtual void Run () = 0; protected: - void Assert(const char *message, ...); - void IsNull(void* reference, - const char* file, - int line); - void IsNotNull(void* reference, - const char* file, - int line); - void IsTrue(bool condition, - const char* file, - int line); - void IsFalse(bool condition, - const char* file, - int line); - void AreEqual(int expected, - int actual, + void Assert ( const char *message, + ... ); + void IsNull ( void* reference, const char* file, - int line); - void AreEqual(const std::string& expected, - const std::string& actual, + int line ); + void IsNotNull ( void* reference, + const char* file, + int line ); + void IsTrue ( bool condition, const char* file, - int line); - void AreNotEqual(int expected, - int actual, - const char* file, - int line); + int line ); + void IsFalse ( bool condition, + const char* file, + int line ); + void AreEqual ( int expected, + int actual, + const char* file, + int line ); + void AreEqual ( const std::string& expected, + const std::string& actual, + const char* file, + int line ); + void AreNotEqual ( int expected, + int actual, + const char* file, + int line ); private: - void Fail(); + void Fail (); };
#define IS_NULL(reference) IsNull((void*)reference,__FILE__,__LINE__) @@ -51,63 +52,65 @@ class ProjectTest : public BaseTest { public: - void Run(); + void Run (); };
class ModuleTest : public BaseTest { public: - void Run(); + void Run (); };
class DefineTest : public BaseTest { public: - void Run(); + void Run (); };
class IncludeTest : public BaseTest { public: - void Run(); + void Run (); };
class InvokeTest : public BaseTest { public: - void Run(); + void Run (); };
class LinkerFlagTest : public BaseTest { public: - void Run(); + void Run (); };
class IfTest : public BaseTest { public: - void Run(); + void Run (); };
class FunctionTest : public BaseTest { public: - void Run(); + void Run (); };
class SourceFileTest : public BaseTest { public: - void Run(); + void Run (); + void IncludeTest (); + void FullParseTest (); private: bool IsParentOf ( const SourceFile* parent, const SourceFile* child ); _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/automaticdepende ncy_include.xml --- branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/automaticdepende ncy_include.xml 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/automaticdepende ncy_include.xml 2005-02-02 22:30:55 UTC (rev 13390) @@ -0,0 +1,12 @@
+<?xml version="1.0" ?> +<project name="Project" makefile="Makefile"> + <directory name="tests"> + <directory name="data"> + <module name="module1" type="buildtool"> + <include base="module1">.</include> + <include base="module1">sourcefile1</include> + <file>sourcefile_include.c</file> + </module> + </directory> + </directory> +</project> _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile1/sour cefile_includenext.h --- branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile1/sour cefile_includenext.h 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile1/sour cefile_includenext.h 2005-02-02 22:30:55 UTC (rev 13390) @@ -0,0 +1 @@
+/* empty */ _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.c --- branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.c 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.c 2005-02-02 22:30:55 UTC (rev 13390) @@ -0,0 +1,2 @@
+# include <sourcefile_include.h> +#include <sourcefile_includenext.h> _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.h --- branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.h 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu de.h 2005-02-02 22:30:55 UTC (rev 13390) @@ -0,0 +1 @@
+/* empty */ _____
Added: branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu denext.h --- branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu denext.h 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/tests/data/sourcefile_inclu denext.h 2005-02-02 22:30:55 UTC (rev 13390) @@ -0,0 +1 @@
+#include_next <sourcefile_includenext.h> _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/tests/sourcefiletest.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/tests/sourcefiletest.cpp 2005-02-02 21:40:33 UTC (rev 13389) +++ branches/xmlbuildsystem/reactos/tools/rbuild/tests/sourcefiletest.cpp 2005-02-02 22:30:55 UTC (rev 13390) @@ -32,11 +32,24 @@
}
void -SourceFileTest::Run () +SourceFileTest::IncludeTest () { - const Project project ( "tests/data/automaticdependency.xml" ); + const Project project ( "tests" SSEP "data" SSEP "automaticdependency_include.xml" ); AutomaticDependency automaticDependency ( project ); automaticDependency.Process (); + ARE_EQUAL( 4, automaticDependency.sourcefile_map.size () ); + const SourceFile* include = automaticDependency.RetrieveFromCache ( "tests" SSEP "data" SSEP "sourcefile_include.h" ); + IS_NOT_NULL( include ); + const SourceFile* includenext = automaticDependency.RetrieveFromCache ( "tests" SSEP "data" SSEP "sourcefile1" SSEP "sourcefile_includenext.h" ); + IS_NOT_NULL( includenext ); +} + +void +SourceFileTest::FullParseTest () +{ + const Project project ( "tests" SSEP "data" SSEP "automaticdependency.xml" ); + AutomaticDependency automaticDependency ( project ); + automaticDependency.Process (); ARE_EQUAL( 5, automaticDependency.sourcefile_map.size () ); const SourceFile* header1 = automaticDependency.RetrieveFromCache ( "tests" SSEP "data" SSEP "sourcefile1_header1.h" ); IS_NOT_NULL( header1 ); @@ -46,4 +59,12 @@ recurse ) ); IS_FALSE( IsParentOf ( recurse, header1 ) ); + } + +void +SourceFileTest::Run () +{ + IncludeTest (); + FullParseTest (); +}