Recovered from cvs revision 2007-09-25 05:49:00

This commit is contained in:
2007-09-25 20:25:00 +00:00
parent 9312940dfa
commit 39e8bdd6ae
36 changed files with 2053 additions and 510 deletions

View File

@ -1,5 +1,7 @@
/*
* $Id: Awk.cpp,v 1.56 2007/09/23 16:48:55 bacon Exp $
* $Id: Awk.cpp,v 1.58 2007/09/24 11:22:22 bacon Exp $
*
* {License}
*/
@ -264,19 +266,23 @@ int Awk::Argument::init (run_t* run, val_t* v)
Awk::long_t Awk::Argument::toInt () const
{
ASE_ASSERT (this->run != ASE_NULL && this->val != ASE_NULL);
if (this->run == ASE_NULL || this->val == ASE_NULL) return 0;
return this->inum;
}
Awk::real_t Awk::Argument::toReal () const
{
ASE_ASSERT (this->run != ASE_NULL && this->val != ASE_NULL);
if (this->run == ASE_NULL || this->val == ASE_NULL) return 0.0;
return this->rnum;
}
const Awk::char_t* Awk::Argument::toStr (size_t* len) const
{
ASE_ASSERT (this->run != ASE_NULL && this->val != ASE_NULL);
if (this->run == ASE_NULL || this->val == ASE_NULL)
{
*len = 0;
return ASE_NULL;
}
if (this->str.ptr != ASE_NULL)
{
@ -476,7 +482,7 @@ int Awk::Run::getGlobal (int id, Argument& global) const
ASE_ASSERT (run != ASE_NULL);
global.clear ();
return global.init (run,ase_awk_getglobal (this->run, id));
return global.init (run, ase_awk_getglobal(this->run,id));
}
//////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,7 @@
/*
* $Id: Awk.hpp,v 1.58 2007/09/23 16:48:55 bacon Exp $
* $Id: Awk.hpp,v 1.60 2007/09/24 11:22:22 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_AWK_HPP_
@ -283,13 +285,14 @@ public:
*/
class Argument
{
protected:
public:
friend class Awk;
friend class Awk::Run;
Argument ();
~Argument ();
protected:
void clear ();
// initialization

View File

@ -1,5 +1,7 @@
/*
* $Id: StdAwk.cpp,v 1.27 2007/09/23 16:48:55 bacon Exp $
* $Id: StdAwk.cpp,v 1.28 2007/09/24 11:22:22 bacon Exp $
*
* {License}
*/
#include <ase/awk/StdAwk.hpp>

View File

@ -1,5 +1,7 @@
/*
* $Id: StdAwk.hpp,v 1.16 2007/09/23 16:48:55 bacon Exp $
* $Id: StdAwk.hpp,v 1.17 2007/09/24 11:22:22 bacon Exp $
*
* {License}
*/
#ifndef _ASE_AWK_STDAWK_HPP_

View File

@ -16,8 +16,148 @@
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug\cpp"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="_DEBUG;WIN32"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="NDEBUG;WIN32"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug MD|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@ -85,77 +225,6 @@
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release\cpp"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="NDEBUG;WIN32"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\..\release\lib\aseawk++.bsc"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
@ -185,6 +254,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\StdAwk.cpp"

View File

@ -16,8 +16,8 @@
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@ -76,7 +76,6 @@
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../release/lib/aseawk.bsc"
/>
<Tool
Name="VCFxCopTool"
@ -87,8 +86,78 @@
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\.."
PreprocessorDefinitions="_DEBUG;WIN32"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
DisableLanguageExtensions="true"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug MD|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@ -185,6 +254,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="err.c"
@ -207,6 +285,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="extio.c"
@ -229,6 +316,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="func.c"
@ -251,6 +347,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="map.c"
@ -273,6 +378,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="misc.c"
@ -295,6 +409,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="parse.c"
@ -317,6 +440,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="rec.c"
@ -339,6 +471,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="rex.c"
@ -361,6 +502,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="run.c"
@ -383,6 +533,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tab.c"
@ -405,6 +564,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tree.c"
@ -427,6 +595,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="val.c"
@ -449,6 +626,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter

View File

@ -16,8 +16,8 @@
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\..\release\lib"
IntermediateDirectory=".\release"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@ -95,7 +95,6 @@
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
OutputFile=".\../release/lib/aseawk_jni.bsc"
/>
<Tool
Name="VCFxCopTool"
@ -112,8 +111,104 @@
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\..\debug\lib"
IntermediateDirectory=".\debug"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\lib"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="true"
SuppressStartupBanner="true"
TargetEnvironment="1"
TypeLibraryName=".\../debug/lib/aseawk_jni.tlb"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..,$(JAVA_HOME)\include,$(JAVA_HOME)\include\win32"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\debug/aseawk_jni.pch"
AssemblerListingLocation=".\debug/"
ObjectFile=".\debug/"
ProgramDataBaseFileName=".\debug/"
WarningLevel="3"
SuppressStartupBanner="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="asecmn.lib aseawk.lib aseutl.lib odbc32.lib odbccp32.lib"
OutputFile="$(OutDir)\aseawk_jni.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="$(OutDir)"
GenerateDebugInformation="true"
ProgramDatabaseFile=".\../debug/lib/aseawk_jni.pdb"
ImportLibrary="debug/aseawk_jni.lib"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug MD|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@ -236,6 +331,15 @@
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug MD|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
</Filter>
<Filter

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.9 2007/09/23 16:48:55 bacon Exp $
* $Id: awk.c,v 1.10 2007/09/24 08:21:25 bacon Exp $
*
* {License}
*/
@ -220,7 +220,12 @@ int ase_awk_clear (ase_awk_t* awk)
awk->src.shared.buf_pos = 0;
awk->src.shared.buf_len = 0;
ase_awk_tab_clear (&awk->parse.globals);
/*ase_awk_tab_clear (&awk->parse.globals);*/
ASE_ASSERT (awk->parse.globals.size == awk->tree.nglobals);
ase_awk_tab_remove (
&awk->parse.globals, awk->tree.nbglobals,
awk->parse.globals.size - awk->tree.nbglobals);
ase_awk_tab_clear (&awk->parse.locals);
ase_awk_tab_clear (&awk->parse.params);
@ -231,8 +236,10 @@ int ase_awk_clear (ase_awk_t* awk)
/* clear parse trees */
awk->tree.ok = 0;
awk->tree.nbglobals = 0;
awk->tree.nglobals = 0;
/*awk->tree.nbglobals = 0;
awk->tree.nglobals = 0; */
awk->tree.nglobals = awk->tree.nbglobals;
awk->tree.cur_afn.ptr = ASE_NULL;
awk->tree.cur_afn.len = 0;
ase_awk_map_clear (awk->tree.afns);

View File

@ -1,5 +1,5 @@
/*
* $Id: jni.c,v 1.14 2007/09/23 16:48:55 bacon Exp $
* $Id: jni.c,v 1.15 2007/09/24 11:15:58 bacon Exp $
*
* {License}
*/
@ -2635,7 +2635,11 @@ JNIEXPORT jint JNICALL Java_ase_awk_Awk_system (
if (mbs == ASE_NULL) return -1;
size_t mbl = wcstombs (mbs, tmp, len*5);
if (mbl == (size_t)-1) return -1;
if (mbl == (size_t)-1)
{
free (mbs);
return -1;
}
mbs[mbl] = '\0';
ret = system(mbs);
free (mbs);

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.c,v 1.14 2007/09/23 16:48:55 bacon Exp $
* $Id: parse.c,v 1.15 2007/09/24 08:21:25 bacon Exp $
*
* {License}
*/
@ -130,7 +130,7 @@ static int parse (ase_awk_t* awk);
static ase_awk_t* parse_progunit (ase_awk_t* awk);
static ase_awk_t* collect_globals (ase_awk_t* awk);
static int adjust_static_globals (ase_awk_t* awk);
static void adjust_static_globals (ase_awk_t* awk);
static int add_global (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len,
@ -295,8 +295,7 @@ static global_t gtab[] =
{ ASE_T("RLENGTH"), 7, 0 },
{ ASE_T("RS"), 2, 0 },
{ ASE_T("RSTART"), 6, 0 },
{ ASE_T("SUBSEP"), 6, 0 },
{ ASE_NULL, 0, 0 }
{ ASE_T("SUBSEP"), 6, 0 }
};
#define GET_CHAR(awk) \
@ -480,11 +479,7 @@ static int parse (ase_awk_t* awk)
return -1;
}
if (adjust_static_globals (awk) == -1)
{
n = -1;
goto exit_parse;
}
adjust_static_globals (awk);
/* the user io handler for the source code input returns 0 when
* it doesn't have any files to open. this is the same condition
@ -519,7 +514,7 @@ static int parse (ase_awk_t* awk)
}
}
awk->tree.nglobals = ase_awk_tab_getsize(&awk->parse.globals);
ASE_ASSERT (awk->tree.nglobals == ase_awk_tab_getsize(&awk->parse.globals));
if (awk->src.ios.out != ASE_NULL)
{
@ -567,12 +562,14 @@ static ase_awk_t* parse_progunit (ase_awk_t* awk)
if (get_token(awk) == -1) return ASE_NULL;
nglobals = ase_awk_tab_getsize(&awk->parse.globals);
ASE_ASSERT (awk->tree.nglobals == ase_awk_tab_getsize(&awk->parse.globals));
nglobals = awk->tree.nglobals;
if (collect_globals (awk) == ASE_NULL)
{
ase_awk_tab_remove (
&awk->parse.globals, nglobals,
ase_awk_tab_getsize(&awk->parse.globals) - nglobals);
awk->tree.nglobals = nglobals;
return ASE_NULL;
}
}
@ -1173,9 +1170,17 @@ static ase_awk_nde_t* parse_block (
}
/* remove unnecessary statements */
if (nde->type == ASE_AWK_NDE_NULL ||
(nde->type == ASE_AWK_NDE_BLK &&
((ase_awk_nde_blk_t*)nde)->body == ASE_NULL)) continue;
if (nde->type == ASE_AWK_NDE_NULL)
{
ase_awk_clrpt (awk, nde);
continue;
}
if (nde->type == ASE_AWK_NDE_BLK &&
((ase_awk_nde_blk_t*)nde)->body == ASE_NULL)
{
ase_awk_clrpt (awk, nde);
continue;
}
if (curr == ASE_NULL) head = nde;
else curr->next = nde;
@ -1198,8 +1203,8 @@ static ase_awk_nde_t* parse_block (
tmp = ase_awk_tab_getsize(&awk->parse.locals);
if (tmp > awk->parse.nlocals_max) awk->parse.nlocals_max = tmp;
ase_awk_tab_remove (
&awk->parse.locals, nlocals, tmp - nlocals);
/* remove all locals to move it up to the top level */
ase_awk_tab_remove (&awk->parse.locals, nlocals, tmp - nlocals);
/* adjust the number of locals for a block without any statements */
/* if (head == ASE_NULL) tmp = 0; */
@ -1209,9 +1214,9 @@ static ase_awk_nde_t* parse_block (
block->next = ASE_NULL;
block->body = head;
/* TODO: not only local variables but also nested blocks,
unless it is part of other constructs such as if, can be promoted
and merged to top-level block */
/* TODO: not only local variables but also nested blocks,
unless it is part of other constructs such as if, can be promoted
and merged to top-level block */
/* migrate all block-local variables to a top-level block */
if (is_top)
@ -1250,7 +1255,6 @@ static ase_awk_nde_t* parse_block_dc (
int ase_awk_initglobals (ase_awk_t* awk)
{
global_t* p = gtab;
int id;
/* ase_awk_initglobals is not generic-purpose. call this from
@ -1258,61 +1262,46 @@ int ase_awk_initglobals (ase_awk_t* awk)
ASE_ASSERT (awk->tree.nbglobals == 0 && awk->tree.nglobals == 0);
awk->tree.nbglobals = 0;
while (p->name != ASE_NULL)
awk->tree.nglobals = 0;
for (id = ASE_AWK_MIN_GLOBAL_ID; id <= ASE_AWK_MAX_GLOBAL_ID; id++)
{
if (ase_awk_tab_add (
&awk->parse.globals, p->name, p->name_len) == (ase_size_t)-1)
{
return -1;
}
ase_size_t g;
g = ase_awk_tab_add (&awk->parse.globals,
gtab[id].name, gtab[id].name_len);
if (g == (ase_size_t)-1) return -1;
ASE_ASSERT (g == id);
awk->tree.nbglobals++;
p++;
awk->tree.nglobals++;
}
ASE_ASSERT (awk->tree.nbglobals ==
ASE_AWK_MAX_GLOBAL_ID-ASE_AWK_MIN_GLOBAL_ID+1);
return 0;
}
static int adjust_static_globals (ase_awk_t* awk)
static void adjust_static_globals (ase_awk_t* awk)
{
/* TODO: */
return 0;
}
#if 0
static ase_awk_t* add_static_globals (ase_awk_t* awk)
{
global_t* p = gtab;
int id;
awk->tree.nbglobals = 0;
while (p->name != ASE_NULL)
ASE_ASSERT (awk->tree.nbglobals >=
ASE_AWK_MAX_GLOBAL_ID - ASE_AWK_MAX_GLOBAL_ID + 1);
for (id = ASE_AWK_MIN_GLOBAL_ID; id <= ASE_AWK_MAX_GLOBAL_ID; id++)
{
if (p->valid != 0 && (awk->option & p->valid) == 0)
if (gtab[id].valid != 0 && (awk->option & gtab[id].valid) == 0)
{
#if 0
/* an invalid global variable are still added
* to the global variable table with an empty name.
* this is to prevent the run-time from looking up
* the variable */
id = add_global (awk, ASE_T(""), 0, 0, 1);
#endif
id = add_global (awk, p->name, p->name_len, 0, 1);
awk->parse.globals.buf[id].name.len = 0;
}
else
else
{
id = add_global (awk, p->name, p->name_len, 0, 0);
awk->parse.globals.buf[id].name.len = gtab[id].name_len;
}
if (id == -1) return ASE_NULL;
awk->tree.nbglobals++;
p++;
}
return awk;
}
#endif
static int add_global (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len,
@ -1320,39 +1309,35 @@ static int add_global (
{
ase_size_t nglobals;
/*
if (!force)
{*/
if (awk->option & ASE_AWK_UNIQUEFN)
if (awk->option & ASE_AWK_UNIQUEFN)
{
/* check if it conflict with a builtin function name */
if (ase_awk_getbfn (awk, name, len) != ASE_NULL)
{
/* check if it conflict with a builtin function name */
if (ase_awk_getbfn (awk, name, len) != ASE_NULL)
{
SETERRARG (
awk, ASE_AWK_EBFNRED, awk->token.line,
name, len);
return -1;
}
/* check if it conflict with a function name */
if (ase_awk_map_get (
awk->tree.afns, name, len) != ASE_NULL)
{
SETERRARG (
awk, ASE_AWK_EAFNRED, line,
name, len);
return -1;
}
}
/* check if it conflicts with other global variable names */
if (ase_awk_tab_find (
&awk->parse.globals, 0, name, len) != (ase_size_t)-1)
{
SETERRARG (awk, ASE_AWK_EDUPGBL, line, name, len);
SETERRARG (
awk, ASE_AWK_EBFNRED, awk->token.line,
name, len);
return -1;
}
/*}*/
/* check if it conflict with a function name */
if (ase_awk_map_get (
awk->tree.afns, name, len) != ASE_NULL)
{
SETERRARG (
awk, ASE_AWK_EAFNRED, line,
name, len);
return -1;
}
}
/* check if it conflicts with other global variable names */
if (ase_awk_tab_find (
&awk->parse.globals, 0, name, len) != (ase_size_t)-1)
{
SETERRARG (awk, ASE_AWK_EDUPGBL, line, name, len);
return -1;
}
nglobals = ase_awk_tab_getsize (&awk->parse.globals);
if (nglobals >= ASE_AWK_MAX_GLOBALS)
@ -1371,6 +1356,9 @@ static int add_global (
* the name length is reset to zero. */
if (disabled) awk->parse.globals.buf[nglobals].name.len = 0;
awk->tree.nglobals = ase_awk_tab_getsize (&awk->parse.globals);
ASE_ASSERT (nglobals == awk->tree.nglobals-1);
/* return the id which is the index to the global table. */
return (int)nglobals;
}
@ -1378,7 +1366,22 @@ static int add_global (
int ase_awk_addglobal (
ase_awk_t* awk, const ase_char_t* name, ase_size_t len)
{
return add_global (awk, name, len, 0, 0);
int n;
if (awk->tree.nglobals > awk->tree.nbglobals)
{
/* this function is not allow after ase_awk_parse is called */
SETERR (awk, ASE_AWK_ENOPER);
return -1;
}
n = add_global (awk, name, len, 0, 0);
/* update the count of the static globals.
* the total global count has been updated inside add_global. */
if (n >= 0) awk->tree.nbglobals++;
return n;
}
int ase_awk_delglobal (
@ -1386,19 +1389,29 @@ int ase_awk_delglobal (
{
ase_size_t n;
n = ase_awk_tab_find (&awk->parse.globals, 0, name, len);
#define ASE_AWK_NUM_STATIC_GLOBALS \
(ASE_AWK_MAX_GLOBAL_ID-ASE_AWK_MIN_GLOBAL_ID+1)
if (awk->tree.nglobals > awk->tree.nbglobals)
{
/* this function is not allow after ase_awk_parse is called */
SETERR (awk, ASE_AWK_ENOPER);
return -1;
}
n = ase_awk_tab_find (&awk->parse.globals,
ASE_AWK_NUM_STATIC_GLOBALS, name, len);
if (n == (ase_size_t)-1)
{
SETERRARG (awk, ASE_AWK_ENOENT, 0, name, len);
return -1;
}
/* clear the name to emulate the action. this approach is
* in align with ase_awk_addglobal adding an ineffective global.
* anyway, this function cannot physically remove the entry
* because the existing global ID's known can all go wrong if
* it does so. the best is not to use this function as a normal
* program has no reason to do so. */
/* invalidate the name if deletion is requested.
* this approach does not delete the entry.
* if ase_awk_addglobal is called with the same name
* again, the entry will be appended again.
* never call this funciton unless it is really required. */
awk->parse.globals.buf[n].name.ptr[0] = ASE_T('\0');;
awk->parse.globals.buf[n].name.len = 0;
@ -1444,6 +1457,7 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
{
ase_char_t* local;
ase_size_t local_len;
ase_size_t n;
while (1)
{
@ -1456,8 +1470,6 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
local = ASE_STR_BUF(&awk->token.name);
local_len = ASE_STR_LEN(&awk->token.name);
/* NOTE: it is not checked againt globals names */
if (awk->option & ASE_AWK_UNIQUEFN)
{
/* check if it conflict with a builtin function name */
@ -1484,8 +1496,8 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
}
/* check if it conflicts with a paremeter name */
if (ase_awk_tab_find (&awk->parse.params,
0, local, local_len) != (ase_size_t)-1)
n = ase_awk_tab_find (&awk->parse.params, 0, local, local_len);
if (n != (ase_size_t)-1)
{
SETERRARG (
awk, ASE_AWK_EPARRED, awk->token.line,
@ -1494,17 +1506,40 @@ static ase_awk_t* collect_locals (ase_awk_t* awk, ase_size_t nlocals)
}
/* check if it conflicts with other local variable names */
if (ase_awk_tab_find (&awk->parse.locals,
n = ase_awk_tab_find (
&awk->parse.locals,
((awk->option & ASE_AWK_SHADING)? nlocals: 0),
local, local_len) != (ase_size_t)-1)
local, local_len);
if (n != (ase_size_t)-1)
{
SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line,
local, local_len);
return ASE_NULL;
}
/* check if it conflicts with global variable names */
n = ase_awk_tab_find (&awk->parse.globals, 0, local, local_len);
if (n != (ase_size_t)-1)
{
if (n < awk->tree.nbglobals)
{
/* conflicting with a static global variable */
SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line,
local, local_len);
return ASE_NULL;
}
if ((awk->option & ASE_AWK_SHADING) == 0)
{
/* conflicting with a normal global variable */
SETERRARG (
awk, ASE_AWK_EDUPLCL, awk->token.line,
local, local_len);
return ASE_NULL;
}
}
if (ase_awk_tab_getsize(&awk->parse.locals) >= ASE_AWK_MAX_LOCALS)
{
SETERRLIN (awk, ASE_AWK_ELCLTM, awk->token.line);

View File

@ -1,5 +1,5 @@
/*
* $Id: run.h,v 1.5 2007/09/23 16:48:55 bacon Exp $
* $Id: run.h,v 1.6 2007/09/24 08:21:25 bacon Exp $
*
* {License}
*/
@ -102,7 +102,11 @@ enum ase_awk_global_id_t
ASE_AWK_GLOBAL_RSTART,
ASE_AWK_GLOBAL_SUBSEP,
ASE_AWK_GLOBAL_MAX /* this is not the actual id. used internally */
/* these are not not the actual IDs and are used internally only
* Make sure you update these values properly if you add more
* ID definitions, however */
ASE_AWK_MIN_GLOBAL_ID = ASE_AWK_GLOBAL_ARGC,
ASE_AWK_MAX_GLOBAL_ID = ASE_AWK_GLOBAL_SUBSEP
};
#ifdef __cplusplus