Esempio n. 1
0
        public CreateObjectAction(ParseInfo parseInfo, Scope scope, NewExpression context)
        {
            if (context.ClassIdentifier == null)
            {
                return;
            }

            // Get the type. Syntax error if there is no type name.
            CreatingObjectOf = parseInfo.TranslateInfo.Types.GetCodeType(context.ClassIdentifier.Text, parseInfo.Script.Diagnostics, context.ClassIdentifier.Range);

            if (CreatingObjectOf != null)
            {
                DocRange nameRange = context.ClassIdentifier.Range;

                // Get the constructor to use.
                OverloadChooser = new OverloadChooser(
                    CreatingObjectOf.Constructors, parseInfo, CreatingObjectOf.ReturningScope(), scope, nameRange, context.Range, new OverloadError("type " + CreatingObjectOf.Name)
                    );
                OverloadChooser.Apply(context.Parameters);

                Constructor       = (Constructor)OverloadChooser.Overload;
                ConstructorValues = OverloadChooser.Values ?? new IExpression[0];

                if (Constructor != null)
                {
                    parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(Constructor, new Location(parseInfo.Script.Uri, nameRange));
                    Constructor.Call(parseInfo, nameRange);
                    parseInfo.Script.AddHover(context.Range, Constructor.GetLabel(true));
                }
            }
        }
Esempio n. 2
0
        public CreateObjectAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Create_objectContext context)
        {
            // Get the type. Syntax error if there is no type name.
            if (context.type == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected a type name.", DocRange.GetRange(context.NEW()));
            }
            else
            {
                CreatingObjectOf = parseInfo.TranslateInfo.Types.GetCodeType(context.type.Text, parseInfo.Script.Diagnostics, DocRange.GetRange(context.type));
            }

            if (CreatingObjectOf != null)
            {
                DocRange nameRange = DocRange.GetRange(context.type);

                // Get the constructor to use.
                OverloadChooser = new OverloadChooser(
                    CreatingObjectOf.Constructors, parseInfo, CreatingObjectOf.ReturningScope(), scope, nameRange, DocRange.GetRange(context), new OverloadError("type " + CreatingObjectOf.Name)
                    );
                OverloadChooser.Apply(context.call_parameters());

                Constructor       = (Constructor)OverloadChooser.Overload;
                ConstructorValues = OverloadChooser.Values ?? new IExpression[0];

                if (Constructor != null)
                {
                    parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(Constructor, new Location(parseInfo.Script.Uri, nameRange));
                    Constructor.Call(parseInfo, DocRange.GetRange(context.type));
                    parseInfo.Script.AddHover(DocRange.GetRange(context), Constructor.GetLabel(true));
                }
            }
        }
Esempio n. 3
0
        public CreateObjectAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Create_objectContext context)
        {
            // Get the type. Syntax error if there is no type name.
            if (context.type == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected a type name.", DocRange.GetRange(context.NEW()));
            }
            else
            {
                CreatingObjectOf = parseInfo.TranslateInfo.GetCodeType(context.type.Text, parseInfo.Script.Diagnostics, DocRange.GetRange(context.type));
            }

            if (CreatingObjectOf != null)
            {
                DocRange nameRange = DocRange.GetRange(context.type);

                // Get the constructor to use.
                OverloadChooser = new OverloadChooser(
                    CreatingObjectOf.Constructors, parseInfo, scope, nameRange, DocRange.GetRange(context), new OverloadError("type " + CreatingObjectOf.Name)
                    );

                if (context.call_parameters() != null)
                {
                    OverloadChooser.SetContext(context.call_parameters());
                }
                else
                {
                    OverloadChooser.SetContext();
                }

                Constructor       = (Constructor)OverloadChooser.Overload;
                ConstructorValues = OverloadChooser.Values ?? new IExpression[0];

                if (Constructor != null)
                {
                    Constructor.Call(parseInfo.Script, DocRange.GetRange(context.type));
                    parseInfo.Script.AddHover(DocRange.GetRange(context), Constructor.GetLabel(true));

                    if (Constructor is DefinedConstructor)
                    {
                        parseInfo.CurrentCallInfo.Call((DefinedConstructor)Constructor, nameRange);
                    }
                }
            }
        }
Esempio n. 4
0
        public CreateObjectAction(ParseInfo parseInfo, Scope scope, NewExpression context)
        {
            if (!context.Type.Valid)
            {
                CreatingObjectOf = parseInfo.Types.Any();
                return;
            }

            // Get the type. Syntax error if there is no type name.
            CreatingObjectOf = TypeFromContext.GetCodeTypeFromContext(parseInfo, scope, context.Type);

            DocRange nameRange = context.Type.GenericToken.Range;

            // Get the constructor to use.
            OverloadChooser = new OverloadChooser(
                CreatingObjectOf.Constructors.Select(c => new ConstructorOverload(c)).ToArray(),
                parseInfo,
                CreatingObjectOf.ReturningScope(),
                scope,
                nameRange,
                context.Range,
                context.Range,
                new OverloadError("type " + CreatingObjectOf.Name)
                );
            OverloadChooser.Apply(context.Parameters, false, null);

            Constructor = (Constructor)OverloadChooser.Overload;

            if (Constructor != null)
            {
                Constructor.Call(parseInfo, nameRange);
                parseInfo.Script.AddHover(context.Range, Constructor.GetLabel(parseInfo.TranslateInfo, LabelInfo.Hover));

                // Default restricted parameter values.
                OverloadChooser.Match.CheckOptionalsRestrictedCalls(parseInfo, nameRange);

                // Bridge other restricted values.
                if (Constructor.CallInfo != null)
                {
                    RestrictedCall.BridgeMethodCall(parseInfo, Constructor.CallInfo, nameRange, context.Type.GenericToken.Text, Constructor.RestrictedValuesAreFatal);
                }
            }
        }