mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-16 08:42:23 +00:00
write local variable declarations into a separate file
This commit is contained in:
parent
a3ad61b4d0
commit
ba847ae9d8
@ -60,6 +60,10 @@ int main (int argc, char **argv)
|
|||||||
codeFile.write (reinterpret_cast<const char *> (&code[0]),
|
codeFile.write (reinterpret_cast<const char *> (&code[0]),
|
||||||
code.size()*sizeof (Interpreter::Type_Code));
|
code.size()*sizeof (Interpreter::Type_Code));
|
||||||
|
|
||||||
|
std::ofstream localFile ((filename + ".locals").c_str());
|
||||||
|
|
||||||
|
parser.getLocals().write (localFile);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ namespace Compiler
|
|||||||
{
|
{
|
||||||
mScriptParser.getCode (code);
|
mScriptParser.getCode (code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Locals& FileParser::getLocals() const
|
||||||
|
{
|
||||||
|
return mLocals;
|
||||||
|
}
|
||||||
|
|
||||||
bool FileParser::parseName (const std::string& name, const TokenLoc& loc,
|
bool FileParser::parseName (const std::string& name, const TokenLoc& loc,
|
||||||
Scanner& scanner)
|
Scanner& scanner)
|
||||||
|
@ -31,6 +31,9 @@ namespace Compiler
|
|||||||
|
|
||||||
void getCode (std::vector<Interpreter::Type_Code>& code) const;
|
void getCode (std::vector<Interpreter::Type_Code>& code) const;
|
||||||
///< store generated code in \æ code.
|
///< store generated code in \æ code.
|
||||||
|
|
||||||
|
const Locals& getLocals() const;
|
||||||
|
///< get local variable declarations.
|
||||||
|
|
||||||
virtual bool parseName (const std::string& name, const TokenLoc& loc,
|
virtual bool parseName (const std::string& name, const TokenLoc& loc,
|
||||||
Scanner& scanner);
|
Scanner& scanner);
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <ostream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
@ -52,6 +54,21 @@ namespace Compiler
|
|||||||
return ' ';
|
return ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Locals::write (std::ostream& localFile) const
|
||||||
|
{
|
||||||
|
localFile
|
||||||
|
<< get ('s').size() << ' '
|
||||||
|
<< get ('l').size() << ' '
|
||||||
|
<< get ('f').size() << std::endl;
|
||||||
|
|
||||||
|
std::copy (get ('s').begin(), get ('s').end(),
|
||||||
|
std::ostream_iterator<std::string> (localFile, " "));
|
||||||
|
std::copy (get ('l').begin(), get ('l').end(),
|
||||||
|
std::ostream_iterator<std::string> (localFile, " "));
|
||||||
|
std::copy (get ('f').begin(), get ('f').end(),
|
||||||
|
std::ostream_iterator<std::string> (localFile, " "));
|
||||||
|
}
|
||||||
|
|
||||||
void Locals::declare (char type, const std::string& name)
|
void Locals::declare (char type, const std::string& name)
|
||||||
{
|
{
|
||||||
get (type).push_back (name);
|
get (type).push_back (name);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
@ -25,6 +26,9 @@ namespace Compiler
|
|||||||
char getType (const std::string& name) const;
|
char getType (const std::string& name) const;
|
||||||
///< 's': short, 'l': long, 'f': float, ' ': does not exist.
|
///< 's': short, 'l': long, 'f': float, ' ': does not exist.
|
||||||
|
|
||||||
|
void write (std::ostream& localFile) const;
|
||||||
|
///< write declarations to file.
|
||||||
|
|
||||||
void declare (char type, const std::string& name);
|
void declare (char type, const std::string& name);
|
||||||
///< declares a variable.
|
///< declares a variable.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user