diff options
author | jofret | 2008-06-06 15:51:00 +0000 |
---|---|---|
committer | jofret | 2008-06-06 15:51:00 +0000 |
commit | 27c9baef26252d9d8163f2aa9de92e9f9a49e691 (patch) | |
tree | af1480c92bf46094b8c25825349c8913a35b45ef /src | |
parent | 00b3a2f8e0c8c6ca5d79ed96733d37c48cb5bc47 (diff) | |
download | scilab2c-27c9baef26252d9d8163f2aa9de92e9f9a49e691.tar.gz scilab2c-27c9baef26252d9d8163f2aa9de92e9f9a49e691.tar.bz2 scilab2c-27c9baef26252d9d8163f2aa9de92e9f9a49e691.zip |
- Clean add for Raffaele.
Diffstat (limited to 'src')
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_AnalyzeScope.sci | 60 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_Del.sci | 27 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_FindPos.sci | 32 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_Get.sci | 48 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_GetInArgInfo.sci | 105 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_GetSymbolInfo.sci | 53 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_InsForCntVars.sci | 116 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_InsOutArg.sci | 114 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_Load.sci | 20 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_MatchSymbol.sci | 51 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_Save.sci | 33 | ||||
-rw-r--r-- | src/Scilab2C/Scilab2C/SymbolTable/ST_Set.sci | 35 |
12 files changed, 694 insertions, 0 deletions
diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_AnalyzeScope.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_AnalyzeScope.sci new file mode 100644 index 00000000..84b8ef4c --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_AnalyzeScope.sci @@ -0,0 +1,60 @@ +function OutArg = ST_AnalyzeScope(OldOutArg,NOutArg,FileInfo,SharedInfo); +// function OutArg = ST_AnalyzeScope(OldOutArg,NOutArg,FileInfo,SharedInfo); +// ----------------------------------------------------------------- +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +SCI2CNInArgCheck(argn(2),4,4); + +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + + +OutArg = OldOutArg; +GlobalVarsFileName = FileInfo.GlobalVarFileName; +LocalVarsFileName = FileInfo.Funct(nxtscifunnumber).LocalVarFileName; +TempVarsFileName = FileInfo.Funct(nxtscifunnumber).TempVarFileName; + +for cntout = 1:NOutArg + TBName = OutArg(cntout).Name; + + SymbolTableFileName = TempVarsFileName; + [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(TBName,SymbolTableFileName); + if (TBFlagfound == 0) + else + SCI2CerrorFile('Found a temp symbol in '+SymbolTableFileName+... + ' with the same name of the equal output argument ""'+TBName+'"".',ReportFileName); + end + + SymbolTableFileName = LocalVarsFileName; + [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(TBName,SymbolTableFileName); + if (TBFlagfound == 0) + else + OutArg(cntout).Scope = 'Local'; + end + + if (TBFlagfound == 0) + SymbolTableFileName = GlobalVarsFileName; + [TBFlagfound2,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(TBName,SymbolTableFileName); + if (TBFlagfound2 == 0) + if SCI2Cstrncmps1size(SharedInfo.ASTReader.TempVarsName,OutArg(cntout).Name) + OutArg(cntout).Scope = 'Temp'; + else + OutArg(cntout).Scope = 'Local'; + end + else + OutArg(cntout).Scope = 'Global'; + end + end + +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_Del.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_Del.sci new file mode 100644 index 00000000..683ef06b --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_Del.sci @@ -0,0 +1,27 @@ +function ST_Del(TBName,SymbolTableFileName) +// function ST_Del(TBName,SymbolTableFileName) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +SCI2CNInArgCheck(argn(2),2,2); + +SCI2CSymbolTable = ST_Load(SymbolTableFileName); + +[TBFlagfound,TBPosition] = ST_FindPos(TBName,SymbolTableFileName); + +if (TBFlagfound == 0) + SCI2Cerror('Missing symbol: trying to del a non existing symbol ""'+TBName+'"".'); +elseif (TBFlagfound == 1) + SCI2CSymbolTable(TBPosition) = []; + + ST_Save(SymbolTableFileName,SCI2CSymbolTable); +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_FindPos.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_FindPos.sci new file mode 100644 index 00000000..7ce0c1ec --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_FindPos.sci @@ -0,0 +1,32 @@ +function [TBFlagfound,TBPosition] = ST_FindPos(TBName,SymbolTableFileName) +// function [TBFlagfound,TBPosition] = ST_FindPos(TBName,SymbolTableFileName) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +SCI2CNInArgCheck(argn(2),2,2); + +SCI2CSymbolTable = ST_Load(SymbolTableFileName); + +TBFlagfound = 0; +TBPosition = 0; +NEntries = max(size(SCI2CSymbolTable)); +for countertable = 1:NEntries + if (mtlb_strcmp(TBName,SCI2CSymbolTable(countertable).Name)) + TBFlagfound = TBFlagfound + 1; + TBPosition = countertable; + end +end + +if (TBFlagfound > 1) + SCI2Cerror('Symbol table conflict: found two symbols with the same name ""'+TBName+'"".'); +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_Get.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_Get.sci new file mode 100644 index 00000000..8713ad70 --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_Get.sci @@ -0,0 +1,48 @@ +function [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(Field_Name,SymbolTableFileName) +// function [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... +// ST_Get(Field_Name,SymbolTableFileName) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +SCI2CNInArgCheck(argn(2),2,2); + +[tmpnams,tmptyps,tmpdims,tmpvols]=listvarinfile(SymbolTableFileName); +if (max(size(tmpnams)) > 1) + SCI2Cerror('More than one variable found in ""'+SymbolTableFileName+'"".'); +end +load(SymbolTableFileName,tmpnams); +SCI2CSymbolTable = eval(tmpnams); + +TBFlagfound = 0; +TBType = ''; +TBSize(1) = ''; +TBSize(2) = ''; +TBValue = %nan; +TBFindLike = %nan; +TBDimension = %nan; +if (TBFlagfound == 0) + NEntries = max(size(SCI2CSymbolTable)); + for countertable = 1:NEntries + if (mtlb_strcmp(Field_Name,SCI2CSymbolTable(countertable).Name)) + TBFlagfound = TBFlagfound + 1; + TBType = SCI2CSymbolTable(countertable).Type; // String + TBSize = SCI2CSymbolTable(countertable).Size; // String + TBValue = SCI2CSymbolTable(countertable).Value; + TBFindLike = SCI2CSymbolTable(countertable).FindLike; // Number: 0 or 1. + TBDimension = SCI2CSymbolTable(countertable).Dimension; // Number: 0 or 1 or 2. + end + end +end + +if (TBFlagfound > 1) + SCI2Cerror('Symbol table conflict: found two symbols with the same name ""'+TBName+'"".'); +end +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_GetInArgInfo.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_GetInArgInfo.sci new file mode 100644 index 00000000..5feb717b --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_GetInArgInfo.sci @@ -0,0 +1,105 @@ +function [UpdatedInArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo) +// function UpdatedInArg = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +SCI2CNInArgCheck(argn(2),4,4); + +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + + +UpdatedInArg = InArg; + +for cntinarg = 1:NInArg + tmpname = InArg(cntinarg).Name; + tmpscope = InArg(cntinarg).Scope; + lengthNumber = length('Number_'); + if (part(tmpscope,1:lengthNumber) == 'Number_') + UpdatedInArg(cntinarg).Type = part(tmpscope,lengthNumber+1:lengthNumber+1); + if (UpdatedInArg(cntinarg).Type == 'x') + UpdatedInArg(cntinarg).Type = SharedInfo.DefaultPrecision; // It is the default. + elseif (UpdatedInArg(cntinarg).Type == 'X') + if (SharedInfo.DefaultPrecision == 's') + UpdatedInArg(cntinarg).Type = 'c'; // It is the default. + elseif (SharedInfo.DefaultPrecision == 'd') + UpdatedInArg(cntinarg).Type = 'z'; // It is the default. + else + SCI2Cerror('Unexpected value for SharedInfo.DefaultPrecision: ""'+SharedInfo.DefaultPrecision+'""'); + end + end + if (tmpname == '%pi') + UpdatedInArg(cntinarg).Name = 'SCI2C_PI'; + numvalue = %pi; + elseif (tmpname == '%T') + UpdatedInArg(cntinarg).Name = 'SCI2C_T'; + numvalue = 1; + elseif (tmpname == '%F') + UpdatedInArg(cntinarg).Name = 'SCI2C_F'; + numvalue = 0; + elseif (tmpname == '%nan') + UpdatedInArg(cntinarg).Name = 'SCI2C_NAN'; + numvalue = %nan; + elseif (tmpname == '%inf') + UpdatedInArg(cntinarg).Name = 'SCI2C_INF'; + numvalue = %nan; // Otherwise it will put in the C code Inf value. + elseif (tmpname == '%i') + UpdatedInArg(cntinarg).Name = 'SCI2C_IMG_'+convstr(UpdatedInArg(cntinarg).Type,'u'); + numvalue = %i; + else + numvalue = eval(tmpname); + end + + UpdatedInArg(cntinarg).Size(1) = '1'; + UpdatedInArg(cntinarg).Size(2) = '1'; + UpdatedInArg(cntinarg).Value = numvalue; + UpdatedInArg(cntinarg).FindLike = 0; + UpdatedInArg(cntinarg).Dimension = 0; + UpdatedInArg(cntinarg).Scope = 'Number'; + + elseif (tmpscope == 'String') + SharedInfo.ASTReader.UsedTempVars = SharedInfo.ASTReader.UsedTempVars + 1; + TmpOutArgName = strcat([SharedInfo.ASTReader.TempVarsName,string(SharedInfo.ASTReader.UsedTempVars)]); + + UpdatedInArg(cntinarg).Name = TmpOutArgName; // Change the name. + UpdatedInArg(cntinarg).Type = 'g'; // it is the default. + UpdatedInArg(cntinarg).Size(1) = '1'; + UpdatedInArg(cntinarg).Size(2) = string(length(tmpname)+1); //+1 = (\0) + UpdatedInArg(cntinarg).Value = '""'+tmpname+'""'; + UpdatedInArg(cntinarg).FindLike = 0; + UpdatedInArg(cntinarg).Dimension = 2; //NUT: in future releases you can set this field to 1. + UpdatedInArg(cntinarg).Scope = 'Temp'; + + ST_InsOutArg(UpdatedInArg(cntinarg),1,FileInfo,SharedInfo,'all'); + + elseif (tmpscope == 'Variable' | tmpscope == 'Global' | tmpscope == 'Local' | tmpscope == 'Temp') + [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ST_GetSymbolInfo(tmpname,FileInfo,SharedInfo); + if (TBFlagfound == 0) + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Unknown symbol ""'+tmpname+'"".',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Be sure to initialize every symbol you are using.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Before running the SCI2C translator, remember to run the code you are trying',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: to translate in order to check syntax errors.',ReportFileName,'both','y'); + PrintStringInfo(' ',ReportFileName,'both','y'); + SCI2Cerror(' '); + end + UpdatedInArg(cntinarg).Type = TBType; + UpdatedInArg(cntinarg).Size = TBSize; + UpdatedInArg(cntinarg).Value = TBValue; + UpdatedInArg(cntinarg).FindLike = TBFindLike; + UpdatedInArg(cntinarg).Dimension = TBDimension; + UpdatedInArg(cntinarg).Scope = TBScope; + + else + SCI2Cerror('Unknown scope identifier ""'+tmpscope+'"" for variable ""'+tmpname+'"".'); + end +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_GetSymbolInfo.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_GetSymbolInfo.sci new file mode 100644 index 00000000..e19611d6 --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_GetSymbolInfo.sci @@ -0,0 +1,53 @@ +function [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ST_GetSymbolInfo(TBName,FileInfo,SharedInfo) +// function [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ST_GetSymbolInfo(TBName,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +SCI2CNInArgCheck(argn(2),3,3); + +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +GlobalVarsFileName = FileInfo.GlobalVarFileName; +LocalVarsFileName = FileInfo.Funct(nxtscifunnumber).LocalVarFileName; +TempVarsFileName = FileInfo.Funct(nxtscifunnumber).TempVarFileName; + +TBFlagfound = 0; +TBType = ''; +TBSize(1) = ''; +TBSize(2) = ''; +TBValue = %nan +TBFindLike = %nan +TBDimension = %nan; +TBScope = ''; + +[TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(TBName,TempVarsFileName); +if (TBFlagfound == 1); + TBScope = 'Temp'; +end + +if (TBFlagfound == 0); + [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(TBName,LocalVarsFileName); + if (TBFlagfound == 1); + TBScope = 'Local'; + end +end + +if (TBFlagfound == 0); + [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension] = ... + ST_Get(TBName,GlobalVarsFileName); + if (TBFlagfound == 1); + TBScope = 'Global'; + end +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_InsForCntVars.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_InsForCntVars.sci new file mode 100644 index 00000000..907fa10f --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_InsForCntVars.sci @@ -0,0 +1,116 @@ +function [OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,FunctionName,FileInfo,SharedInfo) +// function [OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,FunctionName,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +SCI2CNInArgCheck(argn(2),7,7); + +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + + +if ((SharedInfo.ForExpr.OnExec > 0) & (NOutArg==1) & (OutArg.Scope~='Temp')) + + if (FunctionName == 'OpColon') + + SharedInfo.SkipNextFun = 1; + + OutArg.Size(1) = '1'; + OutArg.Size(2) = '1'; + OutArg.Value = %nan; + OutArg.FindLike = 0; + OutArg.Dimension = 0; + SharedInfo.ForExpr.OpColonInfoIn1 = InArg(1).Name; + + if (NInArg == 2) + SharedInfo.ForExpr.OpColonInfoIn2 = '1'; + SharedInfo.ForExpr.OpColonInfoIn3 = InArg(2).Name; + else + SharedInfo.ForExpr.OpColonInfoIn2 = InArg(2).Name; + if isnan(InArg(2).Value) + EM_UnknownStep(ReportFileName); + end + + SharedInfo.ForExpr.OpColonInfoIn3 = InArg(3).Name; + end + + SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.OpColon; + SharedInfo.ForExpr.IntCntArg = []; + SharedInfo.ForExpr.MtxValCntArg = []; + SharedInfo.ForExpr.SclValCntArg = OutArg; + + elseif ((FunctionName == 'OpEqual') & (SharedInfo.ForExpr.AssignmentFun == 0)) + if (OutArg.Dimension > 0) + SharedInfo.SkipNextFun = 1; + OutArg.Size(1) = '1'; + OutArg.Size(2) = '1'; + OutArg.Value = %nan; + OutArg.FindLike = 0; + OutArg.Dimension = 0; + + NNewArg = 1; + NewArg(NNewArg).Name = SharedInfo.ASTReader.TempForCntVarsName+string(SharedInfo.CountForTempVars); + SharedInfo.CountForTempVars = SharedInfo.CountForTempVars + 1; + NewArg(NNewArg).Size(1) = '1'; + NewArg(NNewArg).Size(2) = '1'; + NewArg(NNewArg).Type = 'i'; + NewArg(NNewArg).Value = 0; + NewArg(NNewArg).FindLike = 0; + NewArg(NNewArg).Dimension = 0; + NewArg(NNewArg).Scope = 'Temp'; + + NNewArg = 1; + ST_InsOutArg(NewArg,NNewArg,FileInfo,SharedInfo,'all'); + + SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.EqMatrix; + SharedInfo.ForExpr.IntCntArg = NewArg(1); + SharedInfo.ForExpr.MtxValCntArg = InArg(1); + SharedInfo.ForExpr.SclValCntArg = OutArg; + else + SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.EqScalar; + end + else + if (OutArg.Dimension > 0) + + NewArg = OutArg; + OutArg.Name = SharedInfo.ASTReader.TempForValVarsName+OutArg.Name; + + NNewArg = 1; + NewArg(NNewArg).Size(1) = '1'; + NewArg(NNewArg).Size(2) = '1'; + NewArg(NNewArg).Value = %nan; + NewArg(NNewArg).FindLike = 0; + NewArg(NNewArg).Dimension = 0; + + NNewArg = 2; + NewArg(NNewArg).Name = SharedInfo.ASTReader.TempForCntVarsName+string(SharedInfo.CountForTempVars); + SharedInfo.CountForTempVars = SharedInfo.CountForTempVars + 1; + NewArg(NNewArg).Size(1) = '1'; + NewArg(NNewArg).Size(2) = '1'; + NewArg(NNewArg).Type = 'i'; + NewArg(NNewArg).Value = 0; + NewArg(NNewArg).FindLike = 0; + NewArg(NNewArg).Dimension = 0; + NewArg(NNewArg).Scope = 'Temp'; + + NNewArg = 2; + ST_InsOutArg(NewArg,NNewArg,FileInfo,SharedInfo,'all'); + + SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.GenFunMtx; + SharedInfo.ForExpr.IntCntArg = NewArg(2); + SharedInfo.ForExpr.MtxValCntArg = OutArg(1); + SharedInfo.ForExpr.SclValCntArg = NewArg(1); + end + end +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_InsOutArg.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_InsOutArg.sci new file mode 100644 index 00000000..d4817adb --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_InsOutArg.sci @@ -0,0 +1,114 @@ +function ST_InsOutArg(OutArg,NOutArg,FileInfo,SharedInfo,MatchRule) +// function ST_InsOutArg(OutArg,NOutArg,FileInfo,SharedInfo,MatchRule) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +SCI2CNInArgCheck(argn(2),5,5); + +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CDeclarationFileName = FileInfo.Funct(nxtscifunnumber).CDeclarationFileName; +CGblDeclarFileName = FileInfo.Funct(nxtscifunnumber).CGblDeclarFileName; + +GlobalVarsFileName = FileInfo.GlobalVarFileName; +LocalVarsFileName = FileInfo.Funct(nxtscifunnumber).LocalVarFileName; +TempVarsFileName = FileInfo.Funct(nxtscifunnumber).TempVarFileName; + +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +CPass1FreeFileName = FileInfo.Funct(nxtscifunnumber).CPass1FreeFileName; + + + + +for counteroutput = 1:NOutArg + + if mtlb_strcmp(OutArg(counteroutput).Scope,'Temp') + SymbTableFileName = TempVarsFileName; + elseif mtlb_strcmp(OutArg(counteroutput).Scope,'Local') + SymbTableFileName = LocalVarsFileName; + elseif mtlb_strcmp(OutArg(counteroutput).Scope,'Global') + SymbTableFileName = GlobalVarsFileName; + else + SCI2Cerror('Unknown scope ""'+OutArg(counteroutput).Scope+'"" for symbol: '+OutArg(counteroutput).Name); + end + + + [TBFlagfound,TBFlagEqualSymbols] = ... + ST_MatchSymbol(OutArg(counteroutput).Name,... + OutArg(counteroutput).Type,... + OutArg(counteroutput).Size,... + OutArg(counteroutput).Value,... + OutArg(counteroutput).FindLike,... + OutArg(counteroutput).Dimension,... + SymbTableFileName,MatchRule); + + if (TBFlagfound == 1) + if (TBFlagEqualSymbols == 0) + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Symbol Table Conflict. Trying to insert again symbol ""'+... + OutArg(counteroutput).Name+'"" with different settings',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Please check that you are not using variable ""'+OutArg(counteroutput).Name+'""',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: with different sizes and/or types.',ReportFileName,'both','y'); + PrintStringInfo(' ',ReportFileName,'both','y'); + SCI2Cerror(' '); + else + if ((GetSymbolDimension(OutArg(counteroutput).Size)) == 0) + ST_Set(OutArg(counteroutput).Name,... + OutArg(counteroutput).Type,... + OutArg(counteroutput).Size,... + OutArg(counteroutput).Value,... + OutArg(counteroutput).FindLike,... + OutArg(counteroutput).Dimension,... + SymbTableFileName); + end + if (OutArg(counteroutput).Scope=='Global') + IndentLevelGlobal = 0; //NUT: forced always to 1 + FlagExt = 1; + C_GenDeclarations(OutArg(counteroutput),CGblDeclarFileName,IndentLevelGlobal,ReportFileName,FlagExt); + end + end + elseif (TBFlagfound == 2) + ST_Set(OutArg(counteroutput).Name,... + OutArg(counteroutput).Type,... + OutArg(counteroutput).Size,... + OutArg(counteroutput).Value,... + OutArg(counteroutput).FindLike,... + OutArg(counteroutput).Dimension,... + SymbTableFileName); + IndentLevel = 0; //NUT: forced always to 1 + FlagExt = 0; + C_GenDeclarations(OutArg(counteroutput),CGblDeclarFileName,IndentLevel,ReportFileName,FlagExt); + else + if (OutArg(counteroutput).FindLike == 1) + TmpOutArgSize(1) = '__'+OutArg(counteroutput).Name+'Size[0]'; + TmpOutArgSize(2) = '__'+OutArg(counteroutput).Name+'Size[1]'; + else + TmpOutArgSize(1) = OutArg(counteroutput).Size(1); + TmpOutArgSize(2) = OutArg(counteroutput).Size(2); + end + ST_Set(OutArg(counteroutput).Name,... + OutArg(counteroutput).Type,... + TmpOutArgSize,... + OutArg(counteroutput).Value,... + OutArg(counteroutput).FindLike,... + OutArg(counteroutput).Dimension,... + SymbTableFileName); + IndentLevelDeclaration = 1; //NUT: per ora lo forzo sempre a 1 + IndentLevelMalloc = SharedInfo.NIndent; + FlagExt = 0; + C_GenDeclarations(OutArg(counteroutput),CDeclarationFileName,IndentLevelDeclaration,ReportFileName,FlagExt); + C_MemAllocOutTempVars(OutArg(counteroutput),1,CPass1FileName,CPass1FreeFileName,IndentLevelMalloc,ReportFileName); + end + +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_Load.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_Load.sci new file mode 100644 index 00000000..c272375c --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_Load.sci @@ -0,0 +1,20 @@ +function SCI2CSymbolTable = ST_Load(SymbolTableFileName) +// function SCI2CSymbolTable = ST_Load(SymbolTableFileName) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +[tmpnams,tmptyps,tmpdims,tmpvols]=listvarinfile(SymbolTableFileName); +if (max(size(tmpnams)) > 1) + SCI2Cerror('More than one variable found in ""'+SymbolTableFileName+'"".'); +end +load(SymbolTableFileName,tmpnams); +SCI2CSymbolTable = eval(tmpnams); + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_MatchSymbol.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_MatchSymbol.sci new file mode 100644 index 00000000..d5273973 --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_MatchSymbol.sci @@ -0,0 +1,51 @@ +function [TBFlagfound,TBFlagEqualSymbols] = ST_MatchSymbol(TBName,TBType,TBSize,TBValue,TBFindLike,TBDimension,SymbolTableFileName,MatchRule) +// function [TBFlagfound,TBFlagEqualSymbols] = ST_MatchSymbol(TBName,TBType,TBSize,TBValue,TBFindLike,TBDimension,SymbolTableFileName,MatchRule) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +SCI2CNInArgCheck(argn(2),8,8); + +TBFlagfound = 0; +TBFlagEqualSymbols = 0; + +[TBFlagfound,tmpType,tmpSize,tmpValue,tmpFindLike,tmpDimension] = ... + ST_Get(TBName,SymbolTableFileName); + +if (TBFlagfound == 1) + if (tmpType == 'GBLToBeDefined') + TBFlagfound = 2; + TBFlagEqualSymbols = 0; + else + TBFlagEqualSymbols = 1; + if (MatchRule == 'type' | MatchRule == 'all') + if (mtlb_strcmp(tmpType,TBType) == %F) + TBFlagEqualSymbols = 0; + end + end + if (MatchRule == 'size' | MatchRule == 'all') + if (tmpDimension ~= TBDimension) + TBFlagEqualSymbols = 0; + end + if (SCI2Cisnum(tmpSize(1))) & (SCI2Cisnum(TBSize(1))) + if (mtlb_strcmp(tmpSize(1),TBSize(1)) == %F) + TBFlagEqualSymbols = 0; + end + end + if (SCI2Cisnum(tmpSize(2))) & (SCI2Cisnum(TBSize(2))) + if (mtlb_strcmp(tmpSize(2),TBSize(2)) == %F) + TBFlagEqualSymbols = 0; + end + end + end + end +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_Save.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_Save.sci new file mode 100644 index 00000000..2f0cd241 --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_Save.sci @@ -0,0 +1,33 @@ +function ST_Save(SymbolTableFileName,SCI2CSymbolTable) +// function ST_Save(SymbolTableFileName,SCI2CSymbolTable) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +SCI2CNInArgCheck(argn(2),2,2); + +[tmpnams,tmptyps,tmpdims,tmpvols]=listvarinfile(SymbolTableFileName); +if (max(size(tmpnams)) > 1) + SCI2Cerror('More than one variable found in ""'+SymbolTableFileName+'"".'); +end + +if (mtlb_strcmp(tmpnams,'GlobalVars')) + GlobalVars = SCI2CSymbolTable; + save(SymbolTableFileName,GlobalVars); +elseif (mtlb_strcmp(tmpnams,'LocalVars')) + LocalVars = SCI2CSymbolTable; + save(SymbolTableFileName,LocalVars); +elseif (mtlb_strcmp(tmpnams,'TempVars')) + TempVars = SCI2CSymbolTable; + save(SymbolTableFileName,TempVars); +else + SCI2Cerror('Unknow table: ""'+tmpnams+'"".'); +end + +endfunction diff --git a/src/Scilab2C/Scilab2C/SymbolTable/ST_Set.sci b/src/Scilab2C/Scilab2C/SymbolTable/ST_Set.sci new file mode 100644 index 00000000..158cccf0 --- /dev/null +++ b/src/Scilab2C/Scilab2C/SymbolTable/ST_Set.sci @@ -0,0 +1,35 @@ +function ST_Set(TBName,TBType,TBSize,TBValue,TBFindLike,TBDimension,SymbolTableFileName) +// function ST_Set(TBName,TBType,TBSize,TBValue,TBFindLike,TBDimension,SymbolTableFileName) +// ----------------------------------------------------------------- +// +// Status: +// 26-Oct-2007 -- Raffaele Nutricato: Author. +// 26-Oct-2007 -- Alberto Morea: Test Ok. +// +// Copyright 2007 Raffaele Nutricato & Alberto Morea. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +SCI2CNInArgCheck(argn(2),7,7); + +SCI2CSymbolTable = ST_Load(SymbolTableFileName); + +[TBFlagfound,TBPosition] = ST_FindPos(TBName,SymbolTableFileName); + +if (TBFlagfound == 0) + TBPosition = max(size(SCI2CSymbolTable))+1; +end + +SCI2CSymbolTable(TBPosition).Name = TBName; // string. +SCI2CSymbolTable(TBPosition).Type = TBType; // char. +SCI2CSymbolTable(TBPosition).Size = TBSize; // structure of two strings (Size(1) and Size(2)). +SCI2CSymbolTable(TBPosition).Value = TBValue; // int/real/complex number. %nan when the value is not available or isn't a scalar. +SCI2CSymbolTable(TBPosition).FindLike = TBFindLike; // int number. FindLike = 1, when the symbol comes from a find-like function. + // FindLike = -1 when the function is not find-like but it is making use of input arguments that are find-like. + // FindLike = 0 in all other cases. +SCI2CSymbolTable(TBPosition).Dimension = TBDimension; // int number. + +ST_Save(SymbolTableFileName,SCI2CSymbolTable); + +endfunction |