ProcessConstants is responsible for setting up the language features based on the JSON file that is stored in constants Needs to be called at least once in order for anything to actually happen
()
| 237 | // ProcessConstants is responsible for setting up the language features based on the JSON file that is stored in constants |
| 238 | // Needs to be called at least once in order for anything to actually happen |
| 239 | func ProcessConstants() { |
| 240 | startTime := makeTimestampNano() |
| 241 | for name, value := range languageDatabase { |
| 242 | for _, ext := range value.Extensions { |
| 243 | ExtensionToLanguage[ext] = append(ExtensionToLanguage[ext], name) |
| 244 | } |
| 245 | |
| 246 | for _, fname := range value.FileNames { |
| 247 | FilenameToLanguage[fname] = name |
| 248 | } |
| 249 | |
| 250 | if len(value.SheBangs) != 0 { |
| 251 | ShebangLookup[name] = value.SheBangs |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // If we have anything in CountAs set it up now |
| 256 | if len(CountAs) != 0 { |
| 257 | setupCountAs() |
| 258 | } |
| 259 | |
| 260 | printTraceF("nanoseconds build extension to language: %d", makeTimestampNano()-startTime) |
| 261 | |
| 262 | // Configure COCOMO setting |
| 263 | _, ok := projectType[strings.ToLower(CocomoProjectType)] |
| 264 | if !ok { |
| 265 | // let's see if we can turn it into a custom one |
| 266 | spl := strings.Split(CocomoProjectType, ",") |
| 267 | val := []float64{} |
| 268 | if len(spl) == 5 { |
| 269 | // let's try to convert to float if we can |
| 270 | for i := 1; i < 5; i++ { |
| 271 | f, err := strconv.ParseFloat(spl[i], 64) |
| 272 | if err == nil { |
| 273 | val = append(val, f) |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if len(val) == 4 { |
| 279 | projectType[CocomoProjectType] = val |
| 280 | } else { |
| 281 | // if nothing matches fall back to organic |
| 282 | CocomoProjectType = "organic" |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // If lazy is set then we want to load in the features as we find them not in one go |
| 287 | // however otherwise being used as a library so just load them all in |
| 288 | if !isLazy { |
| 289 | startTime = makeTimestampMilli() |
| 290 | for name, value := range languageDatabase { |
| 291 | processLanguageFeature(name, value) |
| 292 | } |
| 293 | |
| 294 | printTraceF("milliseconds build language features: %d", makeTimestampMilli()-startTime) |
| 295 | } else { |
| 296 | printTrace("configured to lazy load language features") |