public override string ToString()
        {
            string result = Value;

            if (AfterVar)
            {
                result = "var " + result;
            }

            if (GivenType != null)
            {
                result += GivenType.ToString();
            }

            if (NextChild != null)
            {
                Type t = NextChild.GetType();

                if (t != typeof(OperatorFragment))
                {
                    result += " ";
                }
            }

            return(result);
        }
        public override void Handle(Entity element, ParsedAttributeAttribute attribute, KAOSModel model)
        {
            var a = new EntityAttribute(model);

            a.Identifier = attribute.Identifier;

            GivenType givenType;

            if (attribute.Type == null)
            {
                // No given type was specified
                givenType = null;
            }
            else if (attribute.Type is IdentifierExpression)
            {
                var identifier = ((IdentifierExpression)attribute.Type).Value;
                if ((givenType = model.entityRepository.GetGivenType(identifier)) == null)
                {
                    givenType = new GivenType(model, identifier)
                    {
                        Implicit = true
                    };
                    model.entityRepository.Add(givenType);
                }
            }
            else
            {
                throw new UnsupportedValue(element, attribute, attribute.Type);
            }

            a.TypeIdentifier   = givenType?.Identifier;
            a.EntityIdentifier = element.Identifier;

            model.Add(a);
        }
        public void Add(GivenType givenType)
        {
            if (GivenTypes.ContainsKey(givenType.Identifier))
            {
                throw new ArgumentException(string.Format("Given type identifier already exist: {0}", givenType.Identifier));
            }

            GivenTypes.Add(givenType.Identifier, givenType);
        }
Beispiel #4
0
 KAOSTools.Core.EntityAttribute GetOrCreateAttribute(ParsedAttributeReferenceExpression pref,
                                                     Entity entity,
                                                     GivenType type)
 {
     if (entity != null)
     {
         if (pref.AttributeSignature is NameExpression)
         {
             var attribute = entity.Attributes().SingleOrDefault(x => x.Name == pref.AttributeSignature.Value);
             if (attribute == null)
             {
                 attribute = new KAOSTools.Core.EntityAttribute(model)
                 {
                     Name           = pref.AttributeSignature.Value,
                     TypeIdentifier = type?.Identifier,
                     Implicit       = true
                 };
                 attribute.SetEntity(entity);
                 model.Add(attribute);
             }
             else
             {
             }
             return(attribute);
         }
         else if (pref.AttributeSignature is IdentifierExpression)
         {
             var attribute = entity.model.Attributes().SingleOrDefault(x => x.Identifier == pref.AttributeSignature.Value &&
                                                                       x.EntityIdentifier == entity.Identifier);
             if (attribute == null)
             {
                 attribute = new KAOSTools.Core.EntityAttribute(model)
                 {
                     Identifier     = pref.AttributeSignature.Value,
                     TypeIdentifier = type?.Identifier,
                     Implicit       = true
                 };
                 attribute.SetEntity(entity);
                 model.Add(attribute);
             }
             return(attribute);
         }
         else
         {
             throw new NotImplementedException(pref.AttributeSignature.GetType() + " is not yet supported");
         }
     }
     else
     {
         throw new Exception(string.Format("Entity '{0}' not found", entity.Identifier));
     }
 }
        public override string ToString()
        {
            string result = MethodName.ToString();

            if (Brackets != null)
            {
                result += Brackets.ToString();
            }
            if (GivenType != null)
            {
                result += GivenType.ToString();
            }
            return(result);
        }
        public override void BuildDeclare(ParsedDeclare parsedElement, KAOSModel model)
        {
            GivenType g = model.entityRepository.GetGivenType(parsedElement.Identifier);

            if (g == null)
            {
                g = new GivenType(model, parsedElement.Identifier);
                model.entityRepository.Add(g);
            }
            else if (!parsedElement.Override)
            {
                throw new BuilderException("Cannot declare twice the same element. Use override instead.", parsedElement);
            }
        }
Beispiel #7
0
        GivenType GetOrCreateGivenType(string id)
        {
            var type = model.GivenType(t => t.Identifier == id);

            if (type == null)
            {
                type = new GivenType(model)
                {
                    Identifier = id, Implicit = true
                };
                model.Add(type);
            }

            return(type);
        }
Beispiel #8
0
        public override string ToString()
        {
            if (Bracket == StringReader.NULL)
            {
                return(base.ToString());
            }

            string result = Bracket + base.ToString() + CloseBracket;

            if (GivenType != null)
            {
                result += GivenType.ToString();
            }

            return(result);
        }
Beispiel #9
0
        public override CompiledFragment Compile(CompiledMethod method)
        {
            if (!IsParent)
            {
                return(null);
            }

            CodeFragment child = FirstChild;

            while (child != null)
            {
                CodeFragment     next  = child.NextChild;
                CompiledFragment cfrag = child.Compile(method);

                if (cfrag != null)
                {
                    cfrag.AddAfter(child);
                }

                child.Remove();
                child = next;
            }

            if (GivenType != null)
            {
                Type toType = GivenType.FindType(method.Script);

                if (toType == null)
                {
                    Error("Type not found: " + GivenType.ToString() + ".");
                }

                CompiledFragment compiledKid = (CompiledFragment)FirstChild;
                CompiledFragment result      = Types.TryCast(method, compiledKid, toType);

                if (result == null)
                {
                    Error("Cannot cast " + compiledKid.OutputType() + " to " + toType + ".");
                }

                return(result);
            }

            return((CompiledFragment)FirstChild);
        }
Beispiel #10
0
        public override CompiledFragment Compile(CompiledMethod method)
        {
            if (!IsParent)
            {
                return(null);
            }

            CodeFragment child = FirstChild;

            while (child != null)
            {
                CodeFragment     next  = child.NextChild;
                CompiledFragment cfrag = child.Compile(method);

                if (cfrag != null)
                {
                    cfrag.AddAfter(child);
                }

                child.Remove();
                child = next;
            }

            // Is this a cast?
            if (GivenType != null)
            {
                // Get the type being cast to:
                Type toType = GivenType.FindType(method.Script);

                if (toType == null)
                {
                    Error("Type to cast to was not found: " + GivenType.ToString() + ".");
                }

                // Get the object being cast:
                CompiledFragment compiledKid = (CompiledFragment)FirstChild;

                // Create a cast operation with it:
                return(new CastOperation(method, compiledKid, toType));
            }

            return((CompiledFragment)FirstChild);
        }
        public override CompiledFragment Compile(CompiledMethod function)
        {
            if (Value == "null")
            {
                return(new CompiledFragment(null));
            }
            else if (Value == "base")
            {
                return(new BaseOperation(function));
            }
            else if (Value == "true" || Value == "false")
            {
                return(new CompiledFragment(Value == "true"));
            }
            else if (Value == "new")
            {
                Error("A constructor is missing its brackets.");
                return(null);
            }
            else if (IsKeyword())
            {
                return(KeyWords.Compile(this, function));
            }
            else
            {
                // It isn't a keyword (if,for..)

                bool isSet = (
                    GivenType != null ||
                    (
                        AfterVar && NextChild != null &&
                        Types.IsTypeOf(NextChild, typeof(OperatorFragment)) &&
                        ((OperatorFragment)NextChild).IsSetOperator
                    )
                    );

                Variable var = function.GetVariable(Value);

                if (isSet)
                {
                    if (var == null)
                    {
                        Type varType = null;

                        if (GivenType != null)
                        {
                            // Find it:
                            varType = GivenType.FindType(function.Script);

                            // Got it?
                            if (varType == null)
                            {
                                Error("Type '" + GivenType.Value + "' was not found.");
                            }
                        }

                        // Create the local:
                        var = function.GetVariable(Value, true, varType);
                    }
                }

                if (var != null)
                {
                    return(new CompiledFragment(var));
                }

                return(new PropertyOperation(function, Value));
            }
        }