Permalink
Browse files

Избавился от предупреждений в PABCSystem и ABCObjects

  • Loading branch information...
1 parent 573e22d commit 0423e6bdcf834180a1b1d84a296220a77ccccd43 @ibond84 ibond84 committed Sep 27, 2016
Showing with 138 additions and 157 deletions.
  1. +92 −36 Optimizer/Optimizer.cs
  2. +34 −67 bin/Lib/ABCObjects.pas
  3. +12 −54 bin/Lib/PABCSystem.pas
View
@@ -139,22 +139,42 @@ private void VisitMethod(common_method_node cmn)
{
local_variable vdn = vdn2 as local_variable;
VarInfo vi = helper.GetVariable(vdn);
- if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
- else if (vi.num_ass == 0 && vdn.is_ret_value && !cmn.name.StartsWith("<>") && !cmn.cont_type.IsInterface && cmn.polymorphic_state != SemanticTree.polymorphic_state.ps_virtual_abstract
- && cmn.return_value_type != null && !cmn.return_value_type.IsPointer && !cmn.is_constructor && cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
- && !helper.IsExternal(cmn)) warns.Add(new UndefinedReturnValue(cmn.name, cmn.function_code.location));
- //if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.name.Contains("$")) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
+ if (vi.num_use == 0 && !vdn.is_special_name)
+ warns.Add(new UnusedVariable(vdn.name, vdn.loc));
+ else if (vi.num_ass == 0 &&
+ vdn.is_ret_value &&
+ !cmn.name.StartsWith("<") &&
+ !cmn.cont_type.IsInterface &&
+ cmn.polymorphic_state != SemanticTree.polymorphic_state.ps_virtual_abstract &&
+ cmn.return_value_type != null &&
+ !cmn.return_value_type.IsPointer &&
+ !cmn.is_constructor &&
+ cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record &&
+ cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
+ && !helper.IsExternal(cmn))
+ warns.Add(new UndefinedReturnValue(cmn.name, cmn.function_code.location));
}
else if (vdn2 is local_block_variable)
{
local_block_variable vdn = vdn2 as local_block_variable;
VarInfo vi = helper.GetVariable(vdn);
- if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
- else if (vi.num_ass == 0 && vdn.is_ret_value && !cmn.name.StartsWith("<>") && !cmn.cont_type.IsInterface && cmn.polymorphic_state != SemanticTree.polymorphic_state.ps_virtual_abstract
- && cmn.return_value_type != null && !cmn.return_value_type.IsPointer && !cmn.is_constructor && cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
- && !helper.IsExternal(cmn)) warns.Add(new UndefinedReturnValue(cmn.name, cmn.function_code.location));
+ if (vi.num_use == 0 && !vdn.is_special_name)
+ warns.Add(new UnusedVariable(vdn.name, vdn.loc));
+ else if (vi.num_ass == 0 &&
+ vdn.is_ret_value &&
+ !cmn.name.StartsWith("<") &&
+ !cmn.cont_type.IsInterface &&
+ cmn.polymorphic_state != SemanticTree.polymorphic_state.ps_virtual_abstract &&
+ cmn.return_value_type != null &&
+ !cmn.return_value_type.IsPointer &&
+ !cmn.is_constructor &&
+ cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record &&
+ cmn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
+ && !helper.IsExternal(cmn))
+ warns.Add(new UndefinedReturnValue(cmn.name, cmn.function_code.location));
}
- if (vdn2.inital_value != null) VisitExpression(vdn2.inital_value);
+ if (vdn2.inital_value != null)
+ VisitExpression(vdn2.inital_value);
}
foreach (common_parameter prm in cmn.parameters)
{
@@ -236,34 +256,53 @@ private void VisitCommonNamespaceFunctionNode(common_namespace_function_node cnf
{
local_variable vdn = vdn2 as local_variable;
VarInfo vi = helper.GetVariable(vdn);
- if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
- else if (vi.num_ass == 0 && vdn.is_ret_value && !cnfn.name.StartsWith("<>") && cnfn.return_value_type != null && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && !cnfn.return_value_type.IsPointer && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
- && !helper.IsExternal(cnfn)) warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
- if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
- //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
+ if (vi.num_use == 0 && !vdn.is_special_name)
+ warns.Add(new UnusedVariable(vdn.name, vdn.loc));
+ else if (vi.num_ass == 0 &&
+ vdn.is_ret_value &&
+ !cnfn.name.StartsWith("<") &&
+ cnfn.return_value_type != null &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record &&
+ !cnfn.return_value_type.IsPointer &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper &&
+ !helper.IsExternal(cnfn))
+ warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
+ if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name)
+ warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
}
else if (vdn2 is local_block_variable)
{
local_block_variable vdn = vdn2 as local_block_variable;
VarInfo vi = helper.GetVariable(vdn);
- if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
- else if (vi.num_ass == 0 && vdn.is_ret_value && !cnfn.name.StartsWith("<>") && cnfn.return_value_type != null && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && !cnfn.return_value_type.IsPointer && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
- && !helper.IsExternal(cnfn)) warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
- if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
- //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
+ if (vi.num_use == 0 && !vdn.is_special_name)
+ warns.Add(new UnusedVariable(vdn.name, vdn.loc));
+ else if (vi.num_ass == 0 &&
+ vdn.is_ret_value &&
+ !cnfn.name.StartsWith("<") &&
+ cnfn.return_value_type != null &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record &&
+ !cnfn.return_value_type.IsPointer &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper &&
+ !helper.IsExternal(cnfn))
+ warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
+ if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name)
+ warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
}
- if (vdn2.inital_value != null) VisitExpression(vdn2.inital_value);
+ if (vdn2.inital_value != null)
+ VisitExpression(vdn2.inital_value);
}
foreach (common_parameter prm in cnfn.parameters)
{
ParamInfo vi = helper.GetParameter(prm);
- if (prm.inital_value != null) VisitExpression(prm.inital_value);
+ if (prm.inital_value != null)
+ VisitExpression(prm.inital_value);
//if (vi.num_use == 0 && !prm.name.Contains("$")) warns.Add(new UnusedParameter(prm.name, prm.loc));
}
foreach (var_definition_node vdn in cnfn.var_definition_nodes_list)
{
VarInfo vi = helper.GetVariable(vdn);
- if (vdn.inital_value != null) VisitExpression(vdn.inital_value);
+ if (vdn.inital_value != null)
+ VisitExpression(vdn.inital_value);
}
}
@@ -285,34 +324,51 @@ private void VisitNestedFunction(common_in_function_function_node cnfn)
{
local_variable vdn = vdn2 as local_variable;
VarInfo vi = helper.GetVariable(vdn);
- if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
- else if (vi.num_ass == 0 && vdn.is_ret_value && !cnfn.name.StartsWith("<>") && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && !cnfn.return_value_type.IsPointer && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
- && !helper.IsExternal(cnfn)) warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
- if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
- //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
+ if (vi.num_use == 0 && !vdn.is_special_name)
+ warns.Add(new UnusedVariable(vdn.name, vdn.loc));
+ else if (vi.num_ass == 0 &&
+ vdn.is_ret_value &&
+ !cnfn.name.StartsWith("<") &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record &&
+ !cnfn.return_value_type.IsPointer &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper &&
+ !helper.IsExternal(cnfn))
+ warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
+ if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name)
+ warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
}
else if (vdn2 is local_block_variable)
{
local_block_variable vdn = vdn2 as local_block_variable;
VarInfo vi = helper.GetVariable(vdn);
- if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
- else if (vi.num_ass == 0 && vdn.is_ret_value && !cnfn.name.StartsWith("<>") && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record && !cnfn.return_value_type.IsPointer && cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper
- && !helper.IsExternal(cnfn)) warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
- if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
- //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
+ if (vi.num_use == 0 && !vdn.is_special_name)
+ warns.Add(new UnusedVariable(vdn.name, vdn.loc));
+ else if (vi.num_ass == 0 &&
+ vdn.is_ret_value &&
+ !cnfn.name.StartsWith("<") &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.record &&
+ !cnfn.return_value_type.IsPointer &&
+ cnfn.return_value_type.type_special_kind != SemanticTree.type_special_kind.array_wrapper &&
+ !helper.IsExternal(cnfn))
+ warns.Add(new UndefinedReturnValue(cnfn.name, cnfn.function_code.location));
+ if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name)
+ warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
}
- if (vdn2.inital_value != null) VisitExpression(vdn2.inital_value);
+ if (vdn2.inital_value != null)
+ VisitExpression(vdn2.inital_value);
}
foreach (common_parameter prm in cnfn.parameters)
{
ParamInfo vi = helper.GetParameter(prm);
- if (prm.inital_value != null) VisitExpression(prm.inital_value);
+ if (prm.inital_value != null)
+ VisitExpression(prm.inital_value);
//if (vi.num_use == 0 && !prm.name.Contains("$")) warns.Add(new UnusedParameter(prm.name, prm.loc));
}
foreach (var_definition_node vdn in cnfn.var_definition_nodes_list)
{
VarInfo vi = helper.GetVariable(vdn);
- if (vdn.inital_value != null) VisitExpression(vdn.inital_value);
+ if (vdn.inital_value != null)
+ VisitExpression(vdn.inital_value);
}
}
Oops, something went wrong.

0 comments on commit 0423e6b

Please sign in to comment.