Package org.openquark.cal.compiler

Examples of org.openquark.cal.compiler.DataConstructor


    private final Set<FieldName> getCommonFieldNames (TypeConstructor typeConstructor) {
        Set<FieldName> commonFieldNames = new LinkedHashSet<FieldName>();

        int nDCs = typeConstructor.getNDataConstructors();
       
        DataConstructor firstDC = typeConstructor.getNthDataConstructor(0);
        for (int i = 0; i < firstDC.getArity(); ++i) {
            FieldName fn = firstDC.getNthFieldName(i);
            commonFieldNames.add(fn);
        }
       
        for (int i = 1; i < nDCs; ++i) {
            DataConstructor dc = typeConstructor.getNthDataConstructor(i);
            Set<FieldName> commonFieldNamesClone = new LinkedHashSet<FieldName>(commonFieldNames);
           
            for (int j = 0, dcArity = dc.getArity(); j < dcArity; ++j) {
                commonFieldNamesClone.remove(dc.getNthFieldName(j));
            }
           
            commonFieldNames.removeAll(commonFieldNamesClone);
           
        }
View Full Code Here


            for (int i = 0, n = moduleInfo.getNTypeConstructors(); i < n; i++) {
                final TypeConstructor typeCons = moduleInfo.getNthTypeConstructor(i);
                caldocComments.put("type cons " + typeCons.getName().getQualifiedName(), typeCons.getCALDocComment());

                for (int j = 0, m = typeCons.getNDataConstructors(); j < m; j++) {
                    final DataConstructor dataCons = typeCons.getNthDataConstructor(j);
                    caldocComments.put("data cons " + dataCons.getName().getQualifiedName(), dataCons.getCALDocComment());
                }
            }
           
            for (int i = 0, n = moduleInfo.getNTypeClasses(); i < n; i++) {
                final TypeClass typeClass = moduleInfo.getNthTypeClass(i);
View Full Code Here

        TypeExpr valueNodeTypeExpr = valueNode.getTypeExpr();
       
        QualifiedName typeConstructorName = valueNode.getTypeExpr().rootTypeConsApp().getName();
        DataConstructor[] dataConsList = valueEditorManager.getPerspective().getDataConstructorsForType(typeConstructorName);

        DataConstructor currentDataCons = valueNode.getDataConstructor();

        ValueEditorListener childListener = new ChildValueEditorListener();
        KeyAdapter editorPanelKeyListener = new EditorPanelKeyListener();
       
        boolean haveAddedPanel = false;
        FontMetrics fontMetrics = getFontMetrics(getFont().deriveFont(Font.BOLD));
        ScopedEntityNamingPolicy namingPolicy = new UnqualifiedUnlessAmbiguous(valueEditorManager.getPerspective().getWorkingModuleTypeInfo());

        // Remove components in case this is called twice.
        contentPanel.removeAll();

        // Create an editor panel for each supported data constructor.
        for (final DataConstructor dataCons : dataConsList) {

            DataConstructorValueNode newValueNode = null;

            if (currentDataCons.getName().equals(dataCons.getName())) {
               
                // If this is the current data constructor, just transmute the value node.
                newValueNode = (DataConstructorValueNode) valueNode.transmuteValueNode(valueEditorManager.getValueNodeBuilderHelper(),
                                                                                       valueEditorManager.getValueNodeTransformer(),
                                                                                       valueNodeTypeExpr);
View Full Code Here

     * @see org.openquark.gems.client.valueentry.ValueEditor#editorActivated()
     */
    @Override
    public void editorActivated() {

        DataConstructor dataCons = getDataConstructor();
       
        for (final DataConstructorEditorPanel childEditor : editorPanelList) {

            if (dataCons.getName().equals(childEditor.getDataConstructor().getName())) {
                focusChangeListener.setFocusedPanel(childEditor);
                break;
            }
        }
    }
View Full Code Here

       
        for (final ArgumentEditorPanel editorPanel : editorPanels) {
            editorPanel.refreshDisplay(polymorphicVarContext);
        }
       
        DataConstructor dataConstructor = getDataConstructor();
        titleLabel.setToolTipText(ToolTipHelpers.getEntityToolTip(dataConstructor, namingPolicy, parentEditor.valueEditorManager.getWorkspace(), this));
    }
View Full Code Here

       
        return new ValueEditorContext() {

            public TypeExpr getLeastConstrainedTypeExpr() {

                DataConstructor dataConstructor = getDataConstructor();
                TypeExpr leastConstrainedParentType = parentEditor.getContext().getLeastConstrainedTypeExpr();
       
                if (leastConstrainedParentType instanceof TypeVar) {
           
                    // The parent is parametric, that means the child can be whatever it wants.
                    return dataConstructor.getTypeExpr().getTypePieces()[argNum];
       
                } else {
           
                    // The parent is not parametric, so the child must fit the parent constraint.
                    return TypeExpr.getComponentTypeExpr(leastConstrainedParentType, argNum, dataConstructor);
View Full Code Here

     */
    Map<ValueNode, TypeExpr> getValueNodeToUnconstrainedTypeMap(TypeExpr leastConstrainedType) {

        Map<ValueNode, TypeExpr> returnMap = new HashMap<ValueNode, TypeExpr>();
       
        DataConstructor dataCons = getDataConstructor();
       
        returnMap.put(valueNode, leastConstrainedType);

        for (int i = 0; i < editorPanels.length; i++) {

View Full Code Here

            }
            if (unqualifiedClassName.equals(CALToJavaNames.createUnqualifiedClassNameForTagDCFromType(typeConstructor, module))) {
                return builder.getTagDCClass();
            }
            for (int i = 0, nDataConstructors = typeConstructor.getNDataConstructors(); i < nDataConstructors; i++) {
                DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                if (unqualifiedClassName.equals(CALToJavaNames.createClassName(dc, module))) {
                    return builder.getDCClass(dc);
                } else if (unqualifiedClassName.equals(CALToJavaNames.createFieldSelectionClassNameFromDC(dc, module))) {
                    return builder.getDCFieldSelectionClass(dc);
                }
View Full Code Here

         * @param fieldNameToStrictness (FieldName->Boolean) this map will be populated with mappings from field name to strictness
         * @throws CodeGenerationException
         */
        private void setCommonFieldNames(Map<FieldName, JavaTypeName> fieldNameToType, Map<FieldName, Boolean> fieldNameToStrictness) throws CodeGenerationException {
            this.commonFieldNames = new LinkedHashSet<FieldName>();
            DataConstructor firstDC = dataConsList.get(0);
            boolean[] fieldStrictness = firstDC.getArgStrictness();
            for (int i = 0; i < firstDC.getArity(); ++i) {
                TypeExpr[] fieldTypes = SCJavaDefn.getFieldTypesForDC(firstDC);
                FieldName fn = firstDC.getNthFieldName(i);
                commonFieldNames.add(fn);
                int index = firstDC.getFieldIndex(fn);
                fieldNameToType.put (fn, SCJavaDefn.typeExprToTypeName(fieldTypes[index]));
                fieldNameToStrictness.put (fn, Boolean.valueOf (fieldStrictness[i]));
            }

            for (int i = 1; i < dataConsList.size(); ++i) {
                DataConstructor dc = dataConsList.get(i);
                TypeExpr[] fieldTypes = SCJavaDefn.getFieldTypesForDC(dc);
                fieldStrictness = dc.getArgStrictness();
                Set<FieldName> commonFieldNamesClone = new HashSet<FieldName>(commonFieldNames);

                for (int j = 0, dcArity = dc.getArity(); j < dcArity; ++j) {
                    commonFieldNamesClone.remove(dc.getNthFieldName(j));
                }

                for (final FieldName fieldName : commonFieldNamesClone) {
                    commonFieldNames.remove(fieldName);
                }

                HashSet<FieldName> set = new LinkedHashSet<FieldName>();
                for (final FieldName fn : commonFieldNames) {
                    int index = dc.getFieldIndex(fn);
                    JavaTypeName jt = fieldNameToType.get(fn);
                    boolean fs = fieldNameToStrictness.get(fn).booleanValue();

                    if (fs == fieldStrictness[index] &&
                            SCJavaDefn.typeExprToTypeName(fieldTypes[index]).equals(jt)) {
View Full Code Here

            SwitchStatement sw =
                new SwitchStatement(new MethodVariable("dcOrdinal"));

            for (int i = 0, n = dataConsList.size(); i < n; ++i) {
                DataConstructor dc = dataConsList.get(i);
                SwitchStatement.IntCaseGroup icg =
                    new SwitchStatement.IntCaseGroup(
                            dc.getOrdinal(),
                            new ReturnStatement(LiteralWrapper.make(dc.getName().getUnqualifiedName())));
                sw.addCase(icg);
            }

            javaMethod.addStatement(sw);
View Full Code Here

TOP

Related Classes of org.openquark.cal.compiler.DataConstructor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.