mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-02 04:13:34 +00:00
* Parse .cpp, .rc, and .s files
* #include_next support svn path=/branches/xmlbuildsystem/; revision=13390
This commit is contained in:
@@ -87,15 +87,31 @@ SourceFile::SkipWhitespace ()
|
||||
}
|
||||
|
||||
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 @@ SourceFile::ReadInclude ( string& filename )
|
||||
p++;
|
||||
}
|
||||
filename = "";
|
||||
includeNext = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -162,11 +179,27 @@ SourceFile::GetParentSourceFile ()
|
||||
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 @@ SourceFile::Parse ()
|
||||
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 @@ AutomaticDependency::LocateIncludedFile ( const string& directory,
|
||||
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 @@ AutomaticDependency::LocateIncludedFile ( Module& module,
|
||||
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 @@ AutomaticDependency::LocateIncludedFile ( Module& module,
|
||||
if ( LocateIncludedFile ( include->directory,
|
||||
includedFilename,
|
||||
resolvedFilename ) )
|
||||
{
|
||||
if ( includeNext && stricmp ( resolvedFilename.c_str (),
|
||||
sourceFile->filename.c_str () ) == 0 )
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
resolvedFilename = "";
|
||||
|
||||
@@ -63,7 +63,6 @@ public:
|
||||
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 @@ private:
|
||||
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 @@ public:
|
||||
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,
|
||||
|
||||
+39
-36
@@ -8,37 +8,38 @@ class BaseTest
|
||||
{
|
||||
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,
|
||||
const char* file,
|
||||
int line);
|
||||
void AreNotEqual(int expected,
|
||||
int actual,
|
||||
int line );
|
||||
void IsNotNull ( void* reference,
|
||||
const char* file,
|
||||
int line);
|
||||
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,
|
||||
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 @@ private:
|
||||
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 );
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1 @@
|
||||
/* empty */
|
||||
@@ -0,0 +1,2 @@
|
||||
# include <sourcefile_include.h>
|
||||
#include <sourcefile_includenext.h>
|
||||
@@ -0,0 +1 @@
|
||||
/* empty */
|
||||
@@ -0,0 +1 @@
|
||||
#include_next <sourcefile_includenext.h>
|
||||
@@ -32,9 +32,22 @@ SourceFileTest::IsParentOf ( const SourceFile* parent,
|
||||
}
|
||||
|
||||
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 () );
|
||||
@@ -46,4 +59,12 @@ SourceFileTest::Run ()
|
||||
recurse ) );
|
||||
IS_FALSE( IsParentOf ( recurse,
|
||||
header1 ) );
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
SourceFileTest::Run ()
|
||||
{
|
||||
IncludeTest ();
|
||||
FullParseTest ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user