Example #1
0
        public typecast_node NewAsIsConstexpr(expression constterm, op_typecast typecastop, type_definition tdef, LexLocation loc)
        {
            var naic = new typecast_node(constterm as addressed_value, tdef, typecastop, loc); 
			if (!(constterm is addressed_value))
                parsertools.errors.Add(new bad_operand_type(parsertools.CurrentFileName, constterm.source_context, naic));
            return naic;
        }
Example #2
0
 /// <summary>
 /// Создать цикл while
 /// </summary>
 /// <param name="condition">Условие цикла</param>
 /// <param name="body">Тело цикла</param>
 /// <returns></returns>
 public SyntaxTree.while_node CreateWhile(expression condition, statement body)
 {
     SyntaxTree.while_node res = new SyntaxTree.while_node();
     res.CycleType = WhileCycleType.While;
     res.expr = condition;
     res.statements = body;
     return res;
 }
Example #3
0
 /// <summary>
 /// Получение имен после точки
 /// </summary>
 public SymInfo[] GetName(expression expr, string str, int line, int col, PascalABCCompiler.Parsers.KeywordKind keyword, ref SymScope root)
 {
     if (visitor.cur_scope == null) return null;
     if (col + 1 > str.Length)
         col -= str.Length;
     SymScope si = visitor.FindScopeByLocation(line + 1, col + 1);//stv.cur_scope;
     if (si == null)
     {
         si = visitor.FindScopeByLocation(line, col + 1);
         if (si == null)
             return null;
     }
     SetCurrentUsedAssemblies();
     ExpressionVisitor ev = new ExpressionVisitor(expr, si, visitor);
     si = ev.GetScopeOfExpression(true, false);
     root = si;
     if (si is ElementScope) root = (si as ElementScope).sc;
     else if (si is ProcScope) root = (si as ProcScope).return_type;
     if (si != null)
     {
         if (!(si is TypeScope) && !(si is NamespaceScope))
         {
             SymInfo[] syms = si.GetNamesAsInObject(ev);
             SymInfo[] ext_syms = null;
             if (si is ElementScope)
                 ext_syms = visitor.cur_scope.GetSymInfosForExtensionMethods((si as ElementScope).sc as TypeScope);
             List<SymInfo> lst = new List<SymInfo>();
             lst.AddRange(syms);
             if (ext_syms != null)
                 lst.AddRange(ext_syms);
             RestoreCurrentUsedAssemblies();
             List<SymInfo> lst_to_remove = new List<SymInfo>();
             foreach (SymInfo si2 in lst)
                 if (si2.name.StartsWith("operator"))
                     lst_to_remove.Add(si2);
             foreach (SymInfo si2 in lst_to_remove)
                 lst.Remove(si2);
             return lst.ToArray();
         }
         else
         {
             if (si is TypeScope)
             {
                 RestoreCurrentUsedAssemblies();
                 return (si as TypeScope).GetNames(ev, keyword, false);
             }
             else
             {
                 if (ev.entry_scope.InUsesRange(line + 1, col + 1))
                     keyword = PascalABCCompiler.Parsers.KeywordKind.Uses;
                 RestoreCurrentUsedAssemblies();
                 return (si as NamespaceScope).GetNames(ev, keyword);
             }
         }
     }
     RestoreCurrentUsedAssemblies();
     return null;
 }
Example #4
0
 /// <summary>
 /// Создать var-выражение
 /// </summary>
 /// <param name="name">Имя переменной</param>
 /// <param name="initialValue">Начальное значение</param>
 /// <returns></returns>
 public var_def_statement CreateVarDef(string name, expression initialValue)
 {
     ident_list list = new ident_list();
     list.idents.Add(new ident(name));
     var res = new var_def_statement();
     res.inital_value = initialValue;
     res.vars = list;
     return res;
 }
Example #5
0
 /// <summary>
 /// Создать цикл for
 /// </summary>
 /// <param name="varName">Имя переменной цикла</param>
 /// <param name="initValue">Начальное значение переменной цикла</param>
 /// <param name="finishValue">Конечное значение переменной цикла</param>
 /// <param name="body">Тело цикла</param>
 /// <param name="type">Тип цикла(to / downto)</param>
 /// <returns></returns>
 public SyntaxTree.for_node CreateFor(string varName, expression initValue, expression finishValue, statement body, for_cycle_type type)
 {
     SyntaxTree.for_node res = new SyntaxTree.for_node();
     res.loop_variable = new ident(varName);
     res.initial_value = initValue;
     res.finish_value = finishValue;
     res.statements = body;
     res.cycle_type = type;
     return res;
 }
Example #6
0
        public expression NewConstVariable(expression constvariable, expression constvariable2, LexLocation loc)
        {
            if (constvariable2 is dereference) 
				((dereference)constvariable2).dereferencing_value = (addressed_value)constvariable;
			if (constvariable2 is dot_node) 
				((dot_node)constvariable2).left = (addressed_value)constvariable;
			var ncv = constvariable2;
            ncv.source_context = loc;
            return ncv;
        }
 public int32_const Convert(expression expr)
 {
     if (expr == null)
         return null;
     try
     {
         expr.visit(this);
     }
     catch
     {
         return null;
     }
     if (intStack.Count == 1)
     {
         int32_const i = new int32_const(intStack.Pop());
         i.source_context = expr.source_context;
         return i;
     }
     return null;
 }
Example #8
0
 public NameExprPair(ident id, expression ex)
 {
     this.id = id;
     this.ex = ex;
 }
Example #9
0
 public static procedure_definition BuildShortFuncDefinition(formal_parameters fp, procedure_attributes_list att, method_name name, type_definition result, expression ex, SourceContext headsc)
 {
     var ff = new function_header(fp, att, name, null, result, headsc);
     procedure_definition pd = BuildShortProcFuncDefinition(ff, new assign("Result", ex, ex.source_context));
     return pd;
 }
Example #10
0
 public static type_definition BuildSameType(expression ex)
 {
     return new same_type_node(ex);
 }
		public void write_expression(expression _expression)
		{
			write_statement(_expression);
		}
Example #12
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public typed_const_definition(ident _const_name,expression _const_value,type_definition _const_type)
		{
			this._const_name=_const_name;
			this._const_value=_const_value;
			this._const_type=_const_type;
		}
Example #13
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public typed_parameters(ident_list _idents,type_definition _vars_type,parametr_kind _param_kind,expression _inital_value,SourceContext sc)
		{
			this._idents=_idents;
			this._vars_type=_vars_type;
			this._param_kind=_param_kind;
			this._inital_value=_inital_value;
			source_context = sc;
		}
Example #14
0
        public expression NewVariable(addressed_value variable, expression var_specifiers, LexLocation loc)
        {
            if (var_specifiers is dot_node) 
			{
                var dn = (dot_node)var_specifiers;
				dn.left = variable;
			}
			else if (var_specifiers is template_param_list) 
			{
                var tpl = (template_param_list)var_specifiers;
				((dot_node)tpl.dereferencing_value).left = variable;
				parsertools.create_source_context(tpl.dereferencing_value, variable, tpl.dereferencing_value);
			}
			else if (var_specifiers is dereference) 
			{
				((dereference)var_specifiers).dereferencing_value = variable;
			}
			else if (var_specifiers is ident_with_templateparams) 
			{
                ((ident_with_templateparams)var_specifiers).name = (addressed_value_funcname)variable;
			}
            var_specifiers.source_context = loc;
            return var_specifiers;
        }
		public void visit(expression _expression)
		{
			bw.Write((Int16)1);
			write_expression(_expression);
		}
Example #16
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public case_node(expression _param,case_variants _conditions,statement _else_statement,SourceContext sc)
		{
			this._param=_param;
			this._conditions=_conditions;
			this._else_statement=_else_statement;
			source_context = sc;
		}
Example #17
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public case_node(expression _param,case_variants _conditions,statement _else_statement)
		{
			this._param=_param;
			this._conditions=_conditions;
			this._else_statement=_else_statement;
		}
Example #18
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public bin_expr(expression _left,expression _right,Operators _operation_type,SourceContext sc)
		{
			this._left=_left;
			this._right=_right;
			this._operation_type=_operation_type;
			source_context = sc;
		}
Example #19
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public bin_expr(expression _left,expression _right,Operators _operation_type)
		{
			this._left=_left;
			this._right=_right;
			this._operation_type=_operation_type;
		}
Example #20
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public const_definition(ident _const_name,expression _const_value,SourceContext sc)
		{
			this._const_name=_const_name;
			this._const_value=_const_value;
			source_context = sc;
		}
Example #21
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public const_definition(ident _const_name,expression _const_value)
		{
			this._const_name=_const_name;
			this._const_value=_const_value;
		}
Example #22
0
        public while_node NewWhileStmt(token_info tkWhile, expression expr, token_info opt_tk_do, statement stmt, LexLocation loc)
        {
            var nws = new while_node(expr, stmt, WhileCycleType.While, loc); 
			if (opt_tk_do == null)
			{
				file_position fp = expr.source_context.end_position;
				syntax_tree_node err_stn = stmt;
				if (err_stn == null)
					err_stn = expr;
                parsertools.errors.Add(new PABCNETUnexpectedToken(parsertools.CurrentFileName, StringResources.Get("TKDO"), new SourceContext(fp.line_num, fp.column_num + 1, fp.line_num, fp.column_num + 1, 0, 0), err_stn));
			}
            return nws;
        }
Example #23
0
 public for_node NewForStmt(bool opt_var, ident identifier, type_definition for_stmt_decl_or_assign, expression expr1, for_cycle_type fc_type, expression expr2, token_info opt_tk_do, statement stmt, LexLocation loc)
 {
     var nfs = new for_node(identifier, expr1, expr2, stmt, fc_type, null, for_stmt_decl_or_assign, opt_var != false, loc); 
     if (opt_tk_do == null)
     {
         file_position fp = expr2.source_context.end_position;
         syntax_tree_node err_stn = stmt;
         if (err_stn == null)
             err_stn = expr2;
         parsertools.errors.Add(new PABCNETUnexpectedToken(parsertools.CurrentFileName, StringResources.Get("TKDO"), new SourceContext(fp.line_num, fp.column_num + 1, fp.line_num, fp.column_num + 1, 0, 0), err_stn));
     }
     return nfs;
 }
Example #24
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public assign(addressed_value _to,expression _from,Operators _operator_type)
		{
			this._to=_to;
			this._from=_from;
			this._operator_type=_operator_type;
		}
Example #25
0
        public statement_list NewLambdaBody(expression expr_l1, LexLocation loc)
        {
            var _statement_list = new statement_list();
			var id = new ident("result");
			var _op_type_node = new op_type_node(Operators.Assignment);
			//_op_type_node.source_context = parsertools.GetTokenSourceContext();
			var _assign = new assign((addressed_value)id, expr_l1, _op_type_node.type);
			parsertools.create_source_context(_assign, id, expr_l1);
			_statement_list.subnodes.Add((statement)_assign);
            _statement_list.source_context = loc;
			//block _block = new block(null, _statement_list);
			return _statement_list;
        }
Example #26
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public simple_property(ident _property_name,type_definition _property_type,expression _index_expression,property_accessors _accessors,property_array_default _array_default,property_parameter_list _parameter_list,definition_attribute _attr,SourceContext sc)
		{
			this._property_name=_property_name;
			this._property_type=_property_type;
			this._index_expression=_index_expression;
			this._accessors=_accessors;
			this._array_default=_array_default;
			this._parameter_list=_parameter_list;
			this._attr=_attr;
			source_context = sc;
		}
Example #27
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public un_expr(expression _subnode,Operators _operation_type)
		{
			this._subnode=_subnode;
			this._operation_type=_operation_type;
		}
Example #28
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public assign(addressed_value _to,expression _from,Operators _operator_type,SourceContext sc)
		{
			this._to=_to;
			this._from=_from;
			this._operator_type=_operator_type;
			source_context = sc;
		}
		public void write_expression(expression _expression)
		{
			write_declaration(_expression);
		}
Example #30
0
		///<summary>
		///Конструктор с параметрами.
		///</summary>
		public un_expr(expression _subnode,Operators _operation_type,SourceContext sc)
		{
			this._subnode=_subnode;
			this._operation_type=_operation_type;
			source_context = sc;
		}