Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++ #532

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ venv-*/
.venv/
node_modules/
result/

# Visual Studio Code
universal-judge.sln
.data/current/python
.data/current/python-packages
.vscode/
2 changes: 2 additions & 0 deletions tested/languages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from tested.languages.bash.config import Bash
from tested.languages.c.config import C
from tested.languages.cpp.config import CPP
from tested.languages.csharp.config import CSharp
from tested.languages.haskell.config import Haskell
from tested.languages.java.config import Java
Expand All @@ -34,6 +35,7 @@
"python": Python,
"runhaskell": RunHaskell,
"csharp": CSharp,
"cpp": CPP,
}


Expand Down
22 changes: 9 additions & 13 deletions tested/languages/c/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tested.datatypes import AllTypes
from tested.dodona import AnnotateCode, Message
from tested.features import Construct, TypeSupport
from tested.languages.c.generators import CGenerator
from tested.languages.conventionalize import (
EXECUTION_PREFIX,
Conventionable,
Expand Down Expand Up @@ -103,7 +104,7 @@ def modify_solution(self, solution: Path):
# First, check if we have a no-arg main function.
# If so, replace it with a renamed main function that does have args.
no_args = re.compile(r"(int|void)(\s+)main(\s*)\((\s*)\)(\s*{)")
replacement = r"int\2solution_main\3(\4int argc, char** argv)\5"
replacement = r"int\2solution_main\3(\4int argc, char* argv[])\5"
contents, nr = re.subn(no_args, replacement, contents, count=1)
if nr == 0:
# There was no main function without arguments. Now we try a main
Expand Down Expand Up @@ -139,26 +140,21 @@ def cleanup_stacktrace(self, stacktrace: str) -> str:

def is_source_file(self, file: Path) -> bool:
return file.suffix in (".c", ".h")

def generator(self) -> CGenerator:
return CGenerator(self.file_extension())

def generate_statement(self, statement: Statement) -> str:
from tested.languages.c import generators

return generators.convert_statement(statement, full=True)
return self.generator().convert_statement(statement, full=True)

def generate_execution_unit(self, execution_unit: "PreparedExecutionUnit") -> str:
from tested.languages.c import generators

return generators.convert_execution_unit(execution_unit)
return self.generator().convert_execution_unit(execution_unit)

def generate_selector(self, contexts: list[str]) -> str:
from tested.languages.c import generators

return generators.convert_selector(contexts)
return self.generator().convert_selector(contexts)

def generate_encoder(self, values: list[Value]) -> str:
from tested.languages.c import generators

return generators.convert_encoder(values)
return self.generator().convert_encoder(values)

def get_declaration_metadata(self) -> TypeDeclarationMetadata:
return {
Expand Down
Loading
Loading