Example #1
0
        private void IncreaseNumUseVar(local_variable_reference lvr)
        {
            VarInfo vi = helper.GetVariable(lvr.var);

            vi.num_use++;
            vi.act_num_use++;
            vi.cur_use++;
            //if (vi.cur_ass == 0 && !lvr.var.name.Contains("$")) helper.AddTempWarning(lvr.var,new UseWithoutAssign(lvr.var.name, lvr.location));
        }
Example #2
0
        public void AddVariable(var_definition_node vdn)
        {
            VarInfo vi = new VarInfo();

            if (ht[vdn] == null)
            {
                ht[vdn] = vi;
            }
        }
Example #3
0
        private void IncreaseNumAssVar(local_block_variable_reference lvr)
        {
            VarInfo vi = helper.GetVariable(lvr.var);

            vi.num_use++;
            vi.cur_ass++;
            vi.num_ass++;
            vi.last_ass_loc = lvr.location;
            if (vi.last_ass_loc == null)
            {
                vi.num_ass--;
            }
            if (vi.cur_use > 0)
            {
                vi.cur_use--;
            }
        }
Example #4
0
 private void CollectInfoNamespaces(common_namespace_node cnn)
 {
     if (!cnn.from_pcu)
     {
         if (cnn.is_main)
         {
             foreach (var_definition_node vdn2 in cnn.variables)
             {
                 if (vdn2 is namespace_variable)
                 {
                     namespace_variable vdn = vdn2 as namespace_variable;
                     VarInfo            vi  = helper.GetVariable(vdn);
                     if (vi.num_use == 0 && !vdn.is_special_name)
                     {
                         warns.Add(new UnusedVariable(vdn.name, vdn.loc));
                     }
                     if (vi.num_ass > 0 && vi.act_num_use == 0)
                     {
                         warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
                     }
                     //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
                 }
                 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));
                     }
                     if (vi.num_ass > 0 && vi.act_num_use == 0)
                     {
                         warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
                     }
                 }
             }
         }
         foreach (common_type_node ctn in cnn.types)
         {
             CollectInfoFields(ctn);
         }
     }
 }
Example #5
0
        private void VisitStatementList(statements_list stmt)
        {
            statement_node sn = null;

            foreach (local_block_variable lbv in stmt.local_variables)
            {
                helper.AddVariable(lbv);
                if (lbv.inital_value != null)
                {
                    VisitExpression(lbv.inital_value);
                }
                CheckType(lbv.type, lbv.inital_value, lbv.loc);
            }
            for (int i = 0; i < stmt.statements.Count; i++)
            {
                if (is_break_stmt && stmt.statements[i].semantic_node_type != semantic_node_type.empty_statement)
                {
                    warns.Add(new UnreachableCodeDetected(stmt.statements[i].location));
                }
                is_break_stmt = false;
                sn            = stmt.statements[i];
                VisitStatement(sn);
                if (is_break_stmt && i < stmt.statements.Count - 1 && stmt.statements[i + 1].semantic_node_type != semantic_node_type.empty_statement)
                {
                    warns.Add(new UnreachableCodeDetected(stmt.statements[i + 1].location));
                }
                is_break_stmt = false;
            }
            foreach (local_block_variable vdn in stmt.local_variables)
            {
                VarInfo vi = helper.GetVariable(vdn);
                if (vi.num_use == 0 && !vdn.is_special_name)
                {
                    warns.Add(new UnusedVariable(vdn.name, vdn.loc));
                }

                if (vi.num_ass > 0 && vi.act_num_use == 0 && !vdn.is_special_name)
                {
                    warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
                }
            }
        }
Example #6
0
 public void AddVariable(var_definition_node vdn)
 {
     VarInfo vi = new VarInfo();
     ht[vdn] = vi;
 }
Example #7
0
 private void VisitNestedFunction(common_in_function_function_node cnfn)
 {
     if (extended_mode)
     {
         VisitVariables(cnfn.var_definition_nodes_list);
     }
     foreach (var_definition_node vdn in cnfn.var_definition_nodes_list)
     {
         helper.AddVariable(vdn);
     }
     foreach (common_parameter prm in cnfn.parameters)
     {
         helper.AddParameter(prm);
     }
     foreach (common_in_function_function_node nested in cnfn.functions_nodes_list)
     {
         VisitNestedFunction(nested);
     }
     cur_func = cnfn;
     VisitStatement(cnfn.function_code);
     foreach (var_definition_node vdn2 in cnfn.var_definition_nodes_list)
     {
         if (vdn2 is local_variable)
         {
             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));
             }
         }
         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 (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 (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);
         }
     }
 }
Example #8
0
 private void VisitMethod(common_method_node cmn)
 {
     if (extended_mode)
     {
         VisitVariables(cmn.var_definition_nodes_list);
     }
     foreach (var_definition_node vdn in cmn.var_definition_nodes_list)
     {
         helper.AddVariable(vdn);
     }
     foreach (common_parameter prm in cmn.parameters)
     {
         helper.AddParameter(prm);
     }
     foreach (common_in_function_function_node nested in cmn.functions_nodes_list)
     {
         VisitNestedFunction(nested);
     }
     cur_func = cmn;
     VisitStatement(cmn.function_code);
     foreach (var_definition_node vdn2 in cmn.var_definition_nodes_list)
     {
         if (vdn2 is local_variable)
         {
             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));
             }
         }
         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 (vdn2.inital_value != null)
         {
             VisitExpression(vdn2.inital_value);
         }
     }
     foreach (common_parameter prm in cmn.parameters)
     {
         ParamInfo vi = helper.GetParameter(prm);
         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 cmn.var_definition_nodes_list)
     {
         VarInfo vi = helper.GetVariable(vdn);
         if (vdn.inital_value != null)
         {
             VisitExpression(vdn.inital_value);
         }
     }
 }