105 lines
1.7 KiB
C++
105 lines
1.7 KiB
C++
/* -----------------------------------------------------------------------------
|
|
GSFramework
|
|
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
#ifndef __NSQUIRRELANALYZER__
|
|
#define __NSQUIRRELANALYZER__
|
|
|
|
|
|
#include "memory/nshared_ptr.h"
|
|
#include "memory/nweak_ptr.h"
|
|
#include "container/nlist.h"
|
|
#include "nstring/nstring.h"
|
|
|
|
|
|
namespace GS {
|
|
namespace SquirrelAnalyzer {
|
|
|
|
struct Offset
|
|
{
|
|
int line, column;
|
|
|
|
Offset(int l = 0, int c = 0) : line(l), column(c) {}
|
|
};
|
|
|
|
struct Symbol : public SharedObject
|
|
{
|
|
enum Type
|
|
{
|
|
TypeNone,
|
|
TypeVariable,
|
|
TypeFunction,
|
|
TypeClass
|
|
};
|
|
|
|
String name;
|
|
Type type;
|
|
|
|
Offset offset;
|
|
|
|
Symbol() : type(TypeNone) {}
|
|
};
|
|
|
|
struct Variable : public Symbol
|
|
{
|
|
enum VarType
|
|
{
|
|
VarNone,
|
|
VarLocal,
|
|
VarGlobal,
|
|
VarMember,
|
|
VarEnum
|
|
};
|
|
|
|
VarType var_type;
|
|
|
|
Variable() : var_type(VarNone) { type = TypeVariable; }
|
|
};
|
|
|
|
struct Function : public Symbol
|
|
{
|
|
SharedList <Symbol *> symbols;
|
|
String prototype;
|
|
|
|
Function() { type = TypeFunction; }
|
|
};
|
|
|
|
struct Class : public Symbol
|
|
{
|
|
String extends;
|
|
SharedList <Symbol *> symbols;
|
|
|
|
Class() { type = TypeClass; }
|
|
};
|
|
|
|
struct Source
|
|
{
|
|
String name;
|
|
SharedList <Symbol *> symbols;
|
|
};
|
|
|
|
struct SourceSymbol
|
|
{
|
|
SharedPtr <Source> source;
|
|
SharedPtr <Symbol> symbol;
|
|
};
|
|
|
|
struct Program
|
|
{
|
|
AutoList <Source *> sources;
|
|
bool FindSymbol(const char *name, AutoList <SourceSymbol *> &symbols);
|
|
};
|
|
|
|
void DumpProgram(const Program &);
|
|
|
|
/// Analyze a source, store result in program object.
|
|
Source *Analyze(const char *nut, Program &, bool replace = true);
|
|
|
|
} // SquirrelAnalyser
|
|
} // GS
|
|
|
|
|
|
#endif // __NSQUIRRELANALYZER__
|