private static TemplateParam ParseParam(string strname, ref int pos) { ComplexTemplParam topComplex = null; ComplexTemplParam currentComplex = null; int state = 0; bool signed = false; bool unsigned = false; int templParamUdtNameLen = 0; for (; pos < strname.Length; pos++) { char ch = strname[pos]; switch (state) { case 0: if (char.IsDigit(ch)) { templParamUdtNameLen = (int)char.GetNumericValue(ch); state = 1; } else { PrimitiveTemplParam prim = TryParsePrimitive(ch); if (prim != null) { prim.Signed = signed; prim.Unsigned = unsigned; signed = false; unsigned = false; if (currentComplex != null) { currentComplex.Combine(prim); return(topComplex); } else { return(prim); } } else { switch (ch) { case 'u': unsigned = true; break; case 'z': signed = true; break; case 'x': case 'w': ModifierTemplParam newModifier = new ModifierTemplParam(); if (ch == 'x') { newModifier.Attributes |= ModifierAttributes.Const; } else if (ch == 'w') { newModifier.Attributes |= ModifierAttributes.Volatile; } if (topComplex == null) { topComplex = newModifier; currentComplex = newModifier; } else { currentComplex.Combine(newModifier, out currentComplex); } break; case 'p': case 'r': PointerTemplParam newPointer = new PointerTemplParam(); newPointer.IsReference = ch == 'r'; if (topComplex == null) { topComplex = newPointer; currentComplex = newPointer; } else { currentComplex.Combine(newPointer, out currentComplex); } break; case 'q': pos++; FuncTemplParam funcParam = ParseFuncParam(strname, ref pos); if (currentComplex != null) { currentComplex.Combine(funcParam); return(topComplex); } else { return(funcParam); } default: pos--; return(null); } } } break; case 1: if (char.IsDigit(ch)) { templParamUdtNameLen *= 10; templParamUdtNameLen += (int)char.GetNumericValue(ch); } else { if (strname.Length < pos + templParamUdtNameLen) { throw new ApplicationException("Invalid type name length: " + templParamUdtNameLen.ToString() + ", exceed name length: " + strname.Length.ToString()); } TagTemplParam tagTemplParam = new TagTemplParam(); tagTemplParam.Tag = TranslateUdtNameV2(strname.Substring(pos, templParamUdtNameLen)); pos += templParamUdtNameLen - 1; if (currentComplex != null) { currentComplex.Combine(tagTemplParam); return(topComplex); } else { return(tagTemplParam); } } break; } } return(null); }
private static Name TranslateUdtNameV1(string strname) { StringBuilder tag = new StringBuilder(); Name result = new Name(); List<TemplateParam> templateParams = null; int state = 0; //int param = 0; //bool unsigned = false; StringBuilder constTemplParam = null; int templParamUdtNameLen = 0; StringBuilder specialName = null; int i = 0; for (; i < strname.Length; i++) { char ch = strname[i]; switch (state) { case 0: switch (ch) { case '@': if (result.Namespaces == null) result.Namespaces = new List<Name>(); Name currentName = new Name(); currentName.Tag = tag.ToString(); currentName.TemplateParameters = templateParams; result.Namespaces.Add(currentName); tag = new StringBuilder(); templateParams = null; break; case '%': if (tag.Length == 0) { templateParams = new List<TemplateParam>(); state = 1; } else { throw new ApplicationException("Invalid character in state 0:" + ch); } break; case '$': if (tag.Length == 0) state = 12; // special name else state = 14; // parameters break; default: tag.Append(ch); break; } break; case 1: switch (ch) { case '$': state = 2; break; default: tag.Append(ch); break; } break; case 2: switch (ch) { case 'i': state = 9; break; case 'u': //unsigned = true; break; case 't': templParamUdtNameLen = 0; state = 8; break; case '%': state = 0; break; default: throw new ApplicationException("Invalid character while in state 2: " + ch + ", in string: " + strname); } break; case 5: // constant in template if (char.IsDigit(ch)) { constTemplParam.Append(ch); } else { templateParams.Add(new ImmTemplParam(constTemplParam.ToString())); state = 11; i--; } break; case 8: if (char.IsDigit(ch)) { templParamUdtNameLen *= 10; templParamUdtNameLen += (int)char.GetNumericValue(ch); } else { //if (strname.Length < i + templParamUdtNameLen) // throw new ApplicationException("Invalid type name length: " + templParamUdtNameLen.ToString() + ", exceed name length: " + strname.Length.ToString()); TagTemplParam tagpar = new TagTemplParam(); tagpar.Tag = TranslateUdtNameV1(strname.Substring(i, templParamUdtNameLen)); templateParams.Add(tagpar); i += templParamUdtNameLen - 1; state = 11; } break; case 9: switch (ch) { case 'c': //param = 2; state = 10; break; case 'u': //unsigned = true; break; //default: ; // throw new ApplicationException("Invalid character while in state 2: " + ch + ", in string: " + strname); } break; case 10: switch (ch) { case '$': state = 5; constTemplParam = new StringBuilder(); break; default: throw new ApplicationException("Invalid character while in state " + state.ToString() + ": " + ch + ", in string: " + strname); } break; case 11: switch (ch) { case '$': state = 2; break; case '%': state = 2; i--; break; } break; case 12: if (ch == 'b') { state = 13; // special name specialName = new StringBuilder(); } else { throw new ApplicationException("Invalid character in state 9: " + ch); } break; case 13: if (ch == '$') { result.IsSpecial = true; result.SpecialName = StrToSpcName(specialName.ToString()); specialName = null; state = 14; break; } else { specialName.Append(ch); } break; case 14: // ignoring parameters break; default: Debug.Fail("Invalid state: " + state.ToString()); break; } } if (state != 0 && state != 14) throw new ApplicationException("Unexpected end of name while in state: " + state.ToString()); result.Tag = tag.ToString(); result.TemplateParameters = templateParams; return result; }
private static Name TranslateUdtNameV1(string strname) { StringBuilder tag = new StringBuilder(); Name result = new Name(); List <TemplateParam> templateParams = null; int state = 0; //int param = 0; //bool unsigned = false; StringBuilder constTemplParam = null; int templParamUdtNameLen = 0; StringBuilder specialName = null; int i = 0; for (; i < strname.Length; i++) { char ch = strname[i]; switch (state) { case 0: switch (ch) { case '@': if (result.Namespaces == null) { result.Namespaces = new List <Name>(); } Name currentName = new Name(); currentName.Tag = tag.ToString(); currentName.TemplateParameters = templateParams; result.Namespaces.Add(currentName); tag = new StringBuilder(); templateParams = null; break; case '%': if (tag.Length == 0) { templateParams = new List <TemplateParam>(); state = 1; } else { throw new ApplicationException("Invalid character in state 0:" + ch); } break; case '$': if (tag.Length == 0) { state = 12; // special name } else { state = 14; // parameters } break; default: tag.Append(ch); break; } break; case 1: switch (ch) { case '$': state = 2; break; default: tag.Append(ch); break; } break; case 2: switch (ch) { case 'i': state = 9; break; case 'u': //unsigned = true; break; case 't': templParamUdtNameLen = 0; state = 8; break; case '%': state = 0; break; default: throw new ApplicationException("Invalid character while in state 2: " + ch + ", in string: " + strname); } break; case 5: // constant in template if (char.IsDigit(ch)) { constTemplParam.Append(ch); } else { templateParams.Add(new ImmTemplParam(constTemplParam.ToString())); state = 11; i--; } break; case 8: if (char.IsDigit(ch)) { templParamUdtNameLen *= 10; templParamUdtNameLen += (int)char.GetNumericValue(ch); } else { //if (strname.Length < i + templParamUdtNameLen) // throw new ApplicationException("Invalid type name length: " + templParamUdtNameLen.ToString() + ", exceed name length: " + strname.Length.ToString()); TagTemplParam tagpar = new TagTemplParam(); tagpar.Tag = TranslateUdtNameV1(strname.Substring(i, templParamUdtNameLen)); templateParams.Add(tagpar); i += templParamUdtNameLen - 1; state = 11; } break; case 9: switch (ch) { case 'c': //param = 2; state = 10; break; case 'u': //unsigned = true; break; //default: ; // throw new ApplicationException("Invalid character while in state 2: " + ch + ", in string: " + strname); } break; case 10: switch (ch) { case '$': state = 5; constTemplParam = new StringBuilder(); break; default: throw new ApplicationException("Invalid character while in state " + state.ToString() + ": " + ch + ", in string: " + strname); } break; case 11: switch (ch) { case '$': state = 2; break; case '%': state = 2; i--; break; } break; case 12: if (ch == 'b') { state = 13; // special name specialName = new StringBuilder(); } else { throw new ApplicationException("Invalid character in state 9: " + ch); } break; case 13: if (ch == '$') { result.IsSpecial = true; result.SpecialName = StrToSpcName(specialName.ToString()); specialName = null; state = 14; break; } else { specialName.Append(ch); } break; case 14: // ignoring parameters break; default: Debug.Fail("Invalid state: " + state.ToString()); break; } } if (state != 0 && state != 14) { throw new ApplicationException("Unexpected end of name while in state: " + state.ToString()); } result.Tag = tag.ToString(); result.TemplateParameters = templateParams; return(result); }
private static TemplateParam ParseParam(string strname, ref int pos) { ComplexTemplParam topComplex = null; ComplexTemplParam currentComplex = null; int state = 0; bool signed = false; bool unsigned = false; int templParamUdtNameLen = 0; for (; pos < strname.Length; pos++) { char ch = strname[pos]; switch (state) { case 0: if (char.IsDigit(ch)) { templParamUdtNameLen = (int)char.GetNumericValue(ch); state = 1; } else { PrimitiveTemplParam prim = TryParsePrimitive(ch); if (prim != null) { prim.Signed = signed; prim.Unsigned = unsigned; signed = false; unsigned = false; if (currentComplex != null) { currentComplex.Combine(prim); return topComplex; } else { return prim; } } else { switch (ch) { case 'u': unsigned = true; break; case 'z': signed = true; break; case 'x': case 'w': ModifierTemplParam newModifier = new ModifierTemplParam(); if (ch == 'x') newModifier.Attributes |= ModifierAttributes.Const; else if (ch == 'w') newModifier.Attributes |= ModifierAttributes.Volatile; if (topComplex == null) { topComplex = newModifier; currentComplex = newModifier; } else { currentComplex.Combine(newModifier, out currentComplex); } break; case 'p': case 'r': PointerTemplParam newPointer = new PointerTemplParam(); newPointer.IsReference = ch == 'r'; if (topComplex == null) { topComplex = newPointer; currentComplex = newPointer; } else { currentComplex.Combine(newPointer, out currentComplex); } break; case 'q': pos++; FuncTemplParam funcParam = ParseFuncParam(strname, ref pos); if (currentComplex != null) { currentComplex.Combine(funcParam); return topComplex; } else { return funcParam; } default: pos--; return null; } } } break; case 1: if (char.IsDigit(ch)) { templParamUdtNameLen *= 10; templParamUdtNameLen += (int)char.GetNumericValue(ch); } else { if (strname.Length < pos + templParamUdtNameLen) throw new ApplicationException("Invalid type name length: " + templParamUdtNameLen.ToString() + ", exceed name length: " + strname.Length.ToString()); TagTemplParam tagTemplParam = new TagTemplParam(); tagTemplParam.Tag = TranslateUdtNameV2(strname.Substring(pos, templParamUdtNameLen)); pos += templParamUdtNameLen - 1; if (currentComplex != null) { currentComplex.Combine(tagTemplParam); return topComplex; } else { return tagTemplParam; } } break; } } return null; }