public InvokeStm(AAsyncInvokeStm node) { Node = node; if (node.GetName() is AAmbiguousNameLvalue) { AAmbiguousNameLvalue ambigious = (AAmbiguousNameLvalue)node.GetName(); AAName name = (AAName)ambigious.GetAmbiguous(); Name = (TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]; name.GetIdentifier().RemoveAt(name.GetIdentifier().Count - 1); if (name.GetIdentifier().Count == 0) { Base = null; } else { Base = name; } } else { AStructLvalue lvalue = (AStructLvalue)node.GetName(); Name = lvalue.GetName(); Base = lvalue.GetReceiver(); } }
public override void CaseATempCastExp(ATempCastExp node) { //The cast type must be a single identifier if (node.GetType() is ALvalueExp) { ALvalueExp lvalueExp = (ALvalueExp)node.GetType(); if (lvalueExp.GetLvalue() is AAmbiguousNameLvalue) { AAmbiguousNameLvalue ambiguousLvalue = (AAmbiguousNameLvalue)lvalueExp.GetLvalue(); if (ambiguousLvalue.GetAmbiguous() is AAName) { AAName simpleName = (AAName)ambiguousLvalue.GetAmbiguous(); if (simpleName.GetIdentifier().Count == 1) { ACastExp castExp = new ACastExp(node.GetToken(), new ANamedType(simpleName), node.GetExp()); node.ReplaceBy(castExp); castExp.Apply(this); return; } } } } PExp exp = node.GetExp(); node.ReplaceBy(exp); exp.Apply(this); }
public InvokeStm(ASyncInvokeExp node) { Node = node; if (node.GetName() is AAmbiguousNameLvalue) { AAmbiguousNameLvalue ambigious = (AAmbiguousNameLvalue)node.GetName(); AAName name = (AAName)ambigious.GetAmbiguous(); /*List<List<Node>>[] targets; * List<ANamespaceDecl> namespaces = new List<ANamespaceDecl>(); * /*bool b; * TypeLinking.GetTargets(name, out targets, namespaces, data, null, out b); * for (int i = 0; i < 3; i++) * { * * }*/ Name = (TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]; name.GetIdentifier().RemoveAt(name.GetIdentifier().Count - 1); if (name.GetIdentifier().Count == 0) { Base = null; } else { Base = name; } } else { AStructLvalue lvalue = (AStructLvalue)node.GetName(); Name = lvalue.GetName(); Base = lvalue.GetReceiver(); } }
public static void SetPrimitive(this ANamedType node, string primitive) { AAName name = (AAName)node.GetName(); TIdentifier lastIdentifier = (TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]; name.GetIdentifier().Clear(); lastIdentifier.Text = primitive; name.GetIdentifier().Add(lastIdentifier); }
public static List <string> ToStringList(this AAName name) { List <string> returner = new List <string>(); foreach (TIdentifier identifier in name.GetIdentifier()) { returner.Add(identifier.Text); } return(returner); }
public static bool IsPrimitive(this ANamedType node) { AAName name = (AAName)node.GetName(); if (name.GetIdentifier().Count != 1) { return(false); } return(GalaxyKeywords.Primitives.words.Contains(((TIdentifier)name.GetIdentifier()[0]).Text)); }
public static bool IsPrimitive(this ANamedType node, string[] primitives) { AAName name = (AAName)node.GetName(); if (name.GetIdentifier().Count != 1) { return(false); } return(primitives.Contains(((TIdentifier)name.GetIdentifier()[0]).Text)); }
public static string AsIdentifierString(this AAName node) { string s = ""; foreach (TIdentifier identifier in node.GetIdentifier()) { if (s != "") { s += "_"; } s += identifier.Text; } return(s); }
public override void CaseANamedType(ANamedType node) { AAName name = (AAName)node.GetName(); if (name.GetIdentifier().Count > 2) { return; } if (name.GetIdentifier().Count == 2 && ((TIdentifier)name.GetIdentifier()[0]).Text != "Dialogs") { return; } if (name.GetIdentifier().Count == 1) { bool foundDialogs = false; AASourceFile file = Util.GetAncestor <AASourceFile>(node); foreach (AUsingDecl usingDecl in file.GetUsings()) { if (usingDecl.GetNamespace().Count == 1) { TIdentifier identifer = (TIdentifier)usingDecl.GetNamespace()[0]; if (identifer.Text == "Dialogs") { foundDialogs = true; break; } } } if (!foundDialogs) { ANamespaceDecl ns = Util.GetAncestor <ANamespaceDecl>(node); if (!Util.HasAncestor <ANamespaceDecl>(ns.Parent()) && ns.GetName().Text == "Dialogs") { foundDialogs = true; } } if (!foundDialogs) { return; } } if (((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]).Text == oldName) { types.Add((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]); } }
public static bool IsSame(this ANamedType node1, ANamedType node2, bool primitiveOnly) { AAName name1 = (AAName)node1.GetName(); AAName name2 = (AAName)node2.GetName(); if (primitiveOnly && (name1.GetIdentifier().Count > 1 || name2.GetIdentifier().Count > 1)) { return(false); } if (name1.GetIdentifier().Count != name2.GetIdentifier().Count) { return(false); } for (int i = 0; i < name2.GetIdentifier().Count; i++) { TIdentifier identifier1 = (TIdentifier)name1.GetIdentifier()[i]; TIdentifier identifier2 = (TIdentifier)name2.GetIdentifier()[i]; if (identifier1.Text != identifier2.Text) { return(false); } } return(true); }
public override void CaseAAName(AAName node) { Value += node.AsString(); }
public override void OutAAProgram(AAProgram node) { foreach (var pair in Refferences) { if (structsWithGenerics.Contains(pair.Key) && pair.Value.Count > 0) { needAnotherPass = true; } } foreach (var pair in Refferences) { AStructDecl str = pair.Key; if (!copies.ContainsKey(str)) { copies[str] = new List <List <PType> >(); } IList declList; Node parent = str.Parent(); if (parent is AASourceFile) { declList = ((AASourceFile)parent).GetDecl(); } else { declList = ((ANamespaceDecl)parent).GetDecl(); } //AASourceFile pFile = (AASourceFile) str.Parent(); foreach (AGenericType refference in pair.Value) { AStructDecl clone = null; bool addList = true; foreach (List <PType> list in copies[str]) { bool listEqual = true; for (int i = 0; i < list.Count; i++) { if (!Util.TypesEqual(list[i], (PType)refference.GetGenericTypes()[i], data)) { listEqual = false; break; } } if (listEqual) { addList = false; clone = clones[list]; break; } } if (addList) { List <PType> list = new List <PType>(); foreach (PType type in refference.GetGenericTypes()) { list.Add(type); } copies[str].Add(list); clone = (AStructDecl)str.Clone(); declList.Insert(declList.IndexOf(str), clone); clone.Apply(new EnviromentBuilding(errors, data)); clone.Apply(new EnviromentChecking(errors, data, false)); clone.Apply(new LinkNamedTypes(errors, data)); /* * data.Structs.Add(new SharedData.DeclItem<AStructDecl>(pFile, clone)); * data.StructFields[clone] = new List<AALocalDecl>(); * data.StructMethods[clone] = new List<AMethodDecl>(); * data.StructProperties[clone] = new List<APropertyDecl>(); * data.StructConstructors[clone] = new List<AConstructorDecl>(); * foreach (PLocalDecl localDecl in clone.GetLocals()) * { * if (localDecl is AALocalDecl) * { * data.StructFields[clone].Add((AALocalDecl)localDecl); * } * else * { * PDecl decl = ((ADeclLocalDecl) localDecl).GetDecl(); * if (decl is AMethodDecl) * { * data.StructMethods[clone].Add((AMethodDecl) decl); * } * else if (decl is APropertyDecl) * { * data.StructProperties[clone].Add((APropertyDecl)decl); * } * else * { * data.StructConstructors[clone].Add((AConstructorDecl) decl); * } * } * }*/ clones[list] = clone; clone.setGenericVars(new ArrayList()); FixGenericLinks.Parse(str, clone, list, data); clone.GetName().Text = Util.TypeToIdentifierString(refference); } //Change refference to clone ANamedType baseRef = (ANamedType)refference.GetBase(); List <string> cloneNs = Util.GetFullNamespace(clone); cloneNs.Add(clone.GetName().Text); AAName aName = (AAName)baseRef.GetName(); aName.GetIdentifier().Clear(); foreach (var n in cloneNs) { aName.GetIdentifier().Add(new TIdentifier(n)); } data.StructTypeLinks[baseRef] = clone; refference.ReplaceBy(baseRef); } if (!needAnotherPass) { parent.RemoveChild(str); } } if (needAnotherPass) { Refferences.Clear(); structsWithGenerics.Clear(); needAnotherPass = false; CaseAAProgram(node); } }
private static void GetMatchingTypes(ANamedType node, List <string> names, List <ATypedefDecl> typeDefs, List <AStructDecl> structs, List <AMethodDecl> delegates, List <ANamespaceDecl> namespaces, List <TIdentifier> generics) { List <IList> decls = new List <IList>(); List <string> currentNamespace = Util.GetFullNamespace(node); AASourceFile currentSourceFile = Util.GetAncestor <AASourceFile>(node); if (names.Count == 1) { string name = names[0]; //Check generic vars AStructDecl currentStruct = Util.GetAncestor <AStructDecl>(node); if (currentStruct != null) { foreach (TIdentifier genericVar in currentStruct.GetGenericVars()) { if (genericVar.Text == name) { generics.Add(genericVar); } } } //Get all type decls and namespaces matching this name, visible from this location List <IList> visibleDecls = Util.GetVisibleDecls(node, ((AAName)node.GetName()).GetIdentifier().Count == 1); foreach (IList declList in visibleDecls) { bool sameFile = false; if (declList.Count > 0) { sameFile = currentSourceFile == Util.GetAncestor <AASourceFile>((PDecl)declList[0]); } foreach (PDecl decl in declList) { bool sameNS = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace(decl)); if (decl is ANamespaceDecl) { ANamespaceDecl aDecl = (ANamespaceDecl)decl; if (aDecl.GetName().Text == name) { namespaces.Add(aDecl); } continue; } if (decl is ATypedefDecl) { if (Util.IsAncestor(node, decl)) { continue; } ATypedefDecl aDecl = (ATypedefDecl)decl; if (aDecl.GetStatic() != null && !sameFile || aDecl.GetVisibilityModifier() is APrivateVisibilityModifier && !sameNS) { continue; } ANamedType namedType = (ANamedType)aDecl.GetName(); AAName aName = (AAName)namedType.GetName(); string n = ((TIdentifier)aName.GetIdentifier()[0]).Text; if (n == name) { typeDefs.Add(aDecl); } continue; } if (decl is AStructDecl) { AStructDecl aDecl = (AStructDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier) { continue; } if (aDecl.GetName().Text == name) { structs.Add(aDecl); } continue; } if (decl is AMethodDecl) { AMethodDecl aDecl = (AMethodDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier || !sameFile && aDecl.GetStatic() != null) { continue; } if (aDecl.GetDelegate() != null && aDecl.GetName().Text == name) { delegates.Add(aDecl); } continue; } } } } else { string name = names[names.Count - 1]; List <ANamespaceDecl> baseNamespaces = new List <ANamespaceDecl>(); List <string> baseNames = new List <string>(); baseNames.AddRange(names); baseNames.RemoveAt(baseNames.Count - 1); GetMatchingTypes(node, baseNames, new List <ATypedefDecl>(), new List <AStructDecl>(), new List <AMethodDecl>(), baseNamespaces, generics); foreach (ANamespaceDecl ns in baseNamespaces) { bool sameFile = currentSourceFile == Util.GetAncestor <AASourceFile>(ns); foreach (PDecl decl in ns.GetDecl()) { bool sameNS = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace(decl)); if (decl is ANamespaceDecl) { ANamespaceDecl aDecl = (ANamespaceDecl)decl; if (aDecl.GetName().Text == name) { namespaces.Add(aDecl); } continue; } if (decl is ATypedefDecl) { ATypedefDecl aDecl = (ATypedefDecl)decl; ANamedType namedType = (ANamedType)aDecl.GetName(); AAName aName = (AAName)namedType.GetName(); string n = ((TIdentifier)aName.GetIdentifier()[0]).Text; if (n == name) { typeDefs.Add(aDecl); } continue; } if (decl is AStructDecl) { AStructDecl aDecl = (AStructDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier) { continue; } if (aDecl.GetName().Text == name) { structs.Add(aDecl); } continue; } if (decl is AMethodDecl) { AMethodDecl aDecl = (AMethodDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier || !sameFile && aDecl.GetStatic() != null) { continue; } if (aDecl.GetDelegate() != null && aDecl.GetName().Text == name) { delegates.Add(aDecl); } continue; } } } } }
public static Token GetToken(this AAName name) { return((TIdentifier)name.GetIdentifier()[name.GetIdentifier().Count - 1]); }