//protected void SetContext(GMacSymbolTranslatorContext context) //{ // this.SetContext((SymbolTranslatorContext)context); //} /// <summary> /// Take a qualified indetifier node and separate it into a parent symbol and a child symbol name /// </summary> /// <param name="node"></param> /// <param name="parentSymbol"></param> /// <param name="childSymbolName"></param> protected bool Translate_ParentSymbolAndChildSymbolName(ParseTreeNode node, out SymbolWithScope parentSymbol, out string childSymbolName) { var qualList = GenUtils.Translate_Qualified_Identifier(node); childSymbolName = qualList.LastItem; if (qualList.ActiveLength == 1) { parentSymbol = Context.ActiveParentSymbol; } else { qualList.DecreaseActiveEndOffset(); parentSymbol = GMacValueAccessGenerator.Translate_Direct(Context, node, qualList) as SymbolWithScope; } return(ReferenceEquals(parentSymbol, null) == false); }
private static bool TryTranslate_LValue(GMacSymbolTranslatorContext context, ParseTreeNode node, out LanguageValueAccess varAccess) { var qualList = GenUtils.Translate_Qualified_Identifier(node); LanguageSymbol symbol; var flag = context .OpenedDistinctScopes() .LookupSymbol(qualList.FirstItem, out symbol); if (flag == false || (symbol is SymbolLValue) == false) { varAccess = null; return(false); } varAccess = LanguageValueAccess.Create(symbol); return(true); }
//public override void ResetOnAcquire() //{ // base.ResetOnAcquire(); // _generatedMacroTemplate = null; //} private void translate_MacroTemplate() { try { Context.MarkCheckPointState(); var nodeMacro = RootParseNode.ChildNodes[0]; //Read the name of the new macro template var qualList = GenUtils.Translate_Qualified_Identifier(nodeMacro.ChildNodes[0]); if (qualList.ActiveLength > 1) { CompilationLog.RaiseGeneratorError <int>("Template name cannot be a qualified name", RootParseNode.ChildNodes[0]); } var templateName = qualList.FirstItem; if (Context.ParentNamespace.CanDefineChildSymbol(templateName) == false) { CompilationLog.RaiseGeneratorError <int>("Symbol name already used", RootParseNode.ChildNodes[0]); } _generatedMacroTemplate = Context.ParentNamespace.DefineMacroTemplate(templateName, nodeMacro); _generatedMacroTemplate.CodeLocation = Context.GetCodeLocation(RootParseNode); Context.UnmarkCheckPointState(); } catch (CompilerException) { Context.RestoreToCheckPointState(); } catch (Exception e) { Context.RestoreToCheckPointState(); throw new Exception("Unhandled Exception", e); } }
private LanguageValueAccess translate_Qualified_Identifier(ParseTreeNode node) { //If _QualList is not already filled, translate the current parse node into a list of identifiers if (_qualList == null) { _qualList = GenUtils.Translate_Qualified_Identifier(node); } //Lookup the first item of the translated list of identifiers within the current context LanguageSymbol symbol; var flag = _followScopeChain //? Context.LookupSymbolInOpenedDistinctScopes(_qualList.FirstItem, out symbol) ? Context.OpenedDistinctScopes().LookupSymbol(_qualList.FirstItem, out symbol) : Context.ActiveParentScope.LookupSymbol(_qualList.FirstItem, out symbol); if (flag == false) { return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("Symbol name not recognized", RootParseNode)); } //Ignore the first item from the list _qualList.IncreaseActiveStartOffset(1); if (_isLValue) { //This is an l-value switch (symbol.SymbolRoleName) { case RoleNames.StructureDataMember: case RoleNames.MacroParameter: case RoleNames.LocalVariable: return(translate_StartAt_DataSymbol((SymbolDataStore)symbol)); default: return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("LValue symbol name not recognized", RootParseNode)); } } //This is an r-value switch (symbol.SymbolRoleName) { case RoleNames.MacroParameter: case RoleNames.LocalVariable: case RoleNames.Constant: return(translate_StartAt_DataSymbol((SymbolDataStore)symbol)); case RoleNames.FrameBasisVector: case RoleNames.BuiltinType: case RoleNames.FrameMultivector: case RoleNames.Structure: case RoleNames.Macro: case RoleNames.MacroTemplate: case RoleNames.Transform: case RoleNames.FrameSubspace: //case RoleNames.Binding: return(translate_StartAt_DirectSymbol(symbol)); case RoleNames.Frame: return(translate_StartAt_FrameDefinition((GMacFrame)symbol)); case RoleNames.Namespace: return(translate_StartAt_NamespaceDefinition((GMacNamespace)symbol)); default: return(CompilationLog.RaiseGeneratorError <LanguageValueAccess>("RValue symbol name not recognized", RootParseNode)); } }
//public override void ResetOnAcquire() //{ // base.ResetOnAcquire(); // _generatedNamespace = null; //} private void translate_Namespace() { try { Context.MarkCheckPointState(); //Read the namespace name: for example main.conformal.cga5d var qualList = GenUtils.Translate_Qualified_Identifier(RootParseNode.ChildNodes[0]); //Find the root namespace inside the root global scope of the GMacDSL (search for a namespace called 'main') GMacNamespace nameSpace; if (GMacRootAst.LookupRootNamespace(qualList.FirstItem, out nameSpace) == false) { if (GMacRootAst.RootScope.SymbolExists(qualList.FirstItem)) { CompilationLog.RaiseGeneratorError <int>("Namespace name already used", RootParseNode.ChildNodes[0]); } nameSpace = GMacRootAst.DefineRootNamespace(qualList.FirstItem); } //Starting from the created\found root namespace, repeat the previous operation for each child namespace in qual_list for (var i = 1; i < qualList.ActiveLength; i++) { GMacNamespace childNamespace; if (nameSpace.LookupNamespace(qualList[i], out childNamespace)) { nameSpace = childNamespace; } else { if (nameSpace.CanDefineChildSymbol(qualList[i]) == false) { CompilationLog.RaiseGeneratorError <int>("Symbol with same name already exists", RootParseNode.ChildNodes[0]); } nameSpace = nameSpace.DefineNamespace(qualList[i]); } } _generatedNamespace = nameSpace; _generatedNamespace.AddCodeLocation(Context.GetCodeLocation(RootParseNode)); Context.UnmarkCheckPointState(); Context.CompilationLog.ReportNormal("Translated Namespace: " + _generatedNamespace.SymbolAccessName, ProgressEventArgsResult.Success); } catch (CompilerException) { Context.RestoreToCheckPointState(); Context.CompilationLog.ReportNormal("Translate Namespace Failed", ProgressEventArgsResult.Failure); } catch (Exception e) { Context.RestoreToCheckPointState(); Context.CompilationLog.ReportError("Translate Namespace Failed With Error", e); } }