Пример #1
0
    @java.lang.Override
    public ASTNode visit(KApp kapp, Void _)  {
        if (kapp.getLabel() instanceof Token) {
            Token node = (Token) kapp.getLabel();

            /* this code needs to be refactored; this transformer is backend dependent
            so whenever somebody refactors the backends should split this transformer
            for each backend.
             */
            if (kompileOptions.experimental.legacyKast) {
                if (context.variableTokenSorts.contains(node.tokenSort())) {
                    String sort = KSorts.K;
                    String name = node.value();
                    int index = node.value().lastIndexOf(":");
                    if (index > 0) {
                        sort = node.value().substring(index + 1);
                        name = node.value().substring(0, index);
                    }

                    if (Sort.of("#" + sort).isDataSort()) {
                        return KApp.of(KLabelConstant.of(AddSymbolicK.symbolicConstructor(sort)), Token.kAppOf(Sort.BUILTIN_ID, name));
                    } else {
                        return KApp.of(KLabelConstant.of(AddSymbolicK.symbolicConstructor(KSorts.K)), Token.kAppOf(Sort.BUILTIN_ID, node.value()));
                    }
                }
            }

            if (context.variableTokenSorts.contains(node.tokenSort()))
                return new org.kframework.kil.Variable(node.value(), node.tokenSort());
        }
        return super.visit(kapp, _);    //To change body of overridden methods use File | Settings | File Templates.
    }
Пример #2
0
  @Override
  public List<Term> getKComponents() {
    DataStructureSort sort = global.getDefinition().dataStructureSortOf(sort());

    ArrayList<Term> components = Lists.newArrayList();
    elements
        .stream()
        .forEach(
            element ->
                components.add(
                    KItem.of(
                        KLabelConstant.of(sort.elementLabel(), global.getDefinition()),
                        KList.singleton(element),
                        global,
                        element.getSource(),
                        element.getLocation())));

    for (Term term : baseTerms()) {
      if (term instanceof BuiltinSet) {
        components.addAll(((BuiltinSet) term).getKComponents());
      } else {
        components.add(term);
      }
    }

    return components;
  }
Пример #3
0
 public static Term getTerm(Production prod, org.kframework.kil.loader.Context context) {
   if (prod.isSubsort()) {
     final Variable freshVar = Variable.getFreshVar(prod.getItems().get(0).toString());
     if (prod.containsAttribute("klabel")) {
       return KApp.of(KLabelConstant.of(prod.getKLabel(), context), freshVar);
     }
     return freshVar;
   }
   if (prod.isConstant()) {
     String terminal = ((Terminal) prod.getItems().get(0)).getTerminal();
     if (prod.getSort().equals(KSorts.KLABEL)) {
       return KLabelConstant.of(terminal, context);
     } else if (prod.getSort().equals(BoolBuiltin.SORT_NAME)) {
       return BoolBuiltin.kAppOf(terminal);
     } else if (prod.getSort().equals(IntBuiltin.SORT_NAME)) {
       return IntBuiltin.kAppOf(terminal);
     } else if (prod.getSort().equals(StringBuiltin.SORT_NAME)) {
       return StringBuiltin.kAppOf(terminal);
     } else {
       return GenericToken.kAppOf(prod.getSort(), terminal);
     }
   }
   if (prod.isLexical()) {
     return KApp.of(
         KLabelConstant.of("#token", context),
         StringBuiltin.kAppOf(prod.getSort()),
         Variable.getFreshVar("String"));
   }
   TermCons t = new TermCons(prod.getSort(), prod.getCons(), context);
   if (prod.isListDecl()) {
     t.getContents().add(Variable.getFreshVar(((UserList) prod.getItems().get(0)).getSort()));
     t.getContents().add(Variable.getFreshVar(prod.getSort()));
     return t;
   }
   for (ProductionItem item : prod.getItems()) {
     if (item instanceof Sort) {
       t.getContents().add(Variable.getFreshVar(((Sort) item).getName()));
     }
   }
   return t;
 }
Пример #4
0
  public final Term makeSymbolicTerm(String sort, Term term) {
    assert allowSymbolic(sort);

    String ctor = symbolicConstructor(sort);
    Term symTerm;
    if (!allowKSymbolic(sort)) {
      symTerm = new TermCons(sort, ctor, context);
      ((TermCons) symTerm).getContents().add(term);
    } else {
      symTerm = KApp.of(KLabelConstant.of(ctor, context), term);
    }

    return symTerm;
  }
Пример #5
0
 @Override
 public List<Term> getKComponents() {
   return cells
       .values()
       .stream()
       .map(
           c ->
               new KItem(
                   KLabelConstant.of(c.cellLabel.name(), definition),
                   KList.concatenate(c.content),
                   sort(),
                   true))
       .collect(Collectors.toList());
 }
Пример #6
0
 public Term freshSymSortN(String sort, int n) {
   return KApp.of(
       KLabelConstant.of("'#freshSymSortN", context),
       StringBuiltin.kAppOf(sort),
       IntBuiltin.kAppOf(n));
 }
Пример #7
0
 @Override
 public Term unit() {
   org.kframework.kore.KApply kApply = definition.configurationInfo().getUnit(cellSort);
   return new KItem(
       KLabelConstant.of(kApply.klabel().name(), definition), KList.EMPTY, sort(), true);
 }
Пример #8
0
 @Override
 public KLabel constructorLabel() {
   org.kframework.kore.KLabel kLabel = definition.configurationInfo().getConcat(cellSort);
   return KLabelConstant.of(kLabel.name(), definition);
 }
Пример #9
0
Файл: KApp.java Проект: kszr/k
 /**
  * Constructs the application of the given KLabel to a KList with the given elements.
  *
  * @param label the string of a KLabelConstant which is applied to a KList with the given
  *     elements.
  * @param elements the elements of the KList.
  * @return a {@link KApp} which represents the application of the given KLabel to a KList with the
  *     given elements.
  */
 public static KApp of(String label, Term... elements) {
   return KApp.of(KLabelConstant.of(label), elements);
 }