Example #1
0
        public void SetUp()
        {
            var schemaObserver = new SchemaObserver();

            schemaObserver.AddKnownType(new QueryRoot());
            schemaObserver.AddKnownType(new ComplicatedArgs());
            schemaObserver.AddKnownType(new FurColorEnum());
            schemaObserver.AddKnownType(new ComplicatedObjectType());
            schemaObserver.AddKnownType(new ComplicatedInputObjectType());

            var typeTranslator = new TypeTranslator(schemaObserver);

            this.introspector = new Introspector(typeTranslator);
        }
Example #2
0
        public void Equal(Expression e)
        {
            Expression lh;
            Expression rh;

            if (e is BinaryExpression)
            {
                BinaryExpression be = e as BinaryExpression;
                lh = be.Left;
                rh = be.Right;
            }
            else if (e is MethodCallExpression)
            {
                MethodCallExpression mce = e as MethodCallExpression;
                lh = mce.Arguments[0];
                rh = mce.Arguments[1];
            }
            else
            {
                throw new LinqToRdfException("Unrecognised equality expression type");
            }

            if (lh != null && rh != null)
            {
                XsdtPrimitiveDataType dt = TypeTranslator.GetDataType(lh.Type);
                if (dt == XsdtPrimitiveDataType.XsdtString)
                {
                    QueryAppend("regex(");
                    Dispatch(lh);
                    QueryAppend(", ");
                    Dispatch(rh);
                    QueryAppend(") ");
                }
                else
                {
                    //QueryAppend("(");
                    Dispatch(lh);
                    QueryAppend(" = ");
                    //QueryAppend(")=(");
                    Dispatch(rh);
                    //QueryAppend(")");
                    //Log("+ :{0} Handled", e.NodeType);
                }
            }
            else
            {
                Log("Failure during generation of Equal expression");
            }
        }
Example #3
0
 private static void ParseWsdlArrayType(XmlReader reader, XmlAttribute attr)
 {
     if (attr.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && attr.LocalName == "arrayType")
     {
         string text = string.Empty;
         string str;
         string str2;
         TypeTranslator.ParseArrayType(attr.Value, out str, out text, out str2);
         if (text != string.Empty)
         {
             text = reader.LookupNamespace(text) + ":";
         }
         attr.Value = text + str + str2;
     }
 }
Example #4
0
        public override void CollectTypesInto(TranslationProcess translationProcess, SemanticModel semantics)
        {
            var classSymbol = semantics.GetDeclaredSymbol(this.OriginalNode as ClassDeclarationSyntax);

            // Should translate at all?
            var attributes = classSymbol.GetAttributes();

            switch (VerificationSettings.ShouldVerify(attributes, translationProcess.Configuration.VerifyUnmarkedItems))
            {
            case VerificationSetting.DoNotVerify:
                return;

            case VerificationSetting.Contradiction:
                return;
            }

            this.TypeIfCollected = translationProcess.AddToCollectedTypes(this, semantics);
            foreach (Sharpnode node in this.children)
            {
                // Collect fields
                if (node is FieldDeclarationSharpnode)
                {
                    FieldDeclarationSharpnode fieldDeclaration = (FieldDeclarationSharpnode)node;
                    var fieldSymbol = fieldDeclaration.GetSymbol(semantics);
                    if (fieldSymbol.IsConst)
                    {
                        continue;                      // Constants are inlined.
                    }
                    if (fieldSymbol.IsStatic)
                    {
                        translationProcess.AddError(new Error(Diagnostics.SSIL108_FeatureNotSupported,
                                                              node.OriginalNode, "static fields"));
                        continue;
                    }
                    var   typeSymbol = fieldSymbol.Type;
                    Error error;
                    this.TypeIfCollected.InstanceFields.Add(
                        new CollectedField(
                            translationProcess.IdentifierTranslator.RegisterAndGetIdentifier(((FieldDeclarationSharpnode)node).GetSymbol(semantics)),
                            TypeTranslator.TranslateType(typeSymbol, node.OriginalNode, out error)
                            ));
                    if (error != null)
                    {
                        translationProcess.AddError(error);
                    }
                }
            }
        }
        public override void Run(List <ExpressionSharpnode> arguments, SyntaxNode originalNode, TranslationContext context)
        {
            // Get the symbol
            var           methodSymbol = this._method.Symbol as IMethodSymbol;
            var           identifier   = context.Process.IdentifierTranslator.GetIdentifierReference(this._method.Symbol as IMethodSymbol);
            IMethodSymbol theMethod    = (this._method.Symbol as IMethodSymbol);

            // Determine purity
            this.Impure = !(ContractsTranslator.IsMethodPureOrPredicate(theMethod));

            // Add the receiver
            if (!theMethod.IsStatic)
            {
                if (this.methodGroupSharpnode is IdentifierExpressionSharpnode)
                {
                    arguments.Insert(0, new DirectSilvercodeExpressionSharpnode(Constants.SilverThis, this.methodGroup));
                }
                else if (this.methodGroupSharpnode is MemberAccessExpressionSharpnode)
                {
                    arguments.Insert(0, ((MemberAccessExpressionSharpnode)this.methodGroupSharpnode).Container);
                }
                else
                {
                    this.Errors.Add(new Error(Diagnostics.SSIL102_UnexpectedNode, this.methodGroup, this.methodGroup.Kind()));
                }
            }

            // Determine return type
            Error error;

            this.SilverType = TypeTranslator.TranslateType(methodSymbol.ReturnType, this.methodGroup, out error);
            if (error != null)
            {
                this.Errors.Add(error);
            }

            // Translate arguments
            var expressions = ConvertToSilver(arguments, context);

            // Put it together
            this.Silvernode = new CallSilvernode(
                identifier,
                expressions, this.SilverType,
                originalNode
                );
        }
        /// <summary>
        /// Prepares for insertion into quantifier.
        /// Returns true if this lambda expression is valid for translation inside a ForAll or Exists call; false otherwise.
        /// </summary>
        /// <param name="context">The context.</param>
        public bool PrepareForInsertionIntoQuantifier(TranslationContext context)
        {
            if (this.errorneousResult != null)
            {
                this.failedResult = TranslationResult.Error(this.errorneousResult.Node, this.errorneousResult.Diagnostic, this.errorneousResult.DiagnosticArguments);
                return(false);
            }

            // Translate the single parameter's type
            var parameterSymbol = context.Semantics.GetDeclaredSymbol(this.parameter.ParameterSyntax);

            this.VariableIdentifier = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(parameterSymbol);
            this.VariableSilverType = TypeTranslator.TranslateType(parameterSymbol.Type, this.parameter.OriginalNode,
                                                                   out this.errorneousResult);
            if (this.errorneousResult != null)
            {
                this.failedResult = TranslationResult.Error(this.errorneousResult.Node, this.errorneousResult.Diagnostic, this.errorneousResult.DiagnosticArguments);
                return(false);
            }

            // Translate the lambda's body
            TranslationResult res = this.body.Translate(context.ChangePurityContext(PurityContext.PureOrFail));

            if (res.WasTranslationSuccessful)
            {
                this.BodySilvernode = res.Silvernode;
            }
            else
            {
                this.failedResult = res;
                return(false);
            }

            // Nothing went wrong.
            return(true);
        }
        public List<VarDeclarationNode> Walk()
        {
            var varDecls = new List<VarDeclarationNode>();

            var modifiers = Modifier.None;
            ITree modifierNode = node.GetChild(0);
            if (modifierNode.Type == (int) JavaNodeType.MODIFIER_LIST)
            {
                modifiers = new ModifierListTranslator(modifierNode).Walk();
            }

            Type type = new TypeTranslator(node.GetChild(1)).Walk();

            ITree declaratorList = node.GetChild(2);

            for (int i = 0; i < declaratorList.ChildCount; i++)
            {
                ITree declarator = declaratorList.GetChild(i);

                var varDecl = new VarDeclarationNode
                                  {
                                      Modifiers = modifiers,
                                      Type = type,
                                      Name = declarator.GetChild(0).Text,
                                  };

                if (declarator.ChildCount > 1)
                {
                    varDecl.Initialiser = new ExpressionTranslator(declarator.GetChild(1)).Walk();
                }

                varDecls.Add(varDecl);
            }

            return varDecls;
        }
        public TranslationResult Translate(TranslationContext context, IParameterSymbol symbol)
        {
            Error               err;
            ISymbol             parameterSymbol = context.Semantics.GetDeclaredSymbol(this.ParameterSyntax);
            Identifier          identifier      = context.Process.IdentifierTranslator.RegisterAndGetIdentifier(parameterSymbol);
            ParameterSilvernode ps = new ParameterSilvernode(identifier,
                                                             new TypeSilvernode(this.Type.TypeSyntax, TypeTranslator.TranslateType(symbol.Type, this.Type.TypeSyntax, out err)), this.OriginalNode);
            var errlist = new List <Error>();

            if (err != null)
            {
                errlist.Add(err);
            }
            return(TranslationResult.FromSilvernode(ps, errlist));
        }
Example #9
0
        public void Constant(Expression e)
        {
            ConstantExpression ce = (ConstantExpression)e;

            QueryAppend(TypeTranslator.Get(e.Type, ce.Value).ToString());
        }