public CompilerContext(CompilerSettings settings, ReportPrinter reportPrinter) { this.settings = settings; this.report = new Report(this, reportPrinter); this.builtin_types = new BuiltinTypes(); this.TimeReporter = DisabledTimeReporter; }
public static TypeSpec[] CreateBinaryPromotionsTypes (BuiltinTypes types) { return new TypeSpec[] { types.Decimal, types.Double, types.Float, types.ULong, types.Long, types.UInt }; }
public virtual void compilation(compilation ast) { T = ast.global.Types; foreach (compilation_unit x in ast.inputs) { compilation_unit(x); } }
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)); } }
public StringConstant (BuiltinTypes types, string s, Location loc) : this (types.String, s, loc) { }
public CharConstant (BuiltinTypes types, char v, Location loc) : this (types.Char, v, loc) { }
public UIntLiteral(BuiltinTypes types, uint l, Location loc) : base(types, l, loc) { }
public DoubleConstant (BuiltinTypes types, double v, Location loc) : this (types.Double, v, loc) { }
public BoolLiteral (BuiltinTypes types, bool val, Location loc) : base (types, val, loc) { }
public NameSpace(Imports imports) { members = new SymbolTable(this); this.imports = imports; this.Types = new BuiltinTypes(imports); }
public BoolLiteral(BuiltinTypes types, bool val, Location loc) : base(types, val, loc) { }
public DecimalLiteral (BuiltinTypes types, decimal d, Location loc) : base (types, d, loc) { }
public DecimalLiteral(BuiltinTypes types, decimal d, Location loc) : base(types, d, loc) { }
public StringLiteral(BuiltinTypes types, string s, Location loc) : base(types, s, loc) { }
public DoubleLiteral(BuiltinTypes types, double d, Location loc) : base(types, d, loc) { }
public FloatLiteral(BuiltinTypes types, float f, Location loc) : base(types, f, loc) { }
public ULongLiteral(BuiltinTypes types, ulong l, Location loc) : base(types, l, loc) { }
public UShortConstant (BuiltinTypes types, ushort v, Location loc) : this (types.UShort, v, loc) { }
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); }
public XmlLiteral(BuiltinTypes types, string xml, Location loc) : base(loc) { Xml = xml; }
public ReflectionImporter(ModuleContainer module, BuiltinTypes builtin) { throw new NotSupportedException(); }
public StringLiteral (BuiltinTypes types, string s, Location loc) : base (types, s, loc) { }
public CompilerContext (CompilerSettings settings, ReportPrinter reportPrinter) { this.settings = settings; this.report = new Report (this, reportPrinter); this.builtin_types = new BuiltinTypes (); this.TimeReporter = DisabledTimeReporter; }
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); } }
public ULongConstant (BuiltinTypes types, ulong v, Location loc) : this (types.ULong, v, loc) { }
public RegexLiteral (BuiltinTypes types, string regex, string options, Location loc) : base (loc) { Regex = regex; Options = options ?? ""; }
public CharLiteral(BuiltinTypes types, char c, Location loc) : base(types, c, loc) { }
public CompilerContext (CompilerSettings settings, Report report) { this.settings = settings; this.report = report; this.builtin_types = new BuiltinTypes (); this.TimeReporter = DisabledTimeReporter; }
public XmlLiteral (BuiltinTypes types, string xml, Location loc) : base (loc) { Xml = xml; }
public UIntConstant (BuiltinTypes types, uint v, Location loc) : this (types.UInt, v, loc) { }
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); } }
public FloatConstant (BuiltinTypes types, float v, Location loc) : this (types.Float, v, loc) { }
public CharLiteral (BuiltinTypes types, char c, Location loc) : base (types, c, loc) { }
public DecimalConstant (BuiltinTypes types, decimal d, Location loc) : this (types.Decimal, d, loc) { }
public UIntLiteral (BuiltinTypes types, uint l, Location loc) : base (types, l, loc) { }
public BoolConstant (BuiltinTypes types, bool val, Location loc) : this (types.Bool, val, loc) { }
public ULongLiteral (BuiltinTypes types, ulong l, Location loc) : base (types, l, loc) { }
public SByteConstant (BuiltinTypes types, sbyte v, Location loc) : this (types.SByte, v, loc) { }
public FloatLiteral (BuiltinTypes types, float f, Location loc) : base (types, f, loc) { }
public DoubleLiteral (BuiltinTypes types, double d, Location loc) : base (types, d, loc) { }
public RegexLiteral(BuiltinTypes types, string regex, string options, Location loc) : base(loc) { Regex = regex; Options = options ?? ""; }