Ejemplo n.º 1
0
 public CompilerContext(CompilerSettings settings, ReportPrinter reportPrinter)
 {
     this.settings      = settings;
     this.report        = new Report(this, reportPrinter);
     this.builtin_types = new BuiltinTypes();
     this.TimeReporter  = DisabledTimeReporter;
 }
Ejemplo n.º 2
0
		public static TypeSpec[] CreateBinaryPromotionsTypes (BuiltinTypes types)
		{
			return new TypeSpec[] { 
				types.Decimal, types.Double, types.Float,
				types.ULong, types.Long, types.UInt
			};
		}
Ejemplo n.º 3
0
 public virtual void compilation(compilation ast)
 {
     T = ast.global.Types;
     foreach (compilation_unit x in ast.inputs)
     {
         compilation_unit(x);
     }
 }
Ejemplo n.º 4
0
        public static FullNamedExpression CreateDelegateTypeExpression(BuiltinTypes builtinTypes, ParametersCompiled parameters, FullNamedExpression retType, Location loc)
        {
            bool hasParams      = parameters != null && parameters.Count > 0;
            int  paramCount     = hasParams ? parameters.Count : 0;
            bool hasRetType     = !(retType is TypeExpression && ((TypeExpression)retType).Type == builtinTypes.Void);
            int  typeParamCount = paramCount;

            if (hasRetType)
            {
                typeParamCount++;
            }
            TypeArguments typeArgs = null;

            if (typeParamCount > 0)
            {
                var typeArgArray = new FullNamedExpression[typeParamCount];
                for (var i = 0; i < paramCount; i++)
                {
                    if (i < paramCount)
                    {
                        var param = parameters.FixedParameters[i] as Parameter;
                        typeArgArray[i] = param.TypeExpression;
                    }
                    else
                    {
                        typeArgArray[i] = retType;
                    }
                }
                typeArgs = new TypeArguments(typeArgArray);
            }
            if (!hasRetType)
            {
                return(new MemberAccess(new SimpleName("System", loc), "Action", typeArgs, loc));
            }
            else
            {
                return(new MemberAccess(new SimpleName("System", loc), "Func", typeArgs, loc));
            }
        }
Ejemplo n.º 5
0
		public StringConstant (BuiltinTypes types, string s, Location loc)
			: this (types.String, s, loc)
		{
		}
Ejemplo n.º 6
0
		public CharConstant (BuiltinTypes types, char v, Location loc)
			: this (types.Char, v, loc)
		{
		}
Ejemplo n.º 7
0
 public UIntLiteral(BuiltinTypes types, uint l, Location loc)
     : base(types, l, loc)
 {
 }
Ejemplo n.º 8
0
		public DoubleConstant (BuiltinTypes types, double v, Location loc)
			: this (types.Double, v, loc)
		{
		}
Ejemplo n.º 9
0
		public BoolLiteral (BuiltinTypes types, bool val, Location loc)
			: base (types, val, loc)
		{
		}
Ejemplo n.º 10
0
 public NameSpace(Imports imports)
 {
     members      = new SymbolTable(this);
     this.imports = imports;
     this.Types   = new BuiltinTypes(imports);
 }
Ejemplo n.º 11
0
 public BoolLiteral(BuiltinTypes types, bool val, Location loc)
     : base(types, val, loc)
 {
 }
Ejemplo n.º 12
0
		public DecimalLiteral (BuiltinTypes types, decimal d, Location loc)
			: base (types, d, loc)
		{
		}
Ejemplo n.º 13
0
 public DecimalLiteral(BuiltinTypes types, decimal d, Location loc)
     : base(types, d, loc)
 {
 }
Ejemplo n.º 14
0
 public StringLiteral(BuiltinTypes types, string s, Location loc)
     : base(types, s, loc)
 {
 }
Ejemplo n.º 15
0
 public DoubleLiteral(BuiltinTypes types, double d, Location loc)
     : base(types, d, loc)
 {
 }
Ejemplo n.º 16
0
 public FloatLiteral(BuiltinTypes types, float f, Location loc)
     : base(types, f, loc)
 {
 }
Ejemplo n.º 17
0
 public ULongLiteral(BuiltinTypes types, ulong l, Location loc)
     : base(types, l, loc)
 {
 }
Ejemplo n.º 18
0
		public UShortConstant (BuiltinTypes types, ushort v, Location loc)
			: this (types.UShort, v, loc)
		{
		}
Ejemplo n.º 19
0
        public override IEnumerable <MemberResult> GetDefinedMembers(int index, AstMemberType memberType, bool isMemberAccess = false)
        {
            HashSet <MemberResult> members = new HashSet <MemberResult>();

            HashSet <GeneroPackage> includedPackages = new HashSet <GeneroPackage>();

            if (memberType.HasFlag(AstMemberType.SystemTypes) && !isMemberAccess)
            {
                // Built-in types
                members.AddRange(BuiltinTypes.Select(x => new MemberResult(Tokens.TokenKinds[x], GeneroMemberType.Keyword, this)));

                foreach (var package in Packages.Values.Where(x => _importedPackages[x.Name] && x.ContainsInstanceMembers &&
                                                              (this.LanguageVersion >= x.MinimumLanguageVersion && this.LanguageVersion <= x.MaximumLanguageVersion)))
                {
                    members.Add(new MemberResult(package.Name, GeneroMemberType.Module, this));
                    includedPackages.Add(package);
                }
            }
            if (memberType.HasFlag(AstMemberType.Constants) && !isMemberAccess)
            {
                members.AddRange(SystemConstants.Where(x => this.LanguageVersion >= x.Value.MinimumLanguageVersion && this.LanguageVersion <= x.Value.MaximumLanguageVersion)
                                 .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Keyword, this)));
                members.AddRange(SystemMacros.Where(x => this.LanguageVersion >= x.Value.MinimumLanguageVersion && this.LanguageVersion <= x.Value.MaximumLanguageVersion)
                                 .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, this)));
            }
            if (memberType.HasFlag(AstMemberType.Variables) && !isMemberAccess)
            {
                members.AddRange(SystemVariables.Where(x => this.LanguageVersion >= x.Value.MinimumLanguageVersion && this.LanguageVersion <= x.Value.MaximumLanguageVersion)
                                 .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Keyword, this)));
            }
            if (memberType.HasFlag(AstMemberType.Functions) && !isMemberAccess)
            {
                members.AddRange(SystemFunctions.Where(x => this.LanguageVersion >= x.Value.MinimumLanguageVersion && this.LanguageVersion <= x.Value.MaximumLanguageVersion)
                                 .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Function, this)));
                foreach (var package in Packages.Values.Where(x => _importedPackages[x.Name] && x.ContainsStaticClasses &&
                                                              (this.LanguageVersion >= x.MinimumLanguageVersion && this.LanguageVersion <= x.MaximumLanguageVersion)))
                {
                    if (!includedPackages.Contains(package))
                    {
                        members.Add(new MemberResult(package.Name, GeneroMemberType.Module, this));
                    }
                }
            }

            // TODO: need to handle multiple results of the same name
            AstNode containingNode = GetContainingNode(_body, index);

            if (containingNode != null)
            {
                if (containingNode is IFunctionResult)
                {
                    if (memberType.HasFlag(AstMemberType.Variables))
                    {
                        members.AddRange((containingNode as IFunctionResult).Variables.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)));
                        foreach (var varList in (containingNode as IFunctionResult).LimitedScopeVariables)
                        {
                            foreach (var item in varList.Value)
                            {
                                if (item.Item2.IsInSpan(index))
                                {
                                    members.Add(new MemberResult(item.Item1.Name, item.Item1, GeneroMemberType.Instance, this));
                                    break;
                                }
                            }
                        }
                    }
                    if (memberType.HasFlag(AstMemberType.SystemTypes))
                    {
                        members.AddRange((containingNode as IFunctionResult).Types.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.Constants))
                    {
                        members.AddRange((containingNode as IFunctionResult).Constants.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.Functions))
                    {
                        foreach (var res in (containingNode as IFunctionResult).Variables /*.Where(x => x.Value.HasChildFunctions(this))
                                                                                           */.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)))
                        {
                            if (!members.Contains(res))
                            {
                                members.Add(res);
                            }
                        }

                        foreach (var varList in (containingNode as IFunctionResult).LimitedScopeVariables)
                        {
                            foreach (var item in varList.Value)
                            {
                                if (item.Item2.IsInSpan(index))
                                {
                                    members.Add(new MemberResult(item.Item1.Name, item.Item1, GeneroMemberType.Instance, this));
                                    break;
                                }
                            }
                        }
                    }
                }

                if (_body is IModuleResult)
                {
                    // check for module vars, types, and constants (and globals defined in this module)
                    if (memberType.HasFlag(AstMemberType.Variables))
                    {
                        members.AddRange((_body as IModuleResult).Variables.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)));
                        members.AddRange((_body as IModuleResult).GlobalVariables.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.UserDefinedTypes))
                    {
                        members.AddRange((_body as IModuleResult).Types.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, this)));
                        members.AddRange((_body as IModuleResult).GlobalTypes.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.Constants))
                    {
                        members.AddRange((_body as IModuleResult).Constants.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, this)));
                        members.AddRange((_body as IModuleResult).GlobalConstants.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.Dialogs))
                    {
                        members.AddRange((_body as IModuleResult).Functions.Where(x => x.Value is DeclarativeDialogBlock)
                                         .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Dialog, this)));
                        members.AddRange((_body as IModuleResult).FglImports.Select(x => new MemberResult(x, GeneroMemberType.Module, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.Reports))
                    {
                        members.AddRange((_body as IModuleResult).Functions.Where(x => x.Value is ReportBlockNode)
                                         .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Report, this)));
                    }
                    if (memberType.HasFlag(AstMemberType.Functions))
                    {
                        members.AddRange((_body as IModuleResult).Functions
                                         .Where(x => !(x.Value is ReportBlockNode) && !(x.Value is DeclarativeDialogBlock))
                                         .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Method, this)));
                        foreach (var res in (_body as IModuleResult).Variables /*.Where(x => x.Value.HasChildFunctions(this))
                                                                                */.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)))
                        {
                            if (!members.Contains(res))
                            {
                                members.Add(res);
                            }
                        }
                        foreach (var res in (_body as IModuleResult).GlobalVariables /*.Where(x => x.Value.HasChildFunctions(this))
                                                                                      */.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)))
                        {
                            if (!members.Contains(res))
                            {
                                members.Add(res);
                            }
                        }
                    }

                    // Tables and cursors are module specific, and cannot be accessed via fgl import
                    if (memberType.HasFlag(AstMemberType.DeclaredCursors) ||
                        memberType.HasFlag(AstMemberType.PreparedCursors) ||
                        memberType.HasFlag(AstMemberType.Tables))
                    {
                        if (memberType.HasFlag(AstMemberType.DeclaredCursors))
                        {
                            members.AddRange((_body as IModuleResult).Cursors.Where(x => x.Value is DeclareStatement).Select(x => new MemberResult(x.Value.Name, x.Value, GeneroMemberType.Cursor, this)));
                        }
                        if (memberType.HasFlag(AstMemberType.PreparedCursors))
                        {
                            members.AddRange((_body as IModuleResult).Cursors.Where(x => x.Value is PrepareStatement).Select(x => new MemberResult(x.Value.Name, x.Value, GeneroMemberType.Cursor, this)));
                        }
                        if (memberType.HasFlag(AstMemberType.Tables))
                        {
                            members.AddRange((_body as IModuleResult).Tables.Select(x => new MemberResult(x.Value.Name, x.Value, GeneroMemberType.DbTable, this)));
                        }
                    }
                    else
                    {
                        members.AddRange((_body as IModuleResult).FglImports.Select(x => new MemberResult(x, GeneroMemberType.Module, this)));
                    }
                }
            }

            // TODO: this could probably be done more efficiently by having each GeneroAst load globals and functions into
            // dictionaries stored on the IGeneroProject, instead of in each project entry.
            // However, this does required more upkeep when changes occur. Will look into it...
            if (_projEntry != null && _projEntry is IGeneroProjectEntry)
            {
                IGeneroProjectEntry genProj = _projEntry as IGeneroProjectEntry;
                if (genProj.ParentProject != null &&
                    !genProj.FilePath.ToLower().EndsWith(".inc"))
                {
                    foreach (var projEntry in genProj.ParentProject.ProjectEntries.Where(x => x.Value != genProj))
                    {
                        if (projEntry.Value.Analysis != null &&
                            projEntry.Value.Analysis.Body != null)
                        {
                            projEntry.Value.Analysis.Body.SetNamespace(null);
                            IModuleResult modRes = projEntry.Value.Analysis.Body as IModuleResult;
                            if (modRes != null)
                            {
                                // check global types
                                // TODO: need to add an option to enable/disable legacy linking (to not reference other modules' non-public members
                                if (memberType.HasFlag(AstMemberType.Variables))
                                {
                                    members.AddRange(modRes.GlobalVariables.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)));
                                    members.AddRange(modRes.Variables.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)));
                                }
                                if (memberType.HasFlag(AstMemberType.UserDefinedTypes))
                                {
                                    members.AddRange(modRes.GlobalTypes.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, this)));
                                    members.AddRange(modRes.Types.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Class, this)));
                                }
                                if (memberType.HasFlag(AstMemberType.Constants))
                                {
                                    members.AddRange(modRes.GlobalConstants.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, this)));
                                    members.AddRange(modRes.Constants.Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Constant, this)));
                                }
                                if (memberType.HasFlag(AstMemberType.Dialogs))
                                {
                                    members.AddRange(modRes.Functions.Where(x => x.Value is DeclarativeDialogBlock)
                                                     .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Dialog, this)));
                                }
                                if (memberType.HasFlag(AstMemberType.Reports))
                                {
                                    members.AddRange(modRes.Functions.Where(x => x.Value is ReportBlockNode)
                                                     .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Report, this)));
                                }
                                if (memberType.HasFlag(AstMemberType.Functions))
                                {
                                    members.AddRange(modRes.Functions.Where(x => !(x.Value is ReportBlockNode) && !(x.Value is DeclarativeDialogBlock))
                                                     .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Method, this)));
                                    foreach (var res in modRes.GlobalVariables/*.Where(x =>
                                                                               * {
                                                                               * return x.Value.HasChildFunctions(this);
                                                                               * })*/
                                             .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)))
                                    {
                                        if (!members.Contains(res))
                                        {
                                            members.Add(res);
                                        }
                                    }
                                    foreach (var res in modRes.Variables/*.Where(x =>
                                                                         * {
                                                                         * return x.Value.HasChildFunctions(this);
                                                                         * })*/
                                             .Select(x => new MemberResult(x.Key, x.Value, GeneroMemberType.Variable, this)))
                                    {
                                        if (!members.Contains(res))
                                        {
                                            members.Add(res);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (memberType.HasFlag(AstMemberType.Functions))
            {
                _includePublicFunctions = true; // allow for deferred adding of public functions
            }

            if (memberType.HasFlag(AstMemberType.Tables))
            {
                _includeDatabaseTables = true;  // allow for deferred adding of external database tables
            }

            members.AddRange(this.ProjectEntry.GetIncludedFiles().Where(x => x.Analysis != null).SelectMany(x => x.Analysis.GetDefinedMembers(1, memberType)));

            return(members);
        }
Ejemplo n.º 20
0
 public XmlLiteral(BuiltinTypes types, string xml, Location loc)
     : base(loc)
 {
     Xml = xml;
 }
Ejemplo n.º 21
0
 public ReflectionImporter(ModuleContainer module, BuiltinTypes builtin)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 22
0
		public StringLiteral (BuiltinTypes types, string s, Location loc)
			: base (types, s, loc)
		{
		}
Ejemplo n.º 23
0
		public CompilerContext (CompilerSettings settings, ReportPrinter reportPrinter)
		{
			this.settings = settings;
			this.report = new Report (this, reportPrinter);
			this.builtin_types = new BuiltinTypes ();
			this.TimeReporter = DisabledTimeReporter;
		}
Ejemplo n.º 24
0
		public static FullNamedExpression CreateDelegateTypeExpression (BuiltinTypes builtinTypes, ParametersCompiled parameters, FullNamedExpression retType, Location loc){

			// Setup
			bool hasParams = parameters != null && parameters.Count > 0;
			int paramCount = hasParams ? parameters.Count : 0;
			string ns = "System";
			string paramSuffix = "";

			// If last parameter is a PARAMS paramter, use the params versions of the delegate types
			if (hasParams && (parameters.FixedParameters [parameters.FixedParameters.Length - 1].ModFlags & Parameter.Modifier.PARAMS) != 0) {
				ns = "PlayScript";
				paramSuffix = "P";
				paramCount--;
			}

			// Check if this is Func or Action
			bool hasRetType = !(retType is TypeExpression && ((TypeExpression)retType).Type == builtinTypes.Void);
			int typeParamCount = paramCount;
			if (hasRetType)
				typeParamCount++;

			// Create arguments list
			TypeArguments typeArgs = null;
			if (typeParamCount > 0) {
				var typeArgArray = new FullNamedExpression[typeParamCount];
				for (var i = 0; i < typeParamCount; i++) {
					if (i < paramCount) {
						var param = parameters.FixedParameters[i] as Parameter;
						typeArgArray[i] = param.TypeExpression;
					} else {
						typeArgArray[i] = retType;
					}
				}
				typeArgs = new TypeArguments (typeArgArray);
			}

			// Return the expression for the type we want
			if (!hasRetType) {
				return new MemberAccess(new SimpleName(ns, loc), "Action" + paramSuffix, typeArgs, loc);
			} else {
				return new MemberAccess(new SimpleName(ns, loc), "Func" + paramSuffix, typeArgs, loc);
			}
		}
Ejemplo n.º 25
0
		public ULongConstant (BuiltinTypes types, ulong v, Location loc)
			: this (types.ULong, v, loc)
		{
		}
Ejemplo n.º 26
0
		public RegexLiteral (BuiltinTypes types, string regex, string options, Location loc)
			: base (loc)
		{
			Regex = regex;
			Options = options ?? "";
		}
Ejemplo n.º 27
0
 public CharLiteral(BuiltinTypes types, char c, Location loc)
     : base(types, c, loc)
 {
 }
Ejemplo n.º 28
0
		public CompilerContext (CompilerSettings settings, Report report)
		{
			this.settings = settings;
			this.report = report;
			this.builtin_types = new BuiltinTypes ();
			this.TimeReporter = DisabledTimeReporter;
		}
Ejemplo n.º 29
0
		public XmlLiteral (BuiltinTypes types, string xml, Location loc)
			: base (loc)
		{
			Xml = xml;
		}
Ejemplo n.º 30
0
		public UIntConstant (BuiltinTypes types, uint v, Location loc)
			: this (types.UInt, v, loc)
		{
		}
Ejemplo n.º 31
0
		public static FullNamedExpression CreateDelegateTypeExpression (BuiltinTypes builtinTypes, ParametersCompiled parameters, FullNamedExpression retType, Location loc){
			bool hasParams = parameters != null && parameters.Count > 0;
			int paramCount = hasParams ? parameters.Count : 0;
			bool hasRetType = !(retType is TypeExpression && ((TypeExpression)retType).Type == builtinTypes.Void);
			int typeParamCount = paramCount;
			if (hasRetType)
				typeParamCount++;
			TypeArguments typeArgs = null;
			if (typeParamCount > 0) {
				var typeArgArray = new FullNamedExpression[typeParamCount];
				for (var i = 0; i < paramCount; i++) {
					if (i < paramCount) {
						var param = parameters.FixedParameters[i] as Parameter;
						typeArgArray[i] = param.TypeExpression;
					} else {
						typeArgArray[i] = retType;
					}
				}
				typeArgs = new TypeArguments (typeArgArray);
			}
			if (!hasRetType) {
				return new MemberAccess(new SimpleName("System", loc), "Action", typeArgs, loc);
			} else {
				return new MemberAccess(new SimpleName("System", loc), "Func", typeArgs, loc);
			}
		}
Ejemplo n.º 32
0
		public FloatConstant (BuiltinTypes types, float v, Location loc)
			: this (types.Float, v, loc)
		{
		}
Ejemplo n.º 33
0
		public CharLiteral (BuiltinTypes types, char c, Location loc)
			: base (types, c, loc)
		{
		}
Ejemplo n.º 34
0
		public DecimalConstant (BuiltinTypes types, decimal d, Location loc)
			: this (types.Decimal, d, loc)
		{
		}
Ejemplo n.º 35
0
		public UIntLiteral (BuiltinTypes types, uint l, Location loc)
			: base (types, l, loc)
		{
		}
Ejemplo n.º 36
0
		public BoolConstant (BuiltinTypes types, bool val, Location loc)
			: this (types.Bool, val, loc)
		{
		}
Ejemplo n.º 37
0
		public ULongLiteral (BuiltinTypes types, ulong l, Location loc)
			: base (types, l, loc)
		{
		}
Ejemplo n.º 38
0
		public SByteConstant (BuiltinTypes types, sbyte v, Location loc)
			: this (types.SByte, v, loc)
		{
		}
Ejemplo n.º 39
0
		public FloatLiteral (BuiltinTypes types, float f, Location loc)
			: base (types, f, loc)
		{
		}
Ejemplo n.º 40
0
		public DoubleLiteral (BuiltinTypes types, double d, Location loc)
			: base (types, d, loc)
		{
		}
Ejemplo n.º 41
0
 public RegexLiteral(BuiltinTypes types, string regex, string options, Location loc)
     : base(loc)
 {
     Regex   = regex;
     Options = options ?? "";
 }