Ejemplo n.º 1
0
 public void ToEDialect(CodeWriter writer)
 {
     writer.append("fetch one ");
     if (type != null)
     {
         if (type.Mutable)
         {
             writer.append("mutable ");
         }
         writer.append(type.GetTypeName().ToString());
         writer.append(" ");
     }
     writer.append("where ");
     predicate.ToDialect(writer);
     if (include != null)
     {
         writer.append(" include ");
         if (include.Count == 1)
         {
             writer.append(include[0]);
         }
         else
         {
             for (int i = 0; i < include.Count - 1; i++)
             {
                 writer.append(include[i]).append(", ");
             }
             writer.trimLast(", ".Length);
             writer.append(" and ").append(include[include.Count - 1]);
         }
     }
 }
Ejemplo n.º 2
0
        public override IType check(Context context)
        {
            CategoryDeclaration cd = context.getRegisteredDeclaration <CategoryDeclaration>(this.type.GetTypeName());

            if (cd == null)
            {
                throw new SyntaxError("Unknown category " + this.type.GetTypeName());
            }
            checkFirstHomonym(context, cd);
            cd.checkConstructorContext(context);
            if (copyFrom != null)
            {
                IType cft = copyFrom.check(context);
                if (!(cft is CategoryType) && (cft != DocumentType.Instance))
                {
                    throw new SyntaxError("Cannot copy from " + cft.GetTypeName());
                }
            }
            if (arguments != null)
            {
                foreach (Argument argument in arguments)
                {
                    if (!cd.hasAttribute(context, argument.GetName()))
                    {
                        throw new SyntaxError("\"" + argument.GetName() +
                                              "\" is not an attribute of " + type.GetTypeName());
                    }
                    argument.check(context);
                }
            }
            return(((CategoryType)cd.GetIType(context)).AsMutable(context, type.Mutable));
        }
Ejemplo n.º 3
0
 private void ToMDialect(CodeWriter writer)
 {
     writer.append("fetch ");
     if (first != null)
     {
         writer.append("rows ");
         first.ToDialect(writer);
         writer.append(" to ");
         last.ToDialect(writer);
         writer.append(" ");
     }
     else
     {
         writer.append("all ");
     }
     writer.append("( ");
     if (type != null)
     {
         if (type.Mutable)
         {
             writer.append("mutable ");
         }
         writer.append(type.GetTypeName());
         writer.append(" ");
     }
     writer.append(") ");
     if (predicate != null)
     {
         writer.append("where ");
         predicate.ToDialect(writer);
         writer.append(" ");
     }
     if (include != null)
     {
         writer.append(" include ");
         foreach (string name in include)
         {
             writer.append(name).append(", ");
         }
         writer.trimLast(", ".Length);
     }
     if (orderBy != null)
     {
         orderBy.ToDialect(writer);
     }
 }
Ejemplo n.º 4
0
 internal ConcreteCategoryDeclaration getDeclaration()
 {
     if (instance != null)
     {
         return(instance.getDeclaration());
     }
     else
     {
         return(getRegisteredDeclaration <ConcreteCategoryDeclaration>(type.GetTypeName()));
     }
 }
Ejemplo n.º 5
0
 public ConcreteInstance loadSingleton(CategoryType type)
 {
     if (this == globals)
     {
         IValue value = null;
         values.TryGetValue(type.GetTypeName(), out value);
         if (value == null)
         {
             IDeclaration decl = declarations[type.GetTypeName()];
             if (!(decl is ConcreteCategoryDeclaration))
             {
                 throw new InternalError("No such singleton:" + type.GetTypeName());
             }
             value = new ConcreteInstance(this, (ConcreteCategoryDeclaration)decl);
             ((IInstance)value).setMutable(true); // a singleton is protected by "with x do", so always mutable in that context
             ConcreteMethodDeclaration method = ((SingletonCategoryDeclaration)decl).getInitializeMethod(this);
             if (method != null)
             {
                 Context instance = newInstanceContext((IInstance)value, false);
                 Context child    = instance.newChildContext();
                 method.interpret(child);
             }
             values[type.GetTypeName()] = value;
         }
         if (value is ConcreteInstance)
         {
             return((ConcreteInstance)value);
         }
         else
         {
             throw new InternalError("Not a concrete instance:" + value.GetType().Name);
         }
     }
     else
     {
         return(this.globals.loadSingleton(type));
     }
 }
Ejemplo n.º 6
0
 public bool isDerivedFrom(Context context, CategoryType categoryType)
 {
     if (derivedFrom == null)
     {
         return(false);
     }
     foreach (String ancestor in derivedFrom)
     {
         if (ancestor.Equals(categoryType.GetTypeName()))
         {
             return(true);
         }
         if (isAncestorDerivedFrom(ancestor, context, categoryType))
         {
             return(true);
         }
     }
     return(false);
 }