Example #1
0
        public TypeSymbol GetDeclaredType(ResourceScope containingScope, SemanticModel moduleSemanticModel)
        {
            var paramTypeProperties = new List <TypeProperty>();

            foreach (var param in moduleSemanticModel.Root.ParameterDeclarations)
            {
                var typePropertyFlags = TypePropertyFlags.WriteOnly;
                if (SyntaxHelper.TryGetDefaultValue(param.DeclaringParameter) == null)
                {
                    // if there's no default value, it must be specified
                    typePropertyFlags |= TypePropertyFlags.Required;
                }

                paramTypeProperties.Add(new TypeProperty(param.Name, param.Type, typePropertyFlags));
            }

            var outputTypeProperties = new List <TypeProperty>();

            foreach (var output in moduleSemanticModel.Root.OutputDeclarations)
            {
                outputTypeProperties.Add(new TypeProperty(output.Name, output.Type, TypePropertyFlags.ReadOnly));
            }

            return(LanguageConstants.CreateModuleType(paramTypeProperties, outputTypeProperties, moduleSemanticModel.TargetScope, containingScope, "module"));
        }
        public TypeSymbol GetDeclaredType(IBinder binder)
        {
            if (binder.GetSymbolInfo(this) is not ModuleSymbol moduleSymbol)
            {
                // TODO: Ideally we'd still be able to return a type here, but we'd need access to the compilation to get it.
                return(ErrorType.Empty());
            }

            if (!moduleSymbol.TryGetSemanticModel(out var moduleSemanticModel, out var failureDiagnostic))
            {
                return(ErrorType.Create(failureDiagnostic));
            }

            return(LanguageConstants.CreateModuleType(
                       moduleSemanticModel.ParameterTypeProperties,
                       moduleSemanticModel.OutputTypeProperties,
                       moduleSemanticModel.TargetScope,
                       binder.TargetScope,
                       LanguageConstants.TypeNameModule));
        }