/// <summary> /// Resolves literal value of <see cref="Alias"/>. /// </summary> /// <param name="alias">Instance of <see cref="Alias"/>.</param> /// <param name="valueType">Value type of the resolved literal.</param> /// <returns>String representing literal value of the <see cref="Alias"/>.</returns> protected string ResolveValueAlias(Alias alias, out ValueType valueType) { var aliasDef = alias.AliasDefinition; AliasContext.Push(new AliasContextInfo(alias, CurrentModuleMember)); CurrentModuleMember = aliasDef; string result; if (aliasDef.ValueType == ValueType.LiteralChoice) { result = ResolveChoiceValue(alias, out valueType); } else { result = aliasDef.PairValue == null ? ResolveValue(aliasDef, out valueType) : ResolvePairValue(aliasDef.PairValue, out valueType); } CurrentModuleMember = AliasContext.Pop().ModuleMember; return(result); }
/// <summary> /// Ensures that pair value is either Alias or Parameter. /// Validates string concatenation. /// </summary> /// <param name="pair"></param> private void CheckPairValue(Pair pair) { if (pair.Delimiter == DelimiterEnum.CE) { if (pair.PairValue == null || !(pair.PairValue is DOM.Alias) && !(pair.PairValue is DOM.Parameter)) { var mappedPair = pair.PairValue as IMappedPair; Context.AddError(mappedPair != null ? CompilerErrorFactory.AliasOrParameterExpected(mappedPair.NameInterval, _currentModule.FileName) : CompilerErrorFactory.AliasOrParameterExpected(((IMappedPair)pair).NameInterval, _currentModule.FileName)); } else { Visit(pair.PairValue); } } else if (pair.Delimiter == DelimiterEnum.EC) { CheckStringConcatenation(pair); } if (pair.PairValue is DOM.Parameter) { var aliasContext = AliasContext.Peek(); if (aliasContext != null) { ValidateParameter((Parameter)pair.PairValue, aliasContext.Alias, _currentModule.FileName); } } else if (pair.PairValue is DOM.Alias) { Alias alias = (Alias)pair.PairValue; CheckAliasIsDefined(alias); var aliasDef = alias.AliasDefinition; //Do not resolve alias without AliasDef or having circular reference if (aliasDef == null || aliasDef.HasCircularReference) { return; } AliasContext.Push(new AliasContext() { AliasDefinition = aliasDef, Alias = alias, AliasNsInfo = GetContextNsInfo() }); CheckForUnexpectedArguments(alias, aliasDef, _currentModule.FileName); CheckInterpolation(aliasDef); CheckPairValue(aliasDef); if (CheckStartOfChoiceContainer(alias, aliasDef.Entities, aliasDef)) { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); EndChoiceContainer(/*aliasDef, aliasDef.Entities*/); } else { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); } AliasContext.Pop(); } }
public override void OnAlias(DOM.Alias alias) { CheckBlockIntegrityForValueAlias(alias); CheckPairValue(alias); CheckAliasIsDefined(alias); var aliasDef = ((Alias)alias).AliasDefinition; //Do not resolve alias without AliasDef or having circular reference if (aliasDef == null || aliasDef.HasCircularReference) { return; } AliasContext.Push(new AliasContext { AliasDefinition = aliasDef, Alias = (Alias)alias, AliasNsInfo = GetContextNsInfo() }); CheckForUnexpectedArguments((Alias)alias, aliasDef, _currentModule.FileName); CheckInterpolation((Alias)alias); if (CheckStartOfChoiceContainer((Alias)alias, aliasDef.Entities, aliasDef)) { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); EndChoiceContainer(); } else { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); } AliasContext.Pop(); _namespaceResolver.ProcessAlias((Alias)alias); }
/// <inheritdoc /> public override void Visit(DOM.Alias alias) { var aliasDef = ((Alias)alias).AliasDefinition; //Do not resolve alias without AliasDef or having circular reference if (aliasDef == null || aliasDef.HasCircularReference) { return; } AliasContext.Push(new AliasContextInfo((Alias)alias, CurrentModuleMember)); CurrentModuleMember = aliasDef; Visit(aliasDef.Entities.Where(e => !(e is Attribute))); CurrentModuleMember = AliasContext.Pop().ModuleMember; }
/// <summary> /// Resolves attributes in <see cref="Alias"/>. Elements are ignored. /// </summary> /// <param name="alias">Instance of <see cref="Alias"/>.</param> protected void ResolveAttributesInAlias(Alias alias) { var aliasDef = alias.AliasDefinition; //Do not resolve alias without AliasDef or having circular reference if (aliasDef == null || aliasDef.HasCircularReference) { return; } AliasContext.Push(new AliasContextInfo(alias, CurrentModuleMember)); CurrentModuleMember = aliasDef; ResolveAttributes(aliasDef.Entities); CurrentModuleMember = AliasContext.Pop().ModuleMember; }
public override void Visit(DOM.Alias alias) { CheckAliasIsDefined(alias); var aliasDef = ((Alias)alias).AliasDefinition; //Do not resolve alias without AliasDef or having circular reference if (aliasDef == null || aliasDef.HasCircularReference) { return; } CheckBlockIntegrityForValueAlias(alias); CheckPairValue(alias); AliasContext.Push(new AliasContextInfo((Alias)alias, CurrentModuleMember)); CheckForUnexpectedArguments((Alias)alias, aliasDef, _currentModule.FileName); CheckInterpolation((Alias)alias); if (CheckStartOfChoiceContainer((Alias)alias, aliasDef.Entities, aliasDef)) { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); EndChoiceContainer(); } else { if (_blockState.Count > 0 && _blockState.Peek() == JsonGenerator.BlockStateEnum.Array && aliasDef.BlockType == BlockType.JsonObject) { _blockState.Push(JsonGenerator.BlockStateEnum.Object); Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); _blockState.Pop(); } else { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); } } AliasContext.Pop(); }