private SBExpressionData ResolveSingleIdentifier(string identifier, bool inFunctionScope, bool reportUnresolved = false, IToken token = null) { IIdentifierInfo foundIdentifier = null; if (inFunctionScope) { foundIdentifier = this.TryGetLocalVariable(identifier); if (foundIdentifier != null) goto returnFound; foundIdentifier = this.TryGetProcedureParameter(identifier); if (foundIdentifier != null) goto returnFound; if (m_addonManager != null) { foundIdentifier = m_addonManager.Lookup(m_file?.Usings, identifier); if (foundIdentifier != null) { return this.IdentifierToExpressionData(foundIdentifier, token); } var foundScriptUtilsAccess = this.ResolveDotIdentifierTypeReference(s_ScriptUtilsTypeData, SBExpressionData.CreateIdentifier(identifier, token: token)); if (foundScriptUtilsAccess != null) { return foundScriptUtilsAccess; } } } if (m_file != null) { var identifiers = m_file.LookupIdentifier(identifier); if (identifiers != null) { if (identifiers.Count > 1) { throw new ParsingErrorException((token != null) ? token.Line : -1, identifier, "More than one alternative. "); } foundIdentifier = identifiers[0]; } if (foundIdentifier == null) { foundIdentifier = this.TryGetFileElementInScope(m_file?.Usings, identifier); } } returnFound: if (foundIdentifier != null) { return this.IdentifierToExpressionData(foundIdentifier, token); } var foundType = this.ResolveSingleIdentifierType(identifier, false, token); if (foundType != null) { return foundType; } if (reportUnresolved) { m_errors.UnresolvedIdentifier(token, identifier); } return new SBExpressionData(SBExpressionType.UnknownIdentifier, "", identifier, token); }
internal bool AddNamespaceUsing(int line, IIdentifierInfo identifier, string alias = null) { if (m_namespaceUsings.Select(u => u.Identifier.FullName).FirstOrDefault(u => String.Equals(u, identifier.FullName, StringComparison.InvariantCultureIgnoreCase)) != null) { return(false); } m_namespaceUsings.Add(new UsingData(line, alias, identifier)); return(true); }
private SBExpressionData ResolveSingleIdentifierType(string identifier, bool reportUnresolved = false, IToken token = null) { IIdentifierInfo foundIdentifier = null; if (m_file != null) { var identifiers = m_file.LookupIdentifier(identifier); if (identifiers != null) { if (identifiers.Count > 1) { throw new ParsingErrorException((token != null) ? token.Line : -1, identifier, "More than one alternative. "); } return this.IdentifierToExpressionData(identifiers[0], token); } foundIdentifier = this.TryGetFileElementInScope(m_file?.Usings, identifier); // File elements can also act as types. if (foundIdentifier != null) { return this.IdentifierToExpressionData(foundIdentifier, token); } #region TBD foreach (var nsUsing in m_file.ListResolvedNamespaceUsings()) { var foundViaUsing = this.ResolveDotIdentifier(nsUsing, SBExpressionData.CreateIdentifier(identifier, token: token)); if (foundViaUsing != null) { return foundViaUsing; } } #endregion } if (m_addonManager != null) { foundIdentifier = m_addonManager.Lookup(m_file?.Usings, identifier); if (foundIdentifier != null) { return this.IdentifierToExpressionData(foundIdentifier, token); } } if (reportUnresolved) { if (token != null) { m_errors.UnresolvedType(token.Line, token.Column, identifier); } else { m_errors.UnresolvedType(-1, -1, identifier); } } return null; }
public IdentifiedItem(string identifier, IEngineRepository <TItem> repository, IIdentifierInfo <TItem> identifierInfo) : base(identifier, repository) { _repository = repository; _identifierInfo = identifierInfo; IQueryable <TItem> items = _repository.GetAllItems(); Expression <Func <TItem, bool> > identifierPredicate = _identifierInfo.GetPredicate(identifier); Query = items.SingleDefferred(identifierPredicate); }
public IRestDictionary ToDictionary(string identifierName) { IIdentifierInfo <TItem> namedReferenceInfo = _context.Identifiers.GetInfo(identifierName); if (namedReferenceInfo == null) { throw new RestApiException(ErrorStatus.NotFound, "An identifier named '" + identifierName + "' was not found."); } return(new EngineRestDictionary <TItem>(_context, namedReferenceInfo)); }
private void AddRootIdentifier(string name, IIdentifierInfo info) { System.Diagnostics.Debug.WriteLine($"AddRootIdentifier {this.FileName}: {name}"); if (!m_rootIdentifiers.ContainsKey(name)) { var list = new List <IIdentifierInfo>(); list.Add(info); m_rootIdentifiers[name] = list; } else { m_rootIdentifiers[name].Add(info); } }
public IRestItem GetItem(string identifier, string identifierName = null) { _context.Transaction.StartTransaction(); IIdentifierInfo <TItem> identifierInfo = _context.Identifiers.GetInfo(identifierName); if (identifierInfo == null) { throw new IdentifierNotFoundException(identifierName); } IDeferredItem <TItem> item = EngineIdentiferUtility.GetIdentifiedItem(_context, identifierInfo, identifier); if (!_context.AuthorizationChecker.CanGetItem(item)) { throw new NotAuthorizedForItemException(AuthorizableVerb.Get); } return(new EngineRestItem <TItem>(_context, item)); }
private SBExpressionData ResolveDotIdentifier(IIdentifierInfo left, SBExpressionData right) { SBExpressionData leftAsExpData = null; switch (left.Type) { case IdentifierType.UnresolvedType: throw new NotImplementedException(); // TODO: Handle error case IdentifierType.DotNetNamespace: leftAsExpData = new SBExpressionData(HomeType.Immediate, SBExpressionType.Namespace, null, null, left.Reference); break; case IdentifierType.DotNetType: leftAsExpData = new SBExpressionData(HomeType.Immediate, SBExpressionType.TypeReference, left.DataType); break; //case IdentifierType.FileByName: // break; case IdentifierType.FileNamespace: leftAsExpData = new SBExpressionData(HomeType.Immediate, SBExpressionType.ScriptNamespace, null, null, left.Reference); break; default: throw new NotImplementedException(); } return this.ResolveDotIdentifier(leftAsExpData, right); }
public ExpressionAndSetterIdentifierInfo([NotNull] LambdaExpression getterExpr, [CanBeNull] Action <TItem, string> setter, bool multiReferenceCollection) { _setter = setter; _getterIdentifierInfo = GetGetterIdentifierInfo(getterExpr, multiReferenceCollection); }
internal static IDeferredItem <TItem> GetIdentifiedItem <TItem>(IEngineContext <TItem> engineContext, IIdentifierInfo <TItem> identifierInfo, string identifier) where TItem : class { TItem alreadyLoadedItem = identifierInfo.GetAlreadyLoadedItem(identifier); if (alreadyLoadedItem != null) { return(new AlreadyLoadedItem <TItem>(alreadyLoadedItem, identifier)); } return(new IdentifiedItem <TItem>(identifier, engineContext.Repository, identifierInfo)); }
public IdentifierFieldReader(IIdentifierInfo <TItem> identifierInfo) { _identifierInfo = identifierInfo; }
public SingleIdentifierProvider(IIdentifierInfo <TItem> identifierInfo) { _identifierInfo = identifierInfo; }
private SBExpressionData IdentifierToExpressionData(IIdentifierInfo identifier, IToken token = null) { SBExpressionData result = null; if (identifier.Type == IdentifierType.DotNetType) { result = new SBExpressionData(HomeType.Immediate, SBExpressionType.TypeReference, (TypeReference)identifier.DataType, null, null); } else if (identifier.Type == IdentifierType.DotNetMethod) { var methods = new List<MethodInfo>(); methods.Add(identifier.Reference as MethodInfo); result = new SBExpressionData( HomeType.Immediate, SBExpressionType.MethodReference, // Expression type null, // Data type null, // The instance expression methods, // The instance expression token: token); } else if (identifier.Type == IdentifierType.DotNetNamespace) { result = new SBExpressionData(HomeType.Immediate, SBExpressionType.Namespace, null, null, identifier.Reference); } else if (identifier.Type == IdentifierType.Variable || identifier.Type == IdentifierType.Parameter || identifier.Type == IdentifierType.LambdaParameter) { result = new SBExpressionData(HomeType.Immediate, SBExpressionType.LocalVariableReference, (TypeReference)identifier.DataType, (Expression)identifier.Reference); } else if (identifier.Type == IdentifierType.FileElement) { var element = identifier as IFileElement; switch (element.ElementType) { case FileElementType.ProcedureDeclaration: { var procedure = element as FileProcedure; int fileID = Object.ReferenceEquals(procedure.ParentFile, m_file) ? -1 : ((ScriptFile)procedure.ParentFile).UniqueID; var procGetterMethod = s_GetProcedure; if (procedure.DelegateType != null) { procGetterMethod = s_GetProcedureTyped.MakeGenericMethod(procedure.DelegateType); } var getProc = Expression.Call( procGetterMethod, (m_inFunctionScope) ? m_currentProcedure.ContextReferenceInternal : Expression.Constant(null, typeof(Execution.IScriptCallContext)), Expression.Constant(fileID), Expression.Constant(procedure.UniqueID)); result = new SBExpressionData( HomeType.Immediate, SBExpressionType.ProcedureReference, procedure.DataType, getProc, identifier.Reference); } break; case FileElementType.FileVariable: { var fileVariable = element as FileVariable; var container = fileVariable.VariableOwnerAccess.Container; var containerType = typeof(IValueContainer<>).MakeGenericType(container.DataType.Type); var getGlobalVariableTyped = s_GetGlobalVariable.MakeGenericMethod(container.DataType.Type); var context = (m_inFunctionScope) ? m_currentProcedure.ContextReferenceInternal : Expression.Constant(null, typeof(Execution.IScriptCallContext)); result = new SBExpressionData( HomeType.Immediate, SBExpressionType.GlobalVariableReference, (TypeReference)containerType, Expression.Call( getGlobalVariableTyped, context, Expression.Constant((container as IValueContainer).UniqueID)), identifier); } break; case FileElementType.TestList: { var list = element as ITestList; Expression getList = null; if (m_inFunctionScope) { getList = Expression.Convert( Expression.Call( s_GetFileElement, m_currentProcedure.ContextReferenceInternal, Expression.Constant(list.UniqueID)), typeof(ITestList)); } result = new SBExpressionData( HomeType.Immediate, SBExpressionType.TestListReference, new TypeReference(typeof(ITestList), list), getList, list); } break; default: throw new NotImplementedException(); } } else { throw new NotImplementedException(); } return result; }
public EngineRestDictionary(IEngineContext <TItem> context, IIdentifierInfo <TItem> namedReferenceInfo) { _context = context; _namedReferenceInfo = namedReferenceInfo; }