89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
/* -----------------------------------------------------------------------------
|
|
GSFramework
|
|
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
|
#include "script_squirrel/squirrel_analyzer.h"
|
|
#include "log/log.h"
|
|
|
|
using namespace GS;
|
|
using namespace GS::SquirrelAnalyzer;
|
|
|
|
|
|
void DumpSymbols(const SharedList <Symbol *> &, int);
|
|
|
|
//------------------------------------------------------------------------------
|
|
void DumpSymbol(const Symbol *symbol, int tab)
|
|
{
|
|
for (int n = 0; n < tab; ++n)
|
|
__LOG__ << " ";
|
|
|
|
__LOG__ << "offset: line " << symbol->offset.line << ", column " << symbol->offset.column << " -> ";
|
|
|
|
switch (symbol->type)
|
|
{
|
|
case Symbol::TypeClass:
|
|
if (Class *c = (Class *)symbol)
|
|
{
|
|
__LOG__ << "Class " << c->name;
|
|
if (!c->extends.IsEmpty())
|
|
__LOG__ << " extends: " << c->extends << "\n";
|
|
__LOG__ << "\n";
|
|
|
|
DumpSymbols(c->symbols, tab + 4);
|
|
}
|
|
break;
|
|
|
|
case Symbol::TypeFunction:
|
|
if (Function *f = (Function *)symbol)
|
|
{
|
|
__LOG__ << "Function " << f->name << "(" << f->prototype << ")\n";
|
|
DumpSymbols(f->symbols, tab + 4);
|
|
}
|
|
break;
|
|
|
|
case Symbol::TypeVariable:
|
|
if (Variable *v = (Variable *)symbol)
|
|
switch (v->var_type)
|
|
{
|
|
case Variable::VarLocal: __LOG__ << "Local variable " << v->name << "\n"; break;
|
|
case Variable::VarGlobal: __LOG__ << "Global variable " << v->name << "\n"; break;
|
|
case Variable::VarMember: __LOG__ << "Member variable " << v->name << "\n"; break;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
__LOG__ << "Variable " << symbol->name << "\n";
|
|
break;
|
|
}
|
|
}
|
|
void DumpSymbols(const SharedList <Symbol *> &symbols, int tab)
|
|
{
|
|
ListForeachPtr(Symbol *, symbol, symbols)
|
|
DumpSymbol(symbol, tab);
|
|
}
|
|
void DumpSource(const Source *source)
|
|
{
|
|
ListForeachPtr(Symbol *, symbol, source->symbols)
|
|
{
|
|
switch (symbol->type)
|
|
{
|
|
case Symbol::TypeClass: __LOG__ << " Class"; break;
|
|
case Symbol::TypeFunction: __LOG__ << " Function"; break;
|
|
case Symbol::TypeVariable: __LOG__ << " Variable"; break;
|
|
}
|
|
|
|
__LOG__ << " '" << symbol->name << "'\n";
|
|
}
|
|
}
|
|
void DumpProgram(const Program &program)
|
|
{
|
|
ListForeachPtr(Source *, source, program.sources)
|
|
{
|
|
__LOG__ << "Source '" << source->name << "'\n";
|
|
DumpSymbols(source->symbols, 4);
|
|
}
|
|
}
|
|
//------------------------------------------------------------------------------
|