pascalabcnet/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascalParserTools.cs

393 lines
18 KiB
C#
Raw Permalink Normal View History

// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
2015-06-02 22:52:35 +03:00
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System.Collections.Generic;
2015-05-14 22:35:07 +03:00
using PascalABCCompiler.SyntaxTree;
using System.Linq;
using PascalABCCompiler.ParserTools;
using PascalABCCompiler.Parsers;
New languages engine (#3120) * Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
2024-05-25 12:26:32 +03:00
using PascalABCCompiler;
2015-05-14 22:35:07 +03:00
New languages engine (#3120) * Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
2024-05-25 12:26:32 +03:00
namespace Languages.Pascal.Frontend.Core
2015-05-14 22:35:07 +03:00
{
// Класс глобальных описаний и статических методов
// для использования различными подсистемами парсера и сканера
public class PascalParserTools : BaseParserTools
2015-05-14 22:35:07 +03:00
{
public System.Collections.Stack NodesStack; // SSM: для каких-то вспомогательных целей в двух правилах
private int lambdaNum = 0;
public List<function_lambda_definition> pascalABCLambdaDefinitions;
public List<var_def_statement> pascalABCVarStatements;
public List<type_declaration> pascalABCTypeDeclarations;
2015-05-14 22:35:07 +03:00
static PascalParserTools()
2015-05-14 22:35:07 +03:00
{
tokenNum = new Dictionary<string, string>();
tokenNum["tkStatement"] = StringResources.Get("OPERATOR");
tokenNum["tkExpression"] = StringResources.Get("EXPR");
tokenNum["EOF"] = StringResources.Get("EOF1");
tokenNum["tkIdentifier"] = StringResources.Get("TKIDENTIFIER");
2021-01-08 13:53:15 +03:00
tokenNum["tkStringLiteral"] = StringResources.Get("TKSTRINGLITERAL");
2015-05-14 22:35:07 +03:00
tokenNum["tkAmpersend"] = "'";
tokenNum["tkColon"] = "':'";
tokenNum["tkDotDot"] = "'..'";
tokenNum["tkPoint"] = "'.'";
tokenNum["tkRoundOpen"] = "'('";
tokenNum["tkRoundClose"] = "')'";
tokenNum["tkSemiColon"] = "';'";
tokenNum["tkSquareOpen"] = "'['";
tokenNum["tkSquareClose"] = "']'";
tokenNum["tkQuestion"] = "'?'";
tokenNum["tkComma"] = "','";
tokenNum["tkAssign"] = "':='";
tokenNum["tkPlusEqual"] = "'+='";
tokenNum["tkMinusEqual"] = "'-='";
tokenNum["tkMultEqual"] = "'*='";
tokenNum["tkDivEqual"] = "'/='";
tokenNum["tkMinus"] = "'-'";
tokenNum["tkPlus"] = "'+'";
tokenNum["tkSlash"] = "'//'";
tokenNum["tkStar"] = "'*'";
tokenNum["tkEqual"] = "'='";
tokenNum["tkGreater"] = "'>'";
tokenNum["tkGreaterEqual"] = "'>='";
tokenNum["tkLower"] = "'<'";
tokenNum["tkLowerEqual"] = "'<='";
tokenNum["tkNotEqual"] = "'<>'";
tokenNum["tkArrow"] = "'->'";
tokenNum["tkAddressOf"] = "'@'";
tokenNum["tkDeref"] = "'^'";
tokenNum["tkStarStar"] = "'**'";
2015-05-14 22:35:07 +03:00
}
New languages engine (#3120) * Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
2024-05-25 12:26:32 +03:00
public PascalParserTools(IParser parserRef) : base(parserRef)
2015-05-14 22:35:07 +03:00
{
NodesStack = new System.Collections.Stack();
pascalABCLambdaDefinitions = new List<function_lambda_definition>();
pascalABCVarStatements = new List<var_def_statement>();
pascalABCTypeDeclarations = new List<type_declaration>();
2015-05-14 22:35:07 +03:00
}
New languages engine (#3120) * Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
2024-05-25 12:26:32 +03:00
protected override string ExtractDirectiveTextWithoutSpecialSymbols(string directive)
2015-05-14 22:35:07 +03:00
{
// текст без спецсимволов {$}
New languages engine (#3120) * Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
2024-05-25 12:26:32 +03:00
return directive.Substring(2, directive.Length - 3);
2015-05-14 22:35:07 +03:00
}
protected override string GetFromStringResources(string res)
2015-05-14 22:35:07 +03:00
{
return StringResources.Get(res);
2015-05-14 22:35:07 +03:00
}
public int TokenPriority(string tok)
{
switch (tok)
{
case "tkSemiColon":
return 120;
case "tkStatement":
return 100;
case "tkExpression":
return 100;
case "tkEqual":
return 90;
case "tkColon":
return 80;
case "tkAssign":
return 70;
case "tkIdentifier":
return 60;
case "tkRoundClose":
return 50;
case "tkBegin":
return 40;
case "tkEnd":
return 30;
case "tkDotDot":
return 20;
case "tkSquareClose":
return 10;
case "tkGreater":
return 5;
}
return 0;
}
protected override string ReplaceSpecialSymbols(string text)
{
text = text.Replace("''", "'");
return text;
}
2015-05-14 22:35:07 +03:00
public string CreateErrorString(string yytext, params object[] args)
{
string prefix = "";
if (yytext != "")
prefix = StringResources.Get("FOUND{0}");
2018-03-22 23:34:42 +03:00
else
prefix = StringResources.Get("FOUNDEOF");
if (this.buildTreeForFormatterStrings && prefix == StringResources.Get("FOUNDEOF"))
2018-12-30 14:29:13 +03:00
{
yytext = "}";
prefix = StringResources.Get("FOUND{0}");
}
2015-05-14 22:35:07 +03:00
// Преобразовали в список строк - хорошо
List<string> tokens = new List<string>(args.Skip(1).Cast<string>());
// Исключаем, т.к. в реальных программах никогда не встретятся
tokens = tokens.Except((new string[] { "tkParseModeExpression", "tkParseModeStatement", "tkDirectiveName" })).ToList();
// Это - временное решение, пока эти слова относятся к идентификаторам (что неправильно)
if (tokens.Contains("tkIdentifier"))
tokens = tokens.Except((new string[] { "tkAbstract", "tkOverload", "tkReintroduce", "tkOverride", "tkVirtual", "tkAt", "tkOn", "tkName", "tkForward", "tkRead", "tkWrite" })).ToList();
// Добавляем фиктивный токен, что означает, что далее могут идти несколько токенов, начинающих выражение
if (tokens.Contains("tkFor") && tokens.Contains("tkIf") && tokens.Contains("tkRepeat") && tokens.Contains("tkWhile"))
{
tokens.Clear();
tokens.Add("tkStatement");
}
// Добавляем фиктивный токен, что означает, что далее могут идти несколько токенов, начинающих выражение
if (tokens.Contains("tkIdentifier") && tokens.Contains("tkInteger") && tokens.Contains("tkFloat"))
{
tokens.Clear();
tokens.Add("tkExpression");
}
tokens = tokens.OrderByDescending(s => TokenPriority(s)).ToList();
/*if (args.Contains("EOF") && yytext!="")
return "Текст за концом программы недопустим";
if (args.Contains("tkIdentifier"))
return string.Format(prefix + "ожидался идентификатор", "'" + yytext + "'");*/
if (tokens.Contains("tkProgram"))
return string.Format(prefix + StringResources.Get("EXPECTEDBEGIN"), "'" + yytext + "'");
var MaxTok = tokens.First();
2021-01-08 14:14:40 +03:00
if (yytext != null && yytext.ToLower() == "record" && MaxTok == "tkSealed")
return StringResources.Get("WRONG_ATTRIBUTE_FOR_RECORD");
2015-05-14 22:35:07 +03:00
var ExpectedString = StringResources.Get("EXPECTED{1}");
if (MaxTok.Equals("tkStatement") || MaxTok.Equals("tkIdentifier"))
ExpectedString = StringResources.Get("EXPECTEDR{1}");
2021-01-08 13:53:15 +03:00
else if (MaxTok.Equals("tkStringLiteral"))
ExpectedString = StringResources.Get("EXPECTEDF{1}");
if ((MaxTok == "EOF" || MaxTok == "EOF1" || MaxTok == "FOUNDEOF") && this.buildTreeForFormatterStrings)
2018-03-22 23:34:42 +03:00
MaxTok = "}";
2015-05-14 22:35:07 +03:00
var MaxTokHuman = ConvertToHumanName(MaxTok);
// string w = string.Join(" или ", tokens.Select(s => ConvertToHumanName((string)s)));
return string.Format(prefix + ExpectedString, "'" + yytext + "'", MaxTokHuman);
2015-05-14 22:35:07 +03:00
}
public string directive_parameter(string s)
{
var ind = s.IndexOf(" ");
if (ind < 0)
return "";
else
{
s = s.Substring(ind + 1);
s = s.TrimEnd('}');
return s;
}
}
public override literal create_string_const(string text, SourceContext sc)
2015-05-14 22:35:07 +03:00
{
literal lt;
if (text.Length == 3 && text[0] == '\'' && text[2] == '\'')
{
lt = new char_const(text[1]);
lt.source_context = sc;
return lt;
}
text = ReplaceSpecialSymbols(text.Substring(1, text.Length - 2));
lt = new string_const(text);
lt.source_context = sc;
return lt;
2015-05-14 22:35:07 +03:00
}
public function_lambda_definition find_pascalABC_lambda_name(string name)
{
int i = 0;
while (i < pascalABCLambdaDefinitions.Count && (pascalABCLambdaDefinitions[i] == null || ((function_lambda_definition)pascalABCLambdaDefinitions[i]).lambda_name != name))
2015-05-14 22:35:07 +03:00
i++;
if (i < pascalABCLambdaDefinitions.Count)
return (function_lambda_definition)pascalABCLambdaDefinitions[i];
2015-05-14 22:35:07 +03:00
else
return null;
}
public var_def_statement find_var_statements(string name)
{
int i = pascalABCVarStatements.Count - 1;
2015-05-14 22:35:07 +03:00
bool b = false;
while (!b && i >= 0)
{
var_def_statement vds = (var_def_statement)pascalABCVarStatements[i];
2015-05-14 22:35:07 +03:00
int j = 0;
while (j < vds.vars.idents.Count &&
vds.vars.idents[j].name != name)
j++;
if (j < vds.vars.idents.Count)
b = true;
else
i--;
}
if (i >= 0 && i < pascalABCVarStatements.Count &&
((var_def_statement)pascalABCVarStatements[i]).vars_type != null)
return (var_def_statement)pascalABCVarStatements[i];
2015-05-14 22:35:07 +03:00
else
return null;
}
public ident func_decl_lambda(object lr0, object lr2)
{
statement_list _statement_list = (statement_list)lr2;
expression_list _expression_list = new expression_list();
ident_list _i_l = new ident_list();
formal_parameters _formal_parameters = new formal_parameters();
if (lr0 != null)
{
List<object> ar = (List<object>)lr0;
for (int i = 0; i < ar.Count; i++)
if (ar[i] is ident)
_i_l.idents.Add((ident)ar[i]);
else
_i_l.idents.Add(((var_def_statement)ar[i]).vars.idents[0]);
for (int i = 0; i < _i_l.idents.Count; i++)
_expression_list.expressions.Add(_i_l.idents[i]);
for (int i = 0; i < ar.Count; i++)
{
ident_list _ident_list = new ident_list();
ident id = _i_l.idents[i];
_ident_list.idents.Add(id);
string name_param = id.name;
typed_parameters _typed_parameters = null;
int k = 0;
{
named_type_reference _named_type_reference = new named_type_reference();
type_definition t_d = new type_definition();
if (ar[i] is ident)
{
ident idtype = new ident("object");
_named_type_reference.names.Add(idtype);
t_d = (type_definition)_named_type_reference;
}
else
{
t_d = ((var_def_statement)ar[i]).vars_type;
}
_typed_parameters = new typed_parameters(_ident_list, t_d, parametr_kind.none, null);
//parsertools.create_source_context(_typed_parameters, _ident_list, t_d);
}
_formal_parameters.params_list.Add(_typed_parameters);
}
}
//////////////////////////
named_type_reference _named_type_reference1 = new named_type_reference();
ident idtype1 = new ident("object");
_named_type_reference1.source_context = idtype1.source_context;
_named_type_reference1.names.Add(idtype1);
/////////////////////////////
lambdaNum++;
2015-05-14 22:35:07 +03:00
function_lambda_definition _procedure_definition = new function_lambda_definition();
_procedure_definition.formal_parameters = _formal_parameters;
_procedure_definition.return_type = (type_definition)_named_type_reference1;
_procedure_definition.ident_list = _i_l;
_procedure_definition.proc_body = null;
_procedure_definition.parameters = _expression_list;
_procedure_definition.lambda_name = "__lambda__" + lambdaNum;
2015-05-14 22:35:07 +03:00
//new function_lambda_definition(_formal_parameters, (type_definition)_named_type_reference1, _i_l, null, _expression_list, "lambda" + lambda_num);
object rt = _i_l;
_procedure_definition.proc_body = _statement_list;
//////////////////////////////vnutrennie lambda
if (_procedure_definition.defs == null)
_procedure_definition.defs = new List<declaration>();
while (pascalABCLambdaDefinitions.Count > 0 && pascalABCLambdaDefinitions[pascalABCLambdaDefinitions.Count - 1] != null)
2015-05-14 22:35:07 +03:00
{
_procedure_definition.defs.Add(lambda((function_lambda_definition)pascalABCLambdaDefinitions[pascalABCLambdaDefinitions.Count - 1]));
pascalABCLambdaDefinitions.RemoveAt(pascalABCLambdaDefinitions.Count - 1);
2015-05-14 22:35:07 +03:00
}
if (pascalABCLambdaDefinitions.Count > 0 && pascalABCLambdaDefinitions[pascalABCLambdaDefinitions.Count - 1] == null)
pascalABCLambdaDefinitions.RemoveAt(pascalABCLambdaDefinitions.Count - 1);
pascalABCLambdaDefinitions.Add(_procedure_definition);
2015-05-14 22:35:07 +03:00
///////////////////////////////////////////////
//parsertools.create_source_context(_procedure_definition, _expression_list, rt);
ident _name = new ident(_procedure_definition.lambda_name);
if (lr0 != null)
_name.source_context = _i_l.idents[0].source_context;
return _name;
}
public void add_lambda_to_program_block(block _block)
{
//tasha 16.04.2010
if (pascalABCLambdaDefinitions.Count > 0)
2015-05-14 22:35:07 +03:00
{
if (_block.defs == null)
_block.defs = new declarations();
for (int i = 0; i < pascalABCLambdaDefinitions.Count; i++)
_block.defs.defs.Add(lambda((function_lambda_definition)pascalABCLambdaDefinitions[i]));
pascalABCLambdaDefinitions.Clear();
2015-05-14 22:35:07 +03:00
}
}
public void add_lambda(object lr1, procedure_definition _procedure_definition)
{
if (pascalABCLambdaDefinitions.Count > 0)//tasha 16.04.2010
2015-05-14 22:35:07 +03:00
{
block _block = (block)lr1;
if (_block.defs == null)
_block.defs = new declarations();
for (int i = 0; i < pascalABCLambdaDefinitions.Count; i++)
_block.defs.defs.Add(lambda((function_lambda_definition)pascalABCLambdaDefinitions[i]));
pascalABCLambdaDefinitions.Clear();
2015-05-14 22:35:07 +03:00
_procedure_definition.proc_body = (proc_block)_block;
}
else
//////////////////////////tasha 16.04.2010
_procedure_definition.proc_body = (proc_block)lr1;
}
public void for_assignment(object lr0, object lr2)
{
if (lr0 is ident && lr2 is ident && ((ident)lr2).name.Contains("__lambda__"))
{
string type_name = "";
var_def_statement vds = find_var_statements(((ident)lr0).name);
if (vds != null)
type_name = ((named_type_reference)vds.vars_type).names[0].name;
if (type_name != "")
{
int ii = 0;
while (ii < pascalABCTypeDeclarations.Count &&
((type_declaration)pascalABCTypeDeclarations[ii]).type_name.name != type_name)
2015-05-14 22:35:07 +03:00
ii++;
if (ii < pascalABCTypeDeclarations.Count)
2015-05-14 22:35:07 +03:00
{
type_definition td = ((type_declaration)pascalABCTypeDeclarations[ii]).type_def;
2015-05-14 22:35:07 +03:00
function_lambda_definition fld = find_pascalABC_lambda_name(((ident)lr2).name);
fld.return_type = ((function_header)td).return_type;
for (int k = 0; k < fld.formal_parameters.params_list.Count && k < ((function_header)td).parameters.params_list.Count; k++)
fld.formal_parameters.params_list[k].vars_type = ((function_header)td).parameters.params_list[k].vars_type;
}
pascalABCVarStatements.Remove(vds);
2015-05-14 22:35:07 +03:00
}
}
}
}
}