Exemple #1
0
  @Nullable
  /*package*/ SNode getTypeOf(final SNode node) {
    ModelAccess.assertLegalRead();
    if (node == null) return null;

    if (myTypeChecker.isGenerationMode()) {
      TypeCheckingContext context =
          myTypeChecker.hasPerformanceTracer()
              ? new TargetTypecheckingContext_Tracer(node, myTypeChecker)
              : new TargetTypecheckingContext(node, myTypeChecker);
      try {
        return context.getTypeOf_generationMode(node);
      } finally {
        context.dispose();
      }
    }
    // now we are not in generation mode

    final ITypeContextOwner contextOwner = myTypecheckingContextOwner.get();
    TypeCheckingContext context = acquireTypecheckingContext(node, contextOwner);
    if (context == null) {
      return TypesUtil.createRuntimeErrorType();
    }

    try {
      return context.getTypeOf(node, myTypeChecker);
    } finally {
      releaseTypecheckingContext(node, contextOwner);
    }
  }
Exemple #2
0
 public TypeCheckingContext createTypeCheckingContext(SNode node) {
   ModelAccess.assertLegalRead();
   if (myTypeChecker.isGenerationMode()) {
     return new TargetTypecheckingContext(node, myTypeChecker);
   } else {
     return new IncrementalTypecheckingContext(node, myTypeChecker);
   }
 }
Exemple #3
0
 public void rehighlightAllFeaturesNow() {
   ModelAccess.assertLegalRead();
   synchronized (myFeaturesHolder) {
     for (Feature f : ListSequence.fromList(myFeaturesHolder.getAllModelFeatures())) {
       rehighlightFeatureAndDescendants(f);
     }
   }
 }
  public Iterable<TransientModelsModule> getModules() {
    ModelAccess.assertLegalRead();

    List<TransientModelsModule> result = new ArrayList<TransientModelsModule>(myModuleMap.size());
    for (TransientModelsModule m : myModuleMap.values()) {
      if (m.hasPublished()) {
        result.add(m);
      }
    }

    return result;
  }
Exemple #5
0
 private void removeOwnerForRootNodeContext(final SNode node, final ITypeContextOwner owner) {
   ModelAccess.assertLegalRead();
   if (node == null || node.getModel() == null) return;
   final SNode rootNode = node.getContainingRoot();
   // if node is disposed, then context was removed by beforeModelDisposed/beforeRootDeleted
   // listener
   synchronized (myLock) {
     SNodeReference rootNodePointer = new jetbrains.mps.smodel.SNodePointer(rootNode);
     List<TypecheckingContextHolder> contextWithOwners =
         myTypeCheckingContexts.get(rootNodePointer);
     if (contextWithOwners != null) {
       for (ListIterator<TypecheckingContextHolder> it = contextWithOwners.listIterator();
           it.hasNext(); ) {
         TypecheckingContextHolder contextHolder = it.next();
         ITypeContextOwner o = contextHolder.getOwner();
         if (o == owner) {
           if (!owner.reuseTypecheckingContext()) {
             contextHolder.release();
             if (!contextHolder.isActive()) {
               it.remove();
             }
           } else {
             contextHolder.release();
             if (!contextHolder.isActive()) {
               it.remove();
             }
           }
           break;
         }
       }
       if (contextWithOwners.isEmpty()) {
         myTypeCheckingContexts.remove(rootNodePointer);
       }
     }
   }
 }
Exemple #6
0
  private TypeCheckingContext getOrCreateContext(
      SNode node, ITypeContextOwner owner, boolean createIfAbsent) {
    ModelAccess.assertLegalRead();
    if (node == null) return null;
    final SNode rootNode = node.getContainingRoot();
    synchronized (myLock) {
      SNodeReference rootNodePointer = new jetbrains.mps.smodel.SNodePointer(rootNode);

      List<TypecheckingContextHolder> contextWithOwners =
          myTypeCheckingContexts.get(rootNodePointer);
      if (contextWithOwners == null && !createIfAbsent) return null;
      if (contextWithOwners == null) {
        contextWithOwners = new ArrayList<TypecheckingContextHolder>(4);
        myTypeCheckingContexts.put(rootNodePointer, contextWithOwners);
      }

      for (ListIterator<TypecheckingContextHolder> it = contextWithOwners.listIterator();
          it.hasNext(); ) {
        TypecheckingContextHolder contextHolder = it.next();
        if (contextHolder.getOwner() == owner) {

          if (!owner.reuseTypecheckingContext()) {
            assert createIfAbsent;
            return contextHolder.acquire(node);
          } else {
            // reuse the typechecking context
            if (!createIfAbsent) {
              return contextHolder.get(node);
            }

            final TypeCheckingContext ctx = contextHolder.acquire(node);

            // Dirty hack
            if (jetbrains.mps.util.SNodeOperations.isDisposed(ctx.getNode())) {
              removeContextForNode(rootNodePointer);
              LOG.error(
                  "Type Checking Context had a disposed node inside. Node: "
                      + node
                      + " model: "
                      + node.getModel());
              return getOrCreateContext(node, owner, createIfAbsent);
            }

            return ctx;
          }
        }
      }

      // not found, create new
      if (!owner.reuseTypecheckingContext()) {
        assert createIfAbsent;

        final NonReusableTypecheckingContextHolder contextHolder =
            new NonReusableTypecheckingContextHolder(owner);
        contextWithOwners.add(contextHolder);

        return contextHolder.acquire(node);
      } else if (!createIfAbsent) {
        return null;
      } else {
        if (contextWithOwners.size() > 100) {
          if (!myReported) {
            myReported = true;
            LOG.warn(
                "Type checking context for node "
                    + node.getPresentation()
                    + " has too much owners");
          }
        }

        final CountingTypecheckingContextHolder contextHolder =
            new CountingTypecheckingContextHolder(owner);
        contextWithOwners.add(contextHolder);
        return contextHolder.acquire(node);
      }
    }
  }
Exemple #7
0
 public TypeCheckingContext createTracingTypeCheckingContext(SNode node) {
   ModelAccess.assertLegalRead();
   return new TracingTypecheckingContext(node, myTypeChecker);
 }