This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 200981
Collapse All | Expand All

(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/ClassImpl.java (-1 / +1 lines)
Lines 493-499 Link Here
493
                        break;
493
                        break;
494
                    }
494
                    }
495
                    case CPPTokenTypes.CSM_BASE_SPECIFIER:
495
                    case CPPTokenTypes.CSM_BASE_SPECIFIER:
496
                        addInheritance(InheritanceImpl.create(token, getContainingFile(), ClassImpl.this), !isRenderingLocalContext());
496
                        addInheritance(InheritanceImpl.create(token, getContainingFile(), ClassImpl.this, !isRenderingLocalContext()), !isRenderingLocalContext());
497
                        break;
497
                        break;
498
                    // class / struct / union
498
                    // class / struct / union
499
                    case CPPTokenTypes.LITERAL_class:
499
                    case CPPTokenTypes.LITERAL_class:
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/InheritanceImpl.java (-11 / +6 lines)
Lines 48-58 Link Here
48
import org.netbeans.modules.cnd.antlr.collections.AST;
48
import org.netbeans.modules.cnd.antlr.collections.AST;
49
import java.io.IOException;
49
import java.io.IOException;
50
import org.netbeans.modules.cnd.api.model.util.CsmBaseUtilities;
50
import org.netbeans.modules.cnd.api.model.util.CsmBaseUtilities;
51
import org.netbeans.modules.cnd.api.model.util.UIDs;
52
import org.netbeans.modules.cnd.modelimpl.parser.generated.CPPTokenTypes;
51
import org.netbeans.modules.cnd.modelimpl.parser.generated.CPPTokenTypes;
53
import org.netbeans.modules.cnd.modelimpl.csm.core.*;
52
import org.netbeans.modules.cnd.modelimpl.csm.core.*;
54
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
53
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
55
import org.netbeans.modules.cnd.modelimpl.repository.RepositoryUtils;
56
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
54
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
57
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
55
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
58
import org.netbeans.modules.cnd.modelimpl.uid.UIDProviderIml;
56
import org.netbeans.modules.cnd.modelimpl.uid.UIDProviderIml;
Lines 103-110 Link Here
103
        }
101
        }
104
    }
102
    }
105
103
106
    public static InheritanceImpl create(AST ast, CsmFile file, CsmScope scope) {
104
    public static InheritanceImpl create(AST ast, CsmFile file, CsmScope scope, boolean isGlobal) {
107
        return new InheritanceImpl(ast, file, scope);
105
        InheritanceImpl inheritanceImpl = new InheritanceImpl(ast, file, scope);
106
        if (!isGlobal) {
107
            Utils.setSelfUID(inheritanceImpl);
108
        }
109
        return inheritanceImpl;
108
    }
110
    }
109
111
110
    // constructor for LWM factory
112
    // constructor for LWM factory
Lines 143-155 Link Here
143
    public CsmClassifier getClassifier() {
145
    public CsmClassifier getClassifier() {
144
        if (!CsmBaseUtilities.isValid(resolvedClassifier)) {
146
        if (!CsmBaseUtilities.isValid(resolvedClassifier)) {
145
            resolvedClassifier = getAncestorType().getClassifier();
147
            resolvedClassifier = getAncestorType().getClassifier();
146
            if (resolvedClassifier != null) {
147
                if (UIDProviderIml.isPersistable(UIDs.get(this))) {
148
                    if (UIDProviderIml.isPersistable(UIDs.get(resolvedClassifier))) {
149
                        RepositoryUtils.put(this);
150
                    }
151
                }
152
            }
153
        }
148
        }
154
        return resolvedClassifier;
149
        return resolvedClassifier;
155
    }
150
    }
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/NestedType.java (-1 lines)
Lines 137-143 Link Here
137
                classifier = renderClassifier(fqn.toArray(new CharSequence[fqn.size()]));
137
                classifier = renderClassifier(fqn.toArray(new CharSequence[fqn.size()]));
138
            }
138
            }
139
            _setClassifier(classifier);
139
            _setClassifier(classifier);
140
            putTypeOwner();
141
        }
140
        }
142
        if (isInstantiation() && CsmKindUtilities.isTemplate(classifier) && !((CsmTemplate)classifier).getTemplateParameters().isEmpty()) {
141
        if (isInstantiation() && CsmKindUtilities.isTemplate(classifier) && !((CsmTemplate)classifier).getTemplateParameters().isEmpty()) {
143
            CsmInstantiationProvider ip = CsmInstantiationProvider.getDefault();
142
            CsmInstantiationProvider ip = CsmInstantiationProvider.getDefault();
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/ParameterImpl.java (-8 / +2 lines)
Lines 64-72 Link Here
64
    public static ParameterImpl create(AST ast, CsmFile file, CsmType type, NameHolder name, CsmScope scope, boolean global) {
64
    public static ParameterImpl create(AST ast, CsmFile file, CsmType type, NameHolder name, CsmScope scope, boolean global) {
65
        ParameterImpl parameterImpl = new ParameterImpl(ast, file, type, name, scope);
65
        ParameterImpl parameterImpl = new ParameterImpl(ast, file, type, name, scope);
66
        postObjectCreateRegistration(global, parameterImpl);
66
        postObjectCreateRegistration(global, parameterImpl);
67
        if (global && (type instanceof TypeImpl)) {
68
            ((TypeImpl)type).setOwner(parameterImpl);
69
        }
70
        return parameterImpl;
67
        return parameterImpl;
71
    }
68
    }
72
69
Lines 98-105 Link Here
98
        if (getName().length() == 0) {
95
        if (getName().length() == 0) {
99
            super.readUID(input);
96
            super.readUID(input);
100
        }
97
        }
101
        if (getType() instanceof TypeImpl) {
98
    }
102
            ((TypeImpl)getType()).setOwner(this);
99
} 
103
        }
104
    } 
105
}
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/TypeImpl.java (-20 / +97 lines)
Lines 44-49 Link Here
44
44
45
package org.netbeans.modules.cnd.modelimpl.csm;
45
package org.netbeans.modules.cnd.modelimpl.csm;
46
46
47
import org.netbeans.modules.cnd.api.model.xref.CsmReference;
48
import org.netbeans.modules.cnd.api.model.xref.CsmReferenceKind;
47
import org.netbeans.modules.cnd.modelimpl.csm.resolver.ResolverFactory;
49
import org.netbeans.modules.cnd.modelimpl.csm.resolver.ResolverFactory;
48
import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
50
import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
49
import org.netbeans.modules.cnd.modelimpl.debug.TraceFlags;
51
import org.netbeans.modules.cnd.modelimpl.debug.TraceFlags;
Lines 56-62 Link Here
56
import org.netbeans.modules.cnd.api.model.services.CsmIncludeResolver;
58
import org.netbeans.modules.cnd.api.model.services.CsmIncludeResolver;
57
import org.netbeans.modules.cnd.api.model.services.CsmInstantiationProvider;
59
import org.netbeans.modules.cnd.api.model.services.CsmInstantiationProvider;
58
import org.netbeans.modules.cnd.api.model.util.CsmBaseUtilities;
60
import org.netbeans.modules.cnd.api.model.util.CsmBaseUtilities;
59
import org.netbeans.modules.cnd.api.model.util.UIDs;
60
import org.netbeans.modules.cnd.utils.cache.TextCache;
61
import org.netbeans.modules.cnd.utils.cache.TextCache;
61
import org.netbeans.modules.cnd.modelimpl.parser.CsmAST;
62
import org.netbeans.modules.cnd.modelimpl.parser.CsmAST;
62
import org.netbeans.modules.cnd.modelimpl.parser.generated.CPPTokenTypes;
63
import org.netbeans.modules.cnd.modelimpl.parser.generated.CPPTokenTypes;
Lines 67-73 Link Here
67
import org.netbeans.modules.cnd.modelimpl.debug.DiagnosticExceptoins;
68
import org.netbeans.modules.cnd.modelimpl.debug.DiagnosticExceptoins;
68
import org.netbeans.modules.cnd.modelimpl.impl.services.InstantiationProviderImpl;
69
import org.netbeans.modules.cnd.modelimpl.impl.services.InstantiationProviderImpl;
69
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
70
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
70
import org.netbeans.modules.cnd.modelimpl.repository.RepositoryUtils;
71
import org.netbeans.modules.cnd.modelimpl.textcache.NameCache;
71
import org.netbeans.modules.cnd.modelimpl.textcache.NameCache;
72
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
72
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
73
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
73
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
Lines 100-111 Link Here
100
    // FIX for lazy resolver calls
100
    // FIX for lazy resolver calls
101
    private CharSequence[] qname = null;
101
    private CharSequence[] qname = null;
102
    private CsmUID<CsmClassifier> classifierUID;
102
    private CsmUID<CsmClassifier> classifierUID;
103
    private CsmObject owner;
104
103
105
    // package-local - for facory only
104
    // package-local - for facory only
106
    TypeImpl(CsmClassifier classifier, int pointerDepth, boolean reference, int arrayDepth, AST ast, CsmFile file, CsmOffsetable offset) {
105
    TypeImpl(CsmClassifier classifier, int pointerDepth, boolean reference, int arrayDepth, AST ast, CsmFile file, CsmOffsetable offset) {
107
        super(file, offset == null ? getStartOffset(ast) : offset.getStartOffset(), offset == null ? getEndOffset(ast) : offset.getEndOffset());
106
        super(file, offset == null ? getStartOffset(ast) : offset.getStartOffset(), offset == null ? getEndOffset(ast) : offset.getEndOffset());
108
        this._setClassifier(classifier);
107
        this.initClassifier(classifier);
109
        this.pointerDepth = (byte) pointerDepth;
108
        this.pointerDepth = (byte) pointerDepth;
110
        setFlags(FLAGS_REFERENCE, reference);
109
        setFlags(FLAGS_REFERENCE, reference);
111
        this.arrayDepth = (byte) arrayDepth;
110
        this.arrayDepth = (byte) arrayDepth;
Lines 113-119 Link Here
113
        setFlags(FLAGS_CONST, _const);
112
        setFlags(FLAGS_CONST, _const);
114
        if (classifier == null) {
113
        if (classifier == null) {
115
            CndUtils.assertTrueInConsole(false, "why null classifier?");
114
            CndUtils.assertTrueInConsole(false, "why null classifier?");
116
            this._setClassifier(initClassifier(ast));
115
            this.initClassifier(initClassifier(ast));
117
            this.classifierText = initClassifierText(ast);
116
            this.classifierText = initClassifierText(ast);
118
        } else {
117
        } else {
119
            setFlags(FLAGS_TYPE_WITH_CLASSIFIER, true);
118
            setFlags(FLAGS_TYPE_WITH_CLASSIFIER, true);
Lines 537-543 Link Here
537
                lastCache = newCachePair;
536
                lastCache = newCachePair;
538
            }
537
            }
539
            classifier = _getClassifier();
538
            classifier = _getClassifier();
540
            putTypeOwner();
541
        }
539
        }
542
        if (isInstantiation() && CsmKindUtilities.isTemplate(classifier) && !((CsmTemplate)classifier).getTemplateParameters().isEmpty()) {
540
        if (isInstantiation() && CsmKindUtilities.isTemplate(classifier) && !((CsmTemplate)classifier).getTemplateParameters().isEmpty()) {
543
            CsmInstantiationProvider ip = CsmInstantiationProvider.getDefault();
541
            CsmInstantiationProvider ip = CsmInstantiationProvider.getDefault();
Lines 615-632 Link Here
615
        return obj;
613
        return obj;
616
    }     
614
    }     
617
    
615
    
618
    void setOwner(CsmObject owner) {
619
        this.owner = owner;
620
    }
621
622
    protected void putTypeOwner() {
623
        if (owner != null) {
624
            if (UIDProviderIml.isPersistable(UIDs.get(owner))) {
625
                RepositoryUtils.put(owner);
626
            }
627
        }
628
    }
629
    
630
    protected CsmClassifier renderClassifier(CharSequence[] qname) {
616
    protected CsmClassifier renderClassifier(CharSequence[] qname) {
631
        CsmClassifier result = null;
617
        CsmClassifier result = null;
632
        Resolver resolver = ResolverFactory.createResolver(this);
618
        Resolver resolver = ResolverFactory.createResolver(this);
Lines 763-778 Link Here
763
    }
749
    }
764
750
765
    protected CsmClassifier _getClassifier() {
751
    protected CsmClassifier _getClassifier() {
766
        CsmClassifier classifier = UIDCsmConverter.UIDtoDeclaration(classifierUID);
752
        CsmClassifier classifier = null;
753
        if (classifierUID != null) {
754
            classifier = UIDCsmConverter.UIDtoDeclaration(classifierUID);
755
        } else {
756
            FileImpl file = (FileImpl) getContainingFile();
757
            CsmReference typeReference = file.getResolvedReference(new CsmTypeReferenceImpl(this));
758
            if (typeReference != null) {
759
                CsmObject referencedObject = typeReference.getReferencedObject();
760
                if (CsmKindUtilities.isClassifier(referencedObject)) {
761
                    classifier = (CsmClassifier) referencedObject;
762
                    //System.out.println("Hit "+classifier);
763
                }
764
            }
765
        }
767
        // can be null if cached one was removed
766
        // can be null if cached one was removed
768
        return classifier;
767
        return classifier;
769
    }
768
    }
770
769
771
    final void _setClassifier(CsmClassifier classifier) {
770
    private void initClassifier(CsmClassifier classifier) {
772
        this.classifierUID = UIDCsmConverter.declarationToUID(classifier);
771
        this.classifierUID = UIDCsmConverter.declarationToUID(classifier);
773
        assert (classifierUID != null || classifier == null);
772
        assert (classifierUID != null || classifier == null);
774
    }
773
    }
775
774
775
    final void _setClassifier(final CsmClassifier classifier) {
776
        if (classifier == null) {
777
            FileImpl file = (FileImpl) getContainingFile();
778
            file.removeResolvedReference(new CsmTypeReferenceImpl(this));
779
        }
780
        this.classifierUID = UIDCsmConverter.declarationToUID(classifier);
781
        if (classifierUID != null && classifier != null && !CsmKindUtilities.isBuiltIn(classifier) && CsmBaseUtilities.isValid(classifier) && !CsmKindUtilities.isTypedef(classifier)
782
            //&& !CsmKindUtilities.isTemplate(classifier) && !isInstantiation()
783
           ) {
784
            final FileImpl file = (FileImpl) getContainingFile();
785
            file.addResolvedReference(new CsmTypeReferenceImpl(this), classifier);
786
        }
787
        assert (classifierUID != null || classifier == null);
788
    }
789
776
    @Override
790
    @Override
777
    public boolean isBuiltInBased(boolean resolveTypeChain) {
791
    public boolean isBuiltInBased(boolean resolveTypeChain) {
778
        CsmClassifier classifier;
792
        CsmClassifier classifier;
Lines 871-874 Link Here
871
            return "CachePair{" + "parseCount=" + parseCount + ", fileUID=" + fileUID + '}'; // NOI18N
885
            return "CachePair{" + "parseCount=" + parseCount + ", fileUID=" + fileUID + '}'; // NOI18N
872
        }
886
        }
873
    }    
887
    }    
888
889
    private static class CsmTypeReferenceImpl implements CsmReference {
890
        private final TypeImpl type;
891
892
        public CsmTypeReferenceImpl(TypeImpl type) {
893
            this.type = type;
874
}
894
}
895
896
        @Override
897
        public CsmReferenceKind getKind() {
898
            return CsmReferenceKind.DIRECT_USAGE;
899
        }
900
901
        @Override
902
        public CsmObject getReferencedObject() {
903
            return null;
904
        }
905
906
        @Override
907
        public CsmObject getOwner() {
908
            return null;
909
        }
910
911
        @Override
912
        public CsmObject getClosestTopLevelObject() {
913
            return null;
914
        }
915
916
        @Override
917
        public CsmFile getContainingFile() {
918
            throw new UnsupportedOperationException();
919
        }
920
921
        @Override
922
        public int getStartOffset() {
923
            return type.getStartOffset();
924
        }
925
926
        @Override
927
        public int getEndOffset() {
928
            return type.getEndOffset();
929
        }
930
931
        @Override
932
        public Position getStartPosition() {
933
            throw new UnsupportedOperationException();
934
        }
935
936
        @Override
937
        public Position getEndPosition() {
938
            throw new UnsupportedOperationException();
939
        }
940
941
        @Override
942
        public CharSequence getText() {
943
            return type.classifierText;
944
        }
945
946
        @Override
947
        public String toString() {
948
            return type.classifierText+"["+type.getStartOffset()+","+type.getEndOffset()+"]"; //NOI18N
949
        }
950
    }
951
}
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/UsingDeclarationImpl.java (-11 / +85 lines)
Lines 57-73 Link Here
57
import java.util.LinkedHashSet;
57
import java.util.LinkedHashSet;
58
import org.netbeans.modules.cnd.api.model.services.CsmSelect;
58
import org.netbeans.modules.cnd.api.model.services.CsmSelect;
59
import org.netbeans.modules.cnd.api.model.services.CsmSelect.CsmFilter;
59
import org.netbeans.modules.cnd.api.model.services.CsmSelect.CsmFilter;
60
import org.netbeans.modules.cnd.api.model.util.CsmBaseUtilities;
60
import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
61
import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
61
import org.netbeans.modules.cnd.api.model.util.UIDs;
62
import org.netbeans.modules.cnd.api.model.xref.CsmReference;
63
import org.netbeans.modules.cnd.api.model.xref.CsmReferenceKind;
62
import org.netbeans.modules.cnd.modelimpl.parser.CsmAST;
64
import org.netbeans.modules.cnd.modelimpl.parser.CsmAST;
63
import org.netbeans.modules.cnd.modelimpl.csm.core.*;
65
import org.netbeans.modules.cnd.modelimpl.csm.core.*;
64
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
66
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
65
import org.netbeans.modules.cnd.modelimpl.repository.RepositoryUtils;
66
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
67
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
67
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
68
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
68
import org.openide.util.CharSequences;
69
import org.openide.util.CharSequences;
69
import org.netbeans.modules.cnd.modelimpl.textcache.NameCache;
70
import org.netbeans.modules.cnd.modelimpl.textcache.NameCache;
70
import org.netbeans.modules.cnd.modelimpl.uid.UIDProviderIml;
71
import org.netbeans.modules.cnd.repository.spi.RepositoryDataInput;
71
import org.netbeans.modules.cnd.repository.spi.RepositoryDataInput;
72
import org.netbeans.modules.cnd.repository.spi.RepositoryDataOutput;
72
import org.netbeans.modules.cnd.repository.spi.RepositoryDataOutput;
73
73
Lines 238-252 Link Here
238
                synchronized (this) {
238
                synchronized (this) {
239
                    lastParseCount = newParseCount;
239
                    lastParseCount = newParseCount;
240
                    _setReferencedDeclaration(referencedDeclaration);
240
                    _setReferencedDeclaration(referencedDeclaration);
241
                    if (referencedDeclaration != null) {
242
                        if (UIDProviderIml.isPersistable(UIDs.get(this))) {
243
                            if (UIDProviderIml.isPersistable(UIDs.get(referencedDeclaration))) {
244
                                RepositoryUtils.put(this);
245
                            }
246
                        }
247
                    }
248
                }
241
                }
249
            }            
242
            }
250
        }
243
        }
251
        return referencedDeclaration;
244
        return referencedDeclaration;
252
    }
245
    }
Lines 261-266 Link Here
261
            referencedDeclaration = UIDCsmConverter.UIDtoDeclaration(referencedDeclarationUID);
254
            referencedDeclaration = UIDCsmConverter.UIDtoDeclaration(referencedDeclarationUID);
262
            refDeclaration = new WeakReference<CsmDeclaration>(referencedDeclaration);
255
            refDeclaration = new WeakReference<CsmDeclaration>(referencedDeclaration);
263
        }
256
        }
257
        if (referencedDeclarationUID == null) {
258
            FileImpl file = (FileImpl) getContainingFile();
259
            CsmReference typeReference = file.getResolvedReference(new CsmUsingReferenceImpl(this));
260
            if (typeReference != null) {
261
                CsmObject referencedObject = typeReference.getReferencedObject();
262
                if (CsmKindUtilities.isDeclaration(referencedObject)) {
263
                    referencedDeclaration = (CsmDeclaration) referencedObject;
264
                    refDeclaration = new WeakReference<CsmDeclaration>(referencedDeclaration);
265
                    //System.out.println("Hit "+referencedDeclaration);
266
                }
267
            }
268
        }
264
        // can be null if namespace was removed 
269
        // can be null if namespace was removed 
265
        return referencedDeclaration;
270
        return referencedDeclaration;
266
    }    
271
    }    
Lines 270-277 Link Here
270
            refDeclaration = new WeakReference<CsmDeclaration>(referencedDeclaration);
275
            refDeclaration = new WeakReference<CsmDeclaration>(referencedDeclaration);
271
        } else {
276
        } else {
272
            refDeclaration = null;
277
            refDeclaration = null;
278
            FileImpl file = (FileImpl) getContainingFile();
279
            file.removeResolvedReference(new CsmUsingReferenceImpl(this));
273
        }
280
        }
274
        this.referencedDeclarationUID = UIDCsmConverter.declarationToUID(referencedDeclaration);
281
        this.referencedDeclarationUID = UIDCsmConverter.declarationToUID(referencedDeclaration);
282
        if (referencedDeclarationUID != null && referencedDeclaration != null && CsmBaseUtilities.isValid(referencedDeclaration)) {
283
            FileImpl file = (FileImpl) getContainingFile();
284
            file.addResolvedReference(new CsmUsingReferenceImpl(this), referencedDeclaration);
285
        }
275
        assert this.referencedDeclarationUID != null || referencedDeclaration == null;
286
        assert this.referencedDeclarationUID != null || referencedDeclaration == null;
276
    }
287
    }
277
288
Lines 357-360 Link Here
357
368
358
        this.visibility = PersistentUtils.readVisibility(input);
369
        this.visibility = PersistentUtils.readVisibility(input);
359
    }
370
    }
371
    
372
    private static class CsmUsingReferenceImpl implements CsmReference {
373
        private final UsingDeclarationImpl using;
374
375
        public CsmUsingReferenceImpl(UsingDeclarationImpl using) {
376
            this.using = using;
360
}
377
}
378
379
        @Override
380
        public CsmReferenceKind getKind() {
381
            return CsmReferenceKind.DIRECT_USAGE;
382
        }
383
384
        @Override
385
        public CsmObject getReferencedObject() {
386
            return null;
387
        }
388
389
        @Override
390
        public CsmObject getOwner() {
391
            return null;
392
        }
393
394
        @Override
395
        public CsmObject getClosestTopLevelObject() {
396
            return null;
397
        }
398
399
        @Override
400
        public CsmFile getContainingFile() {
401
            throw new UnsupportedOperationException();
402
        }
403
404
        @Override
405
        public int getStartOffset() {
406
            return using.getStartOffset();
407
        }
408
409
        @Override
410
        public int getEndOffset() {
411
            return using.getEndOffset();
412
        }
413
414
        @Override
415
        public Position getStartPosition() {
416
            throw new UnsupportedOperationException();
417
        }
418
419
        @Override
420
        public Position getEndPosition() {
421
            throw new UnsupportedOperationException();
422
        }
423
424
        @Override
425
        public CharSequence getText() {
426
            return using.getName();
427
        }
428
429
        @Override
430
        public String toString() {
431
            return using.getName()+"["+using.getStartOffset()+","+using.getEndOffset()+"]"; //NOI18N
432
        }
433
    }
434
}
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/UsingDirectiveImpl.java (-11 / +89 lines)
Lines 49-64 Link Here
49
import org.netbeans.modules.cnd.api.model.*;
49
import org.netbeans.modules.cnd.api.model.*;
50
import org.netbeans.modules.cnd.antlr.collections.AST;
50
import org.netbeans.modules.cnd.antlr.collections.AST;
51
import java.io.IOException;
51
import java.io.IOException;
52
import org.netbeans.modules.cnd.api.model.util.CsmBaseUtilities;
52
import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
53
import org.netbeans.modules.cnd.api.model.util.CsmKindUtilities;
53
import org.netbeans.modules.cnd.api.model.util.UIDs;
54
import org.netbeans.modules.cnd.api.model.xref.CsmReference;
55
import org.netbeans.modules.cnd.api.model.xref.CsmReferenceKind;
54
import org.netbeans.modules.cnd.modelimpl.parser.CsmAST;
56
import org.netbeans.modules.cnd.modelimpl.parser.CsmAST;
55
import org.netbeans.modules.cnd.modelimpl.csm.core.*;
57
import org.netbeans.modules.cnd.modelimpl.csm.core.*;
56
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
58
import org.netbeans.modules.cnd.modelimpl.repository.PersistentUtils;
57
import org.netbeans.modules.cnd.modelimpl.repository.RepositoryUtils;
58
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
59
import org.netbeans.modules.cnd.modelimpl.uid.UIDCsmConverter;
59
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
60
import org.netbeans.modules.cnd.modelimpl.uid.UIDObjectFactory;
60
import org.netbeans.modules.cnd.modelimpl.textcache.NameCache;
61
import org.netbeans.modules.cnd.modelimpl.textcache.NameCache;
61
import org.netbeans.modules.cnd.modelimpl.uid.UIDProviderIml;
62
import org.netbeans.modules.cnd.repository.spi.RepositoryDataInput;
62
import org.netbeans.modules.cnd.repository.spi.RepositoryDataInput;
63
import org.netbeans.modules.cnd.repository.spi.RepositoryDataOutput;
63
import org.netbeans.modules.cnd.repository.spi.RepositoryDataOutput;
64
64
Lines 106-118 Link Here
106
            if (CsmKindUtilities.isNamespace(result)) {
106
            if (CsmKindUtilities.isNamespace(result)) {
107
                referencedNamespace = (CsmNamespace)result;
107
                referencedNamespace = (CsmNamespace)result;
108
                _setReferencedNamespace(referencedNamespace);
108
                _setReferencedNamespace(referencedNamespace);
109
                if (referencedNamespace != null) {
110
                    if (UIDProviderIml.isPersistable(UIDs.get(this))) {
111
                        if (UIDProviderIml.isPersistable(UIDs.get(referencedNamespace))) {
112
                            RepositoryUtils.put(this);
113
                        }
114
                    }
115
                }
116
            }
109
            }
117
        }
110
        }
118
        return referencedNamespace;
111
        return referencedNamespace;
Lines 120-130 Link Here
120
    
113
    
121
    private CsmNamespace _getReferencedNamespace() {
114
    private CsmNamespace _getReferencedNamespace() {
122
        // can be null if namespace was removed 
115
        // can be null if namespace was removed 
123
        return UIDCsmConverter.UIDtoNamespace(referencedNamespaceUID);
116
        CsmNamespace referencedNamespace = UIDCsmConverter.UIDtoNamespace(referencedNamespaceUID);
117
        if (referencedNamespaceUID == null) {
118
            FileImpl file = (FileImpl) getContainingFile();
119
            CsmReference typeReference = file.getResolvedReference(new CsmUsingReferenceImpl(this));
120
            if (typeReference != null) {
121
                CsmObject referencedObject = typeReference.getReferencedObject();
122
                if (CsmKindUtilities.isNamespace(referencedObject)) {
123
                    referencedNamespace =  (CsmNamespace) referencedObject;
124
                    referencedNamespaceUID = UIDCsmConverter.namespaceToUID(referencedNamespace);
125
                    //System.out.println("Hit "+referencedNamespace);
126
                }    
127
            }
128
        }
129
        return referencedNamespace;
124
    }    
130
    }    
125
131
126
    private void _setReferencedNamespace(CsmNamespace referencedNamespace) {
132
    private void _setReferencedNamespace(CsmNamespace referencedNamespace) {
127
        this.referencedNamespaceUID = UIDCsmConverter.namespaceToUID(referencedNamespace);
133
        this.referencedNamespaceUID = UIDCsmConverter.namespaceToUID(referencedNamespace);
134
        
135
        if (referencedNamespace == null) {
136
            FileImpl file = (FileImpl) getContainingFile();
137
            file.removeResolvedReference(new CsmUsingReferenceImpl(this));
138
        }
139
        if (referencedNamespaceUID != null && referencedNamespace != null && CsmBaseUtilities.isValid(referencedNamespace)) {
140
            FileImpl file = (FileImpl) getContainingFile();
141
            file.addResolvedReference(new CsmUsingReferenceImpl(this), referencedNamespace);
142
        }
143
        
128
        assert this.referencedNamespaceUID != null || referencedNamespace == null;
144
        assert this.referencedNamespaceUID != null || referencedNamespace == null;
129
    }
145
    }
130
 
146
 
Lines 178-181 Link Here
178
        this.referencedNamespaceUID = UIDObjectFactory.getDefaultFactory().readUID(input);        
194
        this.referencedNamespaceUID = UIDObjectFactory.getDefaultFactory().readUID(input);        
179
    }  
195
    }  
180
    
196
    
197
    private static class CsmUsingReferenceImpl implements CsmReference {
198
        private final UsingDirectiveImpl using;
199
200
        public CsmUsingReferenceImpl(UsingDirectiveImpl using) {
201
            this.using = using;
181
}
202
}
203
204
        @Override
205
        public CsmReferenceKind getKind() {
206
            return CsmReferenceKind.DIRECT_USAGE;
207
        }
208
209
        @Override
210
        public CsmObject getReferencedObject() {
211
            return null;
212
        }
213
214
        @Override
215
        public CsmObject getOwner() {
216
            return null;
217
        }
218
219
        @Override
220
        public CsmObject getClosestTopLevelObject() {
221
            return null;
222
        }
223
224
        @Override
225
        public CsmFile getContainingFile() {
226
            throw new UnsupportedOperationException();
227
        }
228
229
        @Override
230
        public int getStartOffset() {
231
            return using.getStartOffset();
232
        }
233
234
        @Override
235
        public int getEndOffset() {
236
            return using.getEndOffset();
237
        }
238
239
        @Override
240
        public Position getStartPosition() {
241
            throw new UnsupportedOperationException();
242
        }
243
244
        @Override
245
        public Position getEndPosition() {
246
            throw new UnsupportedOperationException();
247
        }
248
249
        @Override
250
        public CharSequence getText() {
251
            return using.getName();
252
        }
253
254
        @Override
255
        public String toString() {
256
            return using.getName()+"["+using.getStartOffset()+","+using.getEndOffset()+"]"; //NOI18N
257
        }
258
    }
259
}
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/VariableImpl.java (-9 lines)
Lines 87-95 Link Here
87
    public static<T> VariableImpl<T> create(CsmOffsetable pos, CsmFile file, CsmType type, CharSequence name, CsmScope scope, boolean _static, boolean _extern, boolean registerInProject) {
87
    public static<T> VariableImpl<T> create(CsmOffsetable pos, CsmFile file, CsmType type, CharSequence name, CsmScope scope, boolean _static, boolean _extern, boolean registerInProject) {
88
        VariableImpl<T> variableImpl = new VariableImpl<T>(pos, file, type, name, scope, _static, _extern);
88
        VariableImpl<T> variableImpl = new VariableImpl<T>(pos, file, type, name, scope, _static, _extern);
89
        postObjectCreateRegistration(registerInProject, variableImpl);
89
        postObjectCreateRegistration(registerInProject, variableImpl);
90
        if (registerInProject && (type instanceof TypeImpl)) {
91
            ((TypeImpl)type).setOwner(variableImpl);
92
        }
93
        return variableImpl;
90
        return variableImpl;
94
    }
91
    }
95
92
Lines 106-114 Link Here
106
    public static<T> VariableImpl<T> create(AST ast, CsmFile file, CsmType type, NameHolder name, CsmScope scope,  boolean _static, boolean _extern, boolean global) {
103
    public static<T> VariableImpl<T> create(AST ast, CsmFile file, CsmType type, NameHolder name, CsmScope scope,  boolean _static, boolean _extern, boolean global) {
107
        VariableImpl<T> variableImpl = new VariableImpl<T>(ast, file, type, name, scope, _static, _extern);
104
        VariableImpl<T> variableImpl = new VariableImpl<T>(ast, file, type, name, scope, _static, _extern);
108
        postObjectCreateRegistration(global, variableImpl);
105
        postObjectCreateRegistration(global, variableImpl);
109
        if (global && (type instanceof TypeImpl)) {
110
            ((TypeImpl)type).setOwner(variableImpl);
111
        }
112
        return variableImpl;
106
        return variableImpl;
113
    }
107
    }
114
108
Lines 460-468 Link Here
460
        this._extern = (pack & 2) == 2;
454
        this._extern = (pack & 2) == 2;
461
        this.initExpr = (ExpressionBase) PersistentUtils.readExpression(input);
455
        this.initExpr = (ExpressionBase) PersistentUtils.readExpression(input);
462
        this.type = PersistentUtils.readType(input);
456
        this.type = PersistentUtils.readType(input);
463
        if (type instanceof TypeImpl) {
464
            ((TypeImpl)type).setOwner(this);
465
        }
466
457
467
        this.scopeUID = UIDObjectFactory.getDefaultFactory().readUID(input);
458
        this.scopeUID = UIDObjectFactory.getDefaultFactory().readUID(input);
468
        // could be null UID (i.e. parameter)
459
        // could be null UID (i.e. parameter)
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FileComponentReferences.java (-4 / +69 lines)
Lines 89-94 Link Here
89
    }
89
    }
90
90
91
    private final SortedMap<ReferenceImpl, CsmUID<CsmObject>> references;
91
    private final SortedMap<ReferenceImpl, CsmUID<CsmObject>> references;
92
    private final SortedMap<ReferenceImpl, CsmUID<CsmObject>> type2classifier;
92
    private final ReadWriteLock referencesLock = new ReentrantReadWriteLock();
93
    private final ReadWriteLock referencesLock = new ReentrantReadWriteLock();
93
    private final CsmUID<CsmFile> fileUID;
94
    private final CsmUID<CsmFile> fileUID;
94
95
Lines 107-112 Link Here
107
    public FileComponentReferences(FileImpl file) {
108
    public FileComponentReferences(FileImpl file) {
108
        super(new FileReferencesKey(file));
109
        super(new FileReferencesKey(file));
109
        references = new TreeMap<ReferenceImpl, CsmUID<CsmObject>>();
110
        references = new TreeMap<ReferenceImpl, CsmUID<CsmObject>>();
111
        type2classifier = new TreeMap<ReferenceImpl, CsmUID<CsmObject>>();
110
        this.fileUID = file.getUID();
112
        this.fileUID = file.getUID();
111
        put();
113
        put();
112
    }
114
    }
Lines 116-127 Link Here
116
        UIDObjectFactory defaultFactory = UIDObjectFactory.getDefaultFactory();
118
        UIDObjectFactory defaultFactory = UIDObjectFactory.getDefaultFactory();
117
        fileUID = defaultFactory.readUID(input);
119
        fileUID = defaultFactory.readUID(input);
118
        references = defaultFactory.readReferencesSortedToUIDMap(input, fileUID);
120
        references = defaultFactory.readReferencesSortedToUIDMap(input, fileUID);
121
        type2classifier = defaultFactory.readReferencesSortedToUIDMap(input, fileUID);
119
    }
122
    }
120
123
121
    // only for EMPTY static field
124
    // only for EMPTY static field
122
    private FileComponentReferences() {
125
    private FileComponentReferences() {
123
        super((org.netbeans.modules.cnd.repository.spi.Key) null);
126
        super((org.netbeans.modules.cnd.repository.spi.Key) null);
124
        references = new TreeMap<ReferenceImpl, CsmUID<CsmObject>>();
127
        references = new TreeMap<ReferenceImpl, CsmUID<CsmObject>>();
128
        type2classifier = new TreeMap<ReferenceImpl, CsmUID<CsmObject>>();
125
        fileUID = null;
129
        fileUID = null;
126
    }
130
    }
127
131
Lines 129-134 Link Here
129
        referencesLock.writeLock().lock();
133
        referencesLock.writeLock().lock();
130
        try {
134
        try {
131
            references.clear();
135
            references.clear();
136
            type2classifier.clear();
132
        } finally {
137
        } finally {
133
            referencesLock.writeLock().unlock();
138
            referencesLock.writeLock().unlock();
134
        }
139
        }
Lines 168-175 Link Here
168
        return res;
173
        return res;
169
    }
174
    }
170
175
176
    CsmReference getReference(int offset) {
177
        return getReferenceImpl(offset, references);
178
    }
171
179
172
    CsmReference getReference(int offset) {
180
    CsmReference getResolvedReference(CsmReference ref) {
181
        referencesLock.readLock().lock();
182
        try {
183
            for(Map.Entry<ReferenceImpl, CsmUID<CsmObject>> entry : type2classifier.tailMap(new ReferenceImpl(ref.getStartOffset(), ref.getEndOffset(), ref.getText())).entrySet()) {
184
                if (entry.getKey().start == ref.getStartOffset() && 
185
                    entry.getKey().end == ref.getEndOffset() &&
186
                        entry.getKey().identifier.equals(ref.getText())) {
187
                    //request_hit++;
188
                    return entry.getKey();
189
                } else {
190
                    return null;
191
                }
192
            }
193
        } finally {
194
            referencesLock.readLock().unlock();
195
        }
196
        return null;
197
    }
198
    
199
    CsmReference getReferenceImpl(int offset, SortedMap<ReferenceImpl, CsmUID<CsmObject>> storage) {
173
        //if (request > 0 && request%1000 == 0) {
200
        //if (request > 0 && request%1000 == 0) {
174
        //    System.err.println("Reference statictic:");
201
        //    System.err.println("Reference statictic:");
175
        //    System.err.println("\tRequest:"+request+" hit "+request_hit);
202
        //    System.err.println("\tRequest:"+request+" hit "+request_hit);
Lines 178-184 Link Here
178
        //request++;
205
        //request++;
179
        referencesLock.readLock().lock();
206
        referencesLock.readLock().lock();
180
        try {
207
        try {
181
            for(Map.Entry<ReferenceImpl, CsmUID<CsmObject>> entry : references.tailMap(new ReferenceImpl(offset)).entrySet()) {
208
            for(Map.Entry<ReferenceImpl, CsmUID<CsmObject>> entry : storage.tailMap(new ReferenceImpl(offset)).entrySet()) {
182
                if (entry.getKey().start <= offset && offset < entry.getKey().end) {
209
                if (entry.getKey().start <= offset && offset < entry.getKey().end) {
183
                    //request_hit++;
210
                    //request_hit++;
184
                    return entry.getKey();
211
                    return entry.getKey();
Lines 192-198 Link Here
192
        return null;
219
        return null;
193
    }
220
    }
194
221
222
    boolean addResolvedReference(CsmReference ref, CsmObject cls) {
223
         return addReferenceImpl(ref, cls, type2classifier);
224
    }
225
226
    void removeResolvedReference(CsmReference ref) {
227
        CsmUID<CsmObject> remove;
228
        referencesLock.writeLock().lock();
229
        try {
230
            remove = type2classifier.remove(new ReferenceImpl(ref.getStartOffset(), ref.getEndOffset(), ref.getText()));
231
        } finally {
232
            referencesLock.writeLock().unlock();
233
        }
234
        if (remove != null) {
235
            put();
236
        }
237
    }
238
    
195
    boolean addReference(CsmReference ref, CsmObject referencedObject) {
239
    boolean addReference(CsmReference ref, CsmObject referencedObject) {
240
         return addReferenceImpl(ref, referencedObject, references);
241
    }
242
    
243
    private boolean addReferenceImpl(CsmReference ref, CsmObject referencedObject, Map<ReferenceImpl, CsmUID<CsmObject>> storage) {
196
        //respons++;
244
        //respons++;
197
        if (!UIDCsmConverter.isIdentifiable(referencedObject)) {
245
        if (!UIDCsmConverter.isIdentifiable(referencedObject)) {
198
            // ignore local references
246
            // ignore local references
Lines 222-228 Link Here
222
        //}
270
        //}
223
        referencesLock.writeLock().lock();
271
        referencesLock.writeLock().lock();
224
        try {
272
        try {
225
            references.put(refImpl, referencedUID);
273
            storage.put(refImpl, referencedUID);
226
        } finally {
274
        } finally {
227
            referencesLock.writeLock().unlock();
275
            referencesLock.writeLock().unlock();
228
        }
276
        }
Lines 264-269 Link Here
264
                defaultFactory.writeUID(entry.getValue(), out);
312
                defaultFactory.writeUID(entry.getValue(), out);
265
                entry.getKey().write(defaultFactory, out);
313
                entry.getKey().write(defaultFactory, out);
266
            }
314
            }
315
            out.writeInt(type2classifier.size());
316
            for(Map.Entry<ReferenceImpl, CsmUID<CsmObject>> entry : type2classifier.entrySet()) {
317
                defaultFactory.writeUID(entry.getValue(), out);
318
                entry.getKey().write(defaultFactory, out);
319
            }
267
        } finally {
320
        } finally {
268
            referencesLock.readLock().unlock();
321
            referencesLock.readLock().unlock();
269
        }
322
        }
Lines 291-296 Link Here
291
            this.closestTopLevelObjectUID = null;
344
            this.closestTopLevelObjectUID = null;
292
        }
345
        }
293
346
347
        // to remove
348
        private ReferenceImpl(int start, int end, CharSequence identifier) {
349
            this.start = start;
350
            this.end = end;
351
            this.file = null;
352
            this.refKind = null;
353
            this.refObj = null;
354
            this.identifier = identifier;
355
            this.ownerUID = null;
356
            this.closestTopLevelObjectUID = null;
357
        }
358
294
        private ReferenceImpl(CsmUID<CsmFile> fileUID, CsmReference delegate, CsmUID<CsmObject> refObj, CsmUID<CsmObject> ownerUID, CsmUID<CsmObject> closestTopLevelObjectUID) {
359
        private ReferenceImpl(CsmUID<CsmFile> fileUID, CsmReference delegate, CsmUID<CsmObject> refObj, CsmUID<CsmObject> ownerUID, CsmUID<CsmObject> closestTopLevelObjectUID) {
295
            this.file = fileUID;
360
            this.file = fileUID;
296
            this.refKind = delegate.getKind();
361
            this.refKind = delegate.getKind();
Lines 427-433 Link Here
427
492
428
        @Override
493
        @Override
429
        public String toString() {
494
        public String toString() {
430
            return "ReferenceImpl{" + "file=" + file + ";refKind=" + refKind + ";refObj=" + refObj + ";start=" + start + ";end=" + end + ";identifier=" + identifier + ";topUID=" + closestTopLevelObjectUID + ";ownerUID=" + ownerUID + '}'; // NOI18N
495
            return identifier+"["+start+","+end+"] file=" + file + ";refKind=" + refKind + ";refObj=" + refObj + ";topUID=" + closestTopLevelObjectUID + ";ownerUID=" + ownerUID + '}'; // NOI18N
431
        }
496
        }
432
    }
497
    }
433
}
498
}
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/csm/core/FileImpl.java (+12 lines)
Lines 1374-1379 Link Here
1374
        return getFileReferences().getReference(offset);
1374
        return getFileReferences().getReference(offset);
1375
    }
1375
    }
1376
1376
1377
    public boolean addResolvedReference(CsmReference ref, CsmObject referencedObject) {
1378
        return getFileReferences().addResolvedReference(ref, referencedObject);
1379
    }
1380
1381
    public void removeResolvedReference(CsmReference ref) {
1382
        getFileReferences().removeResolvedReference(ref);
1383
    }
1384
1385
    public CsmReference getResolvedReference(CsmReference ref) {
1386
        return getFileReferences().getResolvedReference(ref);
1387
    }
1388
1377
    public void addMacro(CsmMacro macro) {
1389
    public void addMacro(CsmMacro macro) {
1378
        getFileMacros().addMacro(macro);
1390
        getFileMacros().addMacro(macro);
1379
    }
1391
    }
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/repository/RepositoryUtils.java (-1 / +1 lines)
Lines 88-94 Link Here
88
    /**
88
    /**
89
     * the version of the persistency mechanism
89
     * the version of the persistency mechanism
90
     */
90
     */
91
    private static int CURRENT_VERSION_OF_PERSISTENCY = 111;
91
    private static int CURRENT_VERSION_OF_PERSISTENCY = 112;
92
92
93
    /** Creates a new instance of RepositoryUtils */
93
    /** Creates a new instance of RepositoryUtils */
94
    private RepositoryUtils() {
94
    private RepositoryUtils() {

Return to bug 200981