private LanguageValueAccess translate_StartAt_DirectSymbol(LanguageSymbol startSymbol) { return (_qualList.ActiveLength == 0 ? LanguageValueAccess.Create(startSymbol) : CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Components not recognized", RootParseNode)); }
private string RelativeSymbolAccessName(LanguageSymbol symbol) { return (HasRootSymbol ? symbol.SymbolAccessName.Substring(RootSymbolAccessName.Length + 1) : symbol.SymbolAccessName); }
public LanguageSymbol ParseClassObjectDeclaration(string line, string originalLine, bool isClass) { var nameMatch = isClass ? Regex.Match(line, Language.CLASS_NAME_PATTERN, RegexOptions.IgnoreCase) : Regex.Match(line, Language.OBJECT_NAME_PATTERN, RegexOptions.IgnoreCase); if (nameMatch.Groups.Count > 1) { var symbol = new LanguageSymbol(); symbol.Name = nameMatch.Groups[1].Value; if (string.IsNullOrWhiteSpace(symbol.Name)) { return(null); } symbol.Type = isClass ? SymbolKind.Class : SymbolKind.Object; symbol.StartColumn = originalLine.IndexOf(symbol.Name); symbol.EndColumn = symbol.StartColumn + symbol.Name.Length; symbol.IsContainer = true; return(symbol); } return(null); }
public virtual void Visit(LanguageSymbol langSymbol) { if (SimpleLoggingEnabled) { Log.Append(langSymbol.SymbolAccessName); return; } Log.Append("{"); Log.Append(" <Symbol: " + langSymbol.SymbolAccessName + "> "); if (EnableLogObjectClass) { Log.Append(" <Class: " + langSymbol.GetType().Name + "> "); } if (EnableLogSymbolRole) { Log.Append(" <Role: " + langSymbol.SymbolRoleName + "> "); } Log.Append("} "); }
public bool LookupSymbol(string symbolName, IEnumerable <string> roleNames, out LanguageSymbol symbol) { if (_symbols.TryGetValue(symbolName, out symbol) && roleNames.Contains(symbol.SymbolRoleName)) { return(true); } symbol = null; return(false); }
public bool LookupSymbol(string symbolName, string roleName, out LanguageSymbol symbol) { if (_symbols.TryGetValue(symbolName, out symbol) && (symbol.SymbolRoleName == roleName)) { return(true); } symbol = null; return(false); }
/// <summary> /// True if any access-by-symbol step (including the root step) depends on the given symbol /// </summary> /// <param name="symbol"></param> /// <returns></returns> public bool HasAccessStepWithSymbol(LanguageSymbol symbol) { if (RootSymbol.ObjectId == symbol.ObjectId) { return(true); } return (PartialAccessSymbols .Any(accessStepSymbol => accessStepSymbol.ObjectId == symbol.ObjectId)); }
//These methods are inherited from LanguageExpressionEvaluator but never used for low-level code generation #region Not Implemented Methods protected override ILanguageValue ReadSymbolFullValue(LanguageSymbol symbol) { throw new NotImplementedException(); //if (symbol is SymbolNamedValue) // return ((SymbolNamedValue)symbol).AssociatedValue; ////if (symbol is SymbolLocalVariable || symbol is SymbolProcedureParameter) //// return this.GetSymbolData((SymbolDataStore)symbol); //throw new InvalidOperationException("Invalid symbol type"); }
private bool TryAddSymbol(string symbolName, LanguageSymbol langSymbol) { if (MainSymbols.ContainsKey(symbolName)) { return(false); } MainSymbols.Add(symbolName, langSymbol); return(true); }
/// <summary> /// Get a symbol with a given name and having a role name from a given list of role names in any of the scopes of the given list of scopes. If the symbol is not found an error is raised /// </summary> /// <param name="scopeList">A list of scopes</param> /// <param name="symbolName">The name of the symbol</param> /// <param name="roleNames">A list of possible role names of the symbol</param> /// <returns>A reference to the symbol</returns> public static LanguageSymbol GetSymbol(this IEnumerable <LanguageScope> scopeList, string symbolName, IEnumerable <string> roleNames) { LanguageSymbol symbol = null; if (scopeList.Any(scope => scope.LookupSymbol(symbolName, roleNames, out symbol))) { return(symbol); } throw new KeyNotFoundException(); }
private void AddToSymbolsCache(string symbolName, LanguageSymbol symbol) { if (_symbolsCache.ContainsKey(symbolName)) { _symbolsCache[symbolName] = symbol; } else { _symbolsCache.Add(symbolName, symbol); } }
/// <summary> /// Returns a list of all partial access-by-symbol steps where the access symbol is identical to the given symbol /// </summary> /// <param name="symbol"></param> /// <returns></returns> public IEnumerable <ValueAccessStepByLValue> PartialAccessStepsByLValue(LanguageSymbol symbol) { for (var i = 1; i < _accessSteps.Count; i++) { var step = _accessSteps[i] as ValueAccessStepByLValue; if (step?.AccessLValue.ObjectId == symbol.ObjectId) { yield return(step); } } }
private bool TryAddAsFrameSubspace(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as GMacFrameSubspace; if (symbol == null) { return(false); } FrameSubspaces.Add(symbolName, symbol); return(true); }
private bool TryAddAsNamedValue(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as SymbolNamedValue; if (symbol == null) { return(false); } NamedValues.Add(symbolName, symbol); return(true); }
private bool TryAddAsTransform(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as GMacMultivectorTransform; if (symbol == null) { return(false); } Transforms.Add(symbolName, symbol); return(true); }
private bool TryAddAsMacro(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as GMacMacro; if (symbol == null) { return(false); } Macros.Add(symbolName, symbol); return(true); }
private void AddToSubDictionary(string symbolName, LanguageSymbol langSymbol) { if (TryAddAsNamespace(symbolName, langSymbol)) { return; } if (TryAddAsFrame(symbolName, langSymbol)) { return; } if (TryAddAsFrameBasisVector(symbolName, langSymbol)) { return; } if (TryAddAsFrameMultivector(symbolName, langSymbol)) { return; } if (TryAddAsFrameSubspace(symbolName, langSymbol)) { return; } if (TryAddAsConstant(symbolName, langSymbol)) { return; } if (TryAddAsNamedValue(symbolName, langSymbol)) { return; } if (TryAddAsStructure(symbolName, langSymbol)) { return; } if (TryAddAsMacro(symbolName, langSymbol)) { return; } TryAddAsTransform(symbolName, langSymbol); }
private bool TryAddAsStructure(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as GMacStructure; if (symbol == null) { return(false); } Structures.Add(symbolName, symbol); Types.Add(symbolName, symbol); return(true); }
private bool TryAddAsConstant(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as GMacConstant; if (symbol == null) { return(false); } Constants.Add(symbolName, symbol); NamedValues.Add(symbolName, symbol); return(true); }
private bool TryAddAsFrameMultivector(string symbolName, LanguageSymbol langSymbol) { var symbol = langSymbol as GMacFrameMultivector; if (symbol == null) { return(false); } FrameMultivectors.Add(symbolName, symbol); Types.Add(symbolName, symbol); return(true); }
protected override ILanguageValue ReadSymbolFullValue(LanguageSymbol symbol) { var symbol1 = symbol as SymbolNamedValue; if (symbol1 != null) { return(symbol1.AssociatedValue); } if (symbol is SymbolLocalVariable || symbol is SymbolProcedureParameter) { return(GetSymbolData((SymbolDataStore)symbol)); } throw new InvalidOperationException("Invalid symbol type"); }
public LanguageSymbol ParseStructDeclaration(string line, string originalLine) { var nameMatch = Regex.Match(line, Language.STRUCT_NAME_PATTERN, RegexOptions.IgnoreCase); if (nameMatch.Groups.Count > 1) { var symbol = new LanguageSymbol(); symbol.Name = nameMatch.Groups[1].Value; if (string.IsNullOrWhiteSpace(symbol.Name)) { return(null); } symbol.Type = SymbolKind.Struct; symbol.StartColumn = originalLine.IndexOf(symbol.Name); symbol.EndColumn = symbol.StartColumn + symbol.Name.Length; return(symbol); } return(null); }
public bool LookupSymbolInOpenedDistinctScopes(string symbolName, out LanguageSymbol symbol) { var skipList = new Dictionary <int, int>(); for (var scope = ActiveParentScope; ReferenceEquals(scope, null) == false; scope = scope.ParentScope) { if (skipList.ContainsKey(scope.ObjectId) == false) { skipList.Add(scope.ObjectId, scope.ObjectId); if (scope.LookupSymbol(symbolName, out symbol)) { return(true); } } } foreach (var openedScope in _openedScopes) { for (var scope = openedScope; ReferenceEquals(scope, null) == false; scope = scope.ParentScope) { if (skipList.ContainsKey(scope.ObjectId) == false) { skipList.Add(scope.ObjectId, scope.ObjectId); if (scope.LookupSymbol(symbolName, out symbol)) { return(true); } } } } symbol = null; return(false); }
public LanguageSymbol ParseProcedureDeclaration(string line, string originalLine, bool isProcedureSet) { var nameMatch = isProcedureSet ? Regex.Match(line, Language.PROCEDURE_SET_NAME_PATTERN, RegexOptions.IgnoreCase) : Regex.Match(line, Language.PROCEDURE_NAME_PATTERN, RegexOptions.IgnoreCase); if (nameMatch.Groups.Count > 1) { var symbol = new LanguageSymbol(); symbol.Name = nameMatch.Groups[1].Value; if (string.IsNullOrWhiteSpace(symbol.Name)) { return(null); } symbol.Type = SymbolKind.Method; symbol.StartColumn = originalLine.IndexOf(symbol.Name); symbol.EndColumn = symbol.StartColumn + symbol.Name.Length; return(symbol); } return(null); }
protected override bool AllowUpdateSymbolValue(LanguageSymbol symbol) { throw new NotImplementedException(); }
protected override bool AllowUpdateSymbolValue(LanguageSymbol symbol) { return(symbol is SymbolLocalVariable || symbol is SymbolProcedureParameter); }
private LanguageValueAccess(LanguageSymbol rootSymbol) { var firstAccessStep = ValueAccessStepAsRootSymbol.Create(rootSymbol); _accessSteps.Add(firstAccessStep); }
/// <summary> /// Replace the root symbol in this value access by the given symbol /// for example replacing 'x' in 'x.y.z' by 'a' gives 'a.y.z' /// </summary> /// <param name="symbol"></param> /// <returns></returns> public LanguageValueAccess ReplaceRootSymbol(LanguageSymbol symbol) { ((ValueAccessStepAsRootSymbol)_accessSteps[0]).ReplaceComponentSymbol(symbol); return(this); }
public static LanguageValueAccess Create(LanguageSymbol rootSymbol, IEnumerable <ValueAccessStep> accessSteps) { return((new LanguageValueAccess(rootSymbol)).Append(accessSteps)); }
//public void AcceptVisitor(IASTNodeAcyclicVisitor visitor) //{ // if (visitor is IASTNodeAcyclicVisitor<LanguageValueAccess>) // ((IASTNodeAcyclicVisitor<LanguageValueAccess>)visitor).Visit(this); // //You can write fall back logic here if needed. //} /// <summary> /// Create a new LanguageValueAccess object /// </summary> /// <param name="rootSymbol"></param> /// <returns></returns> public static LanguageValueAccess Create(LanguageSymbol rootSymbol) { return(new LanguageValueAccess(rootSymbol)); }