001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package dwarfvsmodel;
043:
044: import java.util.*;
045: import org.netbeans.modules.cnd.dwarfdump.dwarf.DwarfEntry;
046: import org.netbeans.modules.cnd.dwarfdump.dwarfconsts.TAG;
047:
048: /**
049: * Misc. dwarf-related utility functions
050: * @author vk155633
051: */
052: public class DwarfTree {
053:
054: // We need a tree-like structure
055: // that we'll use for comparison of declarations within bodies
056:
057: /** Creates a node */
058: public static Node<DwarfEntry> createDwarfNode(DwarfEntry parent) {
059: Comparator<DwarfEntry> comparator = new ComparisonUtils.DwarfEntryComparator();
060: Node<DwarfEntry> root = _createDwarfNode(parent);
061: root.flatten();
062: root.sort(comparator);
063: // for( Node<DwarfEntry> child : root.getSubnodes() ) {
064: // child.flatten();
065: // child.sort(comparator);
066: // }
067: return root;
068: }
069:
070: /** Creates a node */
071: private static Node<DwarfEntry> _createDwarfNode(DwarfEntry parent) {
072: Iterable<DwarfEntry> dwarfEntries = parent.getChildren();
073: Node<DwarfEntry> node = new Node<DwarfEntry>();
074: for (DwarfEntry entry : dwarfEntries) {
075: if (ComparisonUtils.isArtificial(entry)) {
076: continue;
077: }
078: TAG kind = entry.getKind();
079: switch (kind) {
080: case DW_TAG_variable:
081: case DW_TAG_class_type:
082: case DW_TAG_structure_type:
083: case DW_TAG_union_type:
084: node.addDeclaration(entry);
085: break;
086: case DW_TAG_lexical_block:
087: case DW_TAG_try_block:
088: case DW_TAG_catch_block:
089: node.addSubnode(_createDwarfNode(entry));
090: break;
091: case DW_TAG_array_type:
092: case DW_TAG_entry_point:
093: case DW_TAG_enumeration_type:
094: case DW_TAG_imported_declaration:
095: case DW_TAG_member:
096: case DW_TAG_pointer_type:
097: case DW_TAG_reference_type:
098: case DW_TAG_compile_unit:
099: case DW_TAG_string_type:
100: case DW_TAG_subroutine_type:
101: case DW_TAG_typedef:
102: case DW_TAG_variant:
103: case DW_TAG_common_block: // fortran only
104: case DW_TAG_common_inclusion:
105: case DW_TAG_inheritance:
106: case DW_TAG_module:
107: case DW_TAG_ptr_to_member_type:
108: case DW_TAG_set_type:
109: case DW_TAG_subrange_type:
110: case DW_TAG_with_stmt:
111: case DW_TAG_access_declaration:
112: case DW_TAG_base_type:
113: case DW_TAG_const_type:
114: case DW_TAG_constant:
115: case DW_TAG_enumerator:
116: case DW_TAG_file_type:
117: case DW_TAG_friend:
118: case DW_TAG_namelist:
119: case DW_TAG_namelist_item:
120: case DW_TAG_packed_type:
121: case DW_TAG_subprogram:
122: case DW_TAG_template_type_param:
123: case DW_TAG_template_value_param:
124: case DW_TAG_thrown_type:
125: case DW_TAG_variant_part:
126: case DW_TAG_volatile_type:
127: case DW_TAG_dwarf_procedure:
128: case DW_TAG_restrict_type:
129: case DW_TAG_interface_type:
130: case DW_TAG_namespace:
131: case DW_TAG_imported_module:
132: case DW_TAG_unspecified_type:
133: case DW_TAG_partial_unit:
134: case DW_TAG_imported_unit:
135: case DW_TAG_condition:
136: case DW_TAG_shared_type:
137: case DW_TAG_lo_user:
138: case DW_TAG_SUN_class_template:
139: case DW_TAG_SUN_rtti_descriptor:
140: case DW_TAG_hi_user:
141: System.err.println("### node kind: " + kind
142: + " entry: " + entry + " in "
143: + entry.getDeclarationFilePath());
144: break;
145: case DW_TAG_label:
146: case DW_TAG_inlined_subroutine:
147: case DW_TAG_formal_parameter:
148: case DW_TAG_unspecified_parameters:
149: // ignore
150: break;
151: default:
152: System.err.println("!!! unknown node kind: " + kind);
153: break;
154:
155: }
156: }
157: return node;
158: }
159: }
|