public static void EnforceCasing(HassiumModule module, SourceLocation location, string identifier, HassiumCasingType casing) { if (CheckCasing(identifier, casing)) { return; } switch (casing) { case HassiumCasingType.Camel: module.AddWarning(location, "Expected casing type 'camelCase'!"); break; case HassiumCasingType.Lower: module.AddWarning(location, "Expected casing type 'lowercase' for locals, funcs, and properties!"); break; case HassiumCasingType.Pascal: module.AddWarning(location, "Expected casing type 'PascalCase' for classes, traits, and enums!"); break; } }
public void Accept(UseFromNode node) { string path = node.Module.Replace(".", "/").Replace("\\", "/"); HassiumObject mod; if (InternalModule.InternalModules.ContainsKey(path)) { mod = InternalModule.InternalModules[path]; } else { mod = resolveModuleByPath(node.SourceLocation, path); } if (mod is HassiumModule && !suppressWarns) { (mod as HassiumModule).DisplayWarnings(); } // Hassium source code imports will contain __global__, this is where // we have to look for the desired classes. if (mod.ContainsAttribute("__global__")) { var globalClass = mod.BoundAttributes["__global__"]; // Copy over the __init__ method into ours foreach (var attrib in globalClass.BoundAttributes) { if (attrib.Key == "__init__") { foreach (var instruction in (attrib.Value as HassiumMethod).Instructions) { methodStack.Peek().Instructions.Add(instruction); } } } // Import *everything* if (node.Class == "*") { // use * is bad module.AddWarning(node.SourceLocation, "Importing '*' is bad practice!"); foreach (var attrib in globalClass.BoundAttributes) { if (!classStack.Peek().ContainsAttribute(attrib.Key)) { var value = attrib.Value.Clone() as HassiumObject; value.Parent = classStack.Peek(); classStack.Peek().AddAttribute(attrib.Key, value); } } } else { classStack.Peek().AddAttribute(node.Class, globalClass.GetAttribute(null, node.Class)); } } else { if (node.Class == "*") { // use * is bad module.AddWarning(node.SourceLocation, "Importing '*' is bad practice!"); foreach (var attrib in mod.BoundAttributes) { if (!module.ContainsAttribute(attrib.Key)) { var value = attrib.Value.Clone() as HassiumObject; value.Parent = classStack.Peek(); if (!module.ContainsAttribute(attrib.Key)) { module.AddAttribute(attrib.Key, value); } } } } else if (!mod.ContainsAttribute(node.Class)) { throw new CompilerException(node.SourceLocation, "Could not find attribute '{0}' in module '{1}'", node.Class, node.Module); } else { module.AddAttribute(node.Class, mod.GetAttribute(null, node.Class)); } } }